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
66 "rpm --eval %_defaultdocdir" | getline docdir
68 "rpm --eval %perl_sitearch" | getline perl_sitearch
69 "rpm --eval %perl_archlib" | getline perl_archlib
70 "rpm --eval %perl_privlib" | getline perl_privlib
71 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
72 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
73 "rpm --eval %perl_sitelib" | getline perl_sitelib
75 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
78 # There should be a comment with CVS keywords on the first line of file.
80 if (!/# \$Revision:/) # If this line is already OK?
81 print "# $" "Revision:$, " "$" "Date:$" # No
84 next # It is enough for first line
88 # If the latest line matched /%files/
90 if (ENVIRON["SKIP_DEFATTR"] != 1) {
91 if ($0 !~ /defattr/) { # If no %defattr
92 print "%defattr(644,root,root,755)" # Add it
94 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
100 function b_makekey(a, b, s) {
103 gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
104 # kill commented out items
105 gsub(/[# \t]*/, "", s);
112 # - mixing BR/R and anything else confuses this (all will be sorted together)
114 # - comments leading the BR/R can not be associated,
115 # so don't adapterize when the BR/R are mixed with comments
116 ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && /(PreReq|(Build)?Requires)/, /(PreReq|(Build)?Requires)/ {
117 if ($1 ~ /PreReq:/) {
118 sub(/PreReq:/, "Requires:", $1);
123 l = substr($0, index($0, $2));
124 b_ktmp = b_makekey($1, l);
125 b_key[b_idx] = b_ktmp;
140 for (i = 1; i <= b_idx; i++) {
141 print "" b_val[b_key[i]];
148 /^#/ && (description == 0) {
149 if (/This file does not like to be adapterized!/) {
150 print # print this message
151 while (getline) # print the rest of spec as it is
153 do_not_touch_anything = 1 # do not touch anything in END()
157 # Generally, comments are printed without touching
164 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
165 if ($2 == "_applnkdir") {
172 # Do not add %define of _prefix if it already is.
173 if ($2 ~ /^_prefix/) {
174 sub("^"prefix, $3, bindir)
175 sub("^"prefix, $3, sbindir)
176 sub("^"prefix, $3, libdir)
177 sub("^"prefix, $3, datadir)
178 sub("^"prefix, $3, includedir)
182 if ($2 ~ /_bindir/ && !/_sbindir/)
188 if ($2 ~ /_sysconfdir/) {
190 # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
191 sysconfdir = "%%%%%%%%%%%%%%"
198 if ($2 ~ /_includedir/)
207 # version related macros
215 # these are used usually when adapterizing external spec
218 if ($2 ~ /^version$/)
220 if ($2 ~ /^release$/)
223 # do nothing further, otherwise adapter thinks we're at preamble
229 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
236 /^%description/, (!/^%description/ && $0 ~ SECTIONS) {
239 if (/^%description/) {
246 if (ENVIRON["SKIP_DESC"] != 1 && description == 1 && !/^%[a-z]+/ && !/^%description/) {
248 format_flush(format_line, format_indent)
252 } else if (/^[ \t]*[-\*][ \t]*/) {
253 format_flush(format_line, format_indent)
255 format_indent = RLENGTH
256 match($0, /^[ \t]*[-\*][ \t]/)
257 format_line = substr($0, RLENGTH)
259 format_line = format_line " " $0
263 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
264 if (NF > 3 && $2 == "-l") {
266 for (i = 4; i <= NF; i++)
270 format_flush(format_line, format_indent)
285 /^%prep/, (!/^%prep/ && $0 ~ SECTIONS) {
291 if (/^%setup/ && !/-q/) {
292 sub(/^%setup/, "%setup -q")
296 $0 = fixedsub(name, "%{name}", $0);
297 $0 = fixedsub(version, "%{version}", $0);
299 $0 = fixedsub(_beta, "%{_beta}", $0);
302 $0 = fixedsub(_rc, "%{_rc}", $0);
305 $0 = fixedsub(_snap, "%{_snap}", $0);
309 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
310 $0 = fixedsub(" -n %{name}-%{version}", "", $0)
314 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
320 /^%build/, (!/^%build/ && $0 ~ SECTIONS) {
329 if (/LDFLAGS="-s"/) {
330 removed["LDFLAGS"] = 1
333 split($0, tmp, "LDFLAGS=")
334 count = split(tmp[2], flags, "\"")
335 if (flags[1] != "" && flags[1] !~ "!?debug") {
336 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
337 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
338 for (i = 2; i < count; i++)
339 $0 = $0 flags[i] "\""
345 if (cflags("CFLAGS") == 0)
349 if (cflags("CXXFLAGS") == 0)
353 if (removed["LDFLAGS"])
355 if (removed["CFLAGS"])
357 if (removed["CXXFLAGS"])
359 # Is there still something?
366 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
369 # use PLD Linux macros
370 $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
371 $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
372 $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
374 sub(/^aclocal$/, "%{__aclocal}");
375 sub(/^autoheader$/, "%{__autoheader}");
376 sub(/^autoconf$/, "%{__autoconf}");
377 sub(/^automake$/, "%{__automake}");
380 $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
381 $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
387 /^%clean/, (!/^%clean/ && $0 ~ SECTIONS) {
390 # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
399 /^%install/, (!/^%install/ && $0 ~ SECTIONS) {
403 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
405 print "rm -rf $RPM_BUILD_ROOT"
409 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
410 print "rm -rf $RPM_BUILD_ROOT"
416 # 'install -d' instead 'mkdir -p'
418 sub(/mkdir -p/, "install -d")
420 # 'install' instead 'cp -p'
422 sub(/cp -p/, "install")
424 # No '-u root' or '-g root' for 'install'
425 if (/^install/ && /-[ug][ \t]*root/)
426 gsub(/-[ug][ \t]*root /, "")
428 if (/^install/ && /-m[ \t]*[0-9]+/)
429 gsub(/-m[ \t]*[0-9]+ /, "")
431 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
432 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
435 # No lines contain 'chmod' if it sets the modes to '644'
436 if ($1 ~ /chmod/ && $2 ~ /644/)
440 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
441 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
444 $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
450 /^%files/, (!/^%files/ && $0 ~ SECTIONS) {
462 /^%changelog/, (!/^%changelog/ && $0 ~ SECTIONS) {
466 # There should be some CVS keywords on the first line of %changelog.
468 if ($0 !~ _cvsmailfeedback)
469 print "* %{date} " _cvsmailfeedback > changelog_file
474 if (boc == 2 && !skip) {
475 if (!/All persons listed below/) {
476 printf "All persons listed below can be reached at " > changelog_file
477 print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
482 if (boc == 1 && !skip) {
485 print "$" "Log:$" > changelog_file
492 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
493 print " date +\"%a %b %d %Y\"`)" > changelog_file
500 if (!/^%[a-z]+$/ || /changelog/)
501 print > changelog_file
510 /^%pre/, (!/^%pre/ && $0 ~ SECTIONS) {
513 # %useradd and %groupadd may not be wrapped
514 if (/%(useradd|groupadd).*\\$/) {
517 $0 = substr(a, 1, length(a) - 1) $0;
521 /^%post/, (!/^%post/ && $0 ~ SECTIONS) {
525 /^%preun/, (!/^%preun/ && $0 ~ SECTIONS) {
528 /^%postun/, (!/^%postun/ && $0 ~ SECTIONS) {
531 /^%triggerin/, (!/^%triggerin/ && $0 ~ SECTIONS) {
534 /^%triggerun/, (!/^%triggerun/ && $0 ~ SECTIONS) {
537 /^%triggerpostun/, (!/^%triggerpostun/ && $0 ~ SECTIONS) {
540 /^%pretrans/, (!/^%pretrans/ && $0 ~ SECTIONS) {
543 /^%posttrans/, (!/^%posttrans/ && $0 ~ SECTIONS) {
551 # There should not be a space after the name of field
552 # and before the colon.
555 if (/^%perl_module_wo_prefix/) {
558 release = "0." fixedsub(".%{disttag}.at", "", $4)
563 if (field ~ /summary:/ && !/etc\.$/) {
566 if (field ~ /group(\([^)]+\)):/)
568 if (field ~ /group:/) {
570 sub(/^Utilities\//,"Applications/",$2)
571 sub(/^Games/,"Applications/Games",$2)
572 sub(/^X11\/Games/,"X11/Applications/Games",$2)
573 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
574 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
575 sub(/^X11\/GNOME/,"X11/Applications",$2)
576 sub(/^X11\/Utilities/,"X11/Applications",$2)
577 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
578 sub(/^Shells/,"Applications/Shells",$2)
580 sub(/^[^ \t]*[ \t]*/,"")
583 sub(/^System Environment\/Libraries$/, "Libraries", Grupa)
584 sub(/^System Environment\/Daemons$/, "Daemons", Grupa)
585 sub(/^Applications\/Internet$/, "Applications/Networking", Grupa)
586 sub(/^Applications\/Daemons$/, "Daemons", Grupa)
587 sub(/^Application\/Multimedia$/, "Applications/Multimedia", Grupa)
588 sub(/^System\/Servers$/, "Daemons", Grupa)
589 sub(/^X11\/Xserver$/, "X11/Servers", Grupa)
590 sub(/^X11\/XFree86/, "X11", Grupa)
591 sub(/^Applications\/Compilers$/, "Development/Languages", Grupa)
592 sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", Grupa)
593 sub(/^Networking\/Deamons$/, "Networking/Daemons", Grupa)
594 sub(/^Development\/Docs$/, "Documentation", Grupa)
596 print "Group:\t\t" Grupa
597 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
600 byl_plik_z_grupami = 0
602 while ((getline linia_grup < groups_file) > 0) {
603 byl_plik_z_grupami = 1
604 if (linia_grup == Grupa) {
610 if (!byl_plik_z_grupami)
611 print "######\t\t" groups_file ": no such file"
612 else if (!byl_opis_grupy)
613 print "######\t\t" "Unknown group!"
619 if (field ~ /prereq:/) {
620 sub(/PreReq:/, "Requires:", $1);
623 # split (build)requires, obsoletes on commas
624 if (field ~ /(obsoletes|requires):/ && $0 ~ /,/) {
625 l = substr($0, index($0, $2));
626 n = split(l, p, / *, */);
628 printf("%s\t%s\n", $1, p[i]);
633 if (field ~ /packager:|distribution:|docdir:|prefix:/)
636 if (field ~ /buildroot:/)
637 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
639 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
640 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
643 if (field ~ /name:/) {
644 if ($2 == "%{name}" && name) {
651 if (field ~ /version:/) {
652 if ($2 == "%{version}" && version) {
659 if (field ~ /release:/) {
660 if ($2 == "%{release}" && release) {
667 if (field ~ /serial:/)
671 if (field ~ /^url:$/)
674 # Use %{name} and %{version} in the filenames in "Source:"
675 if (field ~ /^source/ || field ~ /patch/) {
676 n = split($2, url, /\//)
677 if (url[n] ~ /\.gz$/) {
678 url[n+1] = ".gz" url[n+1]
679 sub(/\.gz$/,"",url[n])
681 if (url[n] ~ /\.zip$/) {
682 url[n+1] = ".zip" url[n+1]
683 sub(/\.zip$/,"",url[n])
685 if (url[n] ~ /\.tar$/) {
686 url[n+1] = ".tar" url[n+1]
687 sub(/\.tar$/,"",url[n])
689 if (url[n] ~ /\.patch$/) {
690 url[n+1] = ".patch" url[n+1]
691 sub(/\.patch$/,"",url[n])
693 if (url[n] ~ /\.bz2$/) {
694 url[n+1] = ".bz2" url[n+1]
695 sub(/\.bz2$/,"",url[n])
697 if (url[n] ~ /\.logrotate$/) {
698 url[n+1] = ".logrotate" url[n+1]
699 sub(/\.logrotate$/,"",url[n])
701 if (url[n] ~ /\.pamd$/) {
702 url[n+1] = ".pamd" url[n+1]
703 sub(/\.pamd$/,"",url[n])
706 # allow %{name} just in last url component
708 for (i = 1; i <= n; i++) {
709 url[i] = fixedsub("%{name}", name, url[i])
720 url[n] = fixedsub(name, "%{name}", url[n])
722 if (field ~ /source/) {
724 url[n] = fixedsub(version, "%{version}", url[n])
727 url[n] = fixedsub(_beta, "%{_beta}", url[n])
730 url[n] = fixedsub(_rc, "%{_rc}", url[n])
733 url[n] = fixedsub(_snap, "%{_snap}", url[n])
736 $2 = fixedsub(filename, url[n], $2)
739 sub("[?]use_mirror=.*$", "", $2);
740 sub("[?]download$", "", $2);
741 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
743 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
744 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
745 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
749 if (field ~ /^source:/)
752 if (field ~ /^patch:/)
757 if (field ~ /requires/) {
759 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
770 if (name_seen == 0 && name) {
775 if (version_seen == 0 && version) {
776 print "Version:\t" version
780 if (release_seen == 0 && release) {
781 print "Release:\t" release
788 if (do_not_touch_anything)
791 close(changelog_file)
792 while ((getline < changelog_file) > 0)
794 system("rm -f " changelog_file)
796 if (did_clean == 0) {
799 print "rm -rf $RPM_BUILD_ROOT"
804 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
807 if (has_changelog == 0)
811 print "* %{date} PLD Team <feedback@pld-linux.org>"
813 printf "All persons listed below can be reached at "
814 print "<cvs_login>@pld-linux.org\n"
820 function fixedsub(s1,s2,t, ind) {
821 # substitutes fixed strings (not regexps)
822 if (ind = index(t,s1))
823 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
827 # There should be one or two tabs after the colon.
828 function format_preamble()
831 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
839 # Replace directly specified directories with macros
840 function use_macros()
842 # -m, --skip-macros, --no-macros -- skip macros subst
843 if (ENVIRON["SKIP_MACROS"]) {
847 gsub(perl_sitearch, "%{perl_sitearch}")
848 gsub(perl_archlib, "%{perl_archlib}")
849 gsub(perl_privlib, "%{perl_privlib}")
850 gsub(perl_vendorlib, "%{perl_vendorlib}")
851 gsub(perl_vendorarch, "%{perl_vendorarch}")
852 gsub(perl_sitelib, "%{perl_sitelib}")
854 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
856 gsub(bindir, "%{_bindir}")
857 gsub("%{prefix}/bin", "%{_bindir}")
858 if(prefix"/bin" == bindir)
859 gsub("%{_prefix}/bin", "%{_bindir}")
861 for (c = 1; c <= NF; c++) {
862 if ($c ~ sbindir "/fix-info-dir")
864 if ($c ~ sbindir "/webapp")
866 if ($c ~ sbindir "/chsh")
868 if ($c ~ sbindir "/usermod")
870 gsub(sbindir, "%{_sbindir}", $c)
873 gsub("%{prefix}/sbin", "%{_sbindir}")
874 if (prefix"/sbin" == sbindir)
875 gsub("%{_prefix}/sbin", "%{_sbindir}")
877 for (c = 1; c <= NF; c++) {
878 if ($c ~ sysconfdir "/{?cron.")
880 if ($c ~ sysconfdir "/{?crontab.d")
882 if ($c ~ sysconfdir "/{?env.d")
884 if ($c ~ sysconfdir "/{?logrotate.d")
886 if ($c ~ sysconfdir "/{?pam.d")
888 if ($c ~ sysconfdir "/{?profile.d")
890 if ($c ~ sysconfdir "/{?rc.d")
892 if ($c ~ sysconfdir "/{?security")
894 if ($c ~ sysconfdir "/{?skel")
896 if ($c ~ sysconfdir "/{?sysconfig")
898 if ($c ~ sysconfdir "/{?shrc.d")
900 if ($c ~ sysconfdir "/{?certs")
902 if ($c ~ sysconfdir "/{?X11")
904 if ($c ~ sysconfdir "/{?ld.so.conf.d")
906 if ($c ~ sysconfdir "/{?httpd") # temp
908 gsub(sysconfdir, "%{_sysconfdir}", $c)
911 gsub(docdir, "%{_docdir}")
913 for (c = 1; c <= NF; c++) {
914 if ($c ~ datadir "/automake")
916 if ($c ~ datadir "/unsermake")
918 if ($c ~ datadir "/file/magic.mime")
920 gsub(datadir, "%{_datadir}", $c)
923 gsub("%{prefix}/share", "%{_datadir}")
924 if (prefix"/share" == datadir)
925 gsub("%{_prefix}/share", "%{_datadir}")
927 # CFLAGS="-I/usr/include/ncurses is usually correct.
928 if (!/-I\/usr\/include/) {
929 gsub(includedir, "%{_includedir}")
932 gsub("%{prefix}/include", "%{_includedir}")
933 if (prefix"/include" == includedir) {
934 gsub("%{_prefix}/include", "%{_includedir}")
937 gsub(mandir, "%{_mandir}")
938 if ($0 !~ "%{_datadir}/manual") {
939 gsub("%{_datadir}/man", "%{_mandir}")
941 gsub("%{_prefix}/share/man", "%{_mandir}")
942 gsub("%{prefix}/share/man", "%{_mandir}")
943 gsub("%{prefix}/man", "%{_mandir}")
944 gsub("%{_prefix}/man", "%{_mandir}")
946 gsub(infodir, "%{_infodir}")
947 gsub("%{prefix}/info", "%{_infodir}")
948 gsub("%{_prefix}/info", "%{_infodir}")
950 if (prefix !~ "/X11R6") {
951 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
954 gsub(examplesdir, "%{_examplesdir}")
957 # leave --with-foo=/usr alone
958 if ($0 !~ "--with.*=.*" prefix) {
959 for (c = 1; c <= NF; c++) {
960 if ($c ~ prefix "/sbin/fix-info-dir")
962 if ($c ~ prefix "/sbin/webapp")
964 if ($c ~ prefix "/sbin/chsh")
966 if ($c ~ prefix "/sbin/usermod")
968 if ($c ~ prefix "/share/automake")
970 if ($c ~ prefix "/share/unsermake")
972 if ($c ~ prefix "/lib/sendmail")
974 if ($c ~ prefix "/lib/pkgconfig")
977 # CFLAGS="-I/usr..." is usually correct.
980 # same for LDFLAGS="-L/usr..."
984 gsub(prefix, "%{_prefix}", $c)
987 gsub("%{prefix}", "%{_prefix}")
991 gsub("%{_includedir}/ncurses", "/usr/include/ncurses")
992 gsub("%{_includedir}/freetype", "/usr/include/freetype")
994 gsub("%{PACKAGE_VERSION}", "%{version}")
995 gsub("%{PACKAGE_NAME}", "%{name}")
997 gsub("^make$", "%{__make}")
998 gsub("^make ", "%{__make} ")
999 gsub("^gcc ", "%{__cc} ")
1002 gsub("^%make$", "%{__make}")
1003 gsub("^%make ", "%{__make} ")
1004 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1005 gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1006 gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1007 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
1008 gsub("^%{__install}", "install")
1009 gsub("^%{__rm}", "rm")
1010 gsub("%optflags", "%{rpmcflags}")
1011 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
1013 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1014 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
1015 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
1016 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
1017 $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
1019 gsub("%_bindir", "%{_bindir}")
1020 gsub("%_datadir", "%{_datadir}")
1021 gsub("%_iconsdir", "%{_iconsdir}")
1022 gsub("%_sbindir", "%{_sbindir}")
1023 gsub("%_mandir", "%{_mandir}")
1024 gsub("%name", "%{name}")
1026 gsub("/usr/src/linux", "%{_kernelsrcdir}")
1027 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
1031 # insertion sort of A[1..n]
1032 # copied from mawk manual
1033 function isort(A,n, i,j,hold) {
1034 for (i = 2; i <= n; i++) {
1036 while (A[j-1] > hold) {
1041 # sentinel A[0] = "" will be created if needed
1045 function use_files_macros( i, n, t, a)
1049 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1050 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1052 # uid/gid nobody is not valid in %files
1053 if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1054 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1058 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1059 gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1060 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1061 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1062 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1063 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1064 gsub("%{_sysconfdir}/security", "/etc/security")
1065 gsub("%{_sysconfdir}/skel", "/etc/skel")
1066 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1067 gsub("%{_sysconfdir}/certs", "/etc/certs")
1068 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1070 # /etc/init.d -> /etc/rc.d/init.d
1071 if (!/^\/etc\/init\.d$/) {
1072 gsub("/etc/init.d", "/etc/rc.d/init.d")
1075 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1076 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1077 $0 = "%attr(754,root,root) " $0
1079 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1080 gsub("^%attr\\(... *,", "%attr(754,");
1084 if (/lib.+\.so/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1085 $0 = "%attr(755,root,root) " $0
1088 # /etc/sysconfig files
1089 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1090 # attr not required, allow default 644 attr
1091 if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1092 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1093 gsub("%config", "%config(noreplace)")
1096 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1097 $NF = "%config(noreplace) " $NF
1100 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1101 gsub("^%attr\\(... *,", "%attr(640,");
1104 if (/\/etc\/sysconfig\// && !/%verify/) {
1105 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1109 # kill leading zeros
1110 if (/%attr\(0[1-9]/) {
1111 gsub("%attr\\(0", "%attr(")
1114 # sort %verify attrs
1115 if (match($0, /%verify\(not([^)]+)\)/)) {
1116 t = substr($0, RSTART, RLENGTH)
1117 # kill commas: %verify(not,md5,size,mtime)
1120 gsub(/^%verify\(not |\)$/, "", t)
1121 n = split(t, a, / /)
1125 for (i = 1 ; i <= n; i++) {
1130 gsub(/%verify\(not[^)]+\)/, s)
1137 # locale dir and no %lang -> bad
1138 if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1139 $(NF + 1) = "# FIXME consider using %find_lang"
1143 $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1144 $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1145 $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1147 gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1148 gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1149 gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1151 gsub("%{_datadir}/applications", "%{_desktopdir}");
1152 gsub("%{_datadir}/icons", "%{_iconsdir}");
1153 gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1156 function fill(ch, n, i) {
1157 for (i = 0; i < n; i++)
1161 function format_flush(line, indent, newline, word, first_word) {
1163 if (format_indent == -1)
1166 newline = fill(" ", format_indent) "- "
1168 while (match(line, /[^\t ]+/)) {
1169 word = substr(line, RSTART, RLENGTH)
1170 if (length(newline) + length(word) + 1 > tw) {
1173 if (format_indent == -1)
1176 newline = fill(" ", format_indent + 2)
1181 newline = newline word
1184 newline = newline " " word
1186 line = substr(line, RSTART + RLENGTH)
1188 if (newline ~ /[^\t ]/) {
1193 function cflags(var)
1195 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1201 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")