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 SECTIONS = "^%(build|changelog|clean|description|install|post|posttrans|postun|pre|prep|pretrans|preun|triggerin|triggerpostun|triggerun)"
26 preamble = 1 # Is it part of preamble? Default - yes
27 boc = 4 # Beginning of %changelog
28 bod = 0 # Beginning of %description
29 tw = 70 # Descriptions width
31 b_idx = 0 # index of BR/R arrays
33 # If variable removed, then 1 (for removing it from export)
34 removed["LDFLAGS"] = 0
36 removed["CXXFLAGS"] = 0
38 # get cvsaddress for changelog section
39 # using rpm macros as too lazy to add ~/.adapterrc parsing support.
40 "rpm --eval '%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'" | getline _cvsmaildomain
41 "rpm --eval '%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'" | getline _cvsmailfeedback
43 # If 1, we are inside of comment block (started with /^#%/)
46 # File with rpm groups
47 "rpm --eval %_sourcedir" | getline groups_file
48 groups_file = groups_file "/rpm.groups"
49 system("cd `rpm --eval %_sourcedir`; [ -f rpm.groups ] || cvs up rpm.groups >/dev/null")
51 # Temporary file for changelog section
52 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
55 "rpm --eval %_prefix" | getline prefix
56 "rpm --eval %_bindir" | getline bindir
57 "rpm --eval %_sbindir" | getline sbindir
58 "rpm --eval %_libdir" | getline libdir
59 "rpm --eval %_sysconfdir" | getline sysconfdir
60 "rpm --eval %_datadir" | getline datadir
61 "rpm --eval %_includedir" | getline includedir
62 "rpm --eval %_mandir" | getline mandir
63 "rpm --eval %_infodir" | getline infodir
64 "rpm --eval %_examplesdir" | getline examplesdir
66 "rpm --eval %perl_sitearch" | getline perl_sitearch
67 "rpm --eval %perl_archlib" | getline perl_archlib
68 "rpm --eval %perl_privlib" | getline perl_privlib
69 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
70 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
71 "rpm --eval %perl_sitelib" | getline perl_sitelib
73 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
76 # There should be a comment with CVS keywords on the first line of file.
78 if (!/# \$Revision:/) # If this line is already OK?
79 print "# $" "Revision:$, " "$" "Date:$" # No
82 next # It is enough for first line
86 # If the latest line matched /%files/
88 if (ENVIRON["SKIP_DEFATTR"] != 1) {
89 if ($0 !~ /defattr/) { # If no %defattr
90 print "%defattr(644,root,root,755)" # Add it
92 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
98 function b_makekey(a, b, s) {
101 gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
102 # kill commented out items
103 gsub(/[# \t]*/, "", s);
110 # - mixing BR/R and anything else confuses this (all will be sorted together)
112 # - comments leading the BR/R can not be associated,
113 # so don't adapterize when the BR/R are mixed with comments
114 ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && /(PreReq|(Build)?Requires)/, /(PreReq|(Build)?Requires)/ {
115 if ($1 ~ /PreReq:/) {
116 sub(/PreReq:/, "Requires:", $1);
121 l = substr($0, index($0, $2));
122 b_ktmp = b_makekey($1, l);
123 b_key[b_idx] = b_ktmp;
138 for (i = 1; i <= b_idx; i++) {
139 print "" b_val[b_key[i]];
146 /^#/ && (description == 0) {
147 if (/This file does not like to be adapterized!/) {
148 print # print this message
149 while (getline) # print the rest of spec as it is
151 do_not_touch_anything = 1 # do not touch anything in END()
155 # Generally, comments are printed without touching
162 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
163 if ($2 == "_applnkdir") {
170 # Do not add %define of _prefix if it already is.
171 if ($2 ~ /^_prefix/) {
172 sub("^"prefix, $3, bindir)
173 sub("^"prefix, $3, sbindir)
174 sub("^"prefix, $3, libdir)
175 sub("^"prefix, $3, datadir)
176 sub("^"prefix, $3, includedir)
180 if ($2 ~ /_bindir/ && !/_sbindir/)
186 if ($2 ~ /_sysconfdir/) {
188 # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
189 sysconfdir = "%%%%%%%%%%%%%%"
196 if ($2 ~ /_includedir/)
203 # version related macros
211 # these are used usually when adapterizing external spec
214 if ($2 ~ /^version$/)
216 if ($2 ~ /^release$/)
219 # do nothing further, otherwise adapter thinks we're at preamble
225 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
232 /^%description/, (!/^%description/ && $0 ~ SECTIONS) {
235 if (/^%description/) {
242 if (ENVIRON["SKIP_DESC"] != 1 && description == 1 && !/^%[a-z]+/ && !/^%description/) {
244 format_flush(format_line, format_indent)
248 } else if (/^[ \t]*[-\*][ \t]*/) {
249 format_flush(format_line, format_indent)
251 format_indent = RLENGTH
252 match($0, /^[ \t]*[-\*][ \t]/)
253 format_line = substr($0, RLENGTH)
255 format_line = format_line " " $0
259 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
260 if (NF > 3 && $2 == "-l") {
262 for (i = 4; i <= NF; i++)
266 format_flush(format_line, format_indent)
281 /^%prep/, (!/^%prep/ && $0 ~ SECTIONS) {
287 if (/^%setup/ && !/-q/) {
288 sub(/^%setup/, "%setup -q")
292 $0 = fixedsub(name, "%{name}", $0);
293 $0 = fixedsub(version, "%{version}", $0);
295 $0 = fixedsub(_beta, "%{_beta}", $0);
298 $0 = fixedsub(_rc, "%{_rc}", $0);
301 $0 = fixedsub(_snap, "%{_snap}", $0);
305 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
306 $0 = fixedsub(" -n %{name}-%{version}", "", $0)
310 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
316 /^%build/, (!/^%build/ && $0 ~ SECTIONS) {
325 if (/LDFLAGS="-s"/) {
326 removed["LDFLAGS"] = 1
329 split($0, tmp, "LDFLAGS=")
330 count = split(tmp[2], flags, "\"")
331 if (flags[1] != "" && flags[1] !~ "!?debug") {
332 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
333 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
334 for (i = 2; i < count; i++)
335 $0 = $0 flags[i] "\""
341 if (cflags("CFLAGS") == 0)
345 if (cflags("CXXFLAGS") == 0)
349 if (removed["LDFLAGS"])
351 if (removed["CFLAGS"])
353 if (removed["CXXFLAGS"])
355 # Is there still something?
362 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
365 # use PLD Linux macros
366 $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
367 $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
368 $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
370 sub(/^aclocal$/, "%{__aclocal}");
371 sub(/^autoheader$/, "%{__autoheader}");
372 sub(/^autoconf$/, "%{__autoconf}");
373 sub(/^automake$/, "%{__automake}");
376 $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
377 $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
383 /^%clean/, (!/^%clean/ && $0 ~ SECTIONS) {
386 # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
395 /^%install/, (!/^%install/ && $0 ~ SECTIONS) {
399 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
401 print "rm -rf $RPM_BUILD_ROOT"
405 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
406 print "rm -rf $RPM_BUILD_ROOT"
412 # 'install -d' instead 'mkdir -p'
414 sub(/mkdir -p/, "install -d")
416 # 'install' instead 'cp -p'
418 sub(/cp -p/, "install")
420 # No '-u root' or '-g root' for 'install'
421 if (/^install/ && /-[ug][ \t]*root/)
422 gsub(/-[ug][ \t]*root /, "")
424 if (/^install/ && /-m[ \t]*[0-9]+/)
425 gsub(/-m[ \t]*[0-9]+ /, "")
427 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
428 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
431 # No lines contain 'chmod' if it sets the modes to '644'
432 if ($1 ~ /chmod/ && $2 ~ /644/)
436 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
437 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
440 $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
446 /^%files/, (!/^%files/ && $0 ~ SECTIONS) {
458 /^%changelog/, (!/^%changelog/ && $0 ~ SECTIONS) {
462 # There should be some CVS keywords on the first line of %changelog.
464 if ($0 !~ _cvsmailfeedback)
465 print "* %{date} " _cvsmailfeedback > changelog_file
470 if (boc == 2 && !skip) {
471 if (!/All persons listed below/) {
472 printf "All persons listed below can be reached at " > changelog_file
473 print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
478 if (boc == 1 && !skip) {
481 print "$" "Log:$" > changelog_file
488 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
489 print " date +\"%a %b %d %Y\"`)" > changelog_file
496 if (!/^%[a-z]+$/ || /changelog/)
497 print > changelog_file
506 /^%pre/, (!/^%pre/ && $0 ~ SECTIONS) {
509 # %useradd and %groupadd may not be wrapped
510 if (/%(useradd|groupadd).*\\$/) {
513 $0 = substr(a, 1, length(a) - 1) $0;
517 /^%post/, (!/^%post/ && $0 ~ SECTIONS) {
520 /^%preun/, (!/^%preun/ && $0 ~ SECTIONS) {
523 /^%postun/, (!/^%postun/ && $0 ~ SECTIONS) {
526 /^%triggerin/, (!/^%triggerin/ && $0 ~ SECTIONS) {
529 /^%triggerun/, (!/^%triggerun/ && $0 ~ SECTIONS) {
532 /^%triggerpostun/, (!/^%triggerpostun/ && $0 ~ SECTIONS) {
535 /^%pretrans/, (!/^%pretrans/ && $0 ~ SECTIONS) {
538 /^%posttrans/, (!/^%posttrans/ && $0 ~ SECTIONS) {
546 # There should not be a space after the name of field
547 # and before the colon.
550 if (/^%perl_module_wo_prefix/) {
553 release = "0." fixedsub(".%{disttag}.at", "", $4)
558 if (field ~ /summary:/) {
561 if (field ~ /group(\([^)]+\)):/)
563 if (field ~ /group:/) {
565 sub(/^Utilities\//,"Applications/",$2)
566 sub(/^Games/,"Applications/Games",$2)
567 sub(/^X11\/Games/,"X11/Applications/Games",$2)
568 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
569 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
570 sub(/^X11\/GNOME/,"X11/Applications",$2)
571 sub(/^X11\/Utilities/,"X11/Applications",$2)
572 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
573 sub(/^Shells/,"Applications/Shells",$2)
575 sub(/^[^ \t]*[ \t]*/,"")
578 sub(/^System Environment\/Libraries$/, "Libraries", Grupa)
579 sub(/^System Environment\/Daemons$/, "Daemons", Grupa)
580 sub(/^Applications\/Internet$/, "Applications/Networking", Grupa)
581 sub(/^Applications\/Daemons$/, "Daemons", Grupa)
582 sub(/^Application\/Multimedia$/, "Applications/Multimedia", Grupa)
583 sub(/^System\/Servers$/, "Daemons", Grupa)
584 sub(/^X11\/Xserver$/, "X11/Servers", Grupa)
585 sub(/^X11\/XFree86/, "X11", Grupa)
586 sub(/^Applications\/Compilers$/, "Development/Languages", Grupa)
587 sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", Grupa)
588 sub(/^Networking\/Deamons$/, "Networking/Daemons", Grupa)
589 sub(/^Development\/Docs$/, "Documentation", Grupa)
591 print "Group:\t\t" Grupa
592 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
595 byl_plik_z_grupami = 0
597 while ((getline linia_grup < groups_file) > 0) {
598 byl_plik_z_grupami = 1
599 if (linia_grup == Grupa) {
605 if (!byl_plik_z_grupami)
606 print "######\t\t" groups_file ": no such file"
607 else if (!byl_opis_grupy)
608 print "######\t\t" "Unknown group!"
614 if (field ~ /prereq:/) {
615 sub(/PreReq:/, "Requires:", $1);
618 # split (build)requires, obsoletes on commas
619 if (field ~ /(obsoletes|requires):/ && $0 ~ /,/) {
620 l = substr($0, index($0, $2));
621 n = split(l, p, / *, */);
623 printf("%s\t%s\n", $1, p[i]);
628 if (field ~ /packager:|distribution:|docdir:|prefix:/)
631 if (field ~ /buildroot:/)
632 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
634 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
635 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
638 if (field ~ /name:/) {
639 if ($2 == "%{name}" && name) {
646 if (field ~ /version:/) {
647 if ($2 == "%{version}" && version) {
654 if (field ~ /release:/) {
655 if ($2 == "%{release}" && release) {
662 if (field ~ /serial:/)
666 if (field ~ /^url:$/)
669 # Use %{name} and %{version} in the filenames in "Source:"
670 if (field ~ /^source/ || field ~ /patch/) {
671 n = split($2, url, /\//)
672 if (url[n] ~ /\.gz$/) {
673 url[n+1] = ".gz" url[n+1]
674 sub(/\.gz$/,"",url[n])
676 if (url[n] ~ /\.zip$/) {
677 url[n+1] = ".zip" url[n+1]
678 sub(/\.zip$/,"",url[n])
680 if (url[n] ~ /\.tar$/) {
681 url[n+1] = ".tar" url[n+1]
682 sub(/\.tar$/,"",url[n])
684 if (url[n] ~ /\.patch$/) {
685 url[n+1] = ".patch" url[n+1]
686 sub(/\.patch$/,"",url[n])
688 if (url[n] ~ /\.bz2$/) {
689 url[n+1] = ".bz2" url[n+1]
690 sub(/\.bz2$/,"",url[n])
692 if (url[n] ~ /\.logrotate$/) {
693 url[n+1] = ".logrotate" url[n+1]
694 sub(/\.logrotate$/,"",url[n])
696 if (url[n] ~ /\.pamd$/) {
697 url[n+1] = ".pamd" url[n+1]
698 sub(/\.pamd$/,"",url[n])
701 # allow %{name} just in last url component
703 for (i = 1; i <= n; i++) {
704 url[i] = fixedsub("%{name}", name, url[i])
715 url[n] = fixedsub(name, "%{name}", url[n])
717 if (field ~ /source/) {
719 url[n] = fixedsub(version, "%{version}", url[n])
722 url[n] = fixedsub(_beta, "%{_beta}", url[n])
725 url[n] = fixedsub(_rc, "%{_rc}", url[n])
728 url[n] = fixedsub(_snap, "%{_snap}", url[n])
731 $2 = fixedsub(filename, url[n], $2)
734 sub("[?]use_mirror=.*$", "", $2);
735 sub("[?]download$", "", $2);
736 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
738 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
739 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
740 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
744 if (field ~ /^source:/)
747 if (field ~ /^patch:/)
752 if (field ~ /requires/) {
754 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
765 if (name_seen == 0 && name) {
770 if (version_seen == 0 && version) {
771 print "Version:\t" version
775 if (release_seen == 0 && release) {
776 print "Release:\t" release
783 if (do_not_touch_anything)
786 close(changelog_file)
787 while ((getline < changelog_file) > 0)
789 system("rm -f " changelog_file)
791 if (did_clean == 0) {
794 print "rm -rf $RPM_BUILD_ROOT"
799 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
802 if (has_changelog == 0)
806 print "* %{date} PLD Team <feedback@pld-linux.org>"
808 printf "All persons listed below can be reached at "
809 print "<cvs_login>@pld-linux.org\n"
815 function fixedsub(s1,s2,t, ind) {
816 # substitutes fixed strings (not regexps)
817 if (ind = index(t,s1))
818 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
822 # There should be one or two tabs after the colon.
823 function format_preamble()
826 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
834 # Replace directly specified directories with macros
835 function use_macros()
837 # -m, --skip-macros, --no-macros -- skip macros subst
838 if (ENVIRON["SKIP_MACROS"]) {
842 gsub(perl_sitearch, "%{perl_sitearch}")
843 gsub(perl_archlib, "%{perl_archlib}")
844 gsub(perl_privlib, "%{perl_privlib}")
845 gsub(perl_vendorlib, "%{perl_vendorlib}")
846 gsub(perl_vendorarch, "%{perl_vendorarch}")
847 gsub(perl_sitelib, "%{perl_sitelib}")
849 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
851 gsub(bindir, "%{_bindir}")
852 gsub("%{prefix}/bin", "%{_bindir}")
853 if(prefix"/bin" == bindir)
854 gsub("%{_prefix}/bin", "%{_bindir}")
856 for (c = 1; c <= NF; c++) {
857 if ($c ~ sbindir "/fix-info-dir")
859 if ($c ~ sbindir "/webapp")
861 if ($c ~ sbindir "/chsh")
863 if ($c ~ sbindir "/usermod")
865 gsub(sbindir, "%{_sbindir}", $c)
868 gsub("%{prefix}/sbin", "%{_sbindir}")
869 if (prefix"/sbin" == sbindir)
870 gsub("%{_prefix}/sbin", "%{_sbindir}")
872 for (c = 1; c <= NF; c++) {
873 if ($c ~ sysconfdir "/{?cron.")
875 if ($c ~ sysconfdir "/{?crontab.d")
877 if ($c ~ sysconfdir "/{?env.d")
879 if ($c ~ sysconfdir "/{?logrotate.d")
881 if ($c ~ sysconfdir "/{?pam.d")
883 if ($c ~ sysconfdir "/{?profile.d")
885 if ($c ~ sysconfdir "/{?rc.d")
887 if ($c ~ sysconfdir "/{?security")
889 if ($c ~ sysconfdir "/{?skel")
891 if ($c ~ sysconfdir "/{?sysconfig")
893 if ($c ~ sysconfdir "/{?shrc.d")
895 if ($c ~ sysconfdir "/{?certs")
897 if ($c ~ sysconfdir "/{?X11")
899 if ($c ~ sysconfdir "/{?ld.so.conf.d")
901 if ($c ~ sysconfdir "/{?httpd") # temp
903 gsub(sysconfdir, "%{_sysconfdir}", $c)
906 for (c = 1; c <= NF; c++) {
907 if ($c ~ datadir "/automake")
909 if ($c ~ datadir "/unsermake")
911 if ($c ~ datadir "/file/magic.mime")
913 gsub(datadir, "%{_datadir}", $c)
916 gsub("%_sbindir", "%{_sbindir}")
917 gsub("%_mandir", "%{_mandir}")
918 gsub("%name", "%{name}")
920 gsub("%{prefix}/share", "%{_datadir}")
921 if (prefix"/share" == datadir)
922 gsub("%{_prefix}/share", "%{_datadir}")
924 # CFLAGS="-I/usr/include/ncurses is usually correct.
925 if (!/-I\/usr\/include/) {
926 gsub(includedir, "%{_includedir}")
929 gsub("%{prefix}/include", "%{_includedir}")
930 if (prefix"/include" == includedir) {
931 gsub("%{_prefix}/include", "%{_includedir}")
934 gsub(mandir, "%{_mandir}")
935 if ($0 !~ "%{_datadir}/manual") {
936 gsub("%{_datadir}/man", "%{_mandir}")
938 gsub("%{_prefix}/share/man", "%{_mandir}")
939 gsub("%{prefix}/share/man", "%{_mandir}")
940 gsub("%{prefix}/man", "%{_mandir}")
941 gsub("%{_prefix}/man", "%{_mandir}")
943 gsub(infodir, "%{_infodir}")
944 gsub("%{prefix}/info", "%{_infodir}")
945 gsub("%{_prefix}/info", "%{_infodir}")
947 if (prefix !~ "/X11R6") {
948 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
951 gsub(examplesdir, "%{_examplesdir}")
954 # leave --with-foo=/usr alone
955 if ($0 !~ "--with.*=.*" prefix) {
956 for (c = 1; c <= NF; c++) {
957 if ($c ~ prefix "/sbin/fix-info-dir")
959 if ($c ~ prefix "/sbin/webapp")
961 if ($c ~ prefix "/sbin/chsh")
963 if ($c ~ prefix "/sbin/usermod")
965 if ($c ~ prefix "/share/automake")
967 if ($c ~ prefix "/share/unsermake")
969 if ($c ~ prefix "/lib/sendmail")
971 if ($c ~ prefix "/lib/pkgconfig")
974 # CFLAGS="-I/usr..." is usually correct.
977 # same for LDFLAGS="-L/usr..."
981 gsub(prefix, "%{_prefix}", $c)
984 gsub("%{prefix}", "%{_prefix}")
987 gsub("%{PACKAGE_VERSION}", "%{version}")
988 gsub("%{PACKAGE_NAME}", "%{name}")
990 gsub("^make$", "%{__make}")
991 gsub("^make ", "%{__make} ")
992 gsub("^gcc ", "%{__cc} ")
995 gsub("^%make$", "%{__make}")
996 gsub("^%make ", "%{__make} ")
997 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
998 gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
999 gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1000 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
1001 gsub("^%{__install}", "install")
1002 gsub("^%{__rm}", "rm")
1003 gsub("%optflags", "%{rpmcflags}")
1004 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
1006 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1007 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
1008 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
1009 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
1010 $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
1012 gsub("%_bindir", "%{_bindir}")
1013 gsub("%_datadir", "%{_datadir}")
1014 gsub("%_iconsdir", "%{_iconsdir}")
1016 gsub("/usr/src/linux", "%{_kernelsrcdir}")
1017 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
1021 # insertion sort of A[1..n]
1022 # copied from mawk manual
1023 function isort(A,n, i,j,hold) {
1024 for (i = 2; i <= n; i++) {
1026 while (A[j-1] > hold) {
1031 # sentinel A[0] = "" will be created if needed
1035 function use_files_macros( i, n, t, a)
1039 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1040 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1042 # uid/gid nobody is not valid in %files
1043 if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1044 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1048 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1049 gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1050 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1051 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1052 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1053 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1054 gsub("%{_sysconfdir}/security", "/etc/security")
1055 gsub("%{_sysconfdir}/skel", "/etc/skel")
1056 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1057 gsub("%{_sysconfdir}/certs", "/etc/certs")
1058 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1060 # /etc/init.d -> /etc/rc.d/init.d
1061 if (!/^\/etc\/init\.d$/) {
1062 gsub("/etc/init.d", "/etc/rc.d/init.d")
1065 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1066 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1067 $0 = "%attr(754,root,root) " $0
1069 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1070 gsub("^%attr\\(... *,", "%attr(754,");
1074 if (/lib.+\.so/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1075 $0 = "%attr(755,root,root) " $0
1078 # /etc/sysconfig files
1079 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1080 # attr not required, allow default 644 attr
1081 if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1082 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1083 gsub("%config", "%config(noreplace)")
1086 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1087 $NF = "%config(noreplace) " $NF
1090 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1091 gsub("^%attr\\(... *,", "%attr(640,");
1094 if (/\/etc\/sysconfig\// && !/%verify/) {
1095 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1099 # kill leading zeros
1100 if (/%attr\(0[1-9]/) {
1101 gsub("%attr\\(0", "%attr(")
1104 # sort %verify attrs
1105 if (match($0, /%verify\(not([^)]+)\)/)) {
1106 t = substr($0, RSTART, RLENGTH)
1107 # kill commas: %verify(not,md5,size,mtime)
1110 gsub(/^%verify\(not |\)$/, "", t)
1111 n = split(t, a, / /)
1115 for (i = 1 ; i <= n; i++) {
1120 gsub(/%verify\(not[^)]+\)/, s)
1127 # locale dir and no %lang -> bad
1128 if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1129 $(NF + 1) = "# FIXME consider using %find_lang"
1133 $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1134 $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1135 $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1137 gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1138 gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1139 gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1141 gsub("%{_datadir}/applications", "%{_desktopdir}");
1142 gsub("%{_datadir}/icons", "%{_iconsdir}");
1143 gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1146 function fill(ch, n, i) {
1147 for (i = 0; i < n; i++)
1151 function format_flush(line, indent, newline, word, first_word) {
1153 if (format_indent == -1)
1156 newline = fill(" ", format_indent) "- "
1158 while (match(line, /[^\t ]+/)) {
1159 word = substr(line, RSTART, RLENGTH)
1160 if (length(newline) + length(word) + 1 > tw) {
1163 if (format_indent == -1)
1166 newline = fill(" ", format_indent + 2)
1171 newline = newline word
1174 newline = newline " " word
1176 line = substr(line, RSTART + RLENGTH)
1178 if (newline ~ /[^\t ]/) {
1183 function cflags(var)
1185 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1191 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")