]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - adapter.awk
- poldek -u works again
[packages/rpm-build-tools.git] / adapter.awk
index cf3e4297c67d74a11296f4a34160fdd3bc73e2f7..36de9035bfeee3a2a60e7ef4d211bbecfb7fef8f 100644 (file)
@@ -7,8 +7,9 @@
 #      Micha³ Kuratczyk <kura@pld.org.pl>
 #      Sebastian Zagrodzki <s.zagrodzki@mimuw.edu.pl>
 #      Tomasz K³oczko <kloczek@rudy.mif.pg.gda.pl>
-#      Artur Frysiak <wiget@pld.org.pl>
+#      Artur Frysiak <wiget@pld-linux.org>
 #      Michal Kochanowicz <mkochano@pld.org.pl>
+#      Elan Ruusamäe <glen@pld-linux.org>
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 
 # TODO
@@ -23,11 +24,18 @@ BEGIN {
        bod = 0                 # Beggining of %description
        tw = 70                 # Descriptions width
 
+       b_idx = 0               # index of BR/R arrays
+
        # If variable removed, then 1 (for removing it from export)
        removed["LDFLAGS"] = 0
        removed["CFLAGS"] = 0
        removed["CXXFLAGS"] = 0
 
+       # get cvsaddress for changelog section
+       # using rpm macros as too lazy to add ~/.adapterrc parsing support.
+       "rpm --eval '%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'" | getline _cvsmaildomain
+       "rpm --eval '%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'" | getline _cvsmailfeedback
+
        # If 1, we are inside of comment block (started with /^#%/)
        comment_block = 0
 
@@ -80,6 +88,40 @@ defattr == 1 {
        defattr = 0
 }
 
+function b_makekey(a, b,       s) {
+       s = a "" b;
+       # kill bcond
+       gsub("%{\\?[_a-zA-Z0-9]+:", "", s);
+       return s;
+}
+
+# sort BR/R!
+#
+# NOTES:
+# - mixing BR/R and anything else confuses this (all will be sorted together)
+#   so don't do that.
+# - comments leading the BR/R can not be associated,
+#   so don't adapterize when the BR/R are mixed with comments
+ENVIRON["SORTBR"] == 1 && preamble == 1 && /(Build)?Requires/, /(Build)?Requires/ { # && !/^%/) {
+       b_idx++;
+       l = substr($0, index($0, $2));
+       b_ktmp = b_makekey($1, l);
+       b_key[b_idx] = b_ktmp;
+       b_val[b_ktmp] = $0;
+
+       next;
+}
+
+preamble == 1 {
+       if (b_idx > 0) {
+               isort(b_key, b_idx);
+               for (i = 1; i <= b_idx; i++) {
+                       print "" b_val[b_key[i]];
+               }
+               b_idx = 0
+       }
+}
+
 # Comments
 /^#/ && (description == 0) {
        if (/This file does not like to be adapterized!/) {
@@ -171,6 +213,20 @@ defattr == 1 {
                sub(/^%setup/, "%setup -q")
        }
 
+       if (/^%setup/) {
+               gsub(name, "%{name}");
+               gsub(version, "%{version}");
+               if (_beta) {
+                       gsub(_beta, "%{_beta}");
+               }
+               if (_rc) {
+                       gsub(_rc, "%{_rc}");
+               }
+               if (_snap) {
+                       gsub(_snap, "%{_snap}");
+               }
+       }
+
        if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
                sub(/ -n %{name}-%{version}/, "")
        }
@@ -225,7 +281,14 @@ defattr == 1 {
                if (/^export[ ]*$/)
                        next
        }
+       
+       # use macros
+       $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
+       $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
 
+       # atrpms
+       $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
+       $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
 }
 
 ##########
@@ -278,6 +341,13 @@ defattr == 1 {
        # No lines contain 'chmod' if it sets the modes to '644'
        if ($1 ~ /chmod/ && $2 ~ /644/)
                next
+
+       # foreign rpms
+       $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
+       $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
+
+       # atrpms
+       $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
 }
 
 ##########
@@ -302,8 +372,8 @@ defattr == 1 {
        skip = 0
        # There should be some CVS keywords on the first line of %changelog.
        if (boc == 3) {
-               if (!/PLD Team/)
-                       print "* %{date} PLD Team <feedback@pld-linux.org>" > changelog_file
+               if ($0 !~ _cvsmailfeedback)
+                       print "* %{date} " _cvsmailfeedback > changelog_file
                else
                        skip = 1
                boc = 2
@@ -311,7 +381,7 @@ defattr == 1 {
        if (boc == 2 && !skip) {
                if (!/All persons listed below/) {
                        printf "All persons listed below can be reached at " > changelog_file
-                       print "<cvs_login>@pld-linux.org\n" > changelog_file
+                       print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
                } else
                        skip = 1
                boc = 1
@@ -346,10 +416,17 @@ defattr == 1 {
 ###########
 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
        preamble = 0
+
+       # %useradd and %groupadd may not be wrapped
+       if (/%(useradd|groupadd).*\\$/) {
+               a = $0; getline;
+               sub(/^[\s\t]*/, "");
+               $0 = substr(a, 1, length(a) - 1) $0;
+       }
 }
+
 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
        preamble = 0
-       use_macros()
 }
 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
        preamble = 0
@@ -381,6 +458,12 @@ preamble == 1 {
        # and before the colon.
        sub(/[ \t]*:/, ":")
 
+       if (/^%perl_module_wo_prefix/) {
+               name = $2
+               version = $3
+               release = "0." fixedsub(".%{disttag}.at", "", $4)
+       }
+
        field = tolower($1)
        fieldnlower = $1
        if (field ~ /group(\([^)]+\)):/)
@@ -423,6 +506,21 @@ preamble == 1 {
                next
        }
 
+       if (field ~ /prereq:/) {
+               $1 = "Requires:"
+               $(NF + 1) = " # FIXME add Requires(scriptlet) -adapter.awk"
+       }
+
+       # split (build)requires on commas
+       if (field ~ /requires:/ && $0 ~ /,/) {
+               l = substr($0, index($0, $2));
+               n = split(l, p, / *, */);
+               for (i in p) {
+                       printf("%s\t%s\n", $1, p[i]);
+               }
+               next;
+       }
+
        if (field ~ /packager:|distribution:|docdir:|prefix:/)
                next
 
@@ -433,11 +531,20 @@ preamble == 1 {
        if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
                $1 = "License:"
 
-       if (field ~ /name:/)
+       if (field ~ /name:/) {
                name = $2
+               name_seen = 1;
+       }
 
-       if (field ~ /version:/)
+       if (field ~ /version:/) {
                version = $2
+               version_seen = 1;
+       }
+
+       if (field ~ /release:/) {
+               release = $2
+               release_seen = 1;
+       }
 
        if (field ~ /serial:/)
                $1 = "Epoch:"
@@ -487,9 +594,13 @@ preamble == 1 {
                $2 = s url[n+1]
 
                filename = url[n]
-               url[n] = fixedsub(name, "%{name}", url[n])
+               if (name) {
+                       url[n] = fixedsub(name, "%{name}", url[n])
+               }
                if (field ~ /source/) {
-                       url[n] = fixedsub(version, "%{version}", url[n])
+                       if (version) {
+                               url[n] = fixedsub(version, "%{version}", url[n])
+                       }
                        if (_beta) {
                                url[n] = fixedsub(_beta, "%{_beta}", url[n])
                        }
@@ -509,6 +620,7 @@ preamble == 1 {
 
                sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
                sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
+               sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
        }
 
 
@@ -555,21 +667,33 @@ preamble == 1 {
                        _snap = $3
        }
 
-       if (field ~ /buildrequires:/) {
-               # obsolete
-               if ($2 ~ /rpm-pythonprov/) {
-                       next
-               }
+       if (field ~ /requires/) {
+               # atrpms
+               $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
        }
 }
 
-
 # main() ;-)
 {
        preamble = 1
 
        sub(/[ \t]+$/, "")
        print
+
+       if (name_seen == 0 && name) {
+               print "Name:\t" name
+               name_seen = 1
+       }
+
+       if (version_seen == 0 && version) {
+               print "Version:\t" version
+               version_seen = 1
+       }
+
+       if (release_seen == 0 && release) {
+               print "Release:\t" release
+               release_seen = 1
+       }
 }
 
 
@@ -582,6 +706,8 @@ END {
                print
        system("rm -f " changelog_file)
 
+
+
        if (did_clean == 0) {
                print ""
                print "%clean"
@@ -735,18 +861,23 @@ function use_macros()
 
        gsub("^make$", "%{__make}")
        gsub("^make ", "%{__make} ")
+       gsub("^gcc ", "%{__cc} ")
 
        # mandrake specs
        gsub("^%make$", "%{__make}")
        gsub("^%make ", "%{__make} ")
        gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
+       gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
        gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
+       gsub("^%{__install}", "install")
+       gsub("^%{__rm}", "rm")
        gsub("%optflags", "%{rpmcflags}")
        gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
 
        gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
        gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
-       gsub("%buildroot", "$RPM_BUILD_ROOT")
+       $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
+       $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
        gsub("%_bindir", "%{_bindir}")
        gsub("%_datadir", "%{_datadir}")
        gsub("%_iconsdir", "%{_iconsdir}")
@@ -798,7 +929,7 @@ function use_files_macros(  i, n, t, a)
                        $0 = "%attr(754,root,root) " $0
                }
                if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
-                       gsub("^%attr\(... *,", "%attr(754,");
+                       gsub("^%attr\\(... *,", "%attr(754,");
                }
        }
 
@@ -819,7 +950,7 @@ function use_files_macros(  i, n, t, a)
                }
 
                if (/\/etc\/sysconfig\// && /%attr\(755/) {
-                       gsub("^%attr\(... *,", "%attr(640,");
+                       gsub("^%attr\\(... *,", "%attr(640,");
                }
 
                if (/\/etc\/sysconfig\// && !/%verify/) {
@@ -829,7 +960,7 @@ function use_files_macros(  i, n, t, a)
 
 
        # kill leading zeros
-       gsub("%attr\(0", "%attr(")
+       gsub("%attr\\(0", "%attr(")
 
        # sort %verify attrs
        if (match($0, /%verify\(not([^)]+)\)/)) {
@@ -850,6 +981,11 @@ function use_files_macros( i, n, t, a)
        if (/%{_mandir}/) {
                gsub("\.gz$", "*")
        }
+
+       # atrpms
+       $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
+       $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
+       $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
 }
 
 function fill(ch, n, i) {
This page took 0.082419 seconds and 4 git commands to generate.