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@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 = 70 # 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"
28 "rpm --eval %_prefix" | getline prefix
29 "rpm --eval %_bindir" | getline bindir
30 "rpm --eval %_sbindir" | getline sbindir
31 "rpm --eval %_libdir" | getline libdir
32 "rpm --eval %_sysconfdir" | getline sysconfdir
33 "rpm --eval %_datadir" | getline datadir
34 "rpm --eval %_includedir" | getline includedir
35 "rpm --eval %_mandir" | getline mandir
36 "rpm --eval %_infodir" | getline infodir
39 # There should be a comment with CVS keywords on the first line of file.
41 if (!/# \$Revision:/) # If this line is already OK?
42 print "# $" "Revision:$, " "$" "Date:$" # No
45 next # It is enough for first line
49 # If the latest line matched /%files/
51 if ($0 !~ /defattr/) # If no %defattr
52 print "%defattr(644,root,root,755)" # Add it
54 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
58 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
60 if ($2 == "_applnkdir")
67 /^%description/, (/^%[a-z]+/ && !/^%description/) {
70 if (/^%description/) {
76 # Define _prefix and _mandir if it is X11 application
77 if (/^%description$/ && x11 == 1) {
78 print "%define\t\t_prefix\t\t/usr/X11R6"
79 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
85 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
87 format_flush(format_line, format_indent)
91 } else if (/^[ \t]*[-\*][ \t]*/) {
92 format_flush(format_line, format_indent)
94 format_indent = RLENGTH
95 match($0, /^[ \t]*[-\*][ \t]/)
96 format_line = substr($0, RLENGTH)
98 format_line = format_line " " $0
102 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
103 format_flush(format_line, format_indent)
116 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
120 if (/^%setup/ && !/-q/)
121 sub(/^%setup/, "%setup -q")
125 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
132 /^%clean/, (/^%[a-z]+$/ && !/^%clean/) {
137 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
141 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
143 print "rm -rf $RPM_BUILD_ROOT"
147 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
148 print "rm -rf $RPM_BUILD_ROOT"
154 # 'install -d' instead 'mkdir -p'
156 sub(/mkdir -p/, "install -d")
158 # No '-u root' or '-g root' for 'install'
159 if (/^install/ && /-[ug][ \t]*root/)
160 gsub(/-[ug][ \t]*root /, "")
162 if (/^install/ && /-m[ \t]*644/)
163 gsub(/-m[ \t]*644 /, "")
165 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
166 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
169 # No lines contain 'chmod' if it sets the modes to '644'
170 if ($1 ~ /chmod/ && $2 ~ /644/)
173 # 'gzip -9nf' for compressing
174 if ($1 ~ /gzip|bzip2/) {
176 sub(/-[A-Za-z0-9]+ /, "", $0)
183 /^%pre/, (/^[a-z]+$/ && !/^%pre/) { script = 1 }
184 /^%preun/, (/^[a-z]+$/ && !/^%preun/) { script = 1 }
185 /^%post/, (/^[a-z]+$/ && !/^%post/) { script = 1 }
186 /^%postun/, (/^[a-z]+$/ && !/^%postun/) { script = 1 }
191 sub(/-[A-Za-z0-9]+ /, "", $0)
199 sub(/-[A-Za-z0-9]+ /, "", $0)
209 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
218 # %changelog section:
219 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
222 # There should be some CVS keywords on the first line of %changelog.
225 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
226 printf "All persons listed below can be reached at " > changelog_file
227 print "<cvs_login>@pld.org.pl\n" > changelog_file
228 print "$" "Log:$" > changelog_file
236 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
237 print " date +\"%a %b %d %Y\"`)" > changelog_file
243 if (!/^%[a-z]+$/ || /changelog/)
244 print > changelog_file
252 # There should not be a space after the name of field
253 # and before the colon.
258 if (Byla_grupa == 1 && field !~ /group(\(..\))?:/) {
260 print "Group:\t\t" Grupa["en"]
261 if (Grupa["en"] ~ /^X11/ && x11 == 0) # Is it X11 application?
264 byl_plik_z_grupami = 0
266 while ((getline linia_grup < groups_file) > 0) {
267 byl_plik_z_grupami = 1
268 if (linia_grup == Grupa["en"]) {
274 if (!byl_plik_z_grupami)
275 print "######\t\t" groups_file ": no such file"
276 else if (!byl_opis_grupy)
277 print "######\t\t" "Unknown group!"
279 while (getline linia_grup < groups_file) {
280 if (linia_grup == "")
282 split(linia_grup, g, /[\[\]:]/)
283 sub(/^[ \t]*/,"",g[4])
290 for (jezyk in Grupa) {
291 print "Group(" jezyk "):\t" Grupa[jezyk]
296 if (field ~ /packager:|distribution:|docdir:|prefix:/)
299 if (field ~ /buildroot:/)
300 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
302 if (field ~ /group(\(..\))?:/) {
305 if (!match(field,/\(..\):/))
308 glang=substr(field,RSTART+1,2)
309 sub(/^[^ \t]*[ \t]*/,"")
313 next # Line is already formatted and printed
316 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
317 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
323 if (field ~ /version:/)
326 if (field ~ /serial:/)
329 # Use %{name} and %{version} in the filenames in "Source:"
330 if (field ~ /source/ || field ~ /patch/) {
331 n = split($2, url, /\//)
333 sub(name, "%{name}", url[n])
334 if (field ~ /source/) sub(version, "%{version}", url[n])
335 sub(filename, url[n], $2)
338 if (field ~ /source:/)
341 if (field ~ /patch:/)
346 if ($1 ~ /%define/) {
347 # Do not add %define of _prefix if it already is.
348 if ($2 ~ /_prefix/) {
349 sub("^"prefix, $3, bindir)
350 sub("^"prefix, $3, sbindir)
351 sub("^"prefix, $3, libdir)
352 sub("^"prefix, $3, datadir)
353 sub("^"prefix, $3, includedir)
357 if ($2 ~ /_bindir/ && !/_sbindir/)
363 if ($2 ~ /_sysconfdir/)
367 if ($2 ~ /_includedir/)
386 close(changelog_file)
387 while ((getline < changelog_file) > 0)
389 system("rm -f " changelog_file)
391 if (did_clean == 0) {
394 print "rm -rf $RPM_BUILD_ROOT"
399 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
402 if (has_changelog == 0)
406 print "* %{date} PLD Team <pld-list@pld.org.pl>"
407 printf "All persons listed below can be reached at "
408 print "<cvs_login>@pld.org.pl\n"
413 # There should be one or two tabs after the colon.
414 function format_preamble()
417 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
425 # Replace directly specified directories with macros
426 function use_macros()
428 gsub(bindir, "%{_bindir}")
429 gsub("%{_prefix}/bin", "%{_bindir}")
430 gsub("%{prefix}/bin", "%{_bindir}")
432 for (c = 1; c <= NF; c++) {
433 if ($c ~ sbindir "/fix-info-dir")
435 gsub(sbindir, "%{_sbindir}", $c)
438 gsub("%{prefix}/sbin", "%{_sbindir}")
439 gsub("%{_prefix}/sbib", "%{_sbindir}")
441 gsub(libdir, "%{_libdir}")
442 gsub("%{prefix}/lib", "%{_libdir}")
443 gsub("%{_prefix}/lib", "%{_libdir}")
445 for (c = 1; c <= NF; c++) {
446 if ($c ~ sysconfdir "/cron.d")
448 if ($c ~ sysconfdir "/crontab.d")
450 if ($c ~ sysconfdir "/logrotate.d")
452 if ($c ~ sysconfdir "/pam.d")
454 if ($c ~ sysconfdir "/profile.d")
456 if ($c ~ sysconfdir "/rc.d")
458 if ($c ~ sysconfdir "/security")
460 if ($c ~ sysconfdir "/skel")
462 if ($c ~ sysconfdir "/sysconfig")
464 gsub(sysconfdir, "%{_sysconfdir}", $c)
467 gsub(datadir, "%{_datadir}")
468 gsub("%{prefix}/share", "%{_datadir}")
469 gsub("%{_prefix}/share", "%{_datadir}")
471 gsub(includedir, "%{_includedir}")
472 gsub("%{prefix}/include", "%{_includedir}")
473 gsub("%{_prefix}/include", "%{_includedir}")
475 gsub(mandir, "%{_mandir}")
476 gsub("%{_datadir}/man", "%{_mandir}")
477 gsub("%{_prefix}/share/man", "%{_mandir}")
478 gsub("%{prefix}/share/man", "%{_mandir}")
479 gsub("%{prefix}/man", "%{_mandir}")
480 gsub("%{_prefix}/man", "%{_mandir}")
482 gsub(infodir, "%{_infodir}")
483 gsub("%{prefix}/info", "%{_infodir}")
484 gsub("%{_prefix}/info", "%{_infodir}")
486 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
489 for (c = 1; c <= NF; c++) {
490 if ($c ~ prefix "/sbin/fix-info-dir")
492 gsub(prefix, "%{_prefix}", $c)
494 gsub("%{prefix}", "%{_prefix}")
497 gsub("%{PACKAGE_VERSION}", "%{version}")
498 gsub("%{PACKAGE_NAME}", "%{name}")
500 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
501 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
503 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
504 gsub("%{_datadir}/applnk", "%{_applnkdir}")
506 gsub("^make$", "%{__make}")
507 gsub("^make ", "%{__make} ")
510 function fill(ch, n, i) {
511 for (i = 0; i < n; i++)
515 function format_flush(line, indent, newline, word, first_word) {
517 if (format_indent == -1)
520 newline = fill(" ", format_indent) "- "
522 while (match(line, /[^\t ]+/)) {
523 word = substr(line, RSTART, RLENGTH)
524 if (length(newline) + length(word) + 1 > tw) {
527 if (format_indent == -1)
530 newline = fill(" ", format_indent + 2)
535 newline = newline word
538 newline = newline " " word
540 line = substr(line, RSTART + RLENGTH)
542 if (newline ~ /[^\t ]/) {