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 RPM_SECTIONS = "package|build|changelog|clean|description|install|post|posttrans|postun|pre|prep|pretrans|preun|triggerin|triggerpostun|triggerun"
25 SECTIONS = "^%(" RPM_SECTIONS ")"
27 preamble = 1 # Is it part of preamble? Default - yes
28 boc = 4 # Beginning of %changelog
29 bod = 0 # Beginning of %description
30 tw = 70 # Descriptions width
32 b_idx = 0 # index of BR/R arrays
34 # If variable removed, then 1 (for removing it from export)
35 removed["LDFLAGS"] = 0
37 removed["CXXFLAGS"] = 0
39 # get cvsaddress for changelog section
40 # using rpm macros as too lazy to add ~/.adapterrc parsing support.
41 "rpm --eval '%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'" | getline _cvsmaildomain
42 "rpm --eval '%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'" | getline _cvsmailfeedback
44 # If 1, we are inside of comment block (started with /^#%/)
47 # File with rpm groups
48 "rpm --eval %_sourcedir" | getline groups_file
49 groups_file = groups_file "/rpm.groups"
50 system("cd `rpm --eval %_sourcedir`; [ -f rpm.groups ] || cvs up rpm.groups >/dev/null")
52 # Temporary file for changelog section
53 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
56 "rpm --eval %_prefix" | getline prefix
57 "rpm --eval %_bindir" | getline bindir
58 "rpm --eval %_sbindir" | getline sbindir
59 "rpm --eval %_libdir" | getline libdir
60 "rpm --eval %_sysconfdir" | getline sysconfdir
61 "rpm --eval %_datadir" | getline datadir
62 "rpm --eval %_includedir" | getline includedir
63 "rpm --eval %_mandir" | getline mandir
64 "rpm --eval %_infodir" | getline infodir
65 "rpm --eval %_examplesdir" | getline examplesdir
67 "rpm --eval %perl_sitearch" | getline perl_sitearch
68 "rpm --eval %perl_archlib" | getline perl_archlib
69 "rpm --eval %perl_privlib" | getline perl_privlib
70 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
71 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
72 "rpm --eval %perl_sitelib" | getline perl_sitelib
74 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
77 # There should be a comment with CVS keywords on the first line of file.
79 if (!/# \$Revision:/) # If this line is already OK?
80 print "# $" "Revision:$, " "$" "Date:$" # No
83 next # It is enough for first line
87 # If the latest line matched /%files/
89 if (ENVIRON["SKIP_DEFATTR"] != 1) {
90 if ($0 !~ /defattr/) { # If no %defattr
91 print "%defattr(644,root,root,755)" # Add it
93 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
99 function b_makekey(a, b, s) {
102 gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
103 # kill commented out items
104 gsub(/[# \t]*/, "", s);
111 # - mixing BR/R and anything else confuses this (all will be sorted together)
113 # - comments leading the BR/R can not be associated,
114 # so don't adapterize when the BR/R are mixed with comments
115 ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && /(PreReq|(Build)?Requires)/, /(PreReq|(Build)?Requires)/ {
116 if ($1 ~ /PreReq:/) {
117 sub(/PreReq:/, "Requires:", $1);
122 l = substr($0, index($0, $2));
123 b_ktmp = b_makekey($1, l);
124 b_key[b_idx] = b_ktmp;
139 for (i = 1; i <= b_idx; i++) {
140 print "" b_val[b_key[i]];
147 /^#/ && (description == 0) {
148 if (/This file does not like to be adapterized!/) {
149 print # print this message
150 while (getline) # print the rest of spec as it is
152 do_not_touch_anything = 1 # do not touch anything in END()
156 # Generally, comments are printed without touching
163 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
164 if ($2 == "_applnkdir") {
171 # Do not add %define of _prefix if it already is.
172 if ($2 ~ /^_prefix/) {
173 sub("^"prefix, $3, bindir)
174 sub("^"prefix, $3, sbindir)
175 sub("^"prefix, $3, libdir)
176 sub("^"prefix, $3, datadir)
177 sub("^"prefix, $3, includedir)
181 if ($2 ~ /_bindir/ && !/_sbindir/)
187 if ($2 ~ /_sysconfdir/) {
189 # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
190 sysconfdir = "%%%%%%%%%%%%%%"
197 if ($2 ~ /_includedir/)
204 # version related macros
212 # these are used usually when adapterizing external spec
215 if ($2 ~ /^version$/)
217 if ($2 ~ /^release$/)
220 # do nothing further, otherwise adapter thinks we're at preamble
226 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
233 /^%description/, (!/^%description/ && $0 ~ SECTIONS) {
236 if (/^%description/) {
243 if (ENVIRON["SKIP_DESC"] != 1 && description == 1 && !/^%[a-z]+/ && !/^%description/) {
245 format_flush(format_line, format_indent)
249 } else if (/^[ \t]*[-\*][ \t]*/) {
250 format_flush(format_line, format_indent)
252 format_indent = RLENGTH
253 match($0, /^[ \t]*[-\*][ \t]/)
254 format_line = substr($0, RLENGTH)
256 format_line = format_line " " $0
260 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
261 if (NF > 3 && $2 == "-l") {
263 for (i = 4; i <= NF; i++)
267 format_flush(format_line, format_indent)
282 /^%prep/, (!/^%prep/ && $0 ~ SECTIONS) {
288 if (/^%setup/ && !/-q/) {
289 sub(/^%setup/, "%setup -q")
293 $0 = fixedsub(name, "%{name}", $0);
294 $0 = fixedsub(version, "%{version}", $0);
296 $0 = fixedsub(_beta, "%{_beta}", $0);
299 $0 = fixedsub(_rc, "%{_rc}", $0);
302 $0 = fixedsub(_snap, "%{_snap}", $0);
306 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
307 $0 = fixedsub(" -n %{name}-%{version}", "", $0)
311 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
317 /^%build/, (!/^%build/ && $0 ~ SECTIONS) {
326 if (/LDFLAGS="-s"/) {
327 removed["LDFLAGS"] = 1
330 split($0, tmp, "LDFLAGS=")
331 count = split(tmp[2], flags, "\"")
332 if (flags[1] != "" && flags[1] !~ "!?debug") {
333 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
334 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
335 for (i = 2; i < count; i++)
336 $0 = $0 flags[i] "\""
342 if (cflags("CFLAGS") == 0)
346 if (cflags("CXXFLAGS") == 0)
350 if (removed["LDFLAGS"])
352 if (removed["CFLAGS"])
354 if (removed["CXXFLAGS"])
356 # Is there still something?
363 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
366 # use PLD Linux macros
367 $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
368 $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
369 $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
371 sub(/^aclocal$/, "%{__aclocal}");
372 sub(/^autoheader$/, "%{__autoheader}");
373 sub(/^autoconf$/, "%{__autoconf}");
374 sub(/^automake$/, "%{__automake}");
377 $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
378 $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
384 /^%clean/, (!/^%clean/ && $0 ~ SECTIONS) {
387 # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
396 /^%install/, (!/^%install/ && $0 ~ SECTIONS) {
400 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
402 print "rm -rf $RPM_BUILD_ROOT"
406 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
407 print "rm -rf $RPM_BUILD_ROOT"
413 # 'install -d' instead 'mkdir -p'
415 sub(/mkdir -p/, "install -d")
417 # 'install' instead 'cp -p'
419 sub(/cp -p/, "install")
421 # No '-u root' or '-g root' for 'install'
422 if (/^install/ && /-[ug][ \t]*root/)
423 gsub(/-[ug][ \t]*root /, "")
425 if (/^install/ && /-m[ \t]*[0-9]+/)
426 gsub(/-m[ \t]*[0-9]+ /, "")
428 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
429 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
432 # No lines contain 'chmod' if it sets the modes to '644'
433 if ($1 ~ /chmod/ && $2 ~ /644/)
437 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
438 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
441 $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
447 /^%files/, (!/^%files/ && $0 ~ SECTIONS) {
459 /^%changelog/, (!/^%changelog/ && $0 ~ SECTIONS) {
463 # There should be some CVS keywords on the first line of %changelog.
465 if ($0 !~ _cvsmailfeedback)
466 print "* %{date} " _cvsmailfeedback > changelog_file
471 if (boc == 2 && !skip) {
472 if (!/All persons listed below/) {
473 printf "All persons listed below can be reached at " > changelog_file
474 print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
479 if (boc == 1 && !skip) {
482 print "$" "Log:$" > changelog_file
489 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
490 print " date +\"%a %b %d %Y\"`)" > changelog_file
497 if (!/^%[a-z]+$/ || /changelog/)
498 print > changelog_file
507 /^%pre/, (!/^%pre/ && $0 ~ SECTIONS) {
510 # %useradd and %groupadd may not be wrapped
511 if (/%(useradd|groupadd).*\\$/) {
514 $0 = substr(a, 1, length(a) - 1) $0;
518 /^%post/, (!/^%post/ && $0 ~ SECTIONS) {
521 /^%preun/, (!/^%preun/ && $0 ~ SECTIONS) {
524 /^%postun/, (!/^%postun/ && $0 ~ SECTIONS) {
527 /^%triggerin/, (!/^%triggerin/ && $0 ~ SECTIONS) {
530 /^%triggerun/, (!/^%triggerun/ && $0 ~ SECTIONS) {
533 /^%triggerpostun/, (!/^%triggerpostun/ && $0 ~ SECTIONS) {
536 /^%pretrans/, (!/^%pretrans/ && $0 ~ SECTIONS) {
539 /^%posttrans/, (!/^%posttrans/ && $0 ~ SECTIONS) {
547 # There should not be a space after the name of field
548 # and before the colon.
551 if (/^%perl_module_wo_prefix/) {
554 release = "0." fixedsub(".%{disttag}.at", "", $4)
559 if (field ~ /summary:/) {
562 if (field ~ /group(\([^)]+\)):/)
564 if (field ~ /group:/) {
566 sub(/^Utilities\//,"Applications/",$2)
567 sub(/^Games/,"Applications/Games",$2)
568 sub(/^X11\/Games/,"X11/Applications/Games",$2)
569 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
570 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
571 sub(/^X11\/GNOME/,"X11/Applications",$2)
572 sub(/^X11\/Utilities/,"X11/Applications",$2)
573 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
574 sub(/^Shells/,"Applications/Shells",$2)
576 sub(/^[^ \t]*[ \t]*/,"")
579 sub(/^System Environment\/Libraries$/, "Libraries", Grupa)
580 sub(/^System Environment\/Daemons$/, "Daemons", Grupa)
581 sub(/^Applications\/Internet$/, "Applications/Networking", Grupa)
582 sub(/^Applications\/Daemons$/, "Daemons", Grupa)
583 sub(/^Application\/Multimedia$/, "Applications/Multimedia", Grupa)
584 sub(/^System\/Servers$/, "Daemons", Grupa)
585 sub(/^X11\/Xserver$/, "X11/Servers", Grupa)
586 sub(/^X11\/XFree86/, "X11", Grupa)
587 sub(/^Applications\/Compilers$/, "Development/Languages", Grupa)
588 sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", Grupa)
589 sub(/^Networking\/Deamons$/, "Networking/Daemons", Grupa)
590 sub(/^Development\/Docs$/, "Documentation", Grupa)
592 print "Group:\t\t" Grupa
593 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
596 byl_plik_z_grupami = 0
598 while ((getline linia_grup < groups_file) > 0) {
599 byl_plik_z_grupami = 1
600 if (linia_grup == Grupa) {
606 if (!byl_plik_z_grupami)
607 print "######\t\t" groups_file ": no such file"
608 else if (!byl_opis_grupy)
609 print "######\t\t" "Unknown group!"
615 if (field ~ /prereq:/) {
616 sub(/PreReq:/, "Requires:", $1);
619 # split (build)requires, obsoletes on commas
620 if (field ~ /(obsoletes|requires):/ && $0 ~ /,/) {
621 l = substr($0, index($0, $2));
622 n = split(l, p, / *, */);
624 printf("%s\t%s\n", $1, p[i]);
629 if (field ~ /packager:|distribution:|docdir:|prefix:/)
632 if (field ~ /buildroot:/)
633 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
635 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
636 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
639 if (field ~ /name:/) {
640 if ($2 == "%{name}" && name) {
647 if (field ~ /version:/) {
648 if ($2 == "%{version}" && version) {
655 if (field ~ /release:/) {
656 if ($2 == "%{release}" && release) {
663 if (field ~ /serial:/)
667 if (field ~ /^url:$/)
670 # Use %{name} and %{version} in the filenames in "Source:"
671 if (field ~ /^source/ || field ~ /patch/) {
672 n = split($2, url, /\//)
673 if (url[n] ~ /\.gz$/) {
674 url[n+1] = ".gz" url[n+1]
675 sub(/\.gz$/,"",url[n])
677 if (url[n] ~ /\.zip$/) {
678 url[n+1] = ".zip" url[n+1]
679 sub(/\.zip$/,"",url[n])
681 if (url[n] ~ /\.tar$/) {
682 url[n+1] = ".tar" url[n+1]
683 sub(/\.tar$/,"",url[n])
685 if (url[n] ~ /\.patch$/) {
686 url[n+1] = ".patch" url[n+1]
687 sub(/\.patch$/,"",url[n])
689 if (url[n] ~ /\.bz2$/) {
690 url[n+1] = ".bz2" url[n+1]
691 sub(/\.bz2$/,"",url[n])
693 if (url[n] ~ /\.logrotate$/) {
694 url[n+1] = ".logrotate" url[n+1]
695 sub(/\.logrotate$/,"",url[n])
697 if (url[n] ~ /\.pamd$/) {
698 url[n+1] = ".pamd" url[n+1]
699 sub(/\.pamd$/,"",url[n])
702 # allow %{name} just in last url component
704 for (i = 1; i <= n; i++) {
705 url[i] = fixedsub("%{name}", name, url[i])
716 url[n] = fixedsub(name, "%{name}", url[n])
718 if (field ~ /source/) {
720 url[n] = fixedsub(version, "%{version}", url[n])
723 url[n] = fixedsub(_beta, "%{_beta}", url[n])
726 url[n] = fixedsub(_rc, "%{_rc}", url[n])
729 url[n] = fixedsub(_snap, "%{_snap}", url[n])
732 $2 = fixedsub(filename, url[n], $2)
735 sub("[?]use_mirror=.*$", "", $2);
736 sub("[?]download$", "", $2);
737 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
739 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
740 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
741 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
745 if (field ~ /^source:/)
748 if (field ~ /^patch:/)
753 if (field ~ /requires/) {
755 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
766 if (name_seen == 0 && name) {
771 if (version_seen == 0 && version) {
772 print "Version:\t" version
776 if (release_seen == 0 && release) {
777 print "Release:\t" release
784 if (do_not_touch_anything)
787 close(changelog_file)
788 while ((getline < changelog_file) > 0)
790 system("rm -f " changelog_file)
792 if (did_clean == 0) {
795 print "rm -rf $RPM_BUILD_ROOT"
800 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
803 if (has_changelog == 0)
807 print "* %{date} PLD Team <feedback@pld-linux.org>"
809 printf "All persons listed below can be reached at "
810 print "<cvs_login>@pld-linux.org\n"
816 function fixedsub(s1,s2,t, ind) {
817 # substitutes fixed strings (not regexps)
818 if (ind = index(t,s1))
819 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
823 # There should be one or two tabs after the colon.
824 function format_preamble()
827 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
835 # Replace directly specified directories with macros
836 function use_macros()
838 # -m, --skip-macros, --no-macros -- skip macros subst
839 if (ENVIRON["SKIP_MACROS"]) {
843 gsub(perl_sitearch, "%{perl_sitearch}")
844 gsub(perl_archlib, "%{perl_archlib}")
845 gsub(perl_privlib, "%{perl_privlib}")
846 gsub(perl_vendorlib, "%{perl_vendorlib}")
847 gsub(perl_vendorarch, "%{perl_vendorarch}")
848 gsub(perl_sitelib, "%{perl_sitelib}")
850 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
852 gsub(bindir, "%{_bindir}")
853 gsub("%{prefix}/bin", "%{_bindir}")
854 if(prefix"/bin" == bindir)
855 gsub("%{_prefix}/bin", "%{_bindir}")
857 for (c = 1; c <= NF; c++) {
858 if ($c ~ sbindir "/fix-info-dir")
860 if ($c ~ sbindir "/webapp")
862 if ($c ~ sbindir "/chsh")
864 if ($c ~ sbindir "/usermod")
866 gsub(sbindir, "%{_sbindir}", $c)
869 gsub("%{prefix}/sbin", "%{_sbindir}")
870 if (prefix"/sbin" == sbindir)
871 gsub("%{_prefix}/sbin", "%{_sbindir}")
873 for (c = 1; c <= NF; c++) {
874 if ($c ~ sysconfdir "/{?cron.")
876 if ($c ~ sysconfdir "/{?crontab.d")
878 if ($c ~ sysconfdir "/{?env.d")
880 if ($c ~ sysconfdir "/{?logrotate.d")
882 if ($c ~ sysconfdir "/{?pam.d")
884 if ($c ~ sysconfdir "/{?profile.d")
886 if ($c ~ sysconfdir "/{?rc.d")
888 if ($c ~ sysconfdir "/{?security")
890 if ($c ~ sysconfdir "/{?skel")
892 if ($c ~ sysconfdir "/{?sysconfig")
894 if ($c ~ sysconfdir "/{?shrc.d")
896 if ($c ~ sysconfdir "/{?certs")
898 if ($c ~ sysconfdir "/{?X11")
900 if ($c ~ sysconfdir "/{?ld.so.conf.d")
902 if ($c ~ sysconfdir "/{?httpd") # temp
904 gsub(sysconfdir, "%{_sysconfdir}", $c)
907 for (c = 1; c <= NF; c++) {
908 if ($c ~ datadir "/automake")
910 if ($c ~ datadir "/unsermake")
912 if ($c ~ datadir "/file/magic.mime")
914 gsub(datadir, "%{_datadir}", $c)
917 gsub("%_sbindir", "%{_sbindir}")
918 gsub("%_mandir", "%{_mandir}")
919 gsub("%name", "%{name}")
921 gsub("%{prefix}/share", "%{_datadir}")
922 if (prefix"/share" == datadir)
923 gsub("%{_prefix}/share", "%{_datadir}")
925 # CFLAGS="-I/usr/include/ncurses is usually correct.
926 if (!/-I\/usr\/include/) {
927 gsub(includedir, "%{_includedir}")
930 gsub("%{prefix}/include", "%{_includedir}")
931 if (prefix"/include" == includedir) {
932 gsub("%{_prefix}/include", "%{_includedir}")
935 gsub(mandir, "%{_mandir}")
936 if ($0 !~ "%{_datadir}/manual") {
937 gsub("%{_datadir}/man", "%{_mandir}")
939 gsub("%{_prefix}/share/man", "%{_mandir}")
940 gsub("%{prefix}/share/man", "%{_mandir}")
941 gsub("%{prefix}/man", "%{_mandir}")
942 gsub("%{_prefix}/man", "%{_mandir}")
944 gsub(infodir, "%{_infodir}")
945 gsub("%{prefix}/info", "%{_infodir}")
946 gsub("%{_prefix}/info", "%{_infodir}")
948 if (prefix !~ "/X11R6") {
949 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
952 gsub(examplesdir, "%{_examplesdir}")
955 # leave --with-foo=/usr alone
956 if ($0 !~ "--with.*=.*" prefix) {
957 for (c = 1; c <= NF; c++) {
958 if ($c ~ prefix "/sbin/fix-info-dir")
960 if ($c ~ prefix "/sbin/webapp")
962 if ($c ~ prefix "/sbin/chsh")
964 if ($c ~ prefix "/sbin/usermod")
966 if ($c ~ prefix "/share/automake")
968 if ($c ~ prefix "/share/unsermake")
970 if ($c ~ prefix "/lib/sendmail")
972 if ($c ~ prefix "/lib/pkgconfig")
975 # CFLAGS="-I/usr..." is usually correct.
978 # same for LDFLAGS="-L/usr..."
982 gsub(prefix, "%{_prefix}", $c)
985 gsub("%{prefix}", "%{_prefix}")
988 gsub("%{PACKAGE_VERSION}", "%{version}")
989 gsub("%{PACKAGE_NAME}", "%{name}")
991 gsub("^make$", "%{__make}")
992 gsub("^make ", "%{__make} ")
993 gsub("^gcc ", "%{__cc} ")
996 gsub("^%make$", "%{__make}")
997 gsub("^%make ", "%{__make} ")
998 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
999 gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1000 gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1001 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
1002 gsub("^%{__install}", "install")
1003 gsub("^%{__rm}", "rm")
1004 gsub("%optflags", "%{rpmcflags}")
1005 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
1007 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1008 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
1009 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
1010 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
1011 $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
1013 gsub("%_bindir", "%{_bindir}")
1014 gsub("%_datadir", "%{_datadir}")
1015 gsub("%_iconsdir", "%{_iconsdir}")
1017 gsub("/usr/src/linux", "%{_kernelsrcdir}")
1018 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
1022 # insertion sort of A[1..n]
1023 # copied from mawk manual
1024 function isort(A,n, i,j,hold) {
1025 for (i = 2; i <= n; i++) {
1027 while (A[j-1] > hold) {
1032 # sentinel A[0] = "" will be created if needed
1036 function use_files_macros( i, n, t, a)
1040 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1041 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1043 # uid/gid nobody is not valid in %files
1044 if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1045 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1049 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1050 gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1051 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1052 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1053 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1054 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1055 gsub("%{_sysconfdir}/security", "/etc/security")
1056 gsub("%{_sysconfdir}/skel", "/etc/skel")
1057 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1058 gsub("%{_sysconfdir}/certs", "/etc/certs")
1059 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1061 # /etc/init.d -> /etc/rc.d/init.d
1062 if (!/^\/etc\/init\.d$/) {
1063 gsub("/etc/init.d", "/etc/rc.d/init.d")
1066 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1067 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1068 $0 = "%attr(754,root,root) " $0
1070 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1071 gsub("^%attr\\(... *,", "%attr(754,");
1075 if (/lib.+\.so/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1076 $0 = "%attr(755,root,root) " $0
1079 # /etc/sysconfig files
1080 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1081 # attr not required, allow default 644 attr
1082 if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1083 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1084 gsub("%config", "%config(noreplace)")
1087 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1088 $NF = "%config(noreplace) " $NF
1091 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1092 gsub("^%attr\\(... *,", "%attr(640,");
1095 if (/\/etc\/sysconfig\// && !/%verify/) {
1096 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1100 # kill leading zeros
1101 if (/%attr\(0[1-9]/) {
1102 gsub("%attr\\(0", "%attr(")
1105 # sort %verify attrs
1106 if (match($0, /%verify\(not([^)]+)\)/)) {
1107 t = substr($0, RSTART, RLENGTH)
1108 # kill commas: %verify(not,md5,size,mtime)
1111 gsub(/^%verify\(not |\)$/, "", t)
1112 n = split(t, a, / /)
1116 for (i = 1 ; i <= n; i++) {
1121 gsub(/%verify\(not[^)]+\)/, s)
1128 # locale dir and no %lang -> bad
1129 if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1130 $(NF + 1) = "# FIXME consider using %find_lang"
1134 $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1135 $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1136 $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1138 gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1139 gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1140 gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1142 gsub("%{_datadir}/applications", "%{_desktopdir}");
1143 gsub("%{_datadir}/icons", "%{_iconsdir}");
1144 gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1147 function fill(ch, n, i) {
1148 for (i = 0; i < n; i++)
1152 function format_flush(line, indent, newline, word, first_word) {
1154 if (format_indent == -1)
1157 newline = fill(" ", format_indent) "- "
1159 while (match(line, /[^\t ]+/)) {
1160 word = substr(line, RSTART, RLENGTH)
1161 if (length(newline) + length(word) + 1 > tw) {
1164 if (format_indent == -1)
1167 newline = fill(" ", format_indent + 2)
1172 newline = newline word
1175 newline = newline " " word
1177 line = substr(line, RSTART + RLENGTH)
1179 if (newline ~ /[^\t ]/) {
1184 function cflags(var)
1186 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1192 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")