3 # This is adapter v0.27. Adapter adapts .spec files for PLD Linux.
6 # Copyright (C) 1999-2006 PLD-Team <feedback@pld-linux.org>
8 # Micha³ Kuratczyk <kura@pld.org.pl>
9 # Sebastian Zagrodzki <s.zagrodzki@mimuw.edu.pl>
10 # Tomasz K³oczko <kloczek@rudy.mif.pg.gda.pl>
11 # Artur Frysiak <wiget@pld-linux.org>
12 # Michal Kochanowicz <mkochano@pld.org.pl>
13 # Elan Ruusamä¤e <glen@pld-linux.org>
15 # See cvs log adapter{,.awk} for list of contributors
17 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
20 # - parse ../PLD-doc/BuildRequires.txt and setup proper BR epoches?
21 # - add "-nc" option to skip CVS interaction
23 # - sort Requires, BuildRequires
24 # - check if %description (lang=C) contains 8bit
25 # - desc wrapping is totally fucked up on global.spec,1.25, dosemu.spec,1.115-
28 RPM_SECTIONS = "package|build|changelog|clean|description|install|post|posttrans|postun|pre|prep|pretrans|preun|triggerin|triggerpostun|triggerun|verifyscript|check"
29 SECTIONS = "^%(" RPM_SECTIONS ")"
31 PREAMBLE_TAGS = "(Summary|Name|Version|Release|License|Group|URL|BuildArch|BuildRoot|Obsoletes|Conflicts|Provides|ExclusiveArch|ExcludeArch|Pre[Rr]eq|(Build)?Requires)"
33 preamble = 1 # Is it part of preamble? Default - yes
34 boc = 4 # Beginning of %changelog
35 bod = 0 # Beginning of %description
36 tw = 70 # Descriptions width
38 b_idx = 0 # index of BR/R arrays
40 # If variable removed, then 1 (for removing it from export)
41 removed["LDFLAGS"] = 0
43 removed["CXXFLAGS"] = 0
45 # get cvsaddress for changelog section
46 # using rpm macros as too lazy to add ~/.adapterrc parsing support.
47 "rpm --eval '%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'" | getline _cvsmaildomain
48 "rpm --eval '%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'" | getline _cvsmailfeedback
50 # If 1, we are inside of comment block (started with /^#%/)
53 # File with rpm groups
54 "rpm --eval %_sourcedir" | getline groups_file
55 groups_file = groups_file "/rpm.groups"
56 system("cd `rpm --eval %_sourcedir`; [ -f rpm.groups ] || cvs up rpm.groups >/dev/null")
57 system("[ -d ../PLD-doc ] && cd ../PLD-doc && ([ -f BuildRequires.txt ] || cvs up BuildRequires.txt >/dev/null)");
59 # Temporary file for changelog section
60 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
63 "rpm --eval %_prefix" | getline prefix
64 "rpm --eval %_bindir" | getline bindir
65 "rpm --eval %_sbindir" | getline sbindir
66 "rpm --eval %_libdir" | getline libdir
67 "rpm --eval %_sysconfdir" | getline sysconfdir
68 "rpm --eval %_datadir" | getline datadir
69 "rpm --eval %_includedir" | getline includedir
70 "rpm --eval %_mandir" | getline mandir
71 "rpm --eval %_infodir" | getline infodir
72 "rpm --eval %_examplesdir" | getline examplesdir
73 "rpm --eval %_defaultdocdir" | getline docdir
75 "rpm --eval %perl_sitearch" | getline perl_sitearch
76 "rpm --eval %perl_archlib" | getline perl_archlib
77 "rpm --eval %perl_privlib" | getline perl_privlib
78 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
79 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
80 "rpm --eval %perl_sitelib" | getline perl_sitelib
82 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
83 "rpm --eval %py_scriptdir " | getline py_scriptdir
84 "rpm --eval %php_pear_dir" | getline php_pear_dir
87 # There should be a comment with CVS keywords on the first line of file.
89 if (!/# \$Revision:/) # If this line is already OK?
90 print "# $" "Revision:$, " "$" "Date:$" # No
93 next # It is enough for first line
97 # If the latest line matched /%files/
99 if (ENVIRON["SKIP_DEFATTR"] != 1) {
100 if ($0 !~ /defattr/) { # If no %defattr
101 print "%defattr(644,root,root,755)" # Add it
103 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
109 function b_makekey(a, b, s) {
112 gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
114 # kill commented out items
115 gsub(/^#[ \t]*/, "", s);
118 gsub(/^Summary\(/, "11Summary(", s);
119 gsub(/^Summary/, "10Summary", s);
120 gsub(/^Name/, "2Name", s);
121 gsub(/^Version/, "3Version", s);
122 gsub(/^Release/, "4Release", s);
123 gsub(/^License/, "5License", s);
124 gsub(/^Group/, "6Group", s);
125 gsub(/^URL/, "7URL", s);
127 gsub(/^BuildRequires/, "B1BuildRequires", s);
128 gsub(/^BuildConflicts/, "B2BuildConflicts", s);
129 gsub(/^Provides/, "X1Provides", s);
130 gsub(/^Obsoletes/, "X2Obsoletes", s);
131 gsub(/^Conflicts/, "X3Conflicts", s);
132 gsub(/^BuildArch/, "X4BuildArch", s);
133 gsub(/^ExclusiveArch/, "X6ExclusiveArch", s);
134 gsub(/^ExcludeArch/, "X7ExcludeArch", s);
135 gsub(/^BuildRoot/, "X9BuildRoot", s);
137 # printf("%s -> %s\n", a""b, s);
142 /^#/ && (description == 0) {
143 if (/This file does not like to be adapterized!/) {
144 print # print this message
145 while (getline) # print the rest of spec as it is
147 do_not_touch_anything = 1 # do not touch anything in END()
151 # Generally, comments are printed without touching
161 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
162 if ($2 == "_applnkdir") {
169 # Do not add %define of _prefix if it already is.
170 if ($2 ~ /^_prefix/) {
171 sub("^"prefix, $3, bindir)
172 sub("^"prefix, $3, sbindir)
173 sub("^"prefix, $3, libdir)
174 sub("^"prefix, $3, datadir)
175 sub("^"prefix, $3, includedir)
179 if ($2 ~ /_bindir/ && !/_sbindir/)
185 if ($2 ~ /_sysconfdir/) {
187 # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
188 sysconfdir = "%%%%%%%%%%%%%%"
195 if ($2 ~ /_includedir/)
204 # version related macros
212 # these are used usually when adapterizing external spec
215 if ($2 ~ /^version$/)
217 if ($2 ~ /^release$/)
220 if ($2 ~ /^mod_name$/)
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 && !$0 ~ SECTIONS && !/^%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);
373 $0 = fixedsub("automake -a --foreign --copy", "%{__automake}", $0);
374 $0 = fixedsub("automake -a -c --foreign", "%{__automake}", $0);
375 $0 = fixedsub("libtoolize --force --automake --copy", "%{__libtoolize}", $0);
376 $0 = fixedsub("libtoolize -c -f --automake", "%{__libtoolize}", $0);
378 sub(/^aclocal$/, "%{__aclocal}");
379 sub(/^autoheader$/, "%{__autoheader}");
380 sub(/^autoconf$/, "%{__autoconf}");
381 sub(/^automake$/, "%{__automake}");
384 $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
385 $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
391 /^%clean/, (!/^%clean/ && $0 ~ SECTIONS) {
394 # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
403 /^%install/, (!/^%install/ && $0 ~ SECTIONS) {
407 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
409 print "rm -rf $RPM_BUILD_ROOT"
413 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
414 print "rm -rf $RPM_BUILD_ROOT"
420 # 'install -d' instead 'mkdir -p'
422 sub(/mkdir -p/, "install -d")
424 # 'install' instead 'cp -p'
426 sub(/cp -p/, "install")
428 # No '-u root' or '-g root' for 'install'
429 if (/^install/ && /-[ug][ \t]*root/)
430 gsub(/-[ug][ \t]*root /, "")
432 if (/^install/ && /-m[ \t]*[0-9]+/)
433 gsub(/-m[ \t]*[0-9]+ /, "")
435 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
436 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
439 # No lines contain 'chmod' if it sets the modes to '644'
440 if ($1 ~ /chmod/ && $2 ~ /644/)
444 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
445 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
448 $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
454 /^%files/, (!/^%files/ && $0 ~ SECTIONS) {
466 /^%changelog/, (!/^%changelog/ && $0 ~ SECTIONS) {
470 # There should be some CVS keywords on the first line of %changelog.
472 if ($0 !~ _cvsmailfeedback)
473 print "* %{date} " _cvsmailfeedback > changelog_file
478 if (boc == 2 && !skip) {
479 if (!/All persons listed below/) {
480 printf "All persons listed below can be reached at " > changelog_file
481 print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
486 if (boc == 1 && !skip) {
489 print "$" "Log:$" > changelog_file
496 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
497 print " date +\"%a %b %d %Y\"`)" > changelog_file
504 if (!/^%[a-z]+$/ || /changelog/)
505 print > changelog_file
514 /^%pre/, (!/^%pre/ && $0 ~ SECTIONS) {
517 # %useradd and %groupadd may not be wrapped
518 if (/%(useradd|groupadd).*\\$/) {
521 $0 = substr(a, 1, length(a) - 1) $0;
525 /^%post/, (!/^%post/ && $0 ~ SECTIONS) {
529 /^%preun/, (!/^%preun/ && $0 ~ SECTIONS) {
532 /^%postun/, (!/^%postun/ && $0 ~ SECTIONS) {
535 /^%triggerin/, (!/^%triggerin/ && $0 ~ SECTIONS) {
538 /^%triggerun/, (!/^%triggerun/ && $0 ~ SECTIONS) {
541 /^%triggerpostun/, (!/^%triggerpostun/ && $0 ~ SECTIONS) {
544 /^%pretrans/, (!/^%pretrans/ && $0 ~ SECTIONS) {
547 /^%posttrans/, (!/^%posttrans/ && $0 ~ SECTIONS) {
550 /^%verifyscript/, (!/^%verifyscript/ && $0 ~ SECTIONS) {
553 /^%check/, (!/^%check/ && $0 ~ SECTIONS) {
561 # There should not be a space after the name of field
562 # and before the colon.
565 if (/^%perl_module_wo_prefix/) {
568 release = "0." fixedsub(".%{disttag}.at", "", $4)
573 if (field ~ /summary:/ && !/etc\.$/) {
576 if (field ~ /group(\([^)]+\)):/)
578 if (field ~ /group:/) {
581 sub(/^[^ \t]*[ \t]*/, "", group);
583 sub(/^Utilities\//,"Applications/", group)
584 sub(/^Games/,"Applications/Games", group)
585 sub(/^X11\/Games/,"X11/Applications/Games", group)
586 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries", group)
587 sub(/^X11\/GNOME\/Applications/,"X11/Applications", group)
588 sub(/^X11\/GNOME/,"X11/Applications", group)
589 sub(/^X11\/Utilities/,"X11/Applications", group)
590 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy", group)
591 sub(/^Shells/,"Applications/Shells", group)
592 sub(/^System Environment\/Libraries$/, "Libraries", group)
593 sub(/^System Environment\/Daemons$/, "Daemons", group)
594 sub(/^Applications\/Internet$/, "Applications/Networking", group)
595 sub(/^Applications\/Daemons$/, "Daemons", group)
596 sub(/^Application\/Multimedia$/, "Applications/Multimedia", group)
597 sub(/^System\/Servers$/, "Daemons", group)
598 sub(/^X11\/Xserver$/, "X11/Servers", group)
599 sub(/^X11\/XFree86/, "X11", group)
600 sub(/^Applications\/Compilers$/, "Development/Languages", group)
601 sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", group)
602 sub(/^Networking\/Deamons$/, "Networking/Daemons", group)
603 sub(/^Development\/Docs$/, "Documentation", group)
605 $0 = "Group:\t\t" group
607 if (group ~ /^X11/ && x11 == 0) # Is it X11 application?
610 byl_plik_z_groupmi = 0
612 while ((getline linia_grup < groups_file) > 0) {
613 byl_plik_z_groupmi = 1
614 if (linia_grup == group) {
620 if (!byl_plik_z_groupmi)
621 print "######\t\t" groups_file ": no such file"
622 else if (!byl_opis_grupy)
623 print "######\t\t" "Unknown group!"
628 if (field ~ /prereq:/) {
629 sub(/PreReq:/, "Requires:", $1);
632 # split (build)requires, obsoletes on commas
633 if (field ~ /(obsoletes|requires):/ && NF > 2) {
634 value = substr($0, index($0, $2));
635 $0 = format_requires($1, value);
638 # obsolete/unwanted tags
639 if (field ~ /vendor:|packager:|distribution:|docdir:|prefix:|icon:/) {
643 if (field ~ /buildroot:/)
644 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
646 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
647 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
650 if (field ~ /name:/) {
651 if ($2 == "%{name}" && name) {
658 if (field ~ /version:/) {
659 if ($2 == "%{version}" && version) {
666 if (field ~ /release:/) {
667 if ($2 == "%{release}" && release) {
674 if (field ~ /serial:/)
678 if (field ~ /^url:$/)
681 # Use %{name} and %{version} in the filenames in "Source:"
682 if (field ~ /^source/ || field ~ /patch/) {
683 n = split($2, url, /\//)
684 if (url[n] ~ /\.gz$/) {
685 url[n+1] = ".gz" url[n+1]
686 sub(/\.gz$/,"",url[n])
688 if (url[n] ~ /\.zip$/) {
689 url[n+1] = ".zip" url[n+1]
690 sub(/\.zip$/,"",url[n])
692 if (url[n] ~ /\.tar$/) {
693 url[n+1] = ".tar" url[n+1]
694 sub(/\.tar$/,"",url[n])
696 if (url[n] ~ /\.patch$/) {
697 url[n+1] = ".patch" url[n+1]
698 sub(/\.patch$/,"",url[n])
700 if (url[n] ~ /\.bz2$/) {
701 url[n+1] = ".bz2" url[n+1]
702 sub(/\.bz2$/,"",url[n])
704 if (url[n] ~ /\.logrotate$/) {
705 url[n+1] = ".logrotate" url[n+1]
706 sub(/\.logrotate$/,"",url[n])
708 if (url[n] ~ /\.pamd$/) {
709 url[n+1] = ".pamd" url[n+1]
710 sub(/\.pamd$/,"",url[n])
713 # allow %{name} only in last url component
715 for (i = 1; i <= n; i++) {
716 url[i] = fixedsub("%{name}", name, url[i])
727 url[n] = fixedsub(name, "%{name}", url[n])
729 if (field ~ /source/) {
731 url[n] = fixedsub(version, "%{version}", url[n])
734 url[n] = fixedsub(_beta, "%{_beta}", url[n])
737 url[n] = fixedsub(_rc, "%{_rc}", url[n])
740 url[n] = fixedsub(_snap, "%{_snap}", url[n])
743 # assigning to $2 kills preamble formatting
744 $2 = fixedsub(filename, url[n], $2)
747 sub("[?]use_mirror=.*$", "", $2);
748 sub("[?]download$", "", $2);
749 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
751 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
752 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
753 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
757 if (field ~ /^source:/)
760 if (field ~ /^patch:/)
763 kill_preamble_macros();
766 if (field ~ /requires/) {
768 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
776 # - mixing BR/R and anything else confuses this (all will be sorted together)
778 # - comments leading the BR/R can not be associated,
779 # so don't adapterize when the BR/R are mixed with comments
780 ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && $0 ~ PREAMBLE_TAGS, $0 ~ PREAMBLE_TAGS {
781 if ($1 ~ /Pre[Rr]eq:/) {
782 sub(/PreReq:/, "Requires:", $1);
785 # kill_preamble_macros(); # breaks tabbing
788 l = substr($0, index($0, $2));
789 b_ktmp = b_makekey($1, l);
790 b_key[b_idx] = b_ktmp;
805 for (i = 1; i <= b_idx; i++) {
806 print "" b_val[b_key[i]];
819 if (name_seen == 0 && name) {
824 if (version_seen == 0 && version) {
825 print "Version:\t" version
829 if (release_seen == 0 && release) {
830 print "Release:\t" release
837 if (do_not_touch_anything)
840 close(changelog_file)
841 while ((getline < changelog_file) > 0)
843 system("rm -f " changelog_file)
845 if (did_clean == 0) {
848 print "rm -rf $RPM_BUILD_ROOT"
853 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
856 if (has_changelog == 0)
860 print "* %{date} PLD Team <feedback@pld-linux.org>"
862 printf "All persons listed below can be reached at "
863 print "<cvs_login>@pld-linux.org\n"
869 function fixedsub(s1,s2,t, ind) {
870 # substitutes fixed strings (not regexps)
871 if (ind = index(t,s1))
872 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
876 # There should be one or two tabs after the colon.
877 function format_preamble()
879 if (/^#/ || /^%bcond_with/) {
883 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
891 # Replace directly specified directories with macros
892 function use_macros()
894 # -m, --skip-macros, --no-macros -- skip macros subst
895 if (ENVIRON["SKIP_MACROS"]) {
899 # leave inline sed lines alone
900 if (/(%{__sed}|sed) -i -e/) {
904 gsub(perl_sitearch, "%{perl_sitearch}")
905 gsub(perl_archlib, "%{perl_archlib}")
906 gsub(perl_privlib, "%{perl_privlib}")
907 gsub(perl_vendorlib, "%{perl_vendorlib}")
908 gsub(perl_vendorarch, "%{perl_vendorarch}")
909 gsub(perl_sitelib, "%{perl_sitelib}")
911 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
912 gsub(py_scriptdir, "%{py_scriptdir}")
914 gsub(bindir, "%{_bindir}")
915 gsub("%{prefix}/bin", "%{_bindir}")
916 if (prefix"/bin" == bindir)
917 gsub("%{_prefix}/bin", "%{_bindir}")
919 for (c = 1; c <= NF; c++) {
920 if ($c ~ sbindir "/fix-info-dir")
922 if ($c ~ sbindir "/webapp")
924 if ($c ~ sbindir "/chsh")
926 if ($c ~ sbindir "/usermod")
928 gsub(sbindir, "%{_sbindir}", $c)
931 gsub("%{prefix}/sbin", "%{_sbindir}")
932 if (prefix"/sbin" == sbindir)
933 gsub("%{_prefix}/sbin", "%{_sbindir}")
935 for (c = 1; c <= NF; c++) {
936 if ($c ~ sysconfdir "/{?cron.")
938 if ($c ~ sysconfdir "/{?crontab.d")
940 if ($c ~ sysconfdir "/{?env.d")
942 if ($c ~ sysconfdir "/{?logrotate.d")
944 if ($c ~ sysconfdir "/{?pam.d")
946 if ($c ~ sysconfdir "/{?profile.d")
948 if ($c ~ sysconfdir "/{?rc.d")
950 if ($c ~ sysconfdir "/{?security")
952 if ($c ~ sysconfdir "/{?skel")
954 if ($c ~ sysconfdir "/{?sysconfig")
956 if ($c ~ sysconfdir "/{?shrc.d")
958 if ($c ~ sysconfdir "/{?certs")
960 if ($c ~ sysconfdir "/{?X11")
962 if ($c ~ sysconfdir "/{?ld.so.conf.d")
964 if ($c ~ sysconfdir "/{?rpm")
966 if ($c ~ sysconfdir "/{?bash_completion.d")
968 if ($c ~ sysconfdir "/{?samba")
970 gsub(sysconfdir, "%{_sysconfdir}", $c)
973 gsub(docdir, "%{_docdir}")
974 gsub(php_pear_dir, "%{php_pear_dir}")
976 for (c = 1; c <= NF; c++) {
977 if ($c ~ datadir "/automake")
979 if ($c ~ datadir "/unsermake")
981 if ($c ~ datadir "/file/magic.mime")
983 gsub(datadir, "%{_datadir}", $c)
986 gsub("%{prefix}/share", "%{_datadir}")
987 if (prefix"/share" == datadir)
988 gsub("%{_prefix}/share", "%{_datadir}")
990 # CFLAGS="-I/usr/include/ncurses is usually correct.
991 if (!/-I\/usr\/include/) {
992 gsub(includedir, "%{_includedir}")
995 gsub("%{prefix}/include", "%{_includedir}")
996 if (prefix"/include" == includedir) {
997 gsub("%{_prefix}/include", "%{_includedir}")
1000 gsub(mandir, "%{_mandir}")
1001 if ($0 !~ "%{_datadir}/manual") {
1002 gsub("%{_datadir}/man", "%{_mandir}")
1004 gsub("%{_prefix}/share/man", "%{_mandir}")
1005 gsub("%{prefix}/share/man", "%{_mandir}")
1006 gsub("%{prefix}/man", "%{_mandir}")
1007 gsub("%{_prefix}/man", "%{_mandir}")
1009 gsub(infodir, "%{_infodir}")
1010 gsub("%{prefix}/info", "%{_infodir}")
1011 gsub("%{_prefix}/info", "%{_infodir}")
1013 if (prefix !~ "/X11R6") {
1014 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
1017 gsub(examplesdir, "%{_examplesdir}")
1019 if (prefix != "/") {
1020 # leave --with-foo=/usr alone
1021 if ($0 !~ "--with.*=.*" prefix) {
1022 for (c = 1; c <= NF; c++) {
1023 if ($c ~ prefix "/sbin/fix-info-dir")
1025 if ($c ~ prefix "/sbin/webapp")
1027 if ($c ~ prefix "/sbin/chsh")
1029 if ($c ~ prefix "/sbin/usermod")
1031 if ($c ~ prefix "/share/automake")
1033 if ($c ~ prefix "/share/unsermake")
1035 if ($c ~ prefix "/lib/sendmail")
1037 if ($c ~ prefix "/lib/pkgconfig")
1040 # CFLAGS="-I/usr..." is usually correct.
1043 # same for LDFLAGS="-L/usr..."
1047 gsub(prefix, "%{_prefix}", $c)
1050 gsub("%{prefix}", "%{_prefix}")
1054 gsub("%{_includedir}/ncurses", "/usr/include/ncurses")
1055 gsub("%{_includedir}/freetype", "/usr/include/freetype")
1057 gsub("%{PACKAGE_VERSION}", "%{version}")
1058 gsub("%{PACKAGE_NAME}", "%{name}")
1060 gsub("^make$", "%{__make}")
1061 gsub("^make ", "%{__make} ")
1062 gsub("^gcc ", "%{__cc} ")
1065 gsub("^%make$", "%{__make}")
1066 gsub("^%make ", "%{__make} ")
1067 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1068 gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1069 gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1070 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
1071 gsub("^%{__install}", "install")
1072 gsub("^%{__rm}", "rm")
1073 gsub("%optflags", "%{rpmcflags}")
1074 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
1076 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1077 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
1078 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
1079 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
1080 $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
1082 # split configure line to multiple lines
1083 if (/%configure / && !/\\$/) {
1084 $0 = format_configure($0);
1087 gsub("%_bindir", "%{_bindir}")
1088 gsub("%_datadir", "%{_datadir}")
1089 gsub("%_iconsdir", "%{_iconsdir}")
1090 gsub("%_sbindir", "%{_sbindir}")
1091 gsub("%_mandir", "%{_mandir}")
1092 gsub("%name", "%{name}")
1094 gsub("/usr/src/linux", "%{_kernelsrcdir}")
1095 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
1098 function format_configure(line, n, a, s) {
1099 n = split(line, a, / /);
1101 for (i = 2; i <= n; i++) {
1102 s = s "\t" a[i] " \\\n"
1108 # insertion sort of A[1..n]
1109 # copied from mawk manual
1110 function isort(A,n, i,j,hold) {
1111 for (i = 2; i <= n; i++) {
1113 while (A[j-1] > hold) {
1118 # sentinel A[0] = "" will be created if needed
1122 function use_files_macros( i, n, t, a)
1131 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1132 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1134 # uid/gid nobody is not valid in %files
1135 if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1136 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1139 # s[gu]id programs with globs are evil
1140 if (/%attr\([246]...,.*\*/ && !/FIXME/) {
1141 $0 = $0 " # FIXME no globs for suid/sgid files"
1145 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1146 gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1147 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1148 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1149 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1150 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1151 gsub("%{_sysconfdir}/security", "/etc/security")
1152 gsub("%{_sysconfdir}/skel", "/etc/skel")
1153 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1154 gsub("%{_sysconfdir}/certs", "/etc/certs")
1155 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1157 # /etc/init.d -> /etc/rc.d/init.d
1158 if (!/^\/etc\/init\.d$/) {
1159 gsub("/etc/init.d", "/etc/rc.d/init.d")
1162 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1163 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1164 $0 = "%attr(754,root,root) " $0
1166 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1167 gsub("^%attr\\(... *,", "%attr(754,");
1171 if (/lib.+\.so/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1172 $0 = "%attr(755,root,root) " $0
1175 if (/%{perl_vendorarch}.*\.so$/ && !/^%attr.*/) {
1176 $0 = "%attr(755,root,root) " $0
1179 # /etc/sysconfig files
1180 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1181 # attr not required, allow default 644 attr
1182 if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1183 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1184 gsub("%config", "%config(noreplace)")
1187 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1188 $NF = "%config(noreplace) " $NF
1191 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1192 gsub("^%attr\\(... *,", "%attr(640,");
1195 if (/\/etc\/sysconfig\// && !/%verify/) {
1196 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1200 # kill leading zeros
1201 if (/%attr\(0[1-9]/) {
1202 gsub("%attr\\(0", "%attr(")
1205 # sort %verify attrs
1206 if (match($0, /%verify\(not([^)]+)\)/)) {
1207 t = substr($0, RSTART, RLENGTH)
1208 # kill commas: %verify(not,md5,size,mtime)
1211 gsub(/^%verify\(not |\)$/, "", t)
1212 n = split(t, a, / /)
1216 for (i = 1 ; i <= n; i++) {
1221 gsub(/%verify\(not[^)]+\)/, s)
1228 # locale dir and no %lang -> bad
1229 if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1230 $(NF + 1) = "# FIXME consider using %find_lang"
1234 $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1235 $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1236 $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1238 gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1239 gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1240 gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1242 gsub("%{_datadir}/applications", "%{_desktopdir}");
1243 gsub("%{_datadir}/icons", "%{_iconsdir}");
1244 gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1247 function fill(ch, n, i) {
1248 for (i = 0; i < n; i++)
1252 function format_flush(line, indent, newline, word, first_word) {
1254 if (format_indent == -1)
1257 newline = fill(" ", format_indent) "- "
1259 while (match(line, /[^\t ]+/)) {
1260 word = substr(line, RSTART, RLENGTH)
1261 if (length(newline) + length(word) + 1 > tw) {
1264 if (format_indent == -1)
1267 newline = fill(" ", format_indent + 2)
1272 newline = newline word
1275 newline = newline " " word
1277 line = substr(line, RSTART + RLENGTH)
1279 if (newline ~ /[^\t ]/) {
1284 function cflags(var)
1286 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1292 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
1296 function demacroize(str)
1299 sub("%{mod_name}", mod_name, str);
1302 sub("%{name}", name, str);
1305 sub("%{version}", version, str);
1308 sub("%{_beta}", _beta, str);
1311 sub("%{_rc}", _rc, str);
1314 sub("%{_snap}", _snap, str);
1319 function kill_preamble_macros()
1321 if ($1 ~ /^URL:/ || $1 ~ /^Obsoletes:/) {
1322 # NB! assigning $2 a value breaks tabbing
1323 $2 = demacroize($2);
1324 # unify sourceforge url
1325 sub("\.sf\.net/$", ".sourceforge.net/", $2);
1329 function get_epoch(pkg, ver, epoch)
1332 # should parse the BR lines more adequately:
1333 # freetype = 2.0.0 -> correct
1334 # freetype = 2.1.9 -> with epoch 1, as epoch 1 was added in 2.1.7
1336 shell = "grep -o '^" pkg ":[^:]\+' ../PLD-doc/BuildRequires.txt | awk '{print $NF}'";
1337 shell | getline epoch;
1341 function format_requires(tag, value, n, p, i, deps, ndeps) {
1342 # skip any formatting for commented out items or some weird macros
1343 if (/^#/ || /%\(/) {
1344 return tag "\t" value
1346 n = split(value, p, / *,? */);
1347 for (i = 1; i <= n; i++) {
1348 if (p[i+1] ~ /[<=>]/) {
1349 # add epoch if the version doesn't have it but BuildRequires.txt has
1350 if (p[i] ~ /^[a-z]/ && p[i+2] !~ /^[0-9]+:/) {
1351 epoch = get_epoch(p[i], p[i+2])
1353 p[i+2] = epoch ":" p[i+2];
1356 deps[ndeps++] = p[i] " " p[i+1] " " p[i+2];
1359 deps[ndeps++] = p[i];
1364 s = s sprintf("%s\t%s\n", tag, deps[i]);
1366 return substr(s, 1, length(s)-1);