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
24 preamble = 1 # Is it part of preamble? Default - yes
25 boc = 4 # Beggining of %changelog
26 bod = 0 # Beggining of %description
27 tw = 70 # Descriptions width
29 b_idx = 0 # index of BR/R arrays
31 # If variable removed, then 1 (for removing it from export)
32 removed["LDFLAGS"] = 0
34 removed["CXXFLAGS"] = 0
36 # get cvsaddress for changelog section
37 # using rpm macros as too lazy to add ~/.adapterrc parsing support.
38 "rpm --eval '%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'" | getline _cvsmaildomain
39 "rpm --eval '%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'" | getline _cvsmailfeedback
41 # If 1, we are inside of comment block (started with /^#%/)
44 # File with rpm groups
45 "rpm --eval %_sourcedir" | getline groups_file
46 groups_file = groups_file "/rpm.groups"
47 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups >/dev/null")
49 # Temporary file for changelog section
50 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
53 "rpm --eval %_prefix" | getline prefix
54 "rpm --eval %_bindir" | getline bindir
55 "rpm --eval %_sbindir" | getline sbindir
56 "rpm --eval %_libdir" | getline libdir
57 "rpm --eval %_sysconfdir" | getline sysconfdir
58 "rpm --eval %_datadir" | getline datadir
59 "rpm --eval %_includedir" | getline includedir
60 "rpm --eval %_mandir" | getline mandir
61 "rpm --eval %_infodir" | getline infodir
62 "rpm --eval %_examplesdir" | getline examplesdir
64 "rpm --eval %perl_sitearch" | getline perl_sitearch
65 "rpm --eval %perl_archlib" | getline perl_archlib
66 "rpm --eval %perl_privlib" | getline perl_privlib
67 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
68 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
69 "rpm --eval %perl_sitelib" | getline perl_sitelib
71 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
74 # There should be a comment with CVS keywords on the first line of file.
76 if (!/# \$Revision:/) # If this line is already OK?
77 print "# $" "Revision:$, " "$" "Date:$" # No
80 next # It is enough for first line
84 # If the latest line matched /%files/
86 if ($0 !~ /defattr/) # If no %defattr
87 print "%defattr(644,root,root,755)" # Add it
89 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
93 function b_makekey(a, b, s) {
96 gsub("%{\\?[_a-zA-Z0-9]+:", "", s);
103 # - mixing BR/R and anything else confuses this (all will be sorted together)
105 # - comments leading the BR/R can not be associated,
106 # so don't adapterize when the BR/R are mixed with comments
107 ENVIRON["SORTBR"] == 1 && preamble == 1 && /(Build)?Requires/, /(Build)?Requires/ { # && !/^%/) {
109 l = substr($0, index($0, $2));
110 b_ktmp = b_makekey($1, l);
111 b_key[b_idx] = b_ktmp;
126 for (i = 1; i <= b_idx; i++) {
127 print "" b_val[b_key[i]];
134 /^#/ && (description == 0) {
135 if (/This file does not like to be adapterized!/) {
136 print # print this message
137 while (getline) # print the rest of spec as it is
139 do_not_touch_anything = 1 # do not touch anything in END()
143 # Generally, comments are printed without touching
149 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
151 if ($2 == "_applnkdir")
156 # do nothing further, otherwise adapter thinks we're at preamble
162 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
169 /^%description/, (/^%[a-z]+/ && !/^%description/ && !/^%((end)?if|else)/) {
172 if (/^%description/) {
179 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
181 format_flush(format_line, format_indent)
185 } else if (/^[ \t]*[-\*][ \t]*/) {
186 format_flush(format_line, format_indent)
188 format_indent = RLENGTH
189 match($0, /^[ \t]*[-\*][ \t]/)
190 format_line = substr($0, RLENGTH)
192 format_line = format_line " " $0
196 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
197 if (NF > 3 && $2 == "-l") {
199 for (i = 4; i <= NF; i++)
203 format_flush(format_line, format_indent)
218 /^%prep/, (/^%[a-z]+$/ && !/^%prep/ && !/^%((end)?if|else)/) {
224 if (/^%setup/ && !/-q/) {
225 sub(/^%setup/, "%setup -q")
229 gsub(name, "%{name}");
230 gsub(version, "%{version}");
232 gsub(_beta, "%{_beta}");
238 gsub(_snap, "%{_snap}");
242 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
243 sub(/ -n %{name}-%{version}/, "")
247 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
253 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
262 if (/LDFLAGS="-s"/) {
263 removed["LDFLAGS"] = 1
266 split($0, tmp, "LDFLAGS=")
267 count = split(tmp[2], flags, "\"")
268 if (flags[1] != "" && flags[1] !~ "!?debug") {
269 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
270 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
271 for (i = 2; i < count; i++)
272 $0 = $0 flags[i] "\""
278 if (cflags("CFLAGS") == 0)
282 if (cflags("CXXFLAGS") == 0)
286 if (removed["LDFLAGS"])
288 if (removed["CFLAGS"])
290 if (removed["CXXFLAGS"])
292 # Is there still something?
299 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
303 $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
304 $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
305 $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
307 sub(/^aclocal$/, "%{__aclocal}");
308 sub(/^autoheader$/, "%{__autoheader}");
309 sub(/^autoconf$/, "%{__autoconf}");
310 sub(/^automake$/, "%{__automake}");
313 $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
314 $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
320 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
328 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
332 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
334 print "rm -rf $RPM_BUILD_ROOT"
338 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
339 print "rm -rf $RPM_BUILD_ROOT"
345 # 'install -d' instead 'mkdir -p'
347 sub(/mkdir -p/, "install -d")
349 # 'install' instead 'cp -p'
351 sub(/cp -p/, "install")
353 # No '-u root' or '-g root' for 'install'
354 if (/^install/ && /-[ug][ \t]*root/)
355 gsub(/-[ug][ \t]*root /, "")
357 if (/^install/ && /-m[ \t]*[0-9]+/)
358 gsub(/-m[ \t]*[0-9]+ /, "")
360 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
361 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
364 # No lines contain 'chmod' if it sets the modes to '644'
365 if ($1 ~ /chmod/ && $2 ~ /644/)
369 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
370 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
373 $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
379 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
392 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
396 # There should be some CVS keywords on the first line of %changelog.
398 if ($0 !~ _cvsmailfeedback)
399 print "* %{date} " _cvsmailfeedback > changelog_file
404 if (boc == 2 && !skip) {
405 if (!/All persons listed below/) {
406 printf "All persons listed below can be reached at " > changelog_file
407 print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
412 if (boc == 1 && !skip) {
415 print "$" "Log:$" > changelog_file
422 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
423 print " date +\"%a %b %d %Y\"`)" > changelog_file
430 if (!/^%[a-z]+$/ || /changelog/)
431 print > changelog_file
440 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
443 # %useradd and %groupadd may not be wrapped
444 if (/%(useradd|groupadd).*\\$/) {
447 $0 = substr(a, 1, length(a) - 1) $0;
451 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
454 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
457 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
460 /^%triggerin/, (/^%[a-z]+$/ && !/^%triggerin/) {
463 /^%triggerun/, (/^%[a-z]+$/ && !/^%triggerun/) {
466 /^%triggerpostun/, (/^%[a-z]+$/ && !/^%triggerpostun/) {
469 /^%pretrans/, (/^%[a-z]+$/ && !/^%pretrans/) {
472 /^%posttrans/, (/^%[a-z]+$/ && !/^%posttrans/) {
480 # There should not be a space after the name of field
481 # and before the colon.
484 if (/^%perl_module_wo_prefix/) {
487 release = "0." fixedsub(".%{disttag}.at", "", $4)
492 if (field ~ /summary:/) {
495 if (field ~ /group(\([^)]+\)):/)
497 if (field ~ /group:/) {
499 sub(/^Utilities\//,"Applications/",$2)
500 sub(/^Games/,"Applications/Games",$2)
501 sub(/^X11\/Games/,"X11/Applications/Games",$2)
502 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
503 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
504 sub(/^X11\/GNOME/,"X11/Applications",$2)
505 sub(/^X11\/Utilities/,"X11/Applications",$2)
506 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
507 sub(/^Shells/,"Applications/Shells",$2)
509 sub(/^[^ \t]*[ \t]*/,"")
512 sub(/^System Environment\/Libraries/, "Libraries", Grupa)
513 sub(/^System Environment\/Daemons/, "Daemons", Grupa)
514 sub(/^Applications\/Internet/, "Applications/Networking", Grupa)
515 sub(/^System\/Servers/, "Daemons", Grupa)
516 sub(/^X11\/Xserver/, "X11/Servers", Grupa)
518 print "Group:\t\t" Grupa
519 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
522 byl_plik_z_grupami = 0
524 while ((getline linia_grup < groups_file) > 0) {
525 byl_plik_z_grupami = 1
526 if (linia_grup == Grupa) {
532 if (!byl_plik_z_grupami)
533 print "######\t\t" groups_file ": no such file"
534 else if (!byl_opis_grupy)
535 print "######\t\t" "Unknown group!"
541 if (field ~ /prereq:/) {
545 # split (build)requires on commas
546 if (field ~ /requires:/ && $0 ~ /,/) {
547 l = substr($0, index($0, $2));
548 n = split(l, p, / *, */);
550 printf("%s\t%s\n", $1, p[i]);
555 if (field ~ /packager:|distribution:|docdir:|prefix:/)
558 if (field ~ /buildroot:/)
559 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
561 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
562 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
565 if (field ~ /name:/) {
566 if ($2 == "%{name}" && name) {
573 if (field ~ /version:/) {
574 if ($2 == "%{version}" && version) {
581 if (field ~ /release:/) {
582 if ($2 == "%{release}" && release) {
589 if (field ~ /serial:/)
593 if (field ~ /^url:$/)
596 # Use %{name} and %{version} in the filenames in "Source:"
597 if (field ~ /^source/ || field ~ /patch/) {
598 n = split($2, url, /\//)
599 if (url[n] ~ /\.gz$/) {
600 url[n+1] = ".gz" url[n+1]
601 sub(/\.gz$/,"",url[n])
603 if (url[n] ~ /\.zip$/) {
604 url[n+1] = ".zip" url[n+1]
605 sub(/\.zip$/,"",url[n])
607 if (url[n] ~ /\.tar$/) {
608 url[n+1] = ".tar" url[n+1]
609 sub(/\.tar$/,"",url[n])
611 if (url[n] ~ /\.patch$/) {
612 url[n+1] = ".patch" url[n+1]
613 sub(/\.patch$/,"",url[n])
615 if (url[n] ~ /\.bz2$/) {
616 url[n+1] = ".bz2" url[n+1]
617 sub(/\.bz2$/,"",url[n])
619 if (url[n] ~ /\.logrotate$/) {
620 url[n+1] = ".logrotate" url[n+1]
621 sub(/\.logrotate$/,"",url[n])
623 if (url[n] ~ /\.pamd$/) {
624 url[n+1] = ".pamd" url[n+1]
625 sub(/\.pamd$/,"",url[n])
628 # allow %{name} just in last url component
630 for (i = 1; i <= n; i++) {
631 url[i] = fixedsub("%{name}", name, url[i])
642 url[n] = fixedsub(name, "%{name}", url[n])
644 if (field ~ /source/) {
646 url[n] = fixedsub(version, "%{version}", url[n])
649 url[n] = fixedsub(_beta, "%{_beta}", url[n])
652 url[n] = fixedsub(_rc, "%{_rc}", url[n])
655 url[n] = fixedsub(_snap, "%{_snap}", url[n])
658 $2 = fixedsub(filename, url[n], $2)
661 sub("[?]use_mirror=.*$", "", $2);
662 sub("[?]download$", "", $2);
663 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
665 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
666 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
667 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
671 if (field ~ /^source:/)
674 if (field ~ /patch:/)
679 if ($1 ~ /%define/) {
680 # Do not add %define of _prefix if it already is.
681 if ($2 ~ /^_prefix/) {
682 sub("^"prefix, $3, bindir)
683 sub("^"prefix, $3, sbindir)
684 sub("^"prefix, $3, libdir)
685 sub("^"prefix, $3, datadir)
686 sub("^"prefix, $3, includedir)
690 if ($2 ~ /_bindir/ && !/_sbindir/)
696 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
700 if ($2 ~ /_includedir/)
716 if ($2 ~ /^version$/)
718 if ($2 ~ /^release$/)
722 if (field ~ /requires/) {
724 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
735 if (name_seen == 0 && name) {
740 if (version_seen == 0 && version) {
741 print "Version:\t" version
745 if (release_seen == 0 && release) {
746 print "Release:\t" release
753 if (do_not_touch_anything)
756 close(changelog_file)
757 while ((getline < changelog_file) > 0)
759 system("rm -f " changelog_file)
763 if (did_clean == 0) {
766 print "rm -rf $RPM_BUILD_ROOT"
771 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
774 if (has_changelog == 0)
778 print "* %{date} PLD Team <feedback@pld-linux.org>"
780 printf "All persons listed below can be reached at "
781 print "<cvs_login>@pld-linux.org\n"
787 function fixedsub(s1,s2,t, ind) {
788 # substitutes fixed strings (not regexps)
789 if (ind = index(t,s1))
790 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
794 # There should be one or two tabs after the colon.
795 function format_preamble()
798 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
806 # Replace directly specified directories with macros
807 function use_macros()
809 gsub(perl_sitearch, "%{perl_sitearch}")
810 gsub(perl_archlib, "%{perl_archlib}")
811 gsub(perl_privlib, "%{perl_privlib}")
812 gsub(perl_vendorlib, "%{perl_vendorlib}")
813 gsub(perl_vendorarch, "%{perl_vendorarch}")
814 gsub(perl_sitelib, "%{perl_sitelib}")
816 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
818 gsub(bindir, "%{_bindir}")
819 gsub("%{prefix}/bin", "%{_bindir}")
820 if(prefix"/bin" == bindir)
821 gsub("%{_prefix}/bin", "%{_bindir}")
823 for (c = 1; c <= NF; c++) {
824 if ($c ~ sbindir "/fix-info-dir")
826 gsub(sbindir, "%{_sbindir}", $c)
829 gsub("%{prefix}/sbin", "%{_sbindir}")
830 if (prefix"/sbin" == sbindir)
831 gsub("%{_prefix}/sbin", "%{_sbindir}")
833 for (c = 1; c <= NF; c++) {
834 if ($c ~ sysconfdir "/{?cron.")
836 if ($c ~ sysconfdir "/{?crontab.d")
838 if ($c ~ sysconfdir "/{?env.d")
840 if ($c ~ sysconfdir "/{?logrotate.d")
842 if ($c ~ sysconfdir "/{?pam.d")
844 if ($c ~ sysconfdir "/{?profile.d")
846 if ($c ~ sysconfdir "/{?rc.d")
848 if ($c ~ sysconfdir "/{?security")
850 if ($c ~ sysconfdir "/{?skel")
852 if ($c ~ sysconfdir "/{?sysconfig")
854 if ($c ~ sysconfdir "/{?certs")
856 gsub(sysconfdir, "%{_sysconfdir}", $c)
859 for (c = 1; c <= NF; c++) {
860 if ($c ~ datadir "/automake")
862 if ($c ~ datadir "/unsermake")
864 if ($c ~ datadir "/file/magic.mime")
866 gsub(datadir, "%{_datadir}", $c)
869 gsub("%_sbindir", "%{_sbindir}")
870 gsub("%_mandir", "%{_mandir}")
871 gsub("%name", "%{name}")
873 gsub("%{prefix}/share", "%{_datadir}")
874 if (prefix"/share" == datadir)
875 gsub("%{_prefix}/share", "%{_datadir}")
877 gsub(includedir, "%{_includedir}")
878 gsub("%{prefix}/include", "%{_includedir}")
879 if (prefix"/include" == includedir)
880 gsub("%{_prefix}/include", "%{_includedir}")
882 gsub(mandir, "%{_mandir}")
883 if ($0 !~ "%{_datadir}/manual")
884 gsub("%{_datadir}/man", "%{_mandir}")
885 gsub("%{_prefix}/share/man", "%{_mandir}")
886 gsub("%{prefix}/share/man", "%{_mandir}")
887 gsub("%{prefix}/man", "%{_mandir}")
888 gsub("%{_prefix}/man", "%{_mandir}")
890 gsub(infodir, "%{_infodir}")
891 gsub("%{prefix}/info", "%{_infodir}")
892 gsub("%{_prefix}/info", "%{_infodir}")
894 if (prefix !~ "/X11R6") {
895 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
898 gsub(examplesdir, "%{_examplesdir}")
901 # leave --with-foo=/usr alone
902 if ($0 !~ "--with.*=.*" prefix) {
903 for (c = 1; c <= NF; c++) {
904 if ($c ~ prefix "/sbin/fix-info-dir")
906 if ($c ~ prefix "/share/automake")
908 if ($c ~ prefix "/share/unsermake")
910 if ($c ~ prefix "/lib/sendmail")
912 if ($c ~ prefix "/lib/pkgconfig")
914 gsub(prefix, "%{_prefix}", $c)
917 gsub("%{prefix}", "%{_prefix}")
920 gsub("%{PACKAGE_VERSION}", "%{version}")
921 gsub("%{PACKAGE_NAME}", "%{name}")
923 gsub("^make$", "%{__make}")
924 gsub("^make ", "%{__make} ")
925 gsub("^gcc ", "%{__cc} ")
928 gsub("^%make$", "%{__make}")
929 gsub("^%make ", "%{__make} ")
930 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
931 gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
932 gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
933 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
934 gsub("^%{__install}", "install")
935 gsub("^%{__rm}", "rm")
936 gsub("%optflags", "%{rpmcflags}")
937 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
939 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
940 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
941 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
942 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
943 $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
945 gsub("%_bindir", "%{_bindir}")
946 gsub("%_datadir", "%{_datadir}")
947 gsub("%_iconsdir", "%{_iconsdir}")
949 gsub("/usr/src/linux", "%{_kernelsrcdir}")
950 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
954 # insertion sort of A[1..n]
955 # copied from mawk manual
956 function isort(A,n, i,j,hold) {
957 for (i = 2; i <= n; i++) {
959 while (A[j-1] > hold) {
964 # sentinel A[0] = "" will be created if needed
968 function use_files_macros( i, n, t, a)
970 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
971 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
973 # uid/gid nobody is not valid in %files
974 if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
975 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
979 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
980 gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
981 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
982 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
983 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
984 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
985 gsub("%{_sysconfdir}/security", "/etc/security")
986 gsub("%{_sysconfdir}/skel", "/etc/skel")
987 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
988 gsub("%{_sysconfdir}/certs", "/etc/certs")
989 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
991 # /etc/init.d -> /etc/rc.d/init.d
992 if (!/^\/etc\/init\.d$/) {
993 gsub("/etc/init.d", "/etc/rc.d/init.d")
996 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
997 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
998 $0 = "%attr(754,root,root) " $0
1000 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1001 gsub("^%attr\\(... *,", "%attr(754,");
1005 if (/lib.+\.so/ && !/^%attr.*/ && !/%exclude/) {
1006 $0 = "%attr(755,root,root) " $0
1009 # /etc/sysconfig files
1010 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1011 # attr not required, allow default 644 attr
1012 if (!/network-scripts/) {
1013 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1014 gsub("%config", "%config(noreplace)")
1017 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1018 $NF = "%config(noreplace) " $NF
1021 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1022 gsub("^%attr\\(... *,", "%attr(640,");
1025 if (/\/etc\/sysconfig\// && !/%verify/) {
1026 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1030 # kill leading zeros
1031 if (/%attr\(0[1-9]/) {
1032 gsub("%attr\\(0", "%attr(")
1035 # sort %verify attrs
1036 if (match($0, /%verify\(not([^)]+)\)/)) {
1037 t = substr($0, RSTART, RLENGTH)
1038 gsub(/^%verify\(not |\)$/, "", t)
1039 n = split(t, a, / /)
1043 for (i = 1 ; i <= n; i++) {
1048 gsub(/%verify\(not[^)]+\)/, s)
1056 $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1057 $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1058 $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1060 gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1061 gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1062 gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1064 gsub("%{_datadir}/applications", "%{_desktopdir}");
1065 gsub("%{_datadir}/icons", "%{_iconsdir}");
1066 gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1069 function fill(ch, n, i) {
1070 for (i = 0; i < n; i++)
1074 function format_flush(line, indent, newline, word, first_word) {
1076 if (format_indent == -1)
1079 newline = fill(" ", format_indent) "- "
1081 while (match(line, /[^\t ]+/)) {
1082 word = substr(line, RSTART, RLENGTH)
1083 if (length(newline) + length(word) + 1 > tw) {
1086 if (format_indent == -1)
1089 newline = fill(" ", format_indent + 2)
1094 newline = newline word
1097 newline = newline " " word
1099 line = substr(line, RSTART + RLENGTH)
1101 if (newline ~ /[^\t ]/) {
1106 function cflags(var)
1108 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1114 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")