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 b_idx = 0 # index of BR/R arrays
28 # If variable removed, then 1 (for removing it from export)
29 removed["LDFLAGS"] = 0
31 removed["CXXFLAGS"] = 0
33 # If 1, we are inside of comment block (started with /^#%/)
36 # File with rpm groups
37 "rpm --eval %_sourcedir" | getline groups_file
38 groups_file = groups_file "/rpm.groups"
39 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups >/dev/null")
41 # Temporary file for changelog section
42 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
45 "rpm --eval %_prefix" | getline prefix
46 "rpm --eval %_bindir" | getline bindir
47 "rpm --eval %_sbindir" | getline sbindir
48 "rpm --eval %_libdir" | getline libdir
49 "rpm --eval %_sysconfdir" | getline sysconfdir
50 "rpm --eval %_datadir" | getline datadir
51 "rpm --eval %_includedir" | getline includedir
52 "rpm --eval %_mandir" | getline mandir
53 "rpm --eval %_infodir" | getline infodir
54 "rpm --eval %_examplesdir" | getline examplesdir
56 "rpm --eval %perl_sitearch" | getline perl_sitearch
57 "rpm --eval %perl_archlib" | getline perl_archlib
58 "rpm --eval %perl_privlib" | getline perl_privlib
59 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
60 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
61 "rpm --eval %perl_sitelib" | getline perl_sitelib
63 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
66 # There should be a comment with CVS keywords on the first line of file.
68 if (!/# \$Revision:/) # If this line is already OK?
69 print "# $" "Revision:$, " "$" "Date:$" # No
72 next # It is enough for first line
76 # If the latest line matched /%files/
78 if ($0 !~ /defattr/) # If no %defattr
79 print "%defattr(644,root,root,755)" # Add it
81 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
85 function b_makekey(a, b, s) {
88 gsub("%{\\?[_a-zA-Z0-9]+:", "", s);
95 # - mixing BR/R and anything else confuses this (all will be sorted together)
97 # - comments leading the BR/R can not be associated,
98 # so don't adapterize when the BR/R are mixed with comments
99 ENVIRON["SORTBR"] == 1 && preamble == 1 && /(Build)?Requires/, /(Build)?Requires/ { # && !/^%/) {
101 b_ktmp = b_makekey($1, $2);
102 b_key[b_idx] = b_ktmp;
111 for (i = 1; i <= b_idx; i++) {
112 print "" b_val[b_key[i]];
119 /^#/ && (description == 0) {
120 if (/This file does not like to be adapterized!/) {
121 print # print this message
122 while (getline) # print the rest of spec as it is
124 do_not_touch_anything = 1 # do not touch anything in END()
128 # Generally, comments are printed without touching
134 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
136 if ($2 == "_applnkdir")
143 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
150 /^%description/, (/^%[a-z]+/ && !/^%description/ && !/^%((end)?if|else)/) {
153 if (/^%description/) {
160 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
162 format_flush(format_line, format_indent)
166 } else if (/^[ \t]*[-\*][ \t]*/) {
167 format_flush(format_line, format_indent)
169 format_indent = RLENGTH
170 match($0, /^[ \t]*[-\*][ \t]/)
171 format_line = substr($0, RLENGTH)
173 format_line = format_line " " $0
177 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
178 if (NF > 3 && $2 == "-l") {
180 for (i = 4; i <= NF; i++)
184 format_flush(format_line, format_indent)
199 /^%prep/, (/^%[a-z]+$/ && !/^%prep/ && !/^%((end)?if|else)/) {
205 if (/^%setup/ && !/-q/) {
206 sub(/^%setup/, "%setup -q")
209 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
210 sub(/ -n %{name}-%{version}/, "")
214 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
220 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
229 if (/LDFLAGS="-s"/) {
230 removed["LDFLAGS"] = 1
233 split($0, tmp, "LDFLAGS=")
234 count = split(tmp[2], flags, "\"")
235 if (flags[1] != "" && flags[1] !~ "!?debug") {
236 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
237 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
238 for (i = 2; i < count; i++)
239 $0 = $0 flags[i] "\""
245 if (cflags("CFLAGS") == 0)
249 if (cflags("CXXFLAGS") == 0)
253 if (removed["LDFLAGS"])
255 if (removed["CFLAGS"])
257 if (removed["CXXFLAGS"])
259 # Is there still something?
269 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
277 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
281 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
283 print "rm -rf $RPM_BUILD_ROOT"
287 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
288 print "rm -rf $RPM_BUILD_ROOT"
294 # 'install -d' instead 'mkdir -p'
296 sub(/mkdir -p/, "install -d")
298 # 'install' instead 'cp -p'
300 sub(/cp -p/, "install")
302 # No '-u root' or '-g root' for 'install'
303 if (/^install/ && /-[ug][ \t]*root/)
304 gsub(/-[ug][ \t]*root /, "")
306 if (/^install/ && /-m[ \t]*[0-9]+/)
307 gsub(/-m[ \t]*[0-9]+ /, "")
309 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
310 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
313 # No lines contain 'chmod' if it sets the modes to '644'
314 if ($1 ~ /chmod/ && $2 ~ /644/)
321 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
334 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
338 # There should be some CVS keywords on the first line of %changelog.
341 print "* %{date} PLD Team <feedback@pld-linux.org>" > changelog_file
346 if (boc == 2 && !skip) {
347 if (!/All persons listed below/) {
348 printf "All persons listed below can be reached at " > changelog_file
349 print "<cvs_login>@pld-linux.org\n" > changelog_file
354 if (boc == 1 && !skip) {
357 print "$" "Log:$" > changelog_file
364 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
365 print " date +\"%a %b %d %Y\"`)" > changelog_file
372 if (!/^%[a-z]+$/ || /changelog/)
373 print > changelog_file
382 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
385 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
388 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
391 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
394 /^%triggerin/, (/^%[a-z]+$/ && !/^%triggerin/) {
397 /^%triggerun/, (/^%[a-z]+$/ && !/^%triggerun/) {
400 /^%triggerpostun/, (/^%[a-z]+$/ && !/^%triggerpostun/) {
403 /^%pretrans/, (/^%[a-z]+$/ && !/^%pretrans/) {
406 /^%posttrans/, (/^%[a-z]+$/ && !/^%posttrans/) {
414 # There should not be a space after the name of field
415 # and before the colon.
420 if (field ~ /group(\([^)]+\)):/)
422 if (field ~ /group:/) {
424 sub(/^Utilities\//,"Applications/",$2)
425 sub(/^Games/,"Applications/Games",$2)
426 sub(/^X11\/Games/,"X11/Applications/Games",$2)
427 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
428 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
429 sub(/^X11\/GNOME/,"X11/Applications",$2)
430 sub(/^X11\/Utilities/,"X11/Applications",$2)
431 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
432 sub(/^Shells/,"Applications/Shells",$2)
434 sub(/^[^ \t]*[ \t]*/,"")
437 print "Group:\t\t" Grupa
438 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
441 byl_plik_z_grupami = 0
443 while ((getline linia_grup < groups_file) > 0) {
444 byl_plik_z_grupami = 1
445 if (linia_grup == Grupa) {
451 if (!byl_plik_z_grupami)
452 print "######\t\t" groups_file ": no such file"
453 else if (!byl_opis_grupy)
454 print "######\t\t" "Unknown group!"
460 if (field ~ /prereq:/) {
462 $(NF + 1) = " # FIXME add Requires(scriptlet) -adapter.awk"
465 if (field ~ /packager:|distribution:|docdir:|prefix:/)
468 if (field ~ /buildroot:/)
469 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
471 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
472 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
478 if (field ~ /version:/)
481 if (field ~ /serial:/)
484 # Use %{name} and %{version} in the filenames in "Source:"
485 if (field ~ /^source/ || field ~ /patch/) {
486 n = split($2, url, /\//)
487 if (url[n] ~ /\.gz$/) {
488 url[n+1] = ".gz" url[n+1]
489 sub(/\.gz$/,"",url[n])
491 if (url[n] ~ /\.zip$/) {
492 url[n+1] = ".zip" url[n+1]
493 sub(/\.zip$/,"",url[n])
495 if (url[n] ~ /\.tar$/) {
496 url[n+1] = ".tar" url[n+1]
497 sub(/\.tar$/,"",url[n])
499 if (url[n] ~ /\.patch$/) {
500 url[n+1] = ".patch" url[n+1]
501 sub(/\.patch$/,"",url[n])
503 if (url[n] ~ /\.bz2$/) {
504 url[n+1] = ".bz2" url[n+1]
505 sub(/\.bz2$/,"",url[n])
507 if (url[n] ~ /\.logrotate$/) {
508 url[n+1] = ".logrotate" url[n+1]
509 sub(/\.logrotate$/,"",url[n])
511 if (url[n] ~ /\.pamd$/) {
512 url[n+1] = ".pamd" url[n+1]
513 sub(/\.pamd$/,"",url[n])
516 # allow %{name} just in last url component
518 for (i = 1; i <= n; i++) {
519 url[i] = fixedsub("%{name}", name, url[i])
529 url[n] = fixedsub(name, "%{name}", url[n])
530 if (field ~ /source/) {
531 url[n] = fixedsub(version, "%{version}", url[n])
533 url[n] = fixedsub(_beta, "%{_beta}", url[n])
536 url[n] = fixedsub(_rc, "%{_rc}", url[n])
539 url[n] = fixedsub(_snap, "%{_snap}", url[n])
542 $2 = fixedsub(filename, url[n], $2)
545 sub("[?]use_mirror=.*$", "", $2);
546 sub("[?]download$", "", $2);
547 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
549 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
550 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
554 if (field ~ /^source:/)
557 if (field ~ /patch:/)
562 if ($1 ~ /%define/) {
563 # Do not add %define of _prefix if it already is.
564 if ($2 ~ /^_prefix/) {
565 sub("^"prefix, $3, bindir)
566 sub("^"prefix, $3, sbindir)
567 sub("^"prefix, $3, libdir)
568 sub("^"prefix, $3, datadir)
569 sub("^"prefix, $3, includedir)
572 if ($2 ~ /_bindir/ && !/_sbindir/)
578 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
582 if ($2 ~ /_includedir/)
597 if (field ~ /buildrequires:/) {
599 if ($2 ~ /rpm-pythonprov/) {
615 if (do_not_touch_anything)
618 close(changelog_file)
619 while ((getline < changelog_file) > 0)
621 system("rm -f " changelog_file)
623 if (did_clean == 0) {
626 print "rm -rf $RPM_BUILD_ROOT"
631 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
634 if (has_changelog == 0)
638 print "* %{date} PLD Team <feedback@pld-linux.org>"
640 printf "All persons listed below can be reached at "
641 print "<cvs_login>@pld-linux.org\n"
647 function fixedsub(s1,s2,t, ind) {
648 # substitutes fixed strings (not regexps)
649 if (ind = index(t,s1))
650 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
654 # There should be one or two tabs after the colon.
655 function format_preamble()
658 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
666 # Replace directly specified directories with macros
667 function use_macros()
669 gsub(perl_sitearch, "%{perl_sitearch}")
670 gsub(perl_archlib, "%{perl_archlib}")
671 gsub(perl_privlib, "%{perl_privlib}")
672 gsub(perl_vendorlib, "%{perl_vendorlib}")
673 gsub(perl_vendorarch, "%{perl_vendorarch}")
674 gsub(perl_sitelib, "%{perl_sitelib}")
676 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
678 gsub(bindir, "%{_bindir}")
679 gsub("%{prefix}/bin", "%{_bindir}")
680 if(prefix"/bin" == bindir)
681 gsub("%{_prefix}/bin", "%{_bindir}")
683 for (c = 1; c <= NF; c++) {
684 if ($c ~ sbindir "/fix-info-dir")
686 gsub(sbindir, "%{_sbindir}", $c)
689 gsub("%{prefix}/sbin", "%{_sbindir}")
690 if (prefix"/sbin" == sbindir)
691 gsub("%{_prefix}/sbin", "%{_sbindir}")
693 for (c = 1; c <= NF; c++) {
694 if ($c ~ sysconfdir "/{?cron.")
696 if ($c ~ sysconfdir "/{?crontab.d")
698 if ($c ~ sysconfdir "/{?logrotate.d")
700 if ($c ~ sysconfdir "/{?pam.d")
702 if ($c ~ sysconfdir "/{?profile.d")
704 if ($c ~ sysconfdir "/{?rc.d")
706 if ($c ~ sysconfdir "/{?security")
708 if ($c ~ sysconfdir "/{?skel")
710 if ($c ~ sysconfdir "/{?sysconfig")
712 if ($c ~ sysconfdir "/{?certs")
714 gsub(sysconfdir, "%{_sysconfdir}", $c)
717 for (c = 1; c <= NF; c++) {
718 if ($c ~ datadir "/automake")
720 if ($c ~ datadir "/unsermake")
722 gsub(datadir, "%{_datadir}", $c)
726 gsub("%{prefix}/share", "%{_datadir}")
727 if (prefix"/share" == datadir)
728 gsub("%{_prefix}/share", "%{_datadir}")
730 gsub(includedir, "%{_includedir}")
731 gsub("%{prefix}/include", "%{_includedir}")
732 if (prefix"/include" == includedir)
733 gsub("%{_prefix}/include", "%{_includedir}")
735 gsub(mandir, "%{_mandir}")
736 if ($0 !~ "%{_datadir}/manual")
737 gsub("%{_datadir}/man", "%{_mandir}")
738 gsub("%{_prefix}/share/man", "%{_mandir}")
739 gsub("%{prefix}/share/man", "%{_mandir}")
740 gsub("%{prefix}/man", "%{_mandir}")
741 gsub("%{_prefix}/man", "%{_mandir}")
743 gsub(infodir, "%{_infodir}")
744 gsub("%{prefix}/info", "%{_infodir}")
745 gsub("%{_prefix}/info", "%{_infodir}")
747 if (prefix !~ "/X11R6") {
748 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
751 gsub(examplesdir, "%{_examplesdir}")
754 for (c = 1; c <= NF; c++) {
755 if ($c ~ prefix "/sbin/fix-info-dir")
757 if ($c ~ prefix "/share/automake")
759 if ($c ~ prefix "/share/unsermake")
761 gsub(prefix, "%{_prefix}", $c)
763 gsub("%{prefix}", "%{_prefix}")
766 gsub("%{PACKAGE_VERSION}", "%{version}")
767 gsub("%{PACKAGE_NAME}", "%{name}")
769 # we can move files between the dirs below
770 if ($0 !~ "%{_applnkdir}") {
771 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
774 gsub("^make$", "%{__make}")
775 gsub("^make ", "%{__make} ")
778 gsub("^%make$", "%{__make}")
779 gsub("^%make ", "%{__make} ")
780 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
781 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
782 gsub("%optflags", "%{rpmcflags}")
783 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
785 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
786 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
787 gsub("%buildroot", "$RPM_BUILD_ROOT")
788 gsub("%_bindir", "%{_bindir}")
789 gsub("%_datadir", "%{_datadir}")
790 gsub("%_iconsdir", "%{_iconsdir}")
792 gsub("/usr/src/linux", "%{_kernelsrcdir}")
793 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
797 # insertion sort of A[1..n]
798 # copied from mawk manual
799 function isort(A,n, i,j,hold) {
800 for (i = 2; i <= n; i++) {
802 while (A[j-1] > hold) {
807 # sentinel A[0] = "" will be created if needed
811 function use_files_macros( i, n, t, a)
813 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
814 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
817 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
818 gsub("%{_sysconfdir}/crontab\.d", "/etc/cron.d")
819 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
820 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
821 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
822 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
823 gsub("%{_sysconfdir}/security", "/etc/security")
824 gsub("%{_sysconfdir}/skel", "/etc/skel")
825 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
826 gsub("%{_sysconfdir}/certs", "/etc/certs")
827 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
829 # /etc/init.d -> /etc/rc.d/init.d
830 if (!/^\/etc\/init\.d$/) {
831 gsub("/etc/init.d", "/etc/rc.d/init.d")
834 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
835 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
836 $0 = "%attr(754,root,root) " $0
838 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
839 gsub("^%attr\\(... *,", "%attr(754,");
843 if (/lib.+\.so/ && !/^%attr.*/) {
844 $0 = "%attr(755,root,root) " $0
847 # /etc/sysconfig files
848 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
849 # attr not required, allow default 644 attr
850 if (!/network-scripts/) {
851 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
852 gsub("%config", "%config(noreplace)")
855 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
856 $NF = "%config(noreplace) " $NF
859 if (/\/etc\/sysconfig\// && /%attr\(755/) {
860 gsub("^%attr\\(... *,", "%attr(640,");
863 if (/\/etc\/sysconfig\// && !/%verify/) {
864 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
870 gsub("%attr\\(0", "%attr(")
873 if (match($0, /%verify\(not([^)]+)\)/)) {
874 t = substr($0, RSTART, RLENGTH)
875 gsub(/^%verify\(not |\)$/, "", t)
880 for (i = 1 ; i <= n; i++) {
885 gsub(/%verify\(not[^)]+\)/, s)
893 function fill(ch, n, i) {
894 for (i = 0; i < n; i++)
898 function format_flush(line, indent, newline, word, first_word) {
900 if (format_indent == -1)
903 newline = fill(" ", format_indent) "- "
905 while (match(line, /[^\t ]+/)) {
906 word = substr(line, RSTART, RLENGTH)
907 if (length(newline) + length(word) + 1 > tw) {
910 if (format_indent == -1)
913 newline = fill(" ", format_indent + 2)
918 newline = newline word
921 newline = newline " " word
923 line = substr(line, RSTART + RLENGTH)
925 if (newline ~ /[^\t ]/) {
932 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
938 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")