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])
536 url[n] = fixedsub(name, "%{name}", url[n])
538 if (field ~ /source/) {
540 url[n] = fixedsub(version, "%{version}", url[n])
543 url[n] = fixedsub(_beta, "%{_beta}", url[n])
546 url[n] = fixedsub(_rc, "%{_rc}", url[n])
549 url[n] = fixedsub(_snap, "%{_snap}", url[n])
552 $2 = fixedsub(filename, url[n], $2)
555 sub("[?]use_mirror=.*$", "", $2);
556 sub("[?]download$", "", $2);
557 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
559 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
560 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
564 if (field ~ /^source:/)
567 if (field ~ /patch:/)
572 if ($1 ~ /%define/) {
573 # Do not add %define of _prefix if it already is.
574 if ($2 ~ /^_prefix/) {
575 sub("^"prefix, $3, bindir)
576 sub("^"prefix, $3, sbindir)
577 sub("^"prefix, $3, libdir)
578 sub("^"prefix, $3, datadir)
579 sub("^"prefix, $3, includedir)
582 if ($2 ~ /_bindir/ && !/_sbindir/)
588 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
592 if ($2 ~ /_includedir/)
618 if (do_not_touch_anything)
621 close(changelog_file)
622 while ((getline < changelog_file) > 0)
624 system("rm -f " changelog_file)
626 if (did_clean == 0) {
629 print "rm -rf $RPM_BUILD_ROOT"
634 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
637 if (has_changelog == 0)
641 print "* %{date} PLD Team <feedback@pld-linux.org>"
643 printf "All persons listed below can be reached at "
644 print "<cvs_login>@pld-linux.org\n"
650 function fixedsub(s1,s2,t, ind) {
651 # substitutes fixed strings (not regexps)
652 if (ind = index(t,s1))
653 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
657 # There should be one or two tabs after the colon.
658 function format_preamble()
661 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
669 # Replace directly specified directories with macros
670 function use_macros()
672 gsub(perl_sitearch, "%{perl_sitearch}")
673 gsub(perl_archlib, "%{perl_archlib}")
674 gsub(perl_privlib, "%{perl_privlib}")
675 gsub(perl_vendorlib, "%{perl_vendorlib}")
676 gsub(perl_vendorarch, "%{perl_vendorarch}")
677 gsub(perl_sitelib, "%{perl_sitelib}")
679 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
681 gsub(bindir, "%{_bindir}")
682 gsub("%{prefix}/bin", "%{_bindir}")
683 if(prefix"/bin" == bindir)
684 gsub("%{_prefix}/bin", "%{_bindir}")
686 for (c = 1; c <= NF; c++) {
687 if ($c ~ sbindir "/fix-info-dir")
689 gsub(sbindir, "%{_sbindir}", $c)
692 gsub("%{prefix}/sbin", "%{_sbindir}")
693 if (prefix"/sbin" == sbindir)
694 gsub("%{_prefix}/sbin", "%{_sbindir}")
696 for (c = 1; c <= NF; c++) {
697 if ($c ~ sysconfdir "/{?cron.")
699 if ($c ~ sysconfdir "/{?crontab.d")
701 if ($c ~ sysconfdir "/{?logrotate.d")
703 if ($c ~ sysconfdir "/{?pam.d")
705 if ($c ~ sysconfdir "/{?profile.d")
707 if ($c ~ sysconfdir "/{?rc.d")
709 if ($c ~ sysconfdir "/{?security")
711 if ($c ~ sysconfdir "/{?skel")
713 if ($c ~ sysconfdir "/{?sysconfig")
715 if ($c ~ sysconfdir "/{?certs")
717 gsub(sysconfdir, "%{_sysconfdir}", $c)
720 for (c = 1; c <= NF; c++) {
721 if ($c ~ datadir "/automake")
723 if ($c ~ datadir "/unsermake")
725 gsub(datadir, "%{_datadir}", $c)
729 gsub("%{prefix}/share", "%{_datadir}")
730 if (prefix"/share" == datadir)
731 gsub("%{_prefix}/share", "%{_datadir}")
733 gsub(includedir, "%{_includedir}")
734 gsub("%{prefix}/include", "%{_includedir}")
735 if (prefix"/include" == includedir)
736 gsub("%{_prefix}/include", "%{_includedir}")
738 gsub(mandir, "%{_mandir}")
739 if ($0 !~ "%{_datadir}/manual")
740 gsub("%{_datadir}/man", "%{_mandir}")
741 gsub("%{_prefix}/share/man", "%{_mandir}")
742 gsub("%{prefix}/share/man", "%{_mandir}")
743 gsub("%{prefix}/man", "%{_mandir}")
744 gsub("%{_prefix}/man", "%{_mandir}")
746 gsub(infodir, "%{_infodir}")
747 gsub("%{prefix}/info", "%{_infodir}")
748 gsub("%{_prefix}/info", "%{_infodir}")
750 if (prefix !~ "/X11R6") {
751 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
754 gsub(examplesdir, "%{_examplesdir}")
757 for (c = 1; c <= NF; c++) {
758 if ($c ~ prefix "/sbin/fix-info-dir")
760 if ($c ~ prefix "/share/automake")
762 if ($c ~ prefix "/share/unsermake")
764 gsub(prefix, "%{_prefix}", $c)
766 gsub("%{prefix}", "%{_prefix}")
769 gsub("%{PACKAGE_VERSION}", "%{version}")
770 gsub("%{PACKAGE_NAME}", "%{name}")
772 # we can move files between the dirs below
773 if ($0 !~ "%{_applnkdir}") {
774 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
777 gsub("^make$", "%{__make}")
778 gsub("^make ", "%{__make} ")
781 gsub("^%make$", "%{__make}")
782 gsub("^%make ", "%{__make} ")
783 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
784 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
785 gsub("%optflags", "%{rpmcflags}")
786 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
788 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
789 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
790 gsub("%buildroot", "$RPM_BUILD_ROOT")
791 gsub("%_bindir", "%{_bindir}")
792 gsub("%_datadir", "%{_datadir}")
793 gsub("%_iconsdir", "%{_iconsdir}")
795 gsub("/usr/src/linux", "%{_kernelsrcdir}")
796 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
800 # insertion sort of A[1..n]
801 # copied from mawk manual
802 function isort(A,n, i,j,hold) {
803 for (i = 2; i <= n; i++) {
805 while (A[j-1] > hold) {
810 # sentinel A[0] = "" will be created if needed
814 function use_files_macros( i, n, t, a)
816 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
817 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
820 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
821 gsub("%{_sysconfdir}/crontab\.d", "/etc/cron.d")
822 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
823 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
824 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
825 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
826 gsub("%{_sysconfdir}/security", "/etc/security")
827 gsub("%{_sysconfdir}/skel", "/etc/skel")
828 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
829 gsub("%{_sysconfdir}/certs", "/etc/certs")
830 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
832 # /etc/init.d -> /etc/rc.d/init.d
833 if (!/^\/etc\/init\.d$/) {
834 gsub("/etc/init.d", "/etc/rc.d/init.d")
837 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
838 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
839 $0 = "%attr(754,root,root) " $0
841 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
842 gsub("^%attr\\(... *,", "%attr(754,");
846 if (/lib.+\.so/ && !/^%attr.*/) {
847 $0 = "%attr(755,root,root) " $0
850 # /etc/sysconfig files
851 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
852 # attr not required, allow default 644 attr
853 if (!/network-scripts/) {
854 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
855 gsub("%config", "%config(noreplace)")
858 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
859 $NF = "%config(noreplace) " $NF
862 if (/\/etc\/sysconfig\// && /%attr\(755/) {
863 gsub("^%attr\\(... *,", "%attr(640,");
866 if (/\/etc\/sysconfig\// && !/%verify/) {
867 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
873 gsub("%attr\\(0", "%attr(")
876 if (match($0, /%verify\(not([^)]+)\)/)) {
877 t = substr($0, RSTART, RLENGTH)
878 gsub(/^%verify\(not |\)$/, "", t)
883 for (i = 1 ; i <= n; i++) {
888 gsub(/%verify\(not[^)]+\)/, s)
896 function fill(ch, n, i) {
897 for (i = 0; i < n; i++)
901 function format_flush(line, indent, newline, word, first_word) {
903 if (format_indent == -1)
906 newline = fill(" ", format_indent) "- "
908 while (match(line, /[^\t ]+/)) {
909 word = substr(line, RSTART, RLENGTH)
910 if (length(newline) + length(word) + 1 > tw) {
913 if (format_indent == -1)
916 newline = fill(" ", format_indent + 2)
921 newline = newline word
924 newline = newline " " word
926 line = substr(line, RSTART + RLENGTH)
928 if (newline ~ /[^\t ]/) {
935 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
941 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")