3 # This is adapter v0.27. Adapter adapts .spec files for PLD Linux.
5 # Copyright (C) 1999-2005 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>
14 # See cvs log adapter{,.awk} for list of contributors
16 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
19 # - parse ../PLD-doc/BuildRequires.txt and setup proper BR epoches?
20 # - add "-nc" option to skip CVS interaction
22 # - sort Requires, BuildRequires
23 # - check if %description (lang=C) contains 8bit
24 # - desc wrapping is totally fucked up on global.spec,1.25, dosemu.spec,1.115-
27 RPM_SECTIONS = "package|build|changelog|clean|description|install|post|posttrans|postun|pre|prep|pretrans|preun|triggerin|triggerpostun|triggerun"
28 SECTIONS = "^%(" RPM_SECTIONS ")"
30 preamble = 1 # Is it part of preamble? Default - yes
31 boc = 4 # Beginning of %changelog
32 bod = 0 # Beginning of %description
33 tw = 70 # Descriptions width
35 b_idx = 0 # index of BR/R arrays
37 # If variable removed, then 1 (for removing it from export)
38 removed["LDFLAGS"] = 0
40 removed["CXXFLAGS"] = 0
42 # get cvsaddress for changelog section
43 # using rpm macros as too lazy to add ~/.adapterrc parsing support.
44 "rpm --eval '%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'" | getline _cvsmaildomain
45 "rpm --eval '%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'" | getline _cvsmailfeedback
47 # If 1, we are inside of comment block (started with /^#%/)
50 # File with rpm groups
51 "rpm --eval %_sourcedir" | getline groups_file
52 groups_file = groups_file "/rpm.groups"
53 system("cd `rpm --eval %_sourcedir`; [ -f rpm.groups ] || cvs up rpm.groups >/dev/null")
55 # Temporary file for changelog section
56 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
59 "rpm --eval %_prefix" | getline prefix
60 "rpm --eval %_bindir" | getline bindir
61 "rpm --eval %_sbindir" | getline sbindir
62 "rpm --eval %_libdir" | getline libdir
63 "rpm --eval %_sysconfdir" | getline sysconfdir
64 "rpm --eval %_datadir" | getline datadir
65 "rpm --eval %_includedir" | getline includedir
66 "rpm --eval %_mandir" | getline mandir
67 "rpm --eval %_infodir" | getline infodir
68 "rpm --eval %_examplesdir" | getline examplesdir
69 "rpm --eval %_defaultdocdir" | getline docdir
71 "rpm --eval %perl_sitearch" | getline perl_sitearch
72 "rpm --eval %perl_archlib" | getline perl_archlib
73 "rpm --eval %perl_privlib" | getline perl_privlib
74 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
75 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
76 "rpm --eval %perl_sitelib" | getline perl_sitelib
78 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
81 # There should be a comment with CVS keywords on the first line of file.
83 if (!/# \$Revision:/) # If this line is already OK?
84 print "# $" "Revision:$, " "$" "Date:$" # No
87 next # It is enough for first line
91 # If the latest line matched /%files/
93 if (ENVIRON["SKIP_DEFATTR"] != 1) {
94 if ($0 !~ /defattr/) { # If no %defattr
95 print "%defattr(644,root,root,755)" # Add it
97 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
103 function b_makekey(a, b, s) {
106 gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
107 # kill commented out items
108 gsub(/[# \t]*/, "", s);
115 # - mixing BR/R and anything else confuses this (all will be sorted together)
117 # - comments leading the BR/R can not be associated,
118 # so don't adapterize when the BR/R are mixed with comments
119 ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && /(PreReq|(Build)?Requires)/, /(PreReq|(Build)?Requires)/ {
120 if ($1 ~ /PreReq:/) {
121 sub(/PreReq:/, "Requires:", $1);
126 l = substr($0, index($0, $2));
127 b_ktmp = b_makekey($1, l);
128 b_key[b_idx] = b_ktmp;
143 for (i = 1; i <= b_idx; i++) {
144 print "" b_val[b_key[i]];
151 /^#/ && (description == 0) {
152 if (/This file does not like to be adapterized!/) {
153 print # print this message
154 while (getline) # print the rest of spec as it is
156 do_not_touch_anything = 1 # do not touch anything in END()
160 # Generally, comments are printed without touching
167 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
168 if ($2 == "_applnkdir") {
175 # Do not add %define of _prefix if it already is.
176 if ($2 ~ /^_prefix/) {
177 sub("^"prefix, $3, bindir)
178 sub("^"prefix, $3, sbindir)
179 sub("^"prefix, $3, libdir)
180 sub("^"prefix, $3, datadir)
181 sub("^"prefix, $3, includedir)
185 if ($2 ~ /_bindir/ && !/_sbindir/)
191 if ($2 ~ /_sysconfdir/) {
193 # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
194 sysconfdir = "%%%%%%%%%%%%%%"
201 if ($2 ~ /_includedir/)
210 # version related macros
218 # these are used usually when adapterizing external spec
221 if ($2 ~ /^version$/)
223 if ($2 ~ /^release$/)
226 # do nothing further, otherwise adapter thinks we're at preamble
232 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
239 /^%description/, (!/^%description/ && $0 ~ SECTIONS) {
242 if (/^%description/) {
249 if (ENVIRON["SKIP_DESC"] != 1 && description == 1 && !/^%[a-z]+/ && !/^%description/) {
251 format_flush(format_line, format_indent)
255 } else if (/^[ \t]*[-\*][ \t]*/) {
256 format_flush(format_line, format_indent)
258 format_indent = RLENGTH
259 match($0, /^[ \t]*[-\*][ \t]/)
260 format_line = substr($0, RLENGTH)
262 format_line = format_line " " $0
266 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
267 if (NF > 3 && $2 == "-l") {
269 for (i = 4; i <= NF; i++)
273 format_flush(format_line, format_indent)
288 /^%prep/, (!/^%prep/ && $0 ~ SECTIONS) {
294 if (/^%setup/ && !/-q/) {
295 sub(/^%setup/, "%setup -q")
299 $0 = fixedsub(name, "%{name}", $0);
300 $0 = fixedsub(version, "%{version}", $0);
302 $0 = fixedsub(_beta, "%{_beta}", $0);
305 $0 = fixedsub(_rc, "%{_rc}", $0);
308 $0 = fixedsub(_snap, "%{_snap}", $0);
312 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
313 $0 = fixedsub(" -n %{name}-%{version}", "", $0)
317 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
323 /^%build/, (!/^%build/ && $0 ~ SECTIONS) {
332 if (/LDFLAGS="-s"/) {
333 removed["LDFLAGS"] = 1
336 split($0, tmp, "LDFLAGS=")
337 count = split(tmp[2], flags, "\"")
338 if (flags[1] != "" && flags[1] !~ "!?debug") {
339 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
340 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
341 for (i = 2; i < count; i++)
342 $0 = $0 flags[i] "\""
348 if (cflags("CFLAGS") == 0)
352 if (cflags("CXXFLAGS") == 0)
356 if (removed["LDFLAGS"])
358 if (removed["CFLAGS"])
360 if (removed["CXXFLAGS"])
362 # Is there still something?
369 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
372 # use PLD Linux macros
373 $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
374 $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
375 $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
377 sub(/^aclocal$/, "%{__aclocal}");
378 sub(/^autoheader$/, "%{__autoheader}");
379 sub(/^autoconf$/, "%{__autoconf}");
380 sub(/^automake$/, "%{__automake}");
383 $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
384 $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
390 /^%clean/, (!/^%clean/ && $0 ~ SECTIONS) {
393 # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
402 /^%install/, (!/^%install/ && $0 ~ SECTIONS) {
406 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
408 print "rm -rf $RPM_BUILD_ROOT"
412 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
413 print "rm -rf $RPM_BUILD_ROOT"
419 # 'install -d' instead 'mkdir -p'
421 sub(/mkdir -p/, "install -d")
423 # 'install' instead 'cp -p'
425 sub(/cp -p/, "install")
427 # No '-u root' or '-g root' for 'install'
428 if (/^install/ && /-[ug][ \t]*root/)
429 gsub(/-[ug][ \t]*root /, "")
431 if (/^install/ && /-m[ \t]*[0-9]+/)
432 gsub(/-m[ \t]*[0-9]+ /, "")
434 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
435 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
438 # No lines contain 'chmod' if it sets the modes to '644'
439 if ($1 ~ /chmod/ && $2 ~ /644/)
443 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
444 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
447 $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
453 /^%files/, (!/^%files/ && $0 ~ SECTIONS) {
465 /^%changelog/, (!/^%changelog/ && $0 ~ SECTIONS) {
469 # There should be some CVS keywords on the first line of %changelog.
471 if ($0 !~ _cvsmailfeedback)
472 print "* %{date} " _cvsmailfeedback > changelog_file
477 if (boc == 2 && !skip) {
478 if (!/All persons listed below/) {
479 printf "All persons listed below can be reached at " > changelog_file
480 print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
485 if (boc == 1 && !skip) {
488 print "$" "Log:$" > changelog_file
495 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
496 print " date +\"%a %b %d %Y\"`)" > changelog_file
503 if (!/^%[a-z]+$/ || /changelog/)
504 print > changelog_file
513 /^%pre/, (!/^%pre/ && $0 ~ SECTIONS) {
516 # %useradd and %groupadd may not be wrapped
517 if (/%(useradd|groupadd).*\\$/) {
520 $0 = substr(a, 1, length(a) - 1) $0;
524 /^%post/, (!/^%post/ && $0 ~ SECTIONS) {
528 /^%preun/, (!/^%preun/ && $0 ~ SECTIONS) {
531 /^%postun/, (!/^%postun/ && $0 ~ SECTIONS) {
534 /^%triggerin/, (!/^%triggerin/ && $0 ~ SECTIONS) {
537 /^%triggerun/, (!/^%triggerun/ && $0 ~ SECTIONS) {
540 /^%triggerpostun/, (!/^%triggerpostun/ && $0 ~ SECTIONS) {
543 /^%pretrans/, (!/^%pretrans/ && $0 ~ SECTIONS) {
546 /^%posttrans/, (!/^%posttrans/ && $0 ~ SECTIONS) {
554 # There should not be a space after the name of field
555 # and before the colon.
558 if (/^%perl_module_wo_prefix/) {
561 release = "0." fixedsub(".%{disttag}.at", "", $4)
566 if (field ~ /summary:/ && !/etc\.$/) {
569 if (field ~ /group(\([^)]+\)):/)
571 if (field ~ /group:/) {
573 sub(/^Utilities\//,"Applications/",$2)
574 sub(/^Games/,"Applications/Games",$2)
575 sub(/^X11\/Games/,"X11/Applications/Games",$2)
576 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
577 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
578 sub(/^X11\/GNOME/,"X11/Applications",$2)
579 sub(/^X11\/Utilities/,"X11/Applications",$2)
580 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
581 sub(/^Shells/,"Applications/Shells",$2)
583 sub(/^[^ \t]*[ \t]*/,"")
586 sub(/^System Environment\/Libraries$/, "Libraries", Grupa)
587 sub(/^System Environment\/Daemons$/, "Daemons", Grupa)
588 sub(/^Applications\/Internet$/, "Applications/Networking", Grupa)
589 sub(/^Applications\/Daemons$/, "Daemons", Grupa)
590 sub(/^Application\/Multimedia$/, "Applications/Multimedia", Grupa)
591 sub(/^System\/Servers$/, "Daemons", Grupa)
592 sub(/^X11\/Xserver$/, "X11/Servers", Grupa)
593 sub(/^X11\/XFree86/, "X11", Grupa)
594 sub(/^Applications\/Compilers$/, "Development/Languages", Grupa)
595 sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", Grupa)
596 sub(/^Networking\/Deamons$/, "Networking/Daemons", Grupa)
597 sub(/^Development\/Docs$/, "Documentation", Grupa)
599 print "Group:\t\t" Grupa
600 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
603 byl_plik_z_grupami = 0
605 while ((getline linia_grup < groups_file) > 0) {
606 byl_plik_z_grupami = 1
607 if (linia_grup == Grupa) {
613 if (!byl_plik_z_grupami)
614 print "######\t\t" groups_file ": no such file"
615 else if (!byl_opis_grupy)
616 print "######\t\t" "Unknown group!"
622 if (field ~ /prereq:/) {
623 sub(/PreReq:/, "Requires:", $1);
626 # split (build)requires, obsoletes on commas
627 if (field ~ /(obsoletes|requires):/ && $0 ~ /,/) {
628 l = substr($0, index($0, $2));
629 n = split(l, p, / *, */);
631 printf("%s\t%s\n", $1, p[i]);
636 if (field ~ /packager:|distribution:|docdir:|prefix:/)
639 if (field ~ /buildroot:/)
640 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
642 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
643 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
646 if (field ~ /name:/) {
647 if ($2 == "%{name}" && name) {
654 if (field ~ /version:/) {
655 if ($2 == "%{version}" && version) {
662 if (field ~ /release:/) {
663 if ($2 == "%{release}" && release) {
670 if (field ~ /serial:/)
674 if (field ~ /^url:$/)
677 # Use %{name} and %{version} in the filenames in "Source:"
678 if (field ~ /^source/ || field ~ /patch/) {
679 n = split($2, url, /\//)
680 if (url[n] ~ /\.gz$/) {
681 url[n+1] = ".gz" url[n+1]
682 sub(/\.gz$/,"",url[n])
684 if (url[n] ~ /\.zip$/) {
685 url[n+1] = ".zip" url[n+1]
686 sub(/\.zip$/,"",url[n])
688 if (url[n] ~ /\.tar$/) {
689 url[n+1] = ".tar" url[n+1]
690 sub(/\.tar$/,"",url[n])
692 if (url[n] ~ /\.patch$/) {
693 url[n+1] = ".patch" url[n+1]
694 sub(/\.patch$/,"",url[n])
696 if (url[n] ~ /\.bz2$/) {
697 url[n+1] = ".bz2" url[n+1]
698 sub(/\.bz2$/,"",url[n])
700 if (url[n] ~ /\.logrotate$/) {
701 url[n+1] = ".logrotate" url[n+1]
702 sub(/\.logrotate$/,"",url[n])
704 if (url[n] ~ /\.pamd$/) {
705 url[n+1] = ".pamd" url[n+1]
706 sub(/\.pamd$/,"",url[n])
709 # allow %{name} just in last url component
711 for (i = 1; i <= n; i++) {
712 url[i] = fixedsub("%{name}", name, url[i])
723 url[n] = fixedsub(name, "%{name}", url[n])
725 if (field ~ /source/) {
727 url[n] = fixedsub(version, "%{version}", url[n])
730 url[n] = fixedsub(_beta, "%{_beta}", url[n])
733 url[n] = fixedsub(_rc, "%{_rc}", url[n])
736 url[n] = fixedsub(_snap, "%{_snap}", url[n])
739 $2 = fixedsub(filename, url[n], $2)
742 sub("[?]use_mirror=.*$", "", $2);
743 sub("[?]download$", "", $2);
744 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
746 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
747 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
748 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
752 if (field ~ /^source:/)
755 if (field ~ /^patch:/)
760 if (field ~ /requires/) {
762 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
773 if (name_seen == 0 && name) {
778 if (version_seen == 0 && version) {
779 print "Version:\t" version
783 if (release_seen == 0 && release) {
784 print "Release:\t" release
791 if (do_not_touch_anything)
794 close(changelog_file)
795 while ((getline < changelog_file) > 0)
797 system("rm -f " changelog_file)
799 if (did_clean == 0) {
802 print "rm -rf $RPM_BUILD_ROOT"
807 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
810 if (has_changelog == 0)
814 print "* %{date} PLD Team <feedback@pld-linux.org>"
816 printf "All persons listed below can be reached at "
817 print "<cvs_login>@pld-linux.org\n"
823 function fixedsub(s1,s2,t, ind) {
824 # substitutes fixed strings (not regexps)
825 if (ind = index(t,s1))
826 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
830 # There should be one or two tabs after the colon.
831 function format_preamble()
834 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
842 # Replace directly specified directories with macros
843 function use_macros()
845 # -m, --skip-macros, --no-macros -- skip macros subst
846 if (ENVIRON["SKIP_MACROS"]) {
850 gsub(perl_sitearch, "%{perl_sitearch}")
851 gsub(perl_archlib, "%{perl_archlib}")
852 gsub(perl_privlib, "%{perl_privlib}")
853 gsub(perl_vendorlib, "%{perl_vendorlib}")
854 gsub(perl_vendorarch, "%{perl_vendorarch}")
855 gsub(perl_sitelib, "%{perl_sitelib}")
857 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
859 gsub(bindir, "%{_bindir}")
860 gsub("%{prefix}/bin", "%{_bindir}")
861 if(prefix"/bin" == bindir)
862 gsub("%{_prefix}/bin", "%{_bindir}")
864 for (c = 1; c <= NF; c++) {
865 if ($c ~ sbindir "/fix-info-dir")
867 if ($c ~ sbindir "/webapp")
869 if ($c ~ sbindir "/chsh")
871 if ($c ~ sbindir "/usermod")
873 gsub(sbindir, "%{_sbindir}", $c)
876 gsub("%{prefix}/sbin", "%{_sbindir}")
877 if (prefix"/sbin" == sbindir)
878 gsub("%{_prefix}/sbin", "%{_sbindir}")
880 for (c = 1; c <= NF; c++) {
881 if ($c ~ sysconfdir "/{?cron.")
883 if ($c ~ sysconfdir "/{?crontab.d")
885 if ($c ~ sysconfdir "/{?env.d")
887 if ($c ~ sysconfdir "/{?logrotate.d")
889 if ($c ~ sysconfdir "/{?pam.d")
891 if ($c ~ sysconfdir "/{?profile.d")
893 if ($c ~ sysconfdir "/{?rc.d")
895 if ($c ~ sysconfdir "/{?security")
897 if ($c ~ sysconfdir "/{?skel")
899 if ($c ~ sysconfdir "/{?sysconfig")
901 if ($c ~ sysconfdir "/{?shrc.d")
903 if ($c ~ sysconfdir "/{?certs")
905 if ($c ~ sysconfdir "/{?X11")
907 if ($c ~ sysconfdir "/{?ld.so.conf.d")
909 if ($c ~ sysconfdir "/{?httpd") # temp
911 gsub(sysconfdir, "%{_sysconfdir}", $c)
914 gsub(docdir, "%{_docdir}")
916 for (c = 1; c <= NF; c++) {
917 if ($c ~ datadir "/automake")
919 if ($c ~ datadir "/unsermake")
921 if ($c ~ datadir "/file/magic.mime")
923 gsub(datadir, "%{_datadir}", $c)
926 gsub("%{prefix}/share", "%{_datadir}")
927 if (prefix"/share" == datadir)
928 gsub("%{_prefix}/share", "%{_datadir}")
930 # CFLAGS="-I/usr/include/ncurses is usually correct.
931 if (!/-I\/usr\/include/) {
932 gsub(includedir, "%{_includedir}")
935 gsub("%{prefix}/include", "%{_includedir}")
936 if (prefix"/include" == includedir) {
937 gsub("%{_prefix}/include", "%{_includedir}")
940 gsub(mandir, "%{_mandir}")
941 if ($0 !~ "%{_datadir}/manual") {
942 gsub("%{_datadir}/man", "%{_mandir}")
944 gsub("%{_prefix}/share/man", "%{_mandir}")
945 gsub("%{prefix}/share/man", "%{_mandir}")
946 gsub("%{prefix}/man", "%{_mandir}")
947 gsub("%{_prefix}/man", "%{_mandir}")
949 gsub(infodir, "%{_infodir}")
950 gsub("%{prefix}/info", "%{_infodir}")
951 gsub("%{_prefix}/info", "%{_infodir}")
953 if (prefix !~ "/X11R6") {
954 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
957 gsub(examplesdir, "%{_examplesdir}")
960 # leave --with-foo=/usr alone
961 if ($0 !~ "--with.*=.*" prefix) {
962 for (c = 1; c <= NF; c++) {
963 if ($c ~ prefix "/sbin/fix-info-dir")
965 if ($c ~ prefix "/sbin/webapp")
967 if ($c ~ prefix "/sbin/chsh")
969 if ($c ~ prefix "/sbin/usermod")
971 if ($c ~ prefix "/share/automake")
973 if ($c ~ prefix "/share/unsermake")
975 if ($c ~ prefix "/lib/sendmail")
977 if ($c ~ prefix "/lib/pkgconfig")
980 # CFLAGS="-I/usr..." is usually correct.
983 # same for LDFLAGS="-L/usr..."
987 gsub(prefix, "%{_prefix}", $c)
990 gsub("%{prefix}", "%{_prefix}")
994 gsub("%{_includedir}/ncurses", "/usr/include/ncurses")
995 gsub("%{_includedir}/freetype", "/usr/include/freetype")
997 gsub("%{PACKAGE_VERSION}", "%{version}")
998 gsub("%{PACKAGE_NAME}", "%{name}")
1000 gsub("^make$", "%{__make}")
1001 gsub("^make ", "%{__make} ")
1002 gsub("^gcc ", "%{__cc} ")
1005 gsub("^%make$", "%{__make}")
1006 gsub("^%make ", "%{__make} ")
1007 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1008 gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1009 gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1010 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
1011 gsub("^%{__install}", "install")
1012 gsub("^%{__rm}", "rm")
1013 gsub("%optflags", "%{rpmcflags}")
1014 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
1016 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1017 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
1018 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
1019 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
1020 $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
1022 gsub("%_bindir", "%{_bindir}")
1023 gsub("%_datadir", "%{_datadir}")
1024 gsub("%_iconsdir", "%{_iconsdir}")
1025 gsub("%_sbindir", "%{_sbindir}")
1026 gsub("%_mandir", "%{_mandir}")
1027 gsub("%name", "%{name}")
1029 gsub("/usr/src/linux", "%{_kernelsrcdir}")
1030 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
1034 # insertion sort of A[1..n]
1035 # copied from mawk manual
1036 function isort(A,n, i,j,hold) {
1037 for (i = 2; i <= n; i++) {
1039 while (A[j-1] > hold) {
1044 # sentinel A[0] = "" will be created if needed
1048 function use_files_macros( i, n, t, a)
1052 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1053 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1055 # uid/gid nobody is not valid in %files
1056 if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1057 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1061 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1062 gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1063 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1064 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1065 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1066 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1067 gsub("%{_sysconfdir}/security", "/etc/security")
1068 gsub("%{_sysconfdir}/skel", "/etc/skel")
1069 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1070 gsub("%{_sysconfdir}/certs", "/etc/certs")
1071 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1073 # /etc/init.d -> /etc/rc.d/init.d
1074 if (!/^\/etc\/init\.d$/) {
1075 gsub("/etc/init.d", "/etc/rc.d/init.d")
1078 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1079 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1080 $0 = "%attr(754,root,root) " $0
1082 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1083 gsub("^%attr\\(... *,", "%attr(754,");
1087 if (/lib.+\.so/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1088 $0 = "%attr(755,root,root) " $0
1091 # /etc/sysconfig files
1092 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1093 # attr not required, allow default 644 attr
1094 if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1095 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1096 gsub("%config", "%config(noreplace)")
1099 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1100 $NF = "%config(noreplace) " $NF
1103 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1104 gsub("^%attr\\(... *,", "%attr(640,");
1107 if (/\/etc\/sysconfig\// && !/%verify/) {
1108 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1112 # kill leading zeros
1113 if (/%attr\(0[1-9]/) {
1114 gsub("%attr\\(0", "%attr(")
1117 # sort %verify attrs
1118 if (match($0, /%verify\(not([^)]+)\)/)) {
1119 t = substr($0, RSTART, RLENGTH)
1120 # kill commas: %verify(not,md5,size,mtime)
1123 gsub(/^%verify\(not |\)$/, "", t)
1124 n = split(t, a, / /)
1128 for (i = 1 ; i <= n; i++) {
1133 gsub(/%verify\(not[^)]+\)/, s)
1140 # locale dir and no %lang -> bad
1141 if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1142 $(NF + 1) = "# FIXME consider using %find_lang"
1146 $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1147 $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1148 $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1150 gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1151 gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1152 gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1154 gsub("%{_datadir}/applications", "%{_desktopdir}");
1155 gsub("%{_datadir}/icons", "%{_iconsdir}");
1156 gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1159 function fill(ch, n, i) {
1160 for (i = 0; i < n; i++)
1164 function format_flush(line, indent, newline, word, first_word) {
1166 if (format_indent == -1)
1169 newline = fill(" ", format_indent) "- "
1171 while (match(line, /[^\t ]+/)) {
1172 word = substr(line, RSTART, RLENGTH)
1173 if (length(newline) + length(word) + 1 > tw) {
1176 if (format_indent == -1)
1179 newline = fill(" ", format_indent + 2)
1184 newline = newline word
1187 newline = newline " " word
1189 line = substr(line, RSTART + RLENGTH)
1191 if (newline ~ /[^\t ]/) {
1196 function cflags(var)
1198 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1204 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")