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")
210 gsub(name, "%{name}");
211 gsub(version, "%{version}");
214 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
215 sub(/ -n %{name}-%{version}/, "")
219 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
225 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
234 if (/LDFLAGS="-s"/) {
235 removed["LDFLAGS"] = 1
238 split($0, tmp, "LDFLAGS=")
239 count = split(tmp[2], flags, "\"")
240 if (flags[1] != "" && flags[1] !~ "!?debug") {
241 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
242 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
243 for (i = 2; i < count; i++)
244 $0 = $0 flags[i] "\""
250 if (cflags("CFLAGS") == 0)
254 if (cflags("CXXFLAGS") == 0)
258 if (removed["LDFLAGS"])
260 if (removed["CFLAGS"])
262 if (removed["CXXFLAGS"])
264 # Is there still something?
274 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
282 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
286 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
288 print "rm -rf $RPM_BUILD_ROOT"
292 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
293 print "rm -rf $RPM_BUILD_ROOT"
299 # 'install -d' instead 'mkdir -p'
301 sub(/mkdir -p/, "install -d")
303 # 'install' instead 'cp -p'
305 sub(/cp -p/, "install")
307 # No '-u root' or '-g root' for 'install'
308 if (/^install/ && /-[ug][ \t]*root/)
309 gsub(/-[ug][ \t]*root /, "")
311 if (/^install/ && /-m[ \t]*[0-9]+/)
312 gsub(/-m[ \t]*[0-9]+ /, "")
314 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
315 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
318 # No lines contain 'chmod' if it sets the modes to '644'
319 if ($1 ~ /chmod/ && $2 ~ /644/)
326 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
339 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
343 # There should be some CVS keywords on the first line of %changelog.
346 print "* %{date} PLD Team <feedback@pld-linux.org>" > changelog_file
351 if (boc == 2 && !skip) {
352 if (!/All persons listed below/) {
353 printf "All persons listed below can be reached at " > changelog_file
354 print "<cvs_login>@pld-linux.org\n" > changelog_file
359 if (boc == 1 && !skip) {
362 print "$" "Log:$" > changelog_file
369 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
370 print " date +\"%a %b %d %Y\"`)" > changelog_file
377 if (!/^%[a-z]+$/ || /changelog/)
378 print > changelog_file
387 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
390 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
393 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
396 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
399 /^%triggerin/, (/^%[a-z]+$/ && !/^%triggerin/) {
402 /^%triggerun/, (/^%[a-z]+$/ && !/^%triggerun/) {
405 /^%triggerpostun/, (/^%[a-z]+$/ && !/^%triggerpostun/) {
408 /^%pretrans/, (/^%[a-z]+$/ && !/^%pretrans/) {
411 /^%posttrans/, (/^%[a-z]+$/ && !/^%posttrans/) {
419 # There should not be a space after the name of field
420 # and before the colon.
425 if (field ~ /group(\([^)]+\)):/)
427 if (field ~ /group:/) {
429 sub(/^Utilities\//,"Applications/",$2)
430 sub(/^Games/,"Applications/Games",$2)
431 sub(/^X11\/Games/,"X11/Applications/Games",$2)
432 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
433 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
434 sub(/^X11\/GNOME/,"X11/Applications",$2)
435 sub(/^X11\/Utilities/,"X11/Applications",$2)
436 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
437 sub(/^Shells/,"Applications/Shells",$2)
439 sub(/^[^ \t]*[ \t]*/,"")
442 print "Group:\t\t" Grupa
443 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
446 byl_plik_z_grupami = 0
448 while ((getline linia_grup < groups_file) > 0) {
449 byl_plik_z_grupami = 1
450 if (linia_grup == Grupa) {
456 if (!byl_plik_z_grupami)
457 print "######\t\t" groups_file ": no such file"
458 else if (!byl_opis_grupy)
459 print "######\t\t" "Unknown group!"
465 if (field ~ /prereq:/) {
467 $(NF + 1) = " # FIXME add Requires(scriptlet) -adapter.awk"
470 if (field ~ /packager:|distribution:|docdir:|prefix:/)
473 if (field ~ /buildroot:/)
474 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
476 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
477 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
483 if (field ~ /version:/)
486 if (field ~ /serial:/)
489 # Use %{name} and %{version} in the filenames in "Source:"
490 if (field ~ /^source/ || field ~ /patch/) {
491 n = split($2, url, /\//)
492 if (url[n] ~ /\.gz$/) {
493 url[n+1] = ".gz" url[n+1]
494 sub(/\.gz$/,"",url[n])
496 if (url[n] ~ /\.zip$/) {
497 url[n+1] = ".zip" url[n+1]
498 sub(/\.zip$/,"",url[n])
500 if (url[n] ~ /\.tar$/) {
501 url[n+1] = ".tar" url[n+1]
502 sub(/\.tar$/,"",url[n])
504 if (url[n] ~ /\.patch$/) {
505 url[n+1] = ".patch" url[n+1]
506 sub(/\.patch$/,"",url[n])
508 if (url[n] ~ /\.bz2$/) {
509 url[n+1] = ".bz2" url[n+1]
510 sub(/\.bz2$/,"",url[n])
512 if (url[n] ~ /\.logrotate$/) {
513 url[n+1] = ".logrotate" url[n+1]
514 sub(/\.logrotate$/,"",url[n])
516 if (url[n] ~ /\.pamd$/) {
517 url[n+1] = ".pamd" url[n+1]
518 sub(/\.pamd$/,"",url[n])
521 # allow %{name} just in last url component
523 for (i = 1; i <= n; i++) {
524 url[i] = fixedsub("%{name}", name, url[i])
534 url[n] = fixedsub(name, "%{name}", url[n])
535 if (field ~ /source/) {
536 url[n] = fixedsub(version, "%{version}", url[n])
538 url[n] = fixedsub(_beta, "%{_beta}", url[n])
541 url[n] = fixedsub(_rc, "%{_rc}", url[n])
544 url[n] = fixedsub(_snap, "%{_snap}", url[n])
547 $2 = fixedsub(filename, url[n], $2)
550 sub("[?]use_mirror=.*$", "", $2);
551 sub("[?]download$", "", $2);
552 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
554 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
555 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
559 if (field ~ /^source:/)
562 if (field ~ /patch:/)
567 if ($1 ~ /%define/) {
568 # Do not add %define of _prefix if it already is.
569 if ($2 ~ /^_prefix/) {
570 sub("^"prefix, $3, bindir)
571 sub("^"prefix, $3, sbindir)
572 sub("^"prefix, $3, libdir)
573 sub("^"prefix, $3, datadir)
574 sub("^"prefix, $3, includedir)
577 if ($2 ~ /_bindir/ && !/_sbindir/)
583 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
587 if ($2 ~ /_includedir/)
602 if (field ~ /buildrequires:/) {
604 if ($2 ~ /rpm-pythonprov/) {
620 if (do_not_touch_anything)
623 close(changelog_file)
624 while ((getline < changelog_file) > 0)
626 system("rm -f " changelog_file)
628 if (did_clean == 0) {
631 print "rm -rf $RPM_BUILD_ROOT"
636 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
639 if (has_changelog == 0)
643 print "* %{date} PLD Team <feedback@pld-linux.org>"
645 printf "All persons listed below can be reached at "
646 print "<cvs_login>@pld-linux.org\n"
652 function fixedsub(s1,s2,t, ind) {
653 # substitutes fixed strings (not regexps)
654 if (ind = index(t,s1))
655 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
659 # There should be one or two tabs after the colon.
660 function format_preamble()
663 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
671 # Replace directly specified directories with macros
672 function use_macros()
674 gsub(perl_sitearch, "%{perl_sitearch}")
675 gsub(perl_archlib, "%{perl_archlib}")
676 gsub(perl_privlib, "%{perl_privlib}")
677 gsub(perl_vendorlib, "%{perl_vendorlib}")
678 gsub(perl_vendorarch, "%{perl_vendorarch}")
679 gsub(perl_sitelib, "%{perl_sitelib}")
681 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
683 gsub(bindir, "%{_bindir}")
684 gsub("%{prefix}/bin", "%{_bindir}")
685 if(prefix"/bin" == bindir)
686 gsub("%{_prefix}/bin", "%{_bindir}")
688 for (c = 1; c <= NF; c++) {
689 if ($c ~ sbindir "/fix-info-dir")
691 gsub(sbindir, "%{_sbindir}", $c)
694 gsub("%{prefix}/sbin", "%{_sbindir}")
695 if (prefix"/sbin" == sbindir)
696 gsub("%{_prefix}/sbin", "%{_sbindir}")
698 for (c = 1; c <= NF; c++) {
699 if ($c ~ sysconfdir "/{?cron.")
701 if ($c ~ sysconfdir "/{?crontab.d")
703 if ($c ~ sysconfdir "/{?logrotate.d")
705 if ($c ~ sysconfdir "/{?pam.d")
707 if ($c ~ sysconfdir "/{?profile.d")
709 if ($c ~ sysconfdir "/{?rc.d")
711 if ($c ~ sysconfdir "/{?security")
713 if ($c ~ sysconfdir "/{?skel")
715 if ($c ~ sysconfdir "/{?sysconfig")
717 if ($c ~ sysconfdir "/{?certs")
719 gsub(sysconfdir, "%{_sysconfdir}", $c)
722 for (c = 1; c <= NF; c++) {
723 if ($c ~ datadir "/automake")
725 if ($c ~ datadir "/unsermake")
727 gsub(datadir, "%{_datadir}", $c)
731 gsub("%{prefix}/share", "%{_datadir}")
732 if (prefix"/share" == datadir)
733 gsub("%{_prefix}/share", "%{_datadir}")
735 gsub(includedir, "%{_includedir}")
736 gsub("%{prefix}/include", "%{_includedir}")
737 if (prefix"/include" == includedir)
738 gsub("%{_prefix}/include", "%{_includedir}")
740 gsub(mandir, "%{_mandir}")
741 if ($0 !~ "%{_datadir}/manual")
742 gsub("%{_datadir}/man", "%{_mandir}")
743 gsub("%{_prefix}/share/man", "%{_mandir}")
744 gsub("%{prefix}/share/man", "%{_mandir}")
745 gsub("%{prefix}/man", "%{_mandir}")
746 gsub("%{_prefix}/man", "%{_mandir}")
748 gsub(infodir, "%{_infodir}")
749 gsub("%{prefix}/info", "%{_infodir}")
750 gsub("%{_prefix}/info", "%{_infodir}")
752 if (prefix !~ "/X11R6") {
753 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
756 gsub(examplesdir, "%{_examplesdir}")
759 for (c = 1; c <= NF; c++) {
760 if ($c ~ prefix "/sbin/fix-info-dir")
762 if ($c ~ prefix "/share/automake")
764 if ($c ~ prefix "/share/unsermake")
766 gsub(prefix, "%{_prefix}", $c)
768 gsub("%{prefix}", "%{_prefix}")
771 gsub("%{PACKAGE_VERSION}", "%{version}")
772 gsub("%{PACKAGE_NAME}", "%{name}")
774 # we can move files between the dirs below
775 if ($0 !~ "%{_applnkdir}") {
776 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
779 gsub("^make$", "%{__make}")
780 gsub("^make ", "%{__make} ")
783 gsub("^%make$", "%{__make}")
784 gsub("^%make ", "%{__make} ")
785 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
786 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
787 gsub("%optflags", "%{rpmcflags}")
788 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
790 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
791 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
792 gsub("%buildroot", "$RPM_BUILD_ROOT")
793 gsub("%_bindir", "%{_bindir}")
794 gsub("%_datadir", "%{_datadir}")
795 gsub("%_iconsdir", "%{_iconsdir}")
797 gsub("/usr/src/linux", "%{_kernelsrcdir}")
798 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
802 # insertion sort of A[1..n]
803 # copied from mawk manual
804 function isort(A,n, i,j,hold) {
805 for (i = 2; i <= n; i++) {
807 while (A[j-1] > hold) {
812 # sentinel A[0] = "" will be created if needed
816 function use_files_macros( i, n, t, a)
818 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
819 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
822 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
823 gsub("%{_sysconfdir}/crontab\.d", "/etc/cron.d")
824 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
825 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
826 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
827 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
828 gsub("%{_sysconfdir}/security", "/etc/security")
829 gsub("%{_sysconfdir}/skel", "/etc/skel")
830 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
831 gsub("%{_sysconfdir}/certs", "/etc/certs")
832 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
834 # /etc/init.d -> /etc/rc.d/init.d
835 if (!/^\/etc\/init\.d$/) {
836 gsub("/etc/init.d", "/etc/rc.d/init.d")
839 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
840 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
841 $0 = "%attr(754,root,root) " $0
843 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
844 gsub("^%attr\\(... *,", "%attr(754,");
848 if (/lib.+\.so/ && !/^%attr.*/) {
849 $0 = "%attr(755,root,root) " $0
852 # /etc/sysconfig files
853 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
854 # attr not required, allow default 644 attr
855 if (!/network-scripts/) {
856 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
857 gsub("%config", "%config(noreplace)")
860 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
861 $NF = "%config(noreplace) " $NF
864 if (/\/etc\/sysconfig\// && /%attr\(755/) {
865 gsub("^%attr\\(... *,", "%attr(640,");
868 if (/\/etc\/sysconfig\// && !/%verify/) {
869 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
875 gsub("%attr\\(0", "%attr(")
878 if (match($0, /%verify\(not([^)]+)\)/)) {
879 t = substr($0, RSTART, RLENGTH)
880 gsub(/^%verify\(not |\)$/, "", t)
885 for (i = 1 ; i <= n; i++) {
890 gsub(/%verify\(not[^)]+\)/, s)
898 function fill(ch, n, i) {
899 for (i = 0; i < n; i++)
903 function format_flush(line, indent, newline, word, first_word) {
905 if (format_indent == -1)
908 newline = fill(" ", format_indent) "- "
910 while (match(line, /[^\t ]+/)) {
911 word = substr(line, RSTART, RLENGTH)
912 if (length(newline) + length(word) + 1 > tw) {
915 if (format_indent == -1)
918 newline = fill(" ", format_indent + 2)
923 newline = newline word
926 newline = newline " " word
928 line = substr(line, RSTART + RLENGTH)
930 if (newline ~ /[^\t ]/) {
937 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
943 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")