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_TAGS = "(Summary|Name|Version|Release|License|Group|URL|BuildArch|BuildRoot|Obsoletes|Conflicts|Provides|ExclusiveArch|ExcludeArch|PreReq|(Build)?Requires)"
32 preamble = 1 # Is it part of preamble? Default - yes
33 boc = 4 # Beginning of %changelog
34 bod = 0 # Beginning of %description
35 tw = 70 # Descriptions width
37 b_idx = 0 # index of BR/R arrays
39 # If variable removed, then 1 (for removing it from export)
40 removed["LDFLAGS"] = 0
42 removed["CXXFLAGS"] = 0
44 # get cvsaddress for changelog section
45 # using rpm macros as too lazy to add ~/.adapterrc parsing support.
46 "rpm --eval '%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'" | getline _cvsmaildomain
47 "rpm --eval '%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'" | getline _cvsmailfeedback
49 # If 1, we are inside of comment block (started with /^#%/)
52 # File with rpm groups
53 "rpm --eval %_sourcedir" | getline groups_file
54 groups_file = groups_file "/rpm.groups"
55 system("cd `rpm --eval %_sourcedir`; [ -f rpm.groups ] || cvs up rpm.groups >/dev/null")
57 # Temporary file for changelog section
58 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
61 "rpm --eval %_prefix" | getline prefix
62 "rpm --eval %_bindir" | getline bindir
63 "rpm --eval %_sbindir" | getline sbindir
64 "rpm --eval %_libdir" | getline libdir
65 "rpm --eval %_sysconfdir" | getline sysconfdir
66 "rpm --eval %_datadir" | getline datadir
67 "rpm --eval %_includedir" | getline includedir
68 "rpm --eval %_mandir" | getline mandir
69 "rpm --eval %_infodir" | getline infodir
70 "rpm --eval %_examplesdir" | getline examplesdir
71 "rpm --eval %_defaultdocdir" | getline docdir
73 "rpm --eval %perl_sitearch" | getline perl_sitearch
74 "rpm --eval %perl_archlib" | getline perl_archlib
75 "rpm --eval %perl_privlib" | getline perl_privlib
76 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
77 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
78 "rpm --eval %perl_sitelib" | getline perl_sitelib
80 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
83 # There should be a comment with CVS keywords on the first line of file.
85 if (!/# \$Revision:/) # If this line is already OK?
86 print "# $" "Revision:$, " "$" "Date:$" # No
89 next # It is enough for first line
93 # If the latest line matched /%files/
95 if (ENVIRON["SKIP_DEFATTR"] != 1) {
96 if ($0 !~ /defattr/) { # If no %defattr
97 print "%defattr(644,root,root,755)" # Add it
99 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
105 function b_makekey(a, b, s) {
108 gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
110 # kill commented out items
111 gsub(/^#[ \t]*/, "", s);
114 gsub(/^Summary\(/, "11Summary(", s);
115 gsub(/^Summary/, "10Summary", s);
116 gsub(/^Name/, "2Name", s);
117 gsub(/^Version/, "3Version", s);
118 gsub(/^Release/, "4Release", s);
119 gsub(/^License/, "5License", s);
120 gsub(/^Group/, "6Group", s);
121 gsub(/^URL/, "7URL", s);
123 gsub(/^Provides/, "X1Provides", s);
124 gsub(/^Obsoletes/, "X2Obsoletes", s);
125 gsub(/^Conflicts/, "X3Conflicts", s);
126 gsub(/^BuildArch/, "X4BuildArch", s);
127 gsub(/^ExclusiveArch/, "X6ExclusiveArch", s);
128 gsub(/^ExcludeArch/, "X7ExcludeArch", s);
129 gsub(/^BuildRoot/, "X9BuildRoot", s);
131 # printf("%s -> %s\n", a""b, s);
136 /^#/ && (description == 0) {
137 if (/This file does not like to be adapterized!/) {
138 print # print this message
139 while (getline) # print the rest of spec as it is
141 do_not_touch_anything = 1 # do not touch anything in END()
145 # Generally, comments are printed without touching
155 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
156 if ($2 == "_applnkdir") {
163 # Do not add %define of _prefix if it already is.
164 if ($2 ~ /^_prefix/) {
165 sub("^"prefix, $3, bindir)
166 sub("^"prefix, $3, sbindir)
167 sub("^"prefix, $3, libdir)
168 sub("^"prefix, $3, datadir)
169 sub("^"prefix, $3, includedir)
173 if ($2 ~ /_bindir/ && !/_sbindir/)
179 if ($2 ~ /_sysconfdir/) {
181 # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
182 sysconfdir = "%%%%%%%%%%%%%%"
189 if ($2 ~ /_includedir/)
198 # version related macros
206 # these are used usually when adapterizing external spec
209 if ($2 ~ /^version$/)
211 if ($2 ~ /^release$/)
214 if ($2 ~ /^mod_name$/)
217 # do nothing further, otherwise adapter thinks we're at preamble
223 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
230 /^%description/, (!/^%description/ && $0 ~ SECTIONS) {
233 if (/^%description/) {
240 if (ENVIRON["SKIP_DESC"] != 1 && description == 1 && !/^%[a-z]+/ && !/^%description/) {
242 format_flush(format_line, format_indent)
246 } else if (/^[ \t]*[-\*][ \t]*/) {
247 format_flush(format_line, format_indent)
249 format_indent = RLENGTH
250 match($0, /^[ \t]*[-\*][ \t]/)
251 format_line = substr($0, RLENGTH)
253 format_line = format_line " " $0
257 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
258 if (NF > 3 && $2 == "-l") {
260 for (i = 4; i <= NF; i++)
264 format_flush(format_line, format_indent)
279 /^%prep/, (!/^%prep/ && $0 ~ SECTIONS) {
285 if (/^%setup/ && !/-q/) {
286 sub(/^%setup/, "%setup -q")
290 $0 = fixedsub(name, "%{name}", $0);
291 $0 = fixedsub(version, "%{version}", $0);
293 $0 = fixedsub(_beta, "%{_beta}", $0);
296 $0 = fixedsub(_rc, "%{_rc}", $0);
299 $0 = fixedsub(_snap, "%{_snap}", $0);
303 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
304 $0 = fixedsub(" -n %{name}-%{version}", "", $0)
308 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
314 /^%build/, (!/^%build/ && $0 ~ SECTIONS) {
323 if (/LDFLAGS="-s"/) {
324 removed["LDFLAGS"] = 1
327 split($0, tmp, "LDFLAGS=")
328 count = split(tmp[2], flags, "\"")
329 if (flags[1] != "" && flags[1] !~ "!?debug") {
330 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
331 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
332 for (i = 2; i < count; i++)
333 $0 = $0 flags[i] "\""
339 if (cflags("CFLAGS") == 0)
343 if (cflags("CXXFLAGS") == 0)
347 if (removed["LDFLAGS"])
349 if (removed["CFLAGS"])
351 if (removed["CXXFLAGS"])
353 # Is there still something?
360 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
363 # use PLD Linux macros
364 $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
365 $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
366 $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
368 sub(/^aclocal$/, "%{__aclocal}");
369 sub(/^autoheader$/, "%{__autoheader}");
370 sub(/^autoconf$/, "%{__autoconf}");
371 sub(/^automake$/, "%{__automake}");
374 $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
375 $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
381 /^%clean/, (!/^%clean/ && $0 ~ SECTIONS) {
384 # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
393 /^%install/, (!/^%install/ && $0 ~ SECTIONS) {
397 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
399 print "rm -rf $RPM_BUILD_ROOT"
403 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
404 print "rm -rf $RPM_BUILD_ROOT"
410 # 'install -d' instead 'mkdir -p'
412 sub(/mkdir -p/, "install -d")
414 # 'install' instead 'cp -p'
416 sub(/cp -p/, "install")
418 # No '-u root' or '-g root' for 'install'
419 if (/^install/ && /-[ug][ \t]*root/)
420 gsub(/-[ug][ \t]*root /, "")
422 if (/^install/ && /-m[ \t]*[0-9]+/)
423 gsub(/-m[ \t]*[0-9]+ /, "")
425 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
426 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
429 # No lines contain 'chmod' if it sets the modes to '644'
430 if ($1 ~ /chmod/ && $2 ~ /644/)
434 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
435 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
438 $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
444 /^%files/, (!/^%files/ && $0 ~ SECTIONS) {
456 /^%changelog/, (!/^%changelog/ && $0 ~ SECTIONS) {
460 # There should be some CVS keywords on the first line of %changelog.
462 if ($0 !~ _cvsmailfeedback)
463 print "* %{date} " _cvsmailfeedback > changelog_file
468 if (boc == 2 && !skip) {
469 if (!/All persons listed below/) {
470 printf "All persons listed below can be reached at " > changelog_file
471 print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
476 if (boc == 1 && !skip) {
479 print "$" "Log:$" > changelog_file
486 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
487 print " date +\"%a %b %d %Y\"`)" > changelog_file
494 if (!/^%[a-z]+$/ || /changelog/)
495 print > changelog_file
504 /^%pre/, (!/^%pre/ && $0 ~ SECTIONS) {
507 # %useradd and %groupadd may not be wrapped
508 if (/%(useradd|groupadd).*\\$/) {
511 $0 = substr(a, 1, length(a) - 1) $0;
515 /^%post/, (!/^%post/ && $0 ~ SECTIONS) {
519 /^%preun/, (!/^%preun/ && $0 ~ SECTIONS) {
522 /^%postun/, (!/^%postun/ && $0 ~ SECTIONS) {
525 /^%triggerin/, (!/^%triggerin/ && $0 ~ SECTIONS) {
528 /^%triggerun/, (!/^%triggerun/ && $0 ~ SECTIONS) {
531 /^%triggerpostun/, (!/^%triggerpostun/ && $0 ~ SECTIONS) {
534 /^%pretrans/, (!/^%pretrans/ && $0 ~ SECTIONS) {
537 /^%posttrans/, (!/^%posttrans/ && $0 ~ SECTIONS) {
545 # There should not be a space after the name of field
546 # and before the colon.
549 if (/^%perl_module_wo_prefix/) {
552 release = "0." fixedsub(".%{disttag}.at", "", $4)
557 if (field ~ /summary:/ && !/etc\.$/) {
560 if (field ~ /group(\([^)]+\)):/)
562 if (field ~ /group:/) {
565 sub(/^[^ \t]*[ \t]*/, "", group);
567 sub(/^Utilities\//,"Applications/", group)
568 sub(/^Games/,"Applications/Games", group)
569 sub(/^X11\/Games/,"X11/Applications/Games", group)
570 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries", group)
571 sub(/^X11\/GNOME\/Applications/,"X11/Applications", group)
572 sub(/^X11\/GNOME/,"X11/Applications", group)
573 sub(/^X11\/Utilities/,"X11/Applications", group)
574 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy", group)
575 sub(/^Shells/,"Applications/Shells", group)
576 sub(/^System Environment\/Libraries$/, "Libraries", group)
577 sub(/^System Environment\/Daemons$/, "Daemons", group)
578 sub(/^Applications\/Internet$/, "Applications/Networking", group)
579 sub(/^Applications\/Daemons$/, "Daemons", group)
580 sub(/^Application\/Multimedia$/, "Applications/Multimedia", group)
581 sub(/^System\/Servers$/, "Daemons", group)
582 sub(/^X11\/Xserver$/, "X11/Servers", group)
583 sub(/^X11\/XFree86/, "X11", group)
584 sub(/^Applications\/Compilers$/, "Development/Languages", group)
585 sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", group)
586 sub(/^Networking\/Deamons$/, "Networking/Daemons", group)
587 sub(/^Development\/Docs$/, "Documentation", group)
589 $0 = "Group:\t\t" group
591 if (group ~ /^X11/ && x11 == 0) # Is it X11 application?
594 byl_plik_z_groupmi = 0
596 while ((getline linia_grup < groups_file) > 0) {
597 byl_plik_z_groupmi = 1
598 if (linia_grup == group) {
604 if (!byl_plik_z_groupmi)
605 print "######\t\t" groups_file ": no such file"
606 else if (!byl_opis_grupy)
607 print "######\t\t" "Unknown group!"
612 if (field ~ /prereq:/) {
613 sub(/PreReq:/, "Requires:", $1);
616 # split (build)requires, obsoletes on commas
617 if (field ~ /(obsoletes|requires):/ && $0 ~ /,/) {
618 l = substr($0, index($0, $2));
619 n = split(l, p, / *, */);
621 printf("%s\t%s\n", $1, p[i]);
626 if (field ~ /packager:|distribution:|docdir:|prefix:/)
629 if (field ~ /buildroot:/)
630 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
632 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
633 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
636 if (field ~ /name:/) {
637 if ($2 == "%{name}" && name) {
644 if (field ~ /version:/) {
645 if ($2 == "%{version}" && version) {
652 if (field ~ /release:/) {
653 if ($2 == "%{release}" && release) {
660 if (field ~ /serial:/)
664 if (field ~ /^url:$/)
667 # Use %{name} and %{version} in the filenames in "Source:"
668 if (field ~ /^source/ || field ~ /patch/) {
669 n = split($2, url, /\//)
670 if (url[n] ~ /\.gz$/) {
671 url[n+1] = ".gz" url[n+1]
672 sub(/\.gz$/,"",url[n])
674 if (url[n] ~ /\.zip$/) {
675 url[n+1] = ".zip" url[n+1]
676 sub(/\.zip$/,"",url[n])
678 if (url[n] ~ /\.tar$/) {
679 url[n+1] = ".tar" url[n+1]
680 sub(/\.tar$/,"",url[n])
682 if (url[n] ~ /\.patch$/) {
683 url[n+1] = ".patch" url[n+1]
684 sub(/\.patch$/,"",url[n])
686 if (url[n] ~ /\.bz2$/) {
687 url[n+1] = ".bz2" url[n+1]
688 sub(/\.bz2$/,"",url[n])
690 if (url[n] ~ /\.logrotate$/) {
691 url[n+1] = ".logrotate" url[n+1]
692 sub(/\.logrotate$/,"",url[n])
694 if (url[n] ~ /\.pamd$/) {
695 url[n+1] = ".pamd" url[n+1]
696 sub(/\.pamd$/,"",url[n])
699 # allow %{name} just in last url component
701 for (i = 1; i <= n; i++) {
702 url[i] = fixedsub("%{name}", name, url[i])
713 url[n] = fixedsub(name, "%{name}", url[n])
715 if (field ~ /source/) {
717 url[n] = fixedsub(version, "%{version}", url[n])
720 url[n] = fixedsub(_beta, "%{_beta}", url[n])
723 url[n] = fixedsub(_rc, "%{_rc}", url[n])
726 url[n] = fixedsub(_snap, "%{_snap}", url[n])
729 $2 = fixedsub(filename, url[n], $2)
732 sub("[?]use_mirror=.*$", "", $2);
733 sub("[?]download$", "", $2);
734 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
736 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
737 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
738 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
742 if (field ~ /^source:/)
745 if (field ~ /^patch:/)
748 kill_preamble_macros();
751 if (field ~ /requires/) {
753 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
761 # - mixing BR/R and anything else confuses this (all will be sorted together)
763 # - comments leading the BR/R can not be associated,
764 # so don't adapterize when the BR/R are mixed with comments
765 ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && $0 ~ PREAMBLE_TAGS, $0 ~ PREAMBLE_TAGS {
766 if ($1 ~ /PreReq:/) {
767 sub(/PreReq:/, "Requires:", $1);
770 kill_preamble_macros();
773 l = substr($0, index($0, $2));
774 b_ktmp = b_makekey($1, l);
775 b_key[b_idx] = b_ktmp;
790 for (i = 1; i <= b_idx; i++) {
791 print "" b_val[b_key[i]];
804 if (name_seen == 0 && name) {
809 if (version_seen == 0 && version) {
810 print "Version:\t" version
814 if (release_seen == 0 && release) {
815 print "Release:\t" release
822 if (do_not_touch_anything)
825 close(changelog_file)
826 while ((getline < changelog_file) > 0)
828 system("rm -f " changelog_file)
830 if (did_clean == 0) {
833 print "rm -rf $RPM_BUILD_ROOT"
838 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
841 if (has_changelog == 0)
845 print "* %{date} PLD Team <feedback@pld-linux.org>"
847 printf "All persons listed below can be reached at "
848 print "<cvs_login>@pld-linux.org\n"
854 function fixedsub(s1,s2,t, ind) {
855 # substitutes fixed strings (not regexps)
856 if (ind = index(t,s1))
857 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
861 # There should be one or two tabs after the colon.
862 function format_preamble()
865 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
873 # Replace directly specified directories with macros
874 function use_macros()
876 # -m, --skip-macros, --no-macros -- skip macros subst
877 if (ENVIRON["SKIP_MACROS"]) {
881 gsub(perl_sitearch, "%{perl_sitearch}")
882 gsub(perl_archlib, "%{perl_archlib}")
883 gsub(perl_privlib, "%{perl_privlib}")
884 gsub(perl_vendorlib, "%{perl_vendorlib}")
885 gsub(perl_vendorarch, "%{perl_vendorarch}")
886 gsub(perl_sitelib, "%{perl_sitelib}")
888 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
890 gsub(bindir, "%{_bindir}")
891 gsub("%{prefix}/bin", "%{_bindir}")
892 if(prefix"/bin" == bindir)
893 gsub("%{_prefix}/bin", "%{_bindir}")
895 for (c = 1; c <= NF; c++) {
896 if ($c ~ sbindir "/fix-info-dir")
898 if ($c ~ sbindir "/webapp")
900 if ($c ~ sbindir "/chsh")
902 if ($c ~ sbindir "/usermod")
904 gsub(sbindir, "%{_sbindir}", $c)
907 gsub("%{prefix}/sbin", "%{_sbindir}")
908 if (prefix"/sbin" == sbindir)
909 gsub("%{_prefix}/sbin", "%{_sbindir}")
911 for (c = 1; c <= NF; c++) {
912 if ($c ~ sysconfdir "/{?cron.")
914 if ($c ~ sysconfdir "/{?crontab.d")
916 if ($c ~ sysconfdir "/{?env.d")
918 if ($c ~ sysconfdir "/{?logrotate.d")
920 if ($c ~ sysconfdir "/{?pam.d")
922 if ($c ~ sysconfdir "/{?profile.d")
924 if ($c ~ sysconfdir "/{?rc.d")
926 if ($c ~ sysconfdir "/{?security")
928 if ($c ~ sysconfdir "/{?skel")
930 if ($c ~ sysconfdir "/{?sysconfig")
932 if ($c ~ sysconfdir "/{?shrc.d")
934 if ($c ~ sysconfdir "/{?certs")
936 if ($c ~ sysconfdir "/{?X11")
938 if ($c ~ sysconfdir "/{?ld.so.conf.d")
940 if ($c ~ sysconfdir "/{?httpd") # temp
942 gsub(sysconfdir, "%{_sysconfdir}", $c)
945 gsub(docdir, "%{_docdir}")
947 for (c = 1; c <= NF; c++) {
948 if ($c ~ datadir "/automake")
950 if ($c ~ datadir "/unsermake")
952 if ($c ~ datadir "/file/magic.mime")
954 gsub(datadir, "%{_datadir}", $c)
957 gsub("%{prefix}/share", "%{_datadir}")
958 if (prefix"/share" == datadir)
959 gsub("%{_prefix}/share", "%{_datadir}")
961 # CFLAGS="-I/usr/include/ncurses is usually correct.
962 if (!/-I\/usr\/include/) {
963 gsub(includedir, "%{_includedir}")
966 gsub("%{prefix}/include", "%{_includedir}")
967 if (prefix"/include" == includedir) {
968 gsub("%{_prefix}/include", "%{_includedir}")
971 gsub(mandir, "%{_mandir}")
972 if ($0 !~ "%{_datadir}/manual") {
973 gsub("%{_datadir}/man", "%{_mandir}")
975 gsub("%{_prefix}/share/man", "%{_mandir}")
976 gsub("%{prefix}/share/man", "%{_mandir}")
977 gsub("%{prefix}/man", "%{_mandir}")
978 gsub("%{_prefix}/man", "%{_mandir}")
980 gsub(infodir, "%{_infodir}")
981 gsub("%{prefix}/info", "%{_infodir}")
982 gsub("%{_prefix}/info", "%{_infodir}")
984 if (prefix !~ "/X11R6") {
985 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
988 gsub(examplesdir, "%{_examplesdir}")
991 # leave --with-foo=/usr alone
992 if ($0 !~ "--with.*=.*" prefix) {
993 for (c = 1; c <= NF; c++) {
994 if ($c ~ prefix "/sbin/fix-info-dir")
996 if ($c ~ prefix "/sbin/webapp")
998 if ($c ~ prefix "/sbin/chsh")
1000 if ($c ~ prefix "/sbin/usermod")
1002 if ($c ~ prefix "/share/automake")
1004 if ($c ~ prefix "/share/unsermake")
1006 if ($c ~ prefix "/lib/sendmail")
1008 if ($c ~ prefix "/lib/pkgconfig")
1011 # CFLAGS="-I/usr..." is usually correct.
1014 # same for LDFLAGS="-L/usr..."
1018 gsub(prefix, "%{_prefix}", $c)
1021 gsub("%{prefix}", "%{_prefix}")
1025 gsub("%{_includedir}/ncurses", "/usr/include/ncurses")
1026 gsub("%{_includedir}/freetype", "/usr/include/freetype")
1028 gsub("%{PACKAGE_VERSION}", "%{version}")
1029 gsub("%{PACKAGE_NAME}", "%{name}")
1031 gsub("^make$", "%{__make}")
1032 gsub("^make ", "%{__make} ")
1033 gsub("^gcc ", "%{__cc} ")
1036 gsub("^%make$", "%{__make}")
1037 gsub("^%make ", "%{__make} ")
1038 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1039 gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1040 gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1041 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
1042 gsub("^%{__install}", "install")
1043 gsub("^%{__rm}", "rm")
1044 gsub("%optflags", "%{rpmcflags}")
1045 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
1047 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1048 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
1049 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
1050 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
1051 $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
1053 gsub("%_bindir", "%{_bindir}")
1054 gsub("%_datadir", "%{_datadir}")
1055 gsub("%_iconsdir", "%{_iconsdir}")
1056 gsub("%_sbindir", "%{_sbindir}")
1057 gsub("%_mandir", "%{_mandir}")
1058 gsub("%name", "%{name}")
1060 gsub("/usr/src/linux", "%{_kernelsrcdir}")
1061 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
1065 # insertion sort of A[1..n]
1066 # copied from mawk manual
1067 function isort(A,n, i,j,hold) {
1068 for (i = 2; i <= n; i++) {
1070 while (A[j-1] > hold) {
1075 # sentinel A[0] = "" will be created if needed
1079 function use_files_macros( i, n, t, a)
1083 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1084 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1086 # uid/gid nobody is not valid in %files
1087 if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1088 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1091 # s[gu]id programs with globs are evil
1092 if (/%attr\([246]...,.*\*/ && !/FIXME/) {
1093 $0 = $0 " # FIXME no globs for suid/sgid files"
1097 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1098 gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1099 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1100 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1101 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1102 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1103 gsub("%{_sysconfdir}/security", "/etc/security")
1104 gsub("%{_sysconfdir}/skel", "/etc/skel")
1105 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1106 gsub("%{_sysconfdir}/certs", "/etc/certs")
1107 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1109 # /etc/init.d -> /etc/rc.d/init.d
1110 if (!/^\/etc\/init\.d$/) {
1111 gsub("/etc/init.d", "/etc/rc.d/init.d")
1114 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1115 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1116 $0 = "%attr(754,root,root) " $0
1118 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1119 gsub("^%attr\\(... *,", "%attr(754,");
1123 if (/lib.+\.so/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1124 $0 = "%attr(755,root,root) " $0
1127 # /etc/sysconfig files
1128 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1129 # attr not required, allow default 644 attr
1130 if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1131 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1132 gsub("%config", "%config(noreplace)")
1135 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1136 $NF = "%config(noreplace) " $NF
1139 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1140 gsub("^%attr\\(... *,", "%attr(640,");
1143 if (/\/etc\/sysconfig\// && !/%verify/) {
1144 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1148 # kill leading zeros
1149 if (/%attr\(0[1-9]/) {
1150 gsub("%attr\\(0", "%attr(")
1153 # sort %verify attrs
1154 if (match($0, /%verify\(not([^)]+)\)/)) {
1155 t = substr($0, RSTART, RLENGTH)
1156 # kill commas: %verify(not,md5,size,mtime)
1159 gsub(/^%verify\(not |\)$/, "", t)
1160 n = split(t, a, / /)
1164 for (i = 1 ; i <= n; i++) {
1169 gsub(/%verify\(not[^)]+\)/, s)
1176 # locale dir and no %lang -> bad
1177 if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1178 $(NF + 1) = "# FIXME consider using %find_lang"
1182 $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1183 $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1184 $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1186 gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1187 gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1188 gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1190 gsub("%{_datadir}/applications", "%{_desktopdir}");
1191 gsub("%{_datadir}/icons", "%{_iconsdir}");
1192 gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1195 function fill(ch, n, i) {
1196 for (i = 0; i < n; i++)
1200 function format_flush(line, indent, newline, word, first_word) {
1202 if (format_indent == -1)
1205 newline = fill(" ", format_indent) "- "
1207 while (match(line, /[^\t ]+/)) {
1208 word = substr(line, RSTART, RLENGTH)
1209 if (length(newline) + length(word) + 1 > tw) {
1212 if (format_indent == -1)
1215 newline = fill(" ", format_indent + 2)
1220 newline = newline word
1223 newline = newline " " word
1225 line = substr(line, RSTART + RLENGTH)
1227 if (newline ~ /[^\t ]/) {
1232 function cflags(var)
1234 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1240 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
1244 function kill_preamble_macros()
1246 if ($1 ~ /^URL:/ || $1 ~ /^Obsoletes:/) {
1247 sub("%{mod_name}", mod_name, $2);