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-linux.org>
11 # Michal Kochanowicz <mkochano@pld.org.pl>
12 # Elan Ruusamäe <glen@pld-linux.org>
13 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
16 # - parse ../PLD-doc/BuildRequires.txt and setup proper BR epoches?
17 # - add "-nc" option to skip CVS interaction
19 # - sort Requires, BuildRequires
22 preamble = 1 # Is it part of preamble? Default - yes
23 boc = 4 # Beggining of %changelog
24 bod = 0 # Beggining of %description
25 tw = 70 # Descriptions width
27 b_idx = 0 # index of BR/R arrays
29 # If variable removed, then 1 (for removing it from export)
30 removed["LDFLAGS"] = 0
32 removed["CXXFLAGS"] = 0
34 # If 1, we are inside of comment block (started with /^#%/)
37 # File with rpm groups
38 "rpm --eval %_sourcedir" | getline groups_file
39 groups_file = groups_file "/rpm.groups"
40 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups >/dev/null")
42 # Temporary file for changelog section
43 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
46 "rpm --eval %_prefix" | getline prefix
47 "rpm --eval %_bindir" | getline bindir
48 "rpm --eval %_sbindir" | getline sbindir
49 "rpm --eval %_libdir" | getline libdir
50 "rpm --eval %_sysconfdir" | getline sysconfdir
51 "rpm --eval %_datadir" | getline datadir
52 "rpm --eval %_includedir" | getline includedir
53 "rpm --eval %_mandir" | getline mandir
54 "rpm --eval %_infodir" | getline infodir
55 "rpm --eval %_examplesdir" | getline examplesdir
57 "rpm --eval %perl_sitearch" | getline perl_sitearch
58 "rpm --eval %perl_archlib" | getline perl_archlib
59 "rpm --eval %perl_privlib" | getline perl_privlib
60 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
61 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
62 "rpm --eval %perl_sitelib" | getline perl_sitelib
64 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
67 # There should be a comment with CVS keywords on the first line of file.
69 if (!/# \$Revision:/) # If this line is already OK?
70 print "# $" "Revision:$, " "$" "Date:$" # No
73 next # It is enough for first line
77 # If the latest line matched /%files/
79 if ($0 !~ /defattr/) # If no %defattr
80 print "%defattr(644,root,root,755)" # Add it
82 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
86 function b_makekey(a, b, s) {
89 gsub("%{\\?[_a-zA-Z0-9]+:", "", s);
96 # - mixing BR/R and anything else confuses this (all will be sorted together)
98 # - comments leading the BR/R can not be associated,
99 # so don't adapterize when the BR/R are mixed with comments
100 ENVIRON["SORTBR"] == 1 && preamble == 1 && /(Build)?Requires/, /(Build)?Requires/ { # && !/^%/) {
102 b_ktmp = b_makekey($1, $2);
103 b_key[b_idx] = b_ktmp;
112 for (i = 1; i <= b_idx; i++) {
113 print "" b_val[b_key[i]];
120 /^#/ && (description == 0) {
121 if (/This file does not like to be adapterized!/) {
122 print # print this message
123 while (getline) # print the rest of spec as it is
125 do_not_touch_anything = 1 # do not touch anything in END()
129 # Generally, comments are printed without touching
135 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
137 if ($2 == "_applnkdir")
144 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
151 /^%description/, (/^%[a-z]+/ && !/^%description/ && !/^%((end)?if|else)/) {
154 if (/^%description/) {
161 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
163 format_flush(format_line, format_indent)
167 } else if (/^[ \t]*[-\*][ \t]*/) {
168 format_flush(format_line, format_indent)
170 format_indent = RLENGTH
171 match($0, /^[ \t]*[-\*][ \t]/)
172 format_line = substr($0, RLENGTH)
174 format_line = format_line " " $0
178 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
179 if (NF > 3 && $2 == "-l") {
181 for (i = 4; i <= NF; i++)
185 format_flush(format_line, format_indent)
200 /^%prep/, (/^%[a-z]+$/ && !/^%prep/ && !/^%((end)?if|else)/) {
206 if (/^%setup/ && !/-q/) {
207 sub(/^%setup/, "%setup -q")
211 gsub(name, "%{name}");
212 gsub(version, "%{version}");
215 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
216 sub(/ -n %{name}-%{version}/, "")
220 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
226 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
235 if (/LDFLAGS="-s"/) {
236 removed["LDFLAGS"] = 1
239 split($0, tmp, "LDFLAGS=")
240 count = split(tmp[2], flags, "\"")
241 if (flags[1] != "" && flags[1] !~ "!?debug") {
242 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
243 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
244 for (i = 2; i < count; i++)
245 $0 = $0 flags[i] "\""
251 if (cflags("CFLAGS") == 0)
255 if (cflags("CXXFLAGS") == 0)
259 if (removed["LDFLAGS"])
261 if (removed["CFLAGS"])
263 if (removed["CXXFLAGS"])
265 # Is there still something?
275 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
283 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
287 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
289 print "rm -rf $RPM_BUILD_ROOT"
293 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
294 print "rm -rf $RPM_BUILD_ROOT"
300 # 'install -d' instead 'mkdir -p'
302 sub(/mkdir -p/, "install -d")
304 # 'install' instead 'cp -p'
306 sub(/cp -p/, "install")
308 # No '-u root' or '-g root' for 'install'
309 if (/^install/ && /-[ug][ \t]*root/)
310 gsub(/-[ug][ \t]*root /, "")
312 if (/^install/ && /-m[ \t]*[0-9]+/)
313 gsub(/-m[ \t]*[0-9]+ /, "")
315 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
316 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
319 # No lines contain 'chmod' if it sets the modes to '644'
320 if ($1 ~ /chmod/ && $2 ~ /644/)
327 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
340 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
344 # There should be some CVS keywords on the first line of %changelog.
347 print "* %{date} PLD Team <feedback@pld-linux.org>" > changelog_file
352 if (boc == 2 && !skip) {
353 if (!/All persons listed below/) {
354 printf "All persons listed below can be reached at " > changelog_file
355 print "<cvs_login>@pld-linux.org\n" > changelog_file
360 if (boc == 1 && !skip) {
363 print "$" "Log:$" > changelog_file
370 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
371 print " date +\"%a %b %d %Y\"`)" > changelog_file
378 if (!/^%[a-z]+$/ || /changelog/)
379 print > changelog_file
388 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
391 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
394 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
397 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
400 /^%triggerin/, (/^%[a-z]+$/ && !/^%triggerin/) {
403 /^%triggerun/, (/^%[a-z]+$/ && !/^%triggerun/) {
406 /^%triggerpostun/, (/^%[a-z]+$/ && !/^%triggerpostun/) {
409 /^%pretrans/, (/^%[a-z]+$/ && !/^%pretrans/) {
412 /^%posttrans/, (/^%[a-z]+$/ && !/^%posttrans/) {
420 # There should not be a space after the name of field
421 # and before the colon.
426 if (field ~ /group(\([^)]+\)):/)
428 if (field ~ /group:/) {
430 sub(/^Utilities\//,"Applications/",$2)
431 sub(/^Games/,"Applications/Games",$2)
432 sub(/^X11\/Games/,"X11/Applications/Games",$2)
433 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
434 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
435 sub(/^X11\/GNOME/,"X11/Applications",$2)
436 sub(/^X11\/Utilities/,"X11/Applications",$2)
437 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
438 sub(/^Shells/,"Applications/Shells",$2)
440 sub(/^[^ \t]*[ \t]*/,"")
443 print "Group:\t\t" Grupa
444 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
447 byl_plik_z_grupami = 0
449 while ((getline linia_grup < groups_file) > 0) {
450 byl_plik_z_grupami = 1
451 if (linia_grup == Grupa) {
457 if (!byl_plik_z_grupami)
458 print "######\t\t" groups_file ": no such file"
459 else if (!byl_opis_grupy)
460 print "######\t\t" "Unknown group!"
466 if (field ~ /prereq:/) {
468 $(NF + 1) = " # FIXME add Requires(scriptlet) -adapter.awk"
471 if (field ~ /packager:|distribution:|docdir:|prefix:/)
474 if (field ~ /buildroot:/)
475 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
477 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
478 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
484 if (field ~ /version:/)
487 if (field ~ /serial:/)
490 # Use %{name} and %{version} in the filenames in "Source:"
491 if (field ~ /^source/ || field ~ /patch/) {
492 n = split($2, url, /\//)
493 if (url[n] ~ /\.gz$/) {
494 url[n+1] = ".gz" url[n+1]
495 sub(/\.gz$/,"",url[n])
497 if (url[n] ~ /\.zip$/) {
498 url[n+1] = ".zip" url[n+1]
499 sub(/\.zip$/,"",url[n])
501 if (url[n] ~ /\.tar$/) {
502 url[n+1] = ".tar" url[n+1]
503 sub(/\.tar$/,"",url[n])
505 if (url[n] ~ /\.patch$/) {
506 url[n+1] = ".patch" url[n+1]
507 sub(/\.patch$/,"",url[n])
509 if (url[n] ~ /\.bz2$/) {
510 url[n+1] = ".bz2" url[n+1]
511 sub(/\.bz2$/,"",url[n])
513 if (url[n] ~ /\.logrotate$/) {
514 url[n+1] = ".logrotate" url[n+1]
515 sub(/\.logrotate$/,"",url[n])
517 if (url[n] ~ /\.pamd$/) {
518 url[n+1] = ".pamd" url[n+1]
519 sub(/\.pamd$/,"",url[n])
522 # allow %{name} just in last url component
524 for (i = 1; i <= n; i++) {
525 url[i] = fixedsub("%{name}", name, url[i])
535 url[n] = fixedsub(name, "%{name}", url[n])
536 if (field ~ /source/) {
537 url[n] = fixedsub(version, "%{version}", url[n])
539 url[n] = fixedsub(_beta, "%{_beta}", url[n])
542 url[n] = fixedsub(_rc, "%{_rc}", url[n])
545 url[n] = fixedsub(_snap, "%{_snap}", url[n])
548 $2 = fixedsub(filename, url[n], $2)
551 sub("[?]use_mirror=.*$", "", $2);
552 sub("[?]download$", "", $2);
553 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
555 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
556 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
560 if (field ~ /^source:/)
563 if (field ~ /patch:/)
568 if ($1 ~ /%define/) {
569 # Do not add %define of _prefix if it already is.
570 if ($2 ~ /^_prefix/) {
571 sub("^"prefix, $3, bindir)
572 sub("^"prefix, $3, sbindir)
573 sub("^"prefix, $3, libdir)
574 sub("^"prefix, $3, datadir)
575 sub("^"prefix, $3, includedir)
578 if ($2 ~ /_bindir/ && !/_sbindir/)
584 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
588 if ($2 ~ /_includedir/)
614 if (do_not_touch_anything)
617 close(changelog_file)
618 while ((getline < changelog_file) > 0)
620 system("rm -f " changelog_file)
622 if (did_clean == 0) {
625 print "rm -rf $RPM_BUILD_ROOT"
630 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
633 if (has_changelog == 0)
637 print "* %{date} PLD Team <feedback@pld-linux.org>"
639 printf "All persons listed below can be reached at "
640 print "<cvs_login>@pld-linux.org\n"
646 function fixedsub(s1,s2,t, ind) {
647 # substitutes fixed strings (not regexps)
648 if (ind = index(t,s1))
649 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
653 # There should be one or two tabs after the colon.
654 function format_preamble()
657 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
665 # Replace directly specified directories with macros
666 function use_macros()
668 gsub(perl_sitearch, "%{perl_sitearch}")
669 gsub(perl_archlib, "%{perl_archlib}")
670 gsub(perl_privlib, "%{perl_privlib}")
671 gsub(perl_vendorlib, "%{perl_vendorlib}")
672 gsub(perl_vendorarch, "%{perl_vendorarch}")
673 gsub(perl_sitelib, "%{perl_sitelib}")
675 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
677 gsub(bindir, "%{_bindir}")
678 gsub("%{prefix}/bin", "%{_bindir}")
679 if(prefix"/bin" == bindir)
680 gsub("%{_prefix}/bin", "%{_bindir}")
682 for (c = 1; c <= NF; c++) {
683 if ($c ~ sbindir "/fix-info-dir")
685 gsub(sbindir, "%{_sbindir}", $c)
688 gsub("%{prefix}/sbin", "%{_sbindir}")
689 if (prefix"/sbin" == sbindir)
690 gsub("%{_prefix}/sbin", "%{_sbindir}")
692 for (c = 1; c <= NF; c++) {
693 if ($c ~ sysconfdir "/{?cron.")
695 if ($c ~ sysconfdir "/{?crontab.d")
697 if ($c ~ sysconfdir "/{?logrotate.d")
699 if ($c ~ sysconfdir "/{?pam.d")
701 if ($c ~ sysconfdir "/{?profile.d")
703 if ($c ~ sysconfdir "/{?rc.d")
705 if ($c ~ sysconfdir "/{?security")
707 if ($c ~ sysconfdir "/{?skel")
709 if ($c ~ sysconfdir "/{?sysconfig")
711 if ($c ~ sysconfdir "/{?certs")
713 gsub(sysconfdir, "%{_sysconfdir}", $c)
716 for (c = 1; c <= NF; c++) {
717 if ($c ~ datadir "/automake")
719 if ($c ~ datadir "/unsermake")
721 gsub(datadir, "%{_datadir}", $c)
725 gsub("%{prefix}/share", "%{_datadir}")
726 if (prefix"/share" == datadir)
727 gsub("%{_prefix}/share", "%{_datadir}")
729 gsub(includedir, "%{_includedir}")
730 gsub("%{prefix}/include", "%{_includedir}")
731 if (prefix"/include" == includedir)
732 gsub("%{_prefix}/include", "%{_includedir}")
734 gsub(mandir, "%{_mandir}")
735 if ($0 !~ "%{_datadir}/manual")
736 gsub("%{_datadir}/man", "%{_mandir}")
737 gsub("%{_prefix}/share/man", "%{_mandir}")
738 gsub("%{prefix}/share/man", "%{_mandir}")
739 gsub("%{prefix}/man", "%{_mandir}")
740 gsub("%{_prefix}/man", "%{_mandir}")
742 gsub(infodir, "%{_infodir}")
743 gsub("%{prefix}/info", "%{_infodir}")
744 gsub("%{_prefix}/info", "%{_infodir}")
746 if (prefix !~ "/X11R6") {
747 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
750 gsub(examplesdir, "%{_examplesdir}")
753 for (c = 1; c <= NF; c++) {
754 if ($c ~ prefix "/sbin/fix-info-dir")
756 if ($c ~ prefix "/share/automake")
758 if ($c ~ prefix "/share/unsermake")
760 gsub(prefix, "%{_prefix}", $c)
762 gsub("%{prefix}", "%{_prefix}")
765 gsub("%{PACKAGE_VERSION}", "%{version}")
766 gsub("%{PACKAGE_NAME}", "%{name}")
768 # we can move files between the dirs below
769 if ($0 !~ "%{_applnkdir}") {
770 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
773 gsub("^make$", "%{__make}")
774 gsub("^make ", "%{__make} ")
777 gsub("^%make$", "%{__make}")
778 gsub("^%make ", "%{__make} ")
779 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
780 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
781 gsub("%optflags", "%{rpmcflags}")
782 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
784 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
785 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
786 gsub("%buildroot", "$RPM_BUILD_ROOT")
787 gsub("%_bindir", "%{_bindir}")
788 gsub("%_datadir", "%{_datadir}")
789 gsub("%_iconsdir", "%{_iconsdir}")
791 gsub("/usr/src/linux", "%{_kernelsrcdir}")
792 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
796 # insertion sort of A[1..n]
797 # copied from mawk manual
798 function isort(A,n, i,j,hold) {
799 for (i = 2; i <= n; i++) {
801 while (A[j-1] > hold) {
806 # sentinel A[0] = "" will be created if needed
810 function use_files_macros( i, n, t, a)
812 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
813 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
816 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
817 gsub("%{_sysconfdir}/crontab\.d", "/etc/cron.d")
818 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
819 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
820 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
821 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
822 gsub("%{_sysconfdir}/security", "/etc/security")
823 gsub("%{_sysconfdir}/skel", "/etc/skel")
824 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
825 gsub("%{_sysconfdir}/certs", "/etc/certs")
826 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
828 # /etc/init.d -> /etc/rc.d/init.d
829 if (!/^\/etc\/init\.d$/) {
830 gsub("/etc/init.d", "/etc/rc.d/init.d")
833 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
834 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
835 $0 = "%attr(754,root,root) " $0
837 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
838 gsub("^%attr\\(... *,", "%attr(754,");
842 if (/lib.+\.so/ && !/^%attr.*/) {
843 $0 = "%attr(755,root,root) " $0
846 # /etc/sysconfig files
847 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
848 # attr not required, allow default 644 attr
849 if (!/network-scripts/) {
850 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
851 gsub("%config", "%config(noreplace)")
854 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
855 $NF = "%config(noreplace) " $NF
858 if (/\/etc\/sysconfig\// && /%attr\(755/) {
859 gsub("^%attr\\(... *,", "%attr(640,");
862 if (/\/etc\/sysconfig\// && !/%verify/) {
863 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
869 gsub("%attr\\(0", "%attr(")
872 if (match($0, /%verify\(not([^)]+)\)/)) {
873 t = substr($0, RSTART, RLENGTH)
874 gsub(/^%verify\(not |\)$/, "", t)
879 for (i = 1 ; i <= n; i++) {
884 gsub(/%verify\(not[^)]+\)/, s)
892 function fill(ch, n, i) {
893 for (i = 0; i < n; i++)
897 function format_flush(line, indent, newline, word, first_word) {
899 if (format_indent == -1)
902 newline = fill(" ", format_indent) "- "
904 while (match(line, /[^\t ]+/)) {
905 word = substr(line, RSTART, RLENGTH)
906 if (length(newline) + length(word) + 1 > tw) {
909 if (format_indent == -1)
912 newline = fill(" ", format_indent + 2)
917 newline = newline word
920 newline = newline " " word
922 line = substr(line, RSTART + RLENGTH)
924 if (newline ~ /[^\t ]/) {
931 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
937 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")