3 # This is adapter v0.27. Adapter adapts .spec files for PLD.
5 # Copyright (C) 1999-2003 PLD-Team <feedback@pld-linux.org>
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@pld.org.pl>
12 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
15 # - parse ../PLD-doc/BuildRequires.txt and setup proper BR epoches?
16 # - add "-nc" option to skip CVS interaction
18 # - sort Requires, BuildRequires
21 preamble = 1 # Is it part of preamble? Default - yes
22 boc = 4 # Beggining of %changelog
23 bod = 0 # Beggining of %description
24 tw = 70 # Descriptions width
26 # If variable removed, then 1 (for removing it from export)
27 removed["LDFLAGS"] = 0
29 removed["CXXFLAGS"] = 0
31 # If 1, we are inside of comment block (started with /^#%/)
34 # File with rpm groups
35 "rpm --eval %_sourcedir" | getline groups_file
36 groups_file = groups_file "/rpm.groups"
37 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups >/dev/null")
39 # Temporary file for changelog section
40 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
43 "rpm --eval %_prefix" | getline prefix
44 "rpm --eval %_bindir" | getline bindir
45 "rpm --eval %_sbindir" | getline sbindir
46 "rpm --eval %_libdir" | getline libdir
47 "rpm --eval %_sysconfdir" | getline sysconfdir
48 "rpm --eval %_datadir" | getline datadir
49 "rpm --eval %_includedir" | getline includedir
50 "rpm --eval %_mandir" | getline mandir
51 "rpm --eval %_infodir" | getline infodir
54 # There should be a comment with CVS keywords on the first line of file.
56 if (!/# \$Revision:/) # If this line is already OK?
57 print "# $" "Revision:$, " "$" "Date:$" # No
60 next # It is enough for first line
64 # If the latest line matched /%files/
66 if ($0 !~ /defattr/) # If no %defattr
67 print "%defattr(644,root,root,755)" # Add it
69 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
74 /^#/ && (description == 0) {
75 if (/This file does not like to be adapterized!/) {
76 print # print this message
77 while (getline) # print the rest of spec as it is
79 do_not_touch_anything = 1 # do not touch anything in END()
83 # Generally, comments are printed without touching
89 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
91 if ($2 == "_applnkdir")
98 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
105 /^%description/, (/^%[a-z]+/ && !/^%description/ && !/^%((end)?if|else)/) {
108 if (/^%description/) {
115 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
117 format_flush(format_line, format_indent)
121 } else if (/^[ \t]*[-\*][ \t]*/) {
122 format_flush(format_line, format_indent)
124 format_indent = RLENGTH
125 match($0, /^[ \t]*[-\*][ \t]/)
126 format_line = substr($0, RLENGTH)
128 format_line = format_line " " $0
132 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
133 if (NF > 3 && $2 == "-l") {
135 for (i = 4; i <= NF; i++)
139 format_flush(format_line, format_indent)
154 /^%prep/, (/^%[a-z]+$/ && !/^%prep/ && !/^%((end)?if|else)/) {
158 if (/^%setup/ && !/-q/)
159 sub(/^%setup/, "%setup -q")
165 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
174 if (/LDFLAGS="-s"/) {
175 removed["LDFLAGS"] = 1
178 split($0, tmp, "LDFLAGS=")
179 count = split(tmp[2], flags, "\"")
180 if (flags[1] != "" && flags[1] !~ "!?debug") {
181 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
182 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
183 for (i = 2; i < count; i++)
184 $0 = $0 flags[i] "\""
190 if (cflags("CFLAGS") == 0)
194 if (cflags("CXXFLAGS") == 0)
198 if (removed["LDFLAGS"])
200 if (removed["CFLAGS"])
202 if (removed["CXXFLAGS"])
204 # Is there still something?
214 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
221 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
225 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
227 print "rm -rf $RPM_BUILD_ROOT"
231 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
232 print "rm -rf $RPM_BUILD_ROOT"
238 # 'install -d' instead 'mkdir -p'
240 sub(/mkdir -p/, "install -d")
242 # 'install' instead 'cp -p'
244 sub(/cp -p/, "install")
246 # No '-u root' or '-g root' for 'install'
247 if (/^install/ && /-[ug][ \t]*root/)
248 gsub(/-[ug][ \t]*root /, "")
250 if (/^install/ && /-m[ \t]*644/)
251 gsub(/-m[ \t]*644 /, "")
253 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
254 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
257 # No lines contain 'chmod' if it sets the modes to '644'
258 if ($1 ~ /chmod/ && $2 ~ /644/)
265 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
278 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
282 # There should be some CVS keywords on the first line of %changelog.
285 print "* %{date} PLD Team <feedback@pld-linux.org>" > changelog_file
290 if (boc == 2 && !skip) {
291 if (!/All persons listed below/) {
292 printf "All persons listed below can be reached at " > changelog_file
293 print "<cvs_login>@pld-linux.org\n" > changelog_file
298 if (boc == 1 && !skip) {
301 print "$" "Log:$" > changelog_file
308 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
309 print " date +\"%a %b %d %Y\"`)" > changelog_file
316 if (!/^%[a-z]+$/ || /changelog/)
317 print > changelog_file
326 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
329 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
332 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
335 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
343 # There should not be a space after the name of field
344 # and before the colon.
349 if (field ~ /group(\([^)]+\)):/)
351 if (field ~ /group:/) {
353 sub(/^Utilities\//,"Applications/",$2)
354 sub(/^Games/,"Applications/Games",$2)
355 sub(/^X11\/Games/,"X11/Applications/Games",$2)
356 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
357 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
358 sub(/^X11\/GNOME/,"X11/Applications",$2)
359 sub(/^X11\/Utilities/,"X11/Applications",$2)
360 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
361 sub(/^Shells/,"Applications/Shells",$2)
363 sub(/^[^ \t]*[ \t]*/,"")
366 print "Group:\t\t" Grupa
367 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
370 byl_plik_z_grupami = 0
372 while ((getline linia_grup < groups_file) > 0) {
373 byl_plik_z_grupami = 1
374 if (linia_grup == Grupa) {
380 if (!byl_plik_z_grupami)
381 print "######\t\t" groups_file ": no such file"
382 else if (!byl_opis_grupy)
383 print "######\t\t" "Unknown group!"
389 if (field ~ /packager:|distribution:|docdir:|prefix:/)
392 if (field ~ /buildroot:/)
393 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
395 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
396 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
402 if (field ~ /version:/)
405 if (field ~ /serial:/)
408 # Use %{name} and %{version} in the filenames in "Source:"
409 if (field ~ /^source/ || field ~ /patch/) {
410 n = split($2, url, /\//)
411 if (url[n] ~ /\.gz$/) {
412 url[n+1] = ".gz" url[n+1]
413 sub(/\.gz$/,"",url[n])
415 if (url[n] ~ /\.zip$/) {
416 url[n+1] = ".zip" url[n+1]
417 sub(/\.zip$/,"",url[n])
419 if (url[n] ~ /\.tar$/) {
420 url[n+1] = ".tar" url[n+1]
421 sub(/\.tar$/,"",url[n])
423 if (url[n] ~ /\.patch$/) {
424 url[n+1] = ".patch" url[n+1]
425 sub(/\.patch$/,"",url[n])
427 if (url[n] ~ /\.bz2$/) {
428 url[n+1] = ".bz2" url[n+1]
429 sub(/\.bz2$/,"",url[n])
431 if (url[n] ~ /\.logrotate$/) {
432 url[n+1] = ".logrotate" url[n+1]
433 sub(/\.logrotate$/,"",url[n])
435 if (url[n] ~ /\.pamd$/) {
436 url[n+1] = ".pamd" url[n+1]
437 sub(/\.pamd$/,"",url[n])
440 # allow %{name} just in last url component
442 for (i = 1; i <= n; i++) {
443 url[i] = fixedsub("%{name}", name, url[i])
453 url[n] = fixedsub(name, "%{name}", url[n])
454 if (field ~ /source/)
455 url[n] = fixedsub(version, "%{version}", url[n])
456 $2 = fixedsub(filename, url[n], $2)
459 sub("[?]use_mirror=.*$", "", $2);
460 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
462 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
463 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
467 if (field ~ /^source:/)
470 if (field ~ /patch:/)
475 if ($1 ~ /%define/) {
476 # Do not add %define of _prefix if it already is.
477 if ($2 ~ /^_prefix/) {
478 sub("^"prefix, $3, bindir)
479 sub("^"prefix, $3, sbindir)
480 sub("^"prefix, $3, libdir)
481 sub("^"prefix, $3, datadir)
482 sub("^"prefix, $3, includedir)
485 if ($2 ~ /_bindir/ && !/_sbindir/)
491 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
495 if ($2 ~ /_includedir/)
503 if (field ~ /buildrequires:/) {
505 if ($2 ~ /rpm-pythonprov/) {
522 if (do_not_touch_anything)
525 close(changelog_file)
526 while ((getline < changelog_file) > 0)
528 system("rm -f " changelog_file)
530 if (did_clean == 0) {
533 print "rm -rf $RPM_BUILD_ROOT"
538 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
541 if (has_changelog == 0)
545 print "* %{date} PLD Team <feedback@pld-linux.org>"
547 printf "All persons listed below can be reached at "
548 print "<cvs_login>@pld-linux.org\n"
554 function fixedsub(s1,s2,t, ind) {
555 # substitutes fixed strings (not regexps)
556 if (ind = index(t,s1))
557 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
561 # There should be one or two tabs after the colon.
562 function format_preamble()
565 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
573 # Replace directly specified directories with macros
574 function use_macros()
576 gsub(bindir, "%{_bindir}")
577 gsub("%{prefix}/bin", "%{_bindir}")
578 if(prefix"/bin" == bindir)
579 gsub("%{_prefix}/bin", "%{_bindir}")
581 for (c = 1; c <= NF; c++) {
582 if ($c ~ sbindir "/fix-info-dir")
584 gsub(sbindir, "%{_sbindir}", $c)
587 gsub("%{prefix}/sbin", "%{_sbindir}")
588 if (prefix"/sbin" == sbindir)
589 gsub("%{_prefix}/sbin", "%{_sbindir}")
591 for (c = 1; c <= NF; c++) {
592 if ($c ~ sysconfdir "/{?cron.")
594 if ($c ~ sysconfdir "/{?crontab.d")
596 if ($c ~ sysconfdir "/{?logrotate.d")
598 if ($c ~ sysconfdir "/{?pam.d")
600 if ($c ~ sysconfdir "/{?profile.d")
602 if ($c ~ sysconfdir "/{?rc.d")
604 if ($c ~ sysconfdir "/{?security")
606 if ($c ~ sysconfdir "/{?skel")
608 if ($c ~ sysconfdir "/{?sysconfig")
610 gsub(sysconfdir, "%{_sysconfdir}", $c)
613 for (c = 1; c <= NF; c++) {
614 if ($c ~ datadir "/automake")
616 if ($c ~ datadir "/unsermake")
618 gsub(datadir, "%{_datadir}", $c)
621 gsub("%{prefix}/share", "%{_datadir}")
622 if (prefix"/share" == datadir)
623 gsub("%{_prefix}/share", "%{_datadir}")
625 gsub(includedir, "%{_includedir}")
626 gsub("%{prefix}/include", "%{_includedir}")
627 if(prefix"/include" == includedir)
628 gsub("%{_prefix}/include", "%{_includedir}")
630 gsub(mandir, "%{_mandir}")
631 if ($0 !~ "%{_datadir}/manual")
632 gsub("%{_datadir}/man", "%{_mandir}")
633 gsub("%{_prefix}/share/man", "%{_mandir}")
634 gsub("%{prefix}/share/man", "%{_mandir}")
635 gsub("%{prefix}/man", "%{_mandir}")
636 gsub("%{_prefix}/man", "%{_mandir}")
638 gsub(infodir, "%{_infodir}")
639 gsub("%{prefix}/info", "%{_infodir}")
640 gsub("%{_prefix}/info", "%{_infodir}")
642 if (prefix !~ "/X11R6") {
643 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
647 for (c = 1; c <= NF; c++) {
648 if ($c ~ prefix "/sbin/fix-info-dir")
650 if ($c ~ prefix "/share/automake")
652 if ($c ~ prefix "/share/unsermake")
654 gsub(prefix, "%{_prefix}", $c)
656 gsub("%{prefix}", "%{_prefix}")
659 gsub("%{PACKAGE_VERSION}", "%{version}")
660 gsub("%{PACKAGE_NAME}", "%{name}")
662 # we can move files between the dirs below
663 if ($0 !~ "%{_applnkdir}") {
664 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
667 gsub("^make$", "%{__make}")
668 gsub("^make ", "%{__make} ")
670 gsub("/usr/src/linux", "%{_kernelsrcdir}")
671 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
675 # insertion sort of A[1..n]
676 # copied from mawk manual
677 function isort(A,n, i,j,hold) {
678 for (i = 2; i <= n; i++) {
680 while (A[j-1] > hold) {
685 # sentinel A[0] = "" will be created if needed
689 function use_files_macros( i, n, t, a)
691 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
692 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
694 gsub("%{_sysconfdir}\/rc\.d\/init.d", "/etc/rc.d/init.d")
695 gsub("%{_sysconfdir}\/init.d", "/etc/rc.d/init.d")
696 gsub("%{_sysconfdir}\/sysconfig", "/etc/sysconfig")
698 if (/\/etc\/rc\.d\/init\.d/) {
699 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
700 $0 = "%attr(754,root,root) " $0
702 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
703 gsub("^%attr\(... *,", "%attr(754,");
708 if (/lib.+\.so/ && !/^%attr.*/) {
709 $0 = "%attr(755,root,root) " $0
712 # /etc/sysconfig files
713 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
714 # attr not required, allow default 644 attr
715 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
716 gsub("%config", "%config(noreplace)")
719 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
720 $NF = "%config(noreplace) " $NF
723 if (/\/etc\/sysconfig\// && /%attr\(755/) {
724 gsub("^%attr\(... *,", "%attr(640,");
727 if (/\/etc\/sysconfig\// && !/%verify/) {
728 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
733 gsub("%attr\(0", "%attr(")
736 if (match($0, /%verify\(not (.*)\)/)) {
737 t = substr($0, RSTART, RLENGTH)
738 gsub(/^%verify\(not |\)$/, "", t)
743 for (i = 1 ; i <= n; i++) {
748 gsub(/%verify\(not .*\)/, s)
752 function fill(ch, n, i) {
753 for (i = 0; i < n; i++)
757 function format_flush(line, indent, newline, word, first_word) {
759 if (format_indent == -1)
762 newline = fill(" ", format_indent) "- "
764 while (match(line, /[^\t ]+/)) {
765 word = substr(line, RSTART, RLENGTH)
766 if (length(newline) + length(word) + 1 > tw) {
769 if (format_indent == -1)
772 newline = fill(" ", format_indent + 2)
777 newline = newline word
780 newline = newline " " word
782 line = substr(line, RSTART + RLENGTH)
784 if (newline ~ /[^\t ]/) {
791 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
797 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")