3 # This is adapter v0.21. Adapter adapts .spec files for PLD.
5 # Copyright (C) 1999, 2000 PLD-Team <pld-list@pld.org.pl>
7 # Micha³ Kuratczyk <kura@pld.org.pl>
8 # Sebastian Zagrodzki <s.zagrodzki@sith.mimuw.edu.pl>
9 # Tomasz K³oczko <kloczek@rudy.mif.pg.gda.pl>
10 # Artur Frysiak <wiget@pld.org.pl>
11 # Michal Kochanowicz <mkochano@ee.pw.edu.pl>
12 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
15 preamble = 1 # Is it part of preamble? Default - yes
16 boc = 2 # Beggining of %changelog
17 bod = 0 # Beggining of %description
18 tw = 75 # Descriptions width
20 # File with rpm groups
21 "rpm --eval %_topdir" | getline groups_file
22 groups_file = groups_file "/groups"
24 # Temporary file for changelog section
25 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
27 # Is 'date' macro already defined?
28 if (is_there_line("%define date"))
32 "rpm --eval %_prefix" | getline prefix
33 "rpm --eval %_bindir" | getline bindir
34 "rpm --eval %_sbindir" | getline sbindir
35 "rpm --eval %_libdir" | getline libdir
36 "rpm --eval %_sysconfdir" | getline sysconfdir
37 "rpm --eval %_datadir" | getline datadir
38 "rpm --eval %_includedir" | getline includedir
39 "rpm --eval %_mandir" | getline mandir
40 "rpm --eval %_infodir" | getline infodir
43 # There should be a comment with CVS keywords on the first line of file.
45 if (!/# \$Revision:/) # If this line is already OK?
46 print "# $" "Revision:$, " "$" "Date:$" # No
49 next # It is enough for first line
53 # If the latest line matched /%files/
55 if ($0 !~ /defattr/) # If no %defattr
56 print "%defattr(644,root,root,755)" # Add it
58 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
62 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
64 if ($2 == "_applnkdir")
69 /^%description/, (/^%[a-z]+/ && !/^%description/) {
72 if (/^%description/) {
78 # Define _prefix and _mandir if it is X11 application
79 if (/^%description$/ && x11 == 1) {
80 print "%define\t\t_prefix\t\t/usr/X11R6"
81 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
87 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
89 format_flush(format_line, format_indent)
93 } else if (/^[ \t]*[-\*][ \t]*/) {
94 format_flush(format_line, format_indent)
96 format_indent = RLENGTH
97 match($0, /^[ \t]*[-\*][ \t]/)
98 format_line = substr($0, RLENGTH)
100 format_line = format_line " " $0
104 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
105 format_flush(format_line, format_indent)
118 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
122 if (/^%setup/ && !/-q/)
123 sub(/^%setup/, "%setup -q")
127 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
134 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
139 # 'install -d' instead 'mkdir -p'
141 sub(/mkdir -p/, "install -d")
143 # No '-u root' or '-g root' for 'install'
144 if (/^install/ && /-[ug][ \t]*root/)
145 gsub(/-[ug][ \t]*root /, "")
147 if (/^install/ && /-m[ \t]*644/)
148 gsub(/-m[ \t]*644 /, "")
150 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
151 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
154 # No lines contain 'chmod' if it sets the modes to '644'
155 if ($1 ~ /chmod/ && $2 ~ /644/)
158 # 'gzip -9nf' for compressing
159 if ($1 ~ /gzip|bzip2/) {
161 sub(/-[A-Za-z0-9]+ /, "", $0)
167 /^%pre /, (/^[a-z]+$/ && !/^%pre /) { preamble = 0 }
168 /^%preun/, (/^[a-z]+$/ && !/^%preun/) { preamble = 0 }
169 /^%post /, (/^[a-z]+$/ && !/^%post /) { preamble = 0 }
170 /^%postun/, (/^[a-z]+$/ && !/^%postun/) { preamble = 0 }
173 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
182 # %changelog section:
183 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
186 # There should be some CVS keywords on the first line of %changelog.
189 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
190 printf "All persons listed below can be reached at " > changelog_file
191 print "<cvs_login>@pld.org.pl\n" > changelog_file
192 print "$" "Log:$" > changelog_file
200 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
201 print " date +\"%a %b %d %Y\"`)" > changelog_file
206 if (!/^%[a-z]+$/ || /changelog/)
207 print > changelog_file
215 # There should not be a space after the name of field
216 # and before the colon.
221 if (field ~ /packager:|distribution:|docdir:|prefix:/)
224 if (field ~ /buildroot:/)
225 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
227 if (field ~ /group:/) {
234 if ($2 ~ /^X11/ && x11 == 0) # Is it X11 application?
237 next # Line is already formatted and printed
240 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
241 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
247 if (field ~ /version:/)
250 # Use %{name} and %{version} in the filenames in "Source:"
251 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
252 n = split($2, url, /\//)
254 sub(name, "%{name}", url[n])
255 sub(version, "%{version}", url[n])
256 sub(filename, url[n], $2)
259 if (field ~ /source:/)
262 if (field ~ /patch:/)
267 if ($1 ~ /%define/) {
268 # Do not add %define of _prefix if it already is.
269 if ($2 ~ /_prefix/) {
273 if ($2 ~ /_bindir/ && !/_sbindir/)
279 if ($2 ~ /_sysconfdir/)
283 if ($2 ~ /_includedir/)
302 close(changelog_file)
303 while ((getline < changelog_file) > 0)
305 system("rm -f " changelog_file)
308 print "* %{date} PLD Team <pld-list@pld.org.pl>"
309 printf "All persons listed below can be reached at "
310 print "<cvs_login>@pld.org.pl\n"
315 # This function uses grep to determine if there is line (in the current file)
316 # which matches regexp.
317 function is_there_line(line, l)
319 command = "grep \"" line "\" " ARGV[1]
329 # This function prints translated names of groups.
330 function translate_group(group)
333 result = getline line < groups_file
336 print "######\t\t" groups_file ": no such file"
341 print "######\t\t" "Unknown group!"
351 if (line ~ /\[[a-z][a-z]\]:/) {
352 split(line, g, /\[|\]|\:/)
353 if (!is_there_line("^Group(" g[2] "):"))
354 printf("Group(%s):%s\n", g[2], g[4])
362 # There should be one or two tabs after the colon.
363 function format_preamble()
366 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
374 # Replace directly specified directories with macros
375 function use_macros()
377 gsub(bindir, "%{_bindir}")
378 gsub("%{_prefix}/bin", "%{_bindir}")
379 gsub("%{prefix}/bin", "%{_bindir}")
381 gsub(sbindir, "%{_sbindir}")
382 gsub("%{prefix}/sbin", "%{_sbindir}")
383 gsub("%{_prefix}/sbib", "%{_sbindir}")
385 gsub(libdir, "%{_libdir}")
386 gsub("%{prefix}/lib", "%{_libdir}")
387 gsub("%{_prefix}/lib", "%{_libdir}")
389 for (c = 1; c <= NF; c++) {
390 if ($c ~ sysconfdir "/sysconfig")
392 if ($c ~ sysconfdir "/rc.d")
394 gsub(sysconfdir, "%{_sysconfdir}", $c)
397 gsub(datadir, "%{_datadir}")
398 gsub("%{prefix}/share", "%{_datadir}")
399 gsub("%{_prefix}/share", "%{_datadir}")
401 gsub(includedir, "%{_includedir}")
402 gsub("%{prefix}/include", "%{_includedir}")
403 gsub("%{_prefix}/include", "%{_includedir}")
405 gsub(mandir, "%{_mandir}")
406 gsub("%{_datadir}/man", "%{_mandir}")
407 gsub("%{_prefix}/share/man", "%{_mandir}")
408 gsub("%{prefix}/share/man", "%{_mandir}")
409 gsub("%{prefix}/man", "%{_mandir}")
410 gsub("%{_prefix}/man", "%{_mandir}")
412 gsub(infodir, "%{_infodir}")
413 gsub("%{prefix}/info", "%{_infodir}")
414 gsub("%{_prefix}/info", "%{_infodir}")
416 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
419 gsub(prefix, "%{_prefix}")
420 gsub("%{prefix}", "%{_prefix}")
423 gsub("%{PACKAGE_VERSION}", "%{version}")
424 gsub("%{PACKAGE_NAME}", "%{name}")
426 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
427 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
429 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
432 function fill(ch, n, i) {
433 for (i = 0; i < n; i++)
437 function format_flush(line, indent, newline, word, first_word) {
439 if (format_indent == -1)
442 newline = fill(" ", format_indent) "- "
444 while (match(line, /[^\t ]+/)) {
445 word = substr(line, RSTART, RLENGTH)
446 if (length(newline) + length(word) + 1 > tw) {
449 if (format_indent == -1)
452 newline = fill(" ", format_indent + 2)
457 newline = newline word
460 newline = newline " " word
462 line = substr(line, RSTART + RLENGTH)
464 if (newline ~ /[^\t ]/) {