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|Epoch|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
74 "rpm --eval %_desktopdir" | getline desktopdir
75 "rpm --eval %_pixmapsdir" | getline pixmapsdir
77 "rpm --eval %perl_sitearch" | getline perl_sitearch
78 "rpm --eval %perl_archlib" | getline perl_archlib
79 "rpm --eval %perl_privlib" | getline perl_privlib
80 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
81 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
82 "rpm --eval %perl_sitelib" | getline perl_sitelib
84 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
85 "rpm --eval %py_sitedir" | getline py_sitedir
86 "rpm --eval %py_scriptdir " | getline py_scriptdir
87 "rpm --eval %php_pear_dir" | getline php_pear_dir
90 # There should be a comment with CVS keywords on the first line of file.
92 if (!/# \$Revision:/) # If this line is already OK?
93 print "# $" "Revision:$, " "$" "Date:$" # No
96 next # It is enough for first line
100 # If the latest line matched /%files/
102 if (ENVIRON["SKIP_DEFATTR"] != 1) {
103 if ($0 !~ /defattr/) { # If no %defattr
104 print "%defattr(644,root,root,755)" # Add it
106 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
112 function b_makekey(a, b, s) {
115 gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
117 # kill commented out items
118 gsub(/^#[ \t]*/, "", s);
121 gsub(/^Summary\(/, "11Summary(", s);
122 gsub(/^Summary/, "10Summary", s);
123 gsub(/^Name/, "2Name", s);
124 gsub(/^Version/, "3Version", s);
125 gsub(/^Release/, "4Release", s);
126 gsub(/^Epoch/, "5Epoch", s);
127 gsub(/^License/, "5License", s);
128 gsub(/^Group/, "6Group", s);
129 gsub(/^URL/, "7URL", s);
131 gsub(/^BuildRequires/, "B1BuildRequires", s);
132 gsub(/^BuildConflicts/, "B2BuildConflicts", s);
133 gsub(/^Provides/, "X1Provides", s);
134 gsub(/^Obsoletes/, "X2Obsoletes", s);
135 gsub(/^Conflicts/, "X3Conflicts", s);
136 gsub(/^BuildArch/, "X4BuildArch", s);
137 gsub(/^ExclusiveArch/, "X6ExclusiveArch", s);
138 gsub(/^ExcludeArch/, "X7ExcludeArch", s);
139 gsub(/^BuildRoot/, "X9BuildRoot", s);
141 # printf("%s -> %s\n", a""b, s);
146 /^#/ && (description == 0) {
147 if (/This file does not like to be adapterized!/) {
148 print # print this message
149 while (getline) # print the rest of spec as it is
151 do_not_touch_anything = 1 # do not touch anything in END()
155 # Generally, comments are printed without touching
165 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
166 if ($2 == "_applnkdir") {
171 if (did_files == 0) {
178 # Do not add %define of _prefix if it already is.
179 if ($2 ~ /^_prefix/) {
180 sub("^"prefix, $3, bindir)
181 sub("^"prefix, $3, sbindir)
182 sub("^"prefix, $3, libdir)
183 sub("^"prefix, $3, datadir)
184 sub("^"prefix, $3, includedir)
188 if ($2 ~ /_bindir/ && !/_sbindir/)
194 if ($2 ~ /_sysconfdir/) {
196 # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
197 sysconfdir = "%%%%%%%%%%%%%%"
204 if ($2 ~ /_includedir/)
213 # version related macros
223 # these are used usually when adapterizing external spec
226 if ($2 ~ /^version$/)
228 if ($2 ~ /^release$/)
231 if ($2 ~ /^mod_name$/)
235 # do nothing further, otherwise adapter thinks we're at preamble
241 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
248 /^%description/, (!/^%description/ && $0 ~ SECTIONS) {
251 if (/^%description/) {
258 if (ENVIRON["SKIP_DESC"] != 1 && description == 1 && !/^%[a-z]+/ && !/^%description/) {
260 format_flush(format_line, format_indent)
264 } else if (/^[ \t]*[-\*][ \t]*/) {
265 format_flush(format_line, format_indent)
267 format_indent = RLENGTH
268 match($0, /^[ \t]*[-\*][ \t]/)
269 format_line = substr($0, RLENGTH)
271 format_line = format_line " " $0
275 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
276 if (NF > 3 && $2 == "-l") {
278 for (i = 4; i <= NF; i++)
282 format_flush(format_line, format_indent)
297 /^%prep/, (!/^%prep/ && $0 ~ SECTIONS) {
304 if (/^%setup/ && !/-q/) {
305 sub(/^%setup/, "%setup -q")
309 $0 = fixedsub(name, "%{name}", $0);
310 $0 = fixedsub(version, "%{version}", $0);
312 $0 = fixedsub(_beta, "%{_beta}", $0);
315 $0 = fixedsub(_rc, "%{_rc}", $0);
318 $0 = fixedsub(_pre, "%{_pre}", $0);
321 $0 = fixedsub(_snap, "%{_snap}", $0);
325 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
326 $0 = fixedsub(" -n %{name}-%{version}", "", $0)
330 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
336 /^%build/, (!/^%build/ && $0 ~ SECTIONS) {
351 if (/LDFLAGS="-s"/) {
352 removed["LDFLAGS"] = 1
355 split($0, tmp, "LDFLAGS=")
356 count = split(tmp[2], flags, "\"")
357 if (flags[1] != "" && flags[1] !~ "!?debug") {
358 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
359 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
360 for (i = 2; i < count; i++)
361 $0 = $0 flags[i] "\""
367 if (cflags("CFLAGS") == 0)
371 if (cflags("CXXFLAGS") == 0)
375 if (removed["LDFLAGS"])
377 if (removed["CFLAGS"])
379 if (removed["CXXFLAGS"])
381 # Is there still something?
388 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
391 # use PLD Linux macros
392 $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
393 $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
394 $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
395 $0 = fixedsub("automake -a --foreign --copy", "%{__automake}", $0);
396 $0 = fixedsub("automake -a -c --foreign", "%{__automake}", $0);
397 $0 = fixedsub("libtoolize --force --automake --copy", "%{__libtoolize}", $0);
398 $0 = fixedsub("libtoolize -c -f --automake", "%{__libtoolize}", $0);
400 sub(/^aclocal$/, "%{__aclocal}");
401 sub(/^autoheader$/, "%{__autoheader}");
402 sub(/^autoconf$/, "%{__autoconf}");
403 sub(/^automake$/, "%{__automake}");
406 $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
407 $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
413 /^%clean/, (!/^%clean/ && $0 ~ SECTIONS) {
416 # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
425 /^%install/, (!/^%install/ && $0 ~ SECTIONS) {
429 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
431 print "rm -rf $RPM_BUILD_ROOT"
435 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
436 print "rm -rf $RPM_BUILD_ROOT"
442 # 'install -d' instead 'mkdir -p'
444 sub(/mkdir -p/, "install -d")
446 # 'install' instead 'cp -p'
448 sub(/cp -p/, "install")
450 # No '-u root' or '-g root' for 'install'
451 if (/^install/ && /-[ug][ \t]*root/)
452 gsub(/-[ug][ \t]*root /, "")
454 if (/^install/ && /-m[ \t]*[0-9]+/)
455 gsub(/-m[ \t]*[0-9]+ /, "")
457 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
458 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
461 # No lines contain 'chmod' if it sets the modes to '644'
462 if ($1 ~ /chmod/ && $2 ~ /644/)
466 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
467 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
470 $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
476 /^%files/, (!/^%files/ && $0 ~ SECTIONS) {
489 /^%changelog/, (!/^%changelog/ && $0 ~ SECTIONS) {
493 # There should be some CVS keywords on the first line of %changelog.
495 if ($0 !~ _cvsmailfeedback)
496 print "* %{date} " _cvsmailfeedback > changelog_file
501 if (boc == 2 && !skip) {
502 if (!/All persons listed below/) {
503 printf "All persons listed below can be reached at " > changelog_file
504 print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
509 if (boc == 1 && !skip) {
512 print "$" "Log:$" > changelog_file
519 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
520 print " date +\"%a %b %d %Y\"`)" > changelog_file
527 if (!/^%[a-z]+$/ || /changelog/)
528 print > changelog_file
537 /^%pre/, (!/^%pre/ && $0 ~ SECTIONS) {
540 if (gsub("/usr/sbin/useradd", "%useradd")) {
541 sub(" 2> /dev/null \|\| :", "");
542 sub(" >/dev/null 2>&1 \|\|:", "");
545 # %useradd and %groupadd may not be wrapped
546 if (/%(useradd|groupadd).*\\$/) {
549 $0 = substr(a, 1, length(a) - 1) $0;
554 /^%post/, (!/^%post/ && $0 ~ SECTIONS) {
558 /^%preun/, (!/^%preun/ && $0 ~ SECTIONS) {
562 /^%postun/, (!/^%postun/ && $0 ~ SECTIONS) {
566 /^%triggerin/, (!/^%triggerin/ && $0 ~ SECTIONS) {
570 /^%triggerun/, (!/^%triggerun/ && $0 ~ SECTIONS) {
574 /^%triggerpostun/, (!/^%triggerpostun/ && $0 ~ SECTIONS) {
578 /^%pretrans/, (!/^%pretrans/ && $0 ~ SECTIONS) {
582 /^%posttrans/, (!/^%posttrans/ && $0 ~ SECTIONS) {
586 /^%verifyscript/, (!/^%verifyscript/ && $0 ~ SECTIONS) {
590 /^%check/, (!/^%check/ && $0 ~ SECTIONS) {
599 # There should not be a space after the name of field
600 # and before the colon.
603 if (/^%perl_module_wo_prefix/) {
606 release = "0." fixedsub(".%{disttag}.at", "", $4)
611 if (field ~ /summary:/ && !/etc\.$/) {
614 if (field ~ /group(\([^)]+\)):/)
616 if (field ~ /group:/) {
619 sub(/^[^ \t]*[ \t]*/, "", group);
621 sub(/^Utilities\//,"Applications/", group)
622 sub(/^Games/,"Applications/Games", group)
623 sub(/^X11\/Games/,"X11/Applications/Games", group)
624 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries", group)
625 sub(/^X11\/GNOME\/Applications/,"X11/Applications", group)
626 sub(/^X11\/GNOME/,"X11/Applications", group)
627 sub(/^X11\/Utilities/,"X11/Applications", group)
628 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy", group)
629 sub(/^Shells/,"Applications/Shells", group)
630 sub(/^System Environment\/Libraries$/, "Libraries", group)
631 sub(/^System Environment\/Daemons$/, "Daemons", group)
632 sub(/^Applications\/Internet$/, "Applications/Networking", group)
633 sub(/^Applications\/Daemons$/, "Daemons", group)
634 sub(/^Application\/Multimedia$/, "Applications/Multimedia", group)
635 sub(/^System\/Servers$/, "Daemons", group)
636 sub(/^X11\/Xserver$/, "X11/Servers", group)
637 sub(/^X11\/XFree86/, "X11", group)
638 sub(/^Applications\/Compilers$/, "Development/Languages", group)
639 sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", group)
640 sub(/^Networking\/Deamons$/, "Networking/Daemons", group)
641 sub(/^Development\/Docs$/, "Documentation", group)
642 sub(/^System Environment\/Kernel$/, "Base/Kernel", group)
644 $0 = "Group:\t\t" group
646 if (group ~ /^X11/ && x11 == 0) # Is it X11 application?
649 byl_plik_z_groupmi = 0
651 while ((getline linia_grup < groups_file) > 0) {
652 byl_plik_z_groupmi = 1
653 if (linia_grup == group) {
659 if (!byl_plik_z_groupmi)
660 print "######\t\t" groups_file ": no such file"
661 else if (!byl_opis_grupy)
662 print "######\t\t" "Unknown group!"
668 if (field ~ /prereq:/) {
669 sub(/Pre[Rr]eq:/, "Requires:", $1);
672 # split (build)requires, obsoletes on commas
673 if (field ~ /(obsoletes|requires|conflicts):/ && NF > 2) {
674 value = substr($0, index($0, $2));
675 $0 = format_requires($1, value);
678 # BR: tar (and others) is to common (rpm-build requires it)
679 if (field ~ /^buildrequires:/) {
680 l = substr($0, index($0, $2));
689 l == "glibc-devel" ||
702 # obsolete/unwanted tags
703 if (field ~ /vendor:|packager:|distribution:|docdir:|prefix:|icon:|author:|author-email:|metadata-version:/) {
707 if (field ~ /buildroot:/) {
708 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
712 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
713 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/) {
717 if (field ~ /license:/) {
718 l = substr($0, index($0, $2));
719 if (l == "Python Software Foundation License") {
726 if (field ~ /name:/) {
727 if ($2 == "%{name}" && name) {
734 if (field ~ /version:/) {
735 if ($2 == "%{version}" && version) {
742 if (field ~ /release:/) {
743 if ($2 == "%{release}" && release) {
746 sub(/%atrelease /, "0.", $0)
752 if (field ~ /serial:/)
755 if (field ~ /home-page:/)
759 if (field ~ /^url:$/)
762 if (field ~ /^description:$/)
763 $1 = "\n%description\n"
765 # Use %{name} and %{version} in the filenames in "Source:"
766 if (field ~ /^source/ || field ~ /patch/) {
767 n = split($2, url, /\//)
768 if (url[n] ~ /\.gz$/) {
769 url[n+1] = ".gz" url[n+1]
770 sub(/\.gz$/,"",url[n])
772 if (url[n] ~ /\.zip$/) {
773 url[n+1] = ".zip" url[n+1]
774 sub(/\.zip$/,"",url[n])
776 if (url[n] ~ /\.tar$/) {
777 url[n+1] = ".tar" url[n+1]
778 sub(/\.tar$/,"",url[n])
780 if (url[n] ~ /\.patch$/) {
781 url[n+1] = ".patch" url[n+1]
782 sub(/\.patch$/,"",url[n])
784 if (url[n] ~ /\.bz2$/) {
785 url[n+1] = ".bz2" url[n+1]
786 sub(/\.bz2$/,"",url[n])
788 if (url[n] ~ /\.logrotate$/) {
789 url[n+1] = ".logrotate" url[n+1]
790 sub(/\.logrotate$/,"",url[n])
792 if (url[n] ~ /\.pamd$/) {
793 url[n+1] = ".pamd" url[n+1]
794 sub(/\.pamd$/,"",url[n])
797 # allow %{name} only in last url component
799 for (i = 1; i <= n; i++) {
800 url[i] = fixedsub("%{name}", name, url[i])
811 url[n] = fixedsub(name, "%{name}", url[n])
813 if (field ~ /source/) {
815 url[n] = fixedsub(version, "%{version}", url[n])
818 url[n] = fixedsub(_beta, "%{_beta}", url[n])
821 url[n] = fixedsub(_rc, "%{_rc}", url[n])
824 url[n] = fixedsub(_pre, "%{_pre}", url[n])
827 url[n] = fixedsub(_snap, "%{_snap}", url[n])
830 # assigning to $2 kills preamble formatting
831 $2 = fixedsub(filename, url[n], $2)
834 sub("[?]use_mirror=.*$", "", $2);
835 sub("[?]download$", "", $2);
836 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
838 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
839 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
840 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
844 if (field ~ /^source:/)
847 if (field ~ /^patch:/)
850 kill_preamble_macros();
853 if (field ~ /requires/) {
855 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
863 # - mixing BR/R and anything else confuses this (all will be sorted together)
865 # - comments leading the BR/R can not be associated,
866 # so don't adapterize when the BR/R are mixed with comments
867 ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && $0 ~ PREAMBLE_TAGS, $0 ~ PREAMBLE_TAGS {
868 if ($1 ~ /Pre[Rr]eq:/) {
869 sub(/Pre[Rr]eq:/, "Requires:", $1);
872 # kill_preamble_macros(); # breaks tabbing
875 l = substr($0, index($0, $2));
876 b_ktmp = b_makekey($1, l);
877 b_key[b_idx] = b_ktmp;
892 for (i = 1; i <= b_idx; i++) {
894 sub(/[ \t]+$/, "", v);
908 if (name_seen == 0 && name) {
913 if (version_seen == 0 && version) {
914 print "Version:\t" version
918 if (release_seen == 0 && release) {
919 print "Release:\t" release
923 if (did_build_root == 0) {
924 # print "BuildRoot:\t%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
927 if (did_groups == 0) {
928 # print "Group:\t\tunknown"
935 if (do_not_touch_anything)
938 close(changelog_file)
939 while ((getline < changelog_file) > 0)
941 system("rm -f " changelog_file)
943 if (did_clean == 0) {
946 print "rm -rf $RPM_BUILD_ROOT"
951 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
954 if (has_changelog == 0)
958 print "* %{date} PLD Team <feedback@pld-linux.org>"
960 printf "All persons listed below can be reached at "
961 print "<cvs_login>@pld-linux.org\n"
967 function fixedsub(s1,s2,t, ind) {
968 # substitutes fixed strings (not regexps)
969 if (ind = index(t,s1))
970 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
974 # There should be one or two tabs after the colon.
975 function format_preamble()
977 if (/^#/ || /^%bcond_with/) {
981 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
989 # Replace directly specified directories with macros
990 function use_macros()
992 # -m, --skip-macros, --no-macros -- skip macros subst
993 if (ENVIRON["SKIP_MACROS"]) {
997 # leave inline sed lines alone
998 if (/(%{__sed}|sed) -i -e/) {
1002 gsub(perl_sitearch, "%{perl_sitearch}")
1003 gsub(perl_archlib, "%{perl_archlib}")
1004 gsub(perl_privlib, "%{perl_privlib}")
1005 gsub(perl_vendorlib, "%{perl_vendorlib}")
1006 gsub(perl_vendorarch, "%{perl_vendorarch}")
1007 gsub(perl_sitelib, "%{perl_sitelib}")
1009 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
1010 gsub(py_sitedir, "%{py_sitedir}")
1011 gsub(py_scriptdir, "%{py_scriptdir}")
1012 gsub("%{_libdir}/python2.4/site-packages", "%{py_sitedir}")
1013 gsub("%{_datadir}/applications", "%{_desktopdir}")
1014 gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}")
1016 gsub(bindir, "%{_bindir}")
1017 gsub("%{prefix}/bin", "%{_bindir}")
1018 if (prefix"/bin" == bindir)
1019 gsub("%{_prefix}/bin", "%{_bindir}")
1021 for (c = 1; c <= NF; c++) {
1022 if ($c ~ sbindir "/fix-info-dir")
1024 if ($c ~ sbindir "/webapp")
1026 if ($c ~ sbindir "/chsh")
1028 if ($c ~ sbindir "/usermod")
1030 if ($c ~ sbindir "/chkconfig")
1032 gsub(sbindir, "%{_sbindir}", $c)
1035 gsub("%{prefix}/sbin", "%{_sbindir}")
1036 if (prefix"/sbin" == sbindir)
1037 gsub("%{_prefix}/sbin", "%{_sbindir}")
1039 for (c = 1; c <= NF; c++) {
1040 if ($c ~ sysconfdir "/{?cron.")
1042 if ($c ~ sysconfdir "/{?crontab.d")
1044 if ($c ~ sysconfdir "/{?env.d")
1046 if ($c ~ sysconfdir "/{?logrotate.d")
1048 if ($c ~ sysconfdir "/{?pam.d")
1050 if ($c ~ sysconfdir "/{?profile.d")
1052 if ($c ~ sysconfdir "/{?rc.d")
1054 if ($c ~ sysconfdir "/{?security")
1056 if ($c ~ sysconfdir "/{?skel")
1058 if ($c ~ sysconfdir "/{?sysconfig")
1060 if ($c ~ sysconfdir "/{?shrc.d")
1062 if ($c ~ sysconfdir "/{?certs")
1064 if ($c ~ sysconfdir "/{?X11")
1066 if ($c ~ sysconfdir "/{?ld.so.conf.d")
1068 if ($c ~ sysconfdir "/{?rpm")
1070 if ($c ~ sysconfdir "/{?bash_completion.d")
1072 if ($c ~ sysconfdir "/{?samba")
1074 gsub(sysconfdir, "%{_sysconfdir}", $c)
1077 gsub(docdir, "%{_docdir}")
1078 gsub(php_pear_dir, "%{php_pear_dir}")
1080 for (c = 1; c <= NF; c++) {
1081 if ($c ~ datadir "/automake")
1083 if ($c ~ datadir "/unsermake")
1085 if ($c ~ datadir "/file/magic.mime")
1087 gsub(datadir, "%{_datadir}", $c)
1090 gsub("%{prefix}/share", "%{_datadir}")
1091 if (prefix"/share" == datadir)
1092 gsub("%{_prefix}/share", "%{_datadir}")
1094 # CFLAGS="-I/usr/include/ncurses is usually correct.
1095 if (!/-I\/usr\/include/) {
1096 gsub(includedir, "%{_includedir}")
1099 gsub("%{prefix}/include", "%{_includedir}")
1100 if (prefix"/include" == includedir) {
1101 gsub("%{_prefix}/include", "%{_includedir}")
1104 gsub(mandir, "%{_mandir}")
1105 if ($0 !~ "%{_datadir}/manual") {
1106 gsub("%{_datadir}/man", "%{_mandir}")
1108 gsub("%{_prefix}/share/man", "%{_mandir}")
1109 gsub("%{prefix}/share/man", "%{_mandir}")
1110 gsub("%{prefix}/man", "%{_mandir}")
1111 gsub("%{_prefix}/man", "%{_mandir}")
1113 gsub(infodir, "%{_infodir}")
1114 gsub("%{prefix}/info", "%{_infodir}")
1115 gsub("%{_prefix}/info", "%{_infodir}")
1117 if (prefix !~ "/X11R6") {
1118 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
1121 gsub(examplesdir, "%{_examplesdir}")
1123 if (prefix != "/") {
1124 # leave --with-foo=/usr alone
1125 if ($0 !~ "--with.*=.*" prefix) {
1126 for (c = 1; c <= NF; c++) {
1127 if ($c ~ prefix "/sbin/fix-info-dir")
1129 if ($c ~ prefix "/sbin/webapp")
1131 if ($c ~ prefix "/sbin/chsh")
1133 if ($c ~ prefix "/sbin/usermod")
1135 if ($c ~ prefix "/share/automake")
1137 if ($c ~ prefix "/share/unsermake")
1139 if ($c ~ prefix "/lib/sendmail")
1141 if ($c ~ prefix "/lib/pkgconfig")
1144 # CFLAGS="-I/usr..." is usually correct.
1147 # same for LDFLAGS="-L/usr..."
1151 gsub(prefix, "%{_prefix}", $c)
1154 gsub("%{prefix}", "%{_prefix}")
1158 gsub("%{_includedir}/ncurses", "/usr/include/ncurses")
1159 gsub("%{_includedir}/freetype", "/usr/include/freetype")
1161 gsub("%{PACKAGE_VERSION}", "%{version}")
1162 gsub("%{PACKAGE_NAME}", "%{name}")
1164 gsub("^make$", "%{__make}")
1165 gsub("^make ", "%{__make} ")
1166 gsub("^gcc ", "%{__cc} ")
1169 gsub("^%make$", "%{__make}")
1170 gsub("^%make ", "%{__make} ")
1171 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1172 gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1173 gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1174 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
1175 gsub("^%{__install}", "install")
1176 gsub("^%{__rm}", "rm")
1177 gsub("%optflags", "%{rpmcflags}")
1178 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
1180 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1181 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
1182 $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
1183 $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
1184 $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
1186 # split configure line to multiple lines
1187 if (/%configure / && !/\\$/) {
1188 $0 = format_configure($0);
1191 gsub("%_bindir", "%{_bindir}")
1192 gsub("%_datadir", "%{_datadir}")
1193 gsub("%_iconsdir", "%{_iconsdir}")
1194 gsub("%_sbindir", "%{_sbindir}")
1195 gsub("%_mandir", "%{_mandir}")
1196 gsub("%name", "%{name}")
1198 gsub("/usr/src/linux", "%{_kernelsrcdir}")
1199 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
1202 function format_configure(line, n, a, s) {
1203 n = split(line, a, / /);
1205 for (i = 2; i <= n; i++) {
1206 s = s "\t" a[i] " \\\n"
1212 # insertion sort of A[1..n]
1213 # copied from mawk manual
1214 function isort(A,n, i,j,hold) {
1215 for (i = 2; i <= n; i++) {
1217 while (A[j-1] > hold) {
1222 # sentinel A[0] = "" will be created if needed
1226 function use_files_macros( i, n, t, a)
1235 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1236 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1238 # uid/gid nobody is not valid in %files
1239 if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1240 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1243 # s[gu]id programs with globs are evil
1244 if (/%attr\([246]...,.*\*/ && !/FIXME/) {
1245 $0 = $0 " # FIXME no globs for suid/sgid files"
1249 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1250 gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1251 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1252 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1253 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1254 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1255 gsub("%{_sysconfdir}/security", "/etc/security")
1256 gsub("%{_sysconfdir}/skel", "/etc/skel")
1257 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1258 gsub("%{_sysconfdir}/certs", "/etc/certs")
1259 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1261 # /etc/init.d -> /etc/rc.d/init.d
1262 if (!/^\/etc\/init\.d$/) {
1263 gsub("/etc/init.d", "/etc/rc.d/init.d")
1266 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1267 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1268 $0 = "%attr(754,root,root) " $0
1270 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1271 gsub("^%attr\\(... *,", "%attr(754,");
1275 if (/lib.+\.so/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1276 $0 = "%attr(755,root,root) " $0
1279 if (/%{perl_vendorarch}.*\.so$/ && !/^%attr.*/) {
1280 $0 = "%attr(755,root,root) " $0
1283 # /etc/sysconfig files
1284 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1285 # attr not required, allow default 644 attr
1286 if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1287 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1288 gsub("%config", "%config(noreplace)")
1291 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1292 $NF = "%config(noreplace) " $NF
1295 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1296 gsub("^%attr\\(... *,", "%attr(640,");
1299 if (/\/etc\/sysconfig\// && !/%verify/) {
1300 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1304 # kill leading zeros
1305 if (/%attr\(0[1-9]/) {
1306 gsub("%attr\\(0", "%attr(")
1309 # sort %verify attrs
1310 if (match($0, /%verify\(not([^)]+)\)/)) {
1311 t = substr($0, RSTART, RLENGTH)
1312 # kill commas: %verify(not,md5,size,mtime)
1315 gsub(/^%verify\(not |\)$/, "", t)
1316 n = split(t, a, / /)
1320 for (i = 1 ; i <= n; i++) {
1325 gsub(/%verify\(not[^)]+\)/, s)
1332 # locale dir and no %lang -> bad
1333 if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1334 $(NF + 1) = "# FIXME consider using %find_lang"
1338 $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1339 $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1340 $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1342 gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1343 gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1344 gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1346 gsub("%{_datadir}/applications", "%{_desktopdir}");
1347 gsub("%{_datadir}/icons", "%{_iconsdir}");
1348 gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1351 function use_script_macros()
1353 if (gsub("/sbin/service", "%service")) {
1354 sub(" >/dev/null 2>&1 \|\|:", "");
1355 sub(" 2> /dev/null \|\| :", "");
1359 function fill(ch, n, i) {
1360 for (i = 0; i < n; i++)
1364 function format_flush(line, indent, newline, word, first_word) {
1366 if (format_indent == -1)
1369 newline = fill(" ", format_indent) "- "
1371 while (match(line, /[^\t ]+/)) {
1372 word = substr(line, RSTART, RLENGTH)
1373 if (length(newline) + length(word) + 1 > tw) {
1376 if (format_indent == -1)
1379 newline = fill(" ", format_indent + 2)
1384 newline = newline word
1387 newline = newline " " word
1389 line = substr(line, RSTART + RLENGTH)
1391 if (newline ~ /[^\t ]/) {
1396 function cflags(var)
1398 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1404 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
1408 function demacroize(str)
1411 sub("%{mod_name}", mod_name, str);
1414 sub("%{name}", name, str);
1417 sub("%{version}", version, str);
1420 sub("%{_beta}", _beta, str);
1423 sub("%{_rc}", _rc, str);
1426 sub("%{_pre}", _pre, str);
1429 sub("%{_snap}", _snap, str);
1434 function kill_preamble_macros()
1436 if ($1 ~ /^URL:/ || $1 ~ /^Obsoletes:/) {
1437 # NB! assigning $2 a value breaks tabbing
1438 $2 = demacroize($2);
1439 # unify sourceforge url
1440 sub("\.sf\.net/$", ".sourceforge.net/", $2);
1444 function get_epoch(pkg, ver, epoch)
1447 # should parse the BR lines more adequately:
1448 # freetype = 2.0.0 -> correct
1449 # freetype = 2.1.9 -> with epoch 1, as epoch 1 was added in 2.1.7
1451 shell = "grep -o '^" pkg ":[^:]\+' ../PLD-doc/BuildRequires.txt | awk '{print $NF}'";
1452 shell | getline epoch;
1456 function format_requires(tag, value, n, p, i, deps, ndeps) {
1457 # skip any formatting for commented out items or some weird macros
1458 if (/^#/ || /%\(/) {
1459 return tag "\t" value
1461 n = split(value, p, / *,? */);
1462 for (i = 1; i <= n; i++) {
1463 if (p[i+1] ~ /[<=>]/) {
1464 # add epoch if the version doesn't have it but BuildRequires.txt has
1465 if (p[i] ~ /^[a-z]/ && p[i+2] !~ /^[0-9]+:/) {
1466 epoch = get_epoch(p[i], p[i+2])
1468 p[i+2] = epoch ":" p[i+2];
1471 deps[ndeps++] = p[i] " " p[i+1] " " p[i+2];
1474 deps[ndeps++] = p[i];
1479 s = s sprintf("%s\t%s\n", tag, deps[i]);
1481 return substr(s, 1, length(s)-1);