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
20 # - check if %description (lang=C) contains 8bit
21 # - desc wrapping is totally fucked up on global.spec,1.25, dosemu.spec,1.115-
24 preamble = 1 # Is it part of preamble? Default - yes
25 boc = 4 # Beginning of %changelog
26 bod = 0 # Beginning of %description
27 tw = 70 # Descriptions width
29 b_idx = 0 # index of BR/R arrays
31 # If variable removed, then 1 (for removing it from export)
32 removed["LDFLAGS"] = 0
34 removed["CXXFLAGS"] = 0
36 # get cvsaddress for changelog section
37 # using rpm macros as too lazy to add ~/.adapterrc parsing support.
38 "rpm --eval '%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'" | getline _cvsmaildomain
39 "rpm --eval '%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'" | getline _cvsmailfeedback
41 # If 1, we are inside of comment block (started with /^#%/)
44 # File with rpm groups
45 "rpm --eval %_sourcedir" | getline groups_file
46 groups_file = groups_file "/rpm.groups"
47 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups >/dev/null")
49 # Temporary file for changelog section
50 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
53 "rpm --eval %_prefix" | getline prefix
54 "rpm --eval %_bindir" | getline bindir
55 "rpm --eval %_sbindir" | getline sbindir
56 "rpm --eval %_libdir" | getline libdir
57 "rpm --eval %_sysconfdir" | getline sysconfdir
58 "rpm --eval %_datadir" | getline datadir
59 "rpm --eval %_includedir" | getline includedir
60 "rpm --eval %_mandir" | getline mandir
61 "rpm --eval %_infodir" | getline infodir
62 "rpm --eval %_examplesdir" | getline examplesdir
64 "rpm --eval %perl_sitearch" | getline perl_sitearch
65 "rpm --eval %perl_archlib" | getline perl_archlib
66 "rpm --eval %perl_privlib" | getline perl_privlib
67 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
68 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
69 "rpm --eval %perl_sitelib" | getline perl_sitelib
71 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
74 # There should be a comment with CVS keywords on the first line of file.
76 if (!/# \$Revision:/) # If this line is already OK?
77 print "# $" "Revision:$, " "$" "Date:$" # No
80 next # It is enough for first line
84 # If the latest line matched /%files/
86 if ($0 !~ /defattr/) # If no %defattr
87 print "%defattr(644,root,root,755)" # Add it
89 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
93 function b_makekey(a, b, s) {
96 gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
103 # - mixing BR/R and anything else confuses this (all will be sorted together)
105 # - comments leading the BR/R can not be associated,
106 # so don't adapterize when the BR/R are mixed with comments
107 ENVIRON["SORTBR"] == 1 && preamble == 1 && /(Build)?Requires/, /(Build)?Requires/ { # && !/^%/) {
109 l = substr($0, index($0, $2));
110 b_ktmp = b_makekey($1, l);
111 b_key[b_idx] = b_ktmp;
126 for (i = 1; i <= b_idx; i++) {
127 print "" b_val[b_key[i]];
134 /^#/ && (description == 0) {
135 if (/This file does not like to be adapterized!/) {
136 print # print this message
137 while (getline) # print the rest of spec as it is
139 do_not_touch_anything = 1 # do not touch anything in END()
143 # Generally, comments are printed without touching
149 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
151 if ($2 == "_applnkdir") {
158 # Do not add %define of _prefix if it already is.
159 if ($2 ~ /^_prefix/) {
160 sub("^"prefix, $3, bindir)
161 sub("^"prefix, $3, sbindir)
162 sub("^"prefix, $3, libdir)
163 sub("^"prefix, $3, datadir)
164 sub("^"prefix, $3, includedir)
168 if ($2 ~ /_bindir/ && !/_sbindir/)
174 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
178 if ($2 ~ /_includedir/)
185 # version related macros
193 # these are used usually when adapterizing external spec
196 if ($2 ~ /^version$/)
198 if ($2 ~ /^release$/)
201 # do nothing further, otherwise adapter thinks we're at preamble
207 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
214 /^%description/, (/^%[a-z]+/ && !/^%description/ && !/^%((end)?if|else)/) {
217 if (/^%description/) {
224 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
226 format_flush(format_line, format_indent)
230 } else if (/^[ \t]*[-\*][ \t]*/) {
231 format_flush(format_line, format_indent)
233 format_indent = RLENGTH
234 match($0, /^[ \t]*[-\*][ \t]/)
235 format_line = substr($0, RLENGTH)
237 format_line = format_line " " $0
241 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
242 if (NF > 3 && $2 == "-l") {
244 for (i = 4; i <= NF; i++)
248 format_flush(format_line, format_indent)
263 /^%prep/, (/^%[a-z]+$/ && !/^%prep/ && !/^%((end)?if|else)/) {
269 if (/^%setup/ && !/-q/) {
270 sub(/^%setup/, "%setup -q")
274 gsub(name, "%{name}");
275 gsub(version, "%{version}");
277 gsub(_beta, "%{_beta}");
283 gsub(_snap, "%{_snap}");
287 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
288 sub(/ -n %{name}-%{version}/, "")
292 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
298 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
307 if (/LDFLAGS="-s"/) {
308 removed["LDFLAGS"] = 1
311 split($0, tmp, "LDFLAGS=")
312 count = split(tmp[2], flags, "\"")
313 if (flags[1] != "" && flags[1] !~ "!?debug") {
314 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
315 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
316 for (i = 2; i < count; i++)
317 $0 = $0 flags[i] "\""
323 if (cflags("CFLAGS") == 0)
327 if (cflags("CXXFLAGS") == 0)
331 if (removed["LDFLAGS"])
333 if (removed["CFLAGS"])
335 if (removed["CXXFLAGS"])
337 # Is there still something?
344 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
347 # use PLD Linux macros
348 $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
349 $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
350 $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
352 sub(/^aclocal$/, "%{__aclocal}");
353 sub(/^autoheader$/, "%{__autoheader}");
354 sub(/^autoconf$/, "%{__autoconf}");
355 sub(/^automake$/, "%{__automake}");
358 $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
359 $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
365 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
368 # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
377 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
381 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
383 print "rm -rf $RPM_BUILD_ROOT"
387 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
388 print "rm -rf $RPM_BUILD_ROOT"
394 # 'install -d' instead 'mkdir -p'
396 sub(/mkdir -p/, "install -d")
398 # 'install' instead 'cp -p'
400 sub(/cp -p/, "install")
402 # No '-u root' or '-g root' for 'install'
403 if (/^install/ && /-[ug][ \t]*root/)
404 gsub(/-[ug][ \t]*root /, "")
406 if (/^install/ && /-m[ \t]*[0-9]+/)
407 gsub(/-m[ \t]*[0-9]+ /, "")
409 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
410 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
413 # No lines contain 'chmod' if it sets the modes to '644'
414 if ($1 ~ /chmod/ && $2 ~ /644/)
418 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
419 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
422 $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
428 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
440 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
444 # There should be some CVS keywords on the first line of %changelog.
446 if ($0 !~ _cvsmailfeedback)
447 print "* %{date} " _cvsmailfeedback > changelog_file
452 if (boc == 2 && !skip) {
453 if (!/All persons listed below/) {
454 printf "All persons listed below can be reached at " > changelog_file
455 print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
460 if (boc == 1 && !skip) {
463 print "$" "Log:$" > changelog_file
470 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
471 print " date +\"%a %b %d %Y\"`)" > changelog_file
478 if (!/^%[a-z]+$/ || /changelog/)
479 print > changelog_file
488 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
491 # %useradd and %groupadd may not be wrapped
492 if (/%(useradd|groupadd).*\\$/) {
495 $0 = substr(a, 1, length(a) - 1) $0;
499 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
502 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
505 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
508 /^%triggerin/, (/^%[a-z]+$/ && !/^%triggerin/) {
511 /^%triggerun/, (/^%[a-z]+$/ && !/^%triggerun/) {
514 /^%triggerpostun/, (/^%[a-z]+$/ && !/^%triggerpostun/) {
517 /^%pretrans/, (/^%[a-z]+$/ && !/^%pretrans/) {
520 /^%posttrans/, (/^%[a-z]+$/ && !/^%posttrans/) {
528 # There should not be a space after the name of field
529 # and before the colon.
532 if (/^%perl_module_wo_prefix/) {
535 release = "0." fixedsub(".%{disttag}.at", "", $4)
540 if (field ~ /summary:/) {
543 if (field ~ /group(\([^)]+\)):/)
545 if (field ~ /group:/) {
547 sub(/^Utilities\//,"Applications/",$2)
548 sub(/^Games/,"Applications/Games",$2)
549 sub(/^X11\/Games/,"X11/Applications/Games",$2)
550 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
551 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
552 sub(/^X11\/GNOME/,"X11/Applications",$2)
553 sub(/^X11\/Utilities/,"X11/Applications",$2)
554 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
555 sub(/^Shells/,"Applications/Shells",$2)
557 sub(/^[^ \t]*[ \t]*/,"")
560 sub(/^System Environment\/Libraries$/, "Libraries", Grupa)
561 sub(/^System Environment\/Daemons$/, "Daemons", Grupa)
562 sub(/^Applications\/Internet$/, "Applications/Networking", Grupa)
563 sub(/^System\/Servers$/, "Daemons", Grupa)
564 sub(/^X11\/Xserver$/, "X11/Servers", Grupa)
565 sub(/^X11\/XFree86$/, "X11", Grupa)
566 sub(/^Applications\/Compilers$/, "Development/Languages", Grupa)
567 sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", Grupa)
568 sub(/^Networking\/Deamons$/, "Networking/Daemons", Grupa)
570 print "Group:\t\t" Grupa
571 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
574 byl_plik_z_grupami = 0
576 while ((getline linia_grup < groups_file) > 0) {
577 byl_plik_z_grupami = 1
578 if (linia_grup == Grupa) {
584 if (!byl_plik_z_grupami)
585 print "######\t\t" groups_file ": no such file"
586 else if (!byl_opis_grupy)
587 print "######\t\t" "Unknown group!"
593 if (field ~ /prereq:/) {
597 # split (build)requires on commas
598 if (field ~ /requires:/ && $0 ~ /,/) {
599 l = substr($0, index($0, $2));
600 n = split(l, p, / *, */);
602 printf("%s\t%s\n", $1, p[i]);
607 if (field ~ /packager:|distribution:|docdir:|prefix:/)
610 if (field ~ /buildroot:/)
611 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
613 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
614 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
617 if (field ~ /name:/) {
618 if ($2 == "%{name}" && name) {
625 if (field ~ /version:/) {
626 if ($2 == "%{version}" && version) {
633 if (field ~ /release:/) {
634 if ($2 == "%{release}" && release) {
641 if (field ~ /serial:/)
645 if (field ~ /^url:$/)
648 # Use %{name} and %{version} in the filenames in "Source:"
649 if (field ~ /^source/ || field ~ /patch/) {
650 n = split($2, url, /\//)
651 if (url[n] ~ /\.gz$/) {
652 url[n+1] = ".gz" url[n+1]
653 sub(/\.gz$/,"",url[n])
655 if (url[n] ~ /\.zip$/) {
656 url[n+1] = ".zip" url[n+1]
657 sub(/\.zip$/,"",url[n])
659 if (url[n] ~ /\.tar$/) {
660 url[n+1] = ".tar" url[n+1]
661 sub(/\.tar$/,"",url[n])
663 if (url[n] ~ /\.patch$/) {
664 url[n+1] = ".patch" url[n+1]
665 sub(/\.patch$/,"",url[n])
667 if (url[n] ~ /\.bz2$/) {
668 url[n+1] = ".bz2" url[n+1]
669 sub(/\.bz2$/,"",url[n])
671 if (url[n] ~ /\.logrotate$/) {
672 url[n+1] = ".logrotate" url[n+1]
673 sub(/\.logrotate$/,"",url[n])
675 if (url[n] ~ /\.pamd$/) {
676 url[n+1] = ".pamd" url[n+1]
677 sub(/\.pamd$/,"",url[n])
680 # allow %{name} just in last url component
682 for (i = 1; i <= n; i++) {
683 url[i] = fixedsub("%{name}", name, url[i])
694 url[n] = fixedsub(name, "%{name}", url[n])
696 if (field ~ /source/) {
698 url[n] = fixedsub(version, "%{version}", url[n])
701 url[n] = fixedsub(_beta, "%{_beta}", url[n])
704 url[n] = fixedsub(_rc, "%{_rc}", url[n])
707 url[n] = fixedsub(_snap, "%{_snap}", url[n])
710 $2 = fixedsub(filename, url[n], $2)
713 sub("[?]use_mirror=.*$", "", $2);
714 sub("[?]download$", "", $2);
715 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
717 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
718 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
719 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
723 if (field ~ /^source:/)
726 if (field ~ /patch:/)
732 if (field ~ /requires/) {
734 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
745 if (name_seen == 0 && name) {
750 if (version_seen == 0 && version) {
751 print "Version:\t" version
755 if (release_seen == 0 && release) {
756 print "Release:\t" release
763 if (do_not_touch_anything)
766 close(changelog_file)
767 while ((getline < changelog_file) > 0)
769 system("rm -f " changelog_file)
773 if (did_clean == 0) {
776 print "rm -rf $RPM_BUILD_ROOT"
781 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
784 if (has_changelog == 0)
788 print "* %{date} PLD Team <feedback@pld-linux.org>"
790 printf "All persons listed below can be reached at "
791 print "<cvs_login>@pld-linux.org\n"
797 function fixedsub(s1,s2,t, ind) {
798 # substitutes fixed strings (not regexps)
799 if (ind = index(t,s1))
800 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
804 # There should be one or two tabs after the colon.
805 function format_preamble()
808 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
816 # Replace directly specified directories with macros
817 function use_macros()
819 gsub(perl_sitearch, "%{perl_sitearch}")
820 gsub(perl_archlib, "%{perl_archlib}")
821 gsub(perl_privlib, "%{perl_privlib}")
822 gsub(perl_vendorlib, "%{perl_vendorlib}")
823 gsub(perl_vendorarch, "%{perl_vendorarch}")
824 gsub(perl_sitelib, "%{perl_sitelib}")
826 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
828 gsub(bindir, "%{_bindir}")
829 gsub("%{prefix}/bin", "%{_bindir}")
830 if(prefix"/bin" == bindir)
831 gsub("%{_prefix}/bin", "%{_bindir}")
833 for (c = 1; c <= NF; c++) {
834 if ($c ~ sbindir "/fix-info-dir")
836 if ($c ~ sbindir "/webapp")
838 if ($c ~ sbindir "/chsh")
840 if ($c ~ sbindir "/usermod")
842 gsub(sbindir, "%{_sbindir}", $c)
845 gsub("%{prefix}/sbin", "%{_sbindir}")
846 if (prefix"/sbin" == sbindir)
847 gsub("%{_prefix}/sbin", "%{_sbindir}")
849 for (c = 1; c <= NF; c++) {
850 if ($c ~ sysconfdir "/{?cron.")
852 if ($c ~ sysconfdir "/{?crontab.d")
854 if ($c ~ sysconfdir "/{?env.d")
856 if ($c ~ sysconfdir "/{?logrotate.d")
858 if ($c ~ sysconfdir "/{?pam.d")
860 if ($c ~ sysconfdir "/{?profile.d")
862 if ($c ~ sysconfdir "/{?rc.d")
864 if ($c ~ sysconfdir "/{?security")
866 if ($c ~ sysconfdir "/{?skel")
868 if ($c ~ sysconfdir "/{?sysconfig")
870 if ($c ~ sysconfdir "/{?shrc.d")
872 if ($c ~ sysconfdir "/{?certs")
874 if ($c ~ sysconfdir "/{?X11")
876 if ($c ~ sysconfdir "/{?ld.so.conf.d")
878 if ($c ~ sysconfdir "/{?httpd") # temp
880 gsub(sysconfdir, "%{_sysconfdir}", $c)
883 for (c = 1; c <= NF; c++) {
884 if ($c ~ datadir "/automake")
886 if ($c ~ datadir "/unsermake")
888 if ($c ~ datadir "/file/magic.mime")
890 gsub(datadir, "%{_datadir}", $c)
893 gsub("%_sbindir", "%{_sbindir}")
894 gsub("%_mandir", "%{_mandir}")
895 gsub("%name", "%{name}")
897 gsub("%{prefix}/share", "%{_datadir}")
898 if (prefix"/share" == datadir)
899 gsub("%{_prefix}/share", "%{_datadir}")
901 gsub(includedir, "%{_includedir}")
902 gsub("%{prefix}/include", "%{_includedir}")
903 if (prefix"/include" == includedir)
904 gsub("%{_prefix}/include", "%{_includedir}")
906 gsub(mandir, "%{_mandir}")
907 if ($0 !~ "%{_datadir}/manual")
908 gsub("%{_datadir}/man", "%{_mandir}")
909 gsub("%{_prefix}/share/man", "%{_mandir}")
910 gsub("%{prefix}/share/man", "%{_mandir}")
911 gsub("%{prefix}/man", "%{_mandir}")
912 gsub("%{_prefix}/man", "%{_mandir}")
914 gsub(infodir, "%{_infodir}")
915 gsub("%{prefix}/info", "%{_infodir}")
916 gsub("%{_prefix}/info", "%{_infodir}")
918 if (prefix !~ "/X11R6") {
919 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
922 gsub(examplesdir, "%{_examplesdir}")
925 # leave --with-foo=/usr alone
926 if ($0 !~ "--with.*=.*" prefix) {
927 for (c = 1; c <= NF; c++) {
928 if ($c ~ prefix "/sbin/fix-info-dir")
930 if ($c ~ prefix "/sbin/webapp")
932 if ($c ~ prefix "/sbin/chsh")
934 if ($c ~ prefix "/sbin/usermod")
936 if ($c ~ prefix "/share/automake")
938 if ($c ~ prefix "/share/unsermake")
940 if ($c ~ prefix "/lib/sendmail")
942 if ($c ~ prefix "/lib/pkgconfig")
944 gsub(prefix, "%{_prefix}", $c)
947 gsub("%{prefix}", "%{_prefix}")
950 gsub("%{PACKAGE_VERSION}", "%{version}")
951 gsub("%{PACKAGE_NAME}", "%{name}")
953 gsub("^make$", "%{__make}")
954 gsub("^make ", "%{__make} ")
955 gsub("^gcc ", "%{__cc} ")
958 gsub("^%make$", "%{__make}")
959 gsub("^%make ", "%{__make} ")
960 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
961 gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
962 gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
963 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
964 gsub("^%{__install}", "install")
965 gsub("^%{__rm}", "rm")
966 gsub("%optflags", "%{rpmcflags}")
967 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
969 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
970 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
971 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
972 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
973 $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
975 gsub("%_bindir", "%{_bindir}")
976 gsub("%_datadir", "%{_datadir}")
977 gsub("%_iconsdir", "%{_iconsdir}")
979 gsub("/usr/src/linux", "%{_kernelsrcdir}")
980 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
984 # insertion sort of A[1..n]
985 # copied from mawk manual
986 function isort(A,n, i,j,hold) {
987 for (i = 2; i <= n; i++) {
989 while (A[j-1] > hold) {
994 # sentinel A[0] = "" will be created if needed
998 function use_files_macros( i, n, t, a)
1002 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1003 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1005 # uid/gid nobody is not valid in %files
1006 if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1007 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1011 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1012 gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1013 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1014 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1015 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1016 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1017 gsub("%{_sysconfdir}/security", "/etc/security")
1018 gsub("%{_sysconfdir}/skel", "/etc/skel")
1019 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1020 gsub("%{_sysconfdir}/certs", "/etc/certs")
1021 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1023 # /etc/init.d -> /etc/rc.d/init.d
1024 if (!/^\/etc\/init\.d$/) {
1025 gsub("/etc/init.d", "/etc/rc.d/init.d")
1028 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1029 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1030 $0 = "%attr(754,root,root) " $0
1032 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1033 gsub("^%attr\\(... *,", "%attr(754,");
1037 if (/lib.+\.so/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1038 $0 = "%attr(755,root,root) " $0
1041 # /etc/sysconfig files
1042 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1043 # attr not required, allow default 644 attr
1044 if (!/network-scripts/ && !/%dir/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1045 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1046 gsub("%config", "%config(noreplace)")
1049 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1050 $NF = "%config(noreplace) " $NF
1053 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1054 gsub("^%attr\\(... *,", "%attr(640,");
1057 if (/\/etc\/sysconfig\// && !/%verify/) {
1058 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1062 # kill leading zeros
1063 if (/%attr\(0[1-9]/) {
1064 gsub("%attr\\(0", "%attr(")
1067 # sort %verify attrs
1068 if (match($0, /%verify\(not([^)]+)\)/)) {
1069 t = substr($0, RSTART, RLENGTH)
1070 gsub(/^%verify\(not |\)$/, "", t)
1071 n = split(t, a, / /)
1075 for (i = 1 ; i <= n; i++) {
1080 gsub(/%verify\(not[^)]+\)/, s)
1087 # locale dir and no %lang -> bad
1088 if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1089 $(NF + 1) = "# FIXME consider using %find_lang"
1093 $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1094 $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1095 $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1097 gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1098 gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1099 gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1101 gsub("%{_datadir}/applications", "%{_desktopdir}");
1102 gsub("%{_datadir}/icons", "%{_iconsdir}");
1103 gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1106 function fill(ch, n, i) {
1107 for (i = 0; i < n; i++)
1111 function format_flush(line, indent, newline, word, first_word) {
1113 if (format_indent == -1)
1116 newline = fill(" ", format_indent) "- "
1118 while (match(line, /[^\t ]+/)) {
1119 word = substr(line, RSTART, RLENGTH)
1120 if (length(newline) + length(word) + 1 > tw) {
1123 if (format_indent == -1)
1126 newline = fill(" ", format_indent + 2)
1131 newline = newline word
1134 newline = newline " " word
1136 line = substr(line, RSTART + RLENGTH)
1138 if (newline ~ /[^\t ]/) {
1143 function cflags(var)
1145 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1151 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")