]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - adapter.awk
- more sf url unify
[packages/rpm-build-tools.git] / adapter.awk
index 21dfa4b58b4e28a929a78a78b2624b2e6a3f8893..171bfc62cfeafe62ea830fb0a82bec2711e1ebb2 100644 (file)
@@ -30,12 +30,13 @@ BEGIN {
 
        PREAMBLE_TAGS = "(Summary|Name|Version|Release|Epoch|License|Group|URL|BuildArch|BuildRoot|Obsoletes|Conflicts|Provides|ExclusiveArch|ExcludeArch|Pre[Rr]eq|(Build)?Requires)"
 
-       preamble = 1            # Is it part of preamble? Default - yes
+       preamble = 1    # Is it part of preamble? Default - yes
        boc = 4                 # Beginning of %changelog
        bod = 0                 # Beginning of %description
        tw = 70                 # Descriptions width
 
        b_idx = 0               # index of BR/R arrays
+    BR_count = 0   # number of additional BuildRequires
 
        # If variable removed, then 1 (for removing it from export)
        removed["LDFLAGS"] = 0
@@ -81,9 +82,16 @@ BEGIN {
        "rpm --eval %perl_vendorarch" | getline perl_vendorarch
        "rpm --eval %perl_sitelib" | getline perl_sitelib
 
-       "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
-       "rpm --eval %py_sitedir" | getline py_sitedir
-       "rpm --eval %py_scriptdir " | getline py_scriptdir
+       "rpm --eval %py_sitescriptdir 2>/dev/null" | getline py_sitescriptdir
+       "rpm --eval %py_sitedir 2>/dev/null" | getline py_sitedir
+       "rpm --eval %py_scriptdir 2>/dev/null" | getline py_scriptdir
+
+       "rpm --eval %ruby_archdir" | getline ruby_archdir
+       "rpm --eval %ruby_ridir" | getline ruby_ridir
+       "rpm --eval %ruby_rubylibdir" | getline ruby_rubylibdir
+       "rpm --eval %ruby_sitearchdir" | getline ruby_sitearchdir
+       "rpm --eval %ruby_sitelibdir" | getline ruby_sitelibdir
+
        "rpm --eval %php_pear_dir" | getline php_pear_dir
        "rpm --eval %tmpdir" | getline tmpdir
 }
@@ -318,7 +326,7 @@ function b_makekey(a, b,    s) {
                sub(/^%setup/, "%setup -q")
        }
 
-       if (/^%setup/) {
+       if (/^%setup/ && name != "setup") {
                $0 = fixedsub(name, "%{name}", $0);
                $0 = fixedsub(version, "%{version}", $0);
                if (_beta) {
@@ -338,6 +346,7 @@ function b_makekey(a, b,    s) {
        if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
                $0 = fixedsub(" -n %{name}-%{version}", "", $0)
        }
+    sub("^%patch ", "%patch0 ");
 
        # invalid in %prep
        sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
@@ -427,10 +436,7 @@ function b_makekey(a, b,   s) {
 /^%clean/, (!/^%clean/ && $0 ~ SECTIONS) {
        did_clean = 1
 
-       # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
-       if (!/^%post/) {
-               use_macros()
-       }
+    use_macros()
 }
 
 ############
@@ -440,7 +446,12 @@ function b_makekey(a, b,   s) {
 
        preamble = 0
 
-       if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
+       # foreign rpms
+       sub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
+    sub("%buildroot", "$RPM_BUILD_ROOT");
+    sub("%{buildroot}", "$RPM_BUILD_ROOT");
+
+       if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+(\${?RPM_BUILD_ROOT}?|%{?buildroot}?)/ && did_rmroot==0) {
                did_rmroot=1
                print "rm -rf $RPM_BUILD_ROOT"
                next
@@ -456,15 +467,18 @@ function b_makekey(a, b,  s) {
                gsub(buildroot, "$RPM_BUILD_ROOT")
     }
 
+    if (!/%{_lib}/) {
+        sub("\$RPM_BUILD_ROOT/%", "$RPM_BUILD_ROOT%")
+    }
+
        use_macros()
 
        # 'install -d' instead 'mkdir -p'
        if (/mkdir -p/)
                sub(/mkdir -p/, "install -d")
 
-       # 'install' instead 'cp -p'
-       if (/cp -p\b/)
-               sub(/cp -p/, "install")
+       # cp -a already implies cp -r
+    sub(/^cp -ar/, "cp -a")
 
        # No '-u root' or '-g root' for 'install'
        if (/^install/ && /-[ug][ \t]*root/)
@@ -481,10 +495,6 @@ function b_makekey(a, b,   s) {
        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);
 }
@@ -645,8 +655,10 @@ preamble == 1 {
                sub(/^X11\/GNOME/,"X11/Applications", group)
                sub(/^X11\/Utilities/,"X11/Applications", group)
                sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy", group)
+               sub(/^X11\/Library/,"X11/Libraries", group)
                sub(/^Shells/,"Applications/Shells", group)
                sub(/^System Environment\/Libraries$/, "Libraries", group)
+               sub(/^Library\/Development$/, "Development/Libraries", group)
                sub(/^System Environment\/Daemons$/, "Daemons", group)
                sub(/^Applications\/Internet$/, "Applications/Networking", group)
                sub(/^Applications\/Daemons$/, "Daemons", group)
@@ -665,6 +677,8 @@ preamble == 1 {
                sub(/^Development\/Testing$/, "Development", group)
                sub(/^Text Processing\/Markup\/HTML$/, "Applications/Text", group)
                sub(/^Text Processing\/Markup\/XML$/, "Applications/Text", group)
+               sub(/^Web\/Database$/, "Applications/WWW", group)
+               sub(/^System Environment\/Base$/, "Base", group)
 
                $0 = "Group:\t\t" group
 
@@ -699,7 +713,7 @@ preamble == 1 {
                value = substr($0, index($0, $2));
                $0 = format_requires($1, value);
        }
-
+    
        # BR: tar (and others) is to common (rpm-build requires it)
        if (field ~ /^buildrequires:/) {
                l = substr($0, index($0, $2));
@@ -733,8 +747,15 @@ preamble == 1 {
                sub(/^ant-junit$/, "jakarta-ant", $2);
                sub(/^ldapjdk$/, "ldapsdk", $2);
                sub(/^saxon-scripts$/, "saxon", $2);
+
+        replace_php_virtual_deps();
        }
 
+       if (field ~ /^requires:/) {
+        replace_php_virtual_deps();
+    }
+
+
        # obsolete/unwanted tags
        if (field ~ /vendor:|packager:|distribution:|docdir:|prefix:|icon:|author:|author-email:|metadata-version:/) {
                next
@@ -867,10 +888,15 @@ preamble == 1 {
                $2 = fixedsub(filename, url[n], $2)
 
                # sourceforge urls
+               sub("[?&]big_mirror=.*$", "", $2);
+               sub("[?&]modtime=.*$", "", $2);
+
                sub("[?]use_mirror=.*$", "", $2);
                sub("[?]download$", "", $2);
+
                sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
                sub("^http://download\.sf\.net/", "http://dl.sourceforge.net/", $2)
+               sub("^http://download\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
 
                sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
                sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
@@ -942,7 +968,7 @@ preamble == 1 {
        print
 
        if (name_seen == 0 && name) {
-               print "Name:\t" name
+               print "Name:\t\t" name
                name_seen = 1
        }
 
@@ -971,6 +997,13 @@ END {
        if (do_not_touch_anything)
                exit 0
 
+    # TODO: need to output these in proper place
+    if (BR_count > 0) {
+        for (i = 0; i <= BR_count; i++) {
+            print BR[i];
+        }
+    }
+
        close(changelog_file)
        while ((getline < changelog_file) > 0)
                print
@@ -987,17 +1020,20 @@ END {
                print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
        }
 
-       if (has_changelog == 0)
+       if (has_changelog == 0) {
                print "%changelog"
+    }
 
-       if (boc > 2)
+       if (boc > 2) {
                print "* %{date} PLD Team <feedback@pld-linux.org>"
+    }
        if (boc > 1) {
                printf "All persons listed below can be reached at "
                print "<cvs_login>@pld-linux.org\n"
        }
-       if (boc > 0)
+       if (boc > 0) {
                print "$" "Log:$"
+    }
 }
 
 function fixedsub(s1,s2,t, ind) {
@@ -1035,6 +1071,12 @@ function use_macros()
                return;
        }
 
+    sub("%{_defaultdocdir}", "%{_docdir}");
+    sub("%{_bindir}/perl", "%{__perl}");
+    sub("%{_bindir}/python", "%{__python}");
+
+       gsub(infodir, "%{_infodir}")
+
        gsub(perl_sitearch, "%{perl_sitearch}")
        gsub(perl_archlib, "%{perl_archlib}")
        gsub(perl_privlib, "%{perl_privlib}")
@@ -1047,6 +1089,13 @@ function use_macros()
        gsub(py_scriptdir, "%{py_scriptdir}")
        gsub("%{_libdir}/python2.4/site-packages", "%{py_sitedir}")
        gsub("%{python_sitelib}", "%{py_sitedir}")
+
+       gsub(ruby_archdir, "%{ruby_archdir}")
+       gsub(ruby_ridir, "%{ruby_ridir}")
+       gsub(ruby_rubylibdir, "%{ruby_rubylibdir}")
+       gsub(ruby_sitearchdir, "%{ruby_sitearchdir}")
+       gsub(ruby_sitelibdir, "%{ruby_sitelibdir}")
+
        gsub("%{_datadir}/applications", "%{_desktopdir}")
        gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}")
 
@@ -1060,6 +1109,8 @@ function use_macros()
                        continue;
                if ($c ~ sbindir "/webapp")
                        continue;
+               if ($c ~ sbindir "/ldconfig")
+                       continue;
                if ($c ~ sbindir "/chsh")
                        continue;
                if ($c ~ sbindir "/usermod")
@@ -1085,6 +1136,8 @@ function use_macros()
                        continue;
                if ($c ~ sysconfdir "/{?modprobe.(d|conf)")
                        continue;
+               if ($c ~ sysconfdir "/{?udev/rules.d")
+                       continue;
                if ($c ~ sysconfdir "/{?logrotate.d")
                        continue;
                if ($c ~ sysconfdir "/{?pam.d")
@@ -1113,6 +1166,8 @@ function use_macros()
                        continue;
                if ($c ~ sysconfdir "/{?samba")
                        continue;
+               if ($c ~ sysconfdir "/shells")
+                       continue;
                gsub(sysconfdir, "%{_sysconfdir}", $c)
        }
 
@@ -1238,7 +1293,6 @@ function use_macros()
        gsub("%_sbindir", "%{_sbindir}")
        gsub("%_mandir", "%{_mandir}")
        gsub("%name", "%{name}")
-    gsub(/%ant/, "ant")
     gsub(/%__rm/, "rm");
     gsub(/%__mkdir_p/, "install -d");
     gsub(/%__cp/, "cp");
@@ -1249,6 +1303,13 @@ function use_macros()
 
        gsub("/usr/src/linux", "%{_kernelsrcdir}")
        gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
+
+       if (/^ant /) {
+               sub(/^ant/, "%ant")
+        add_br("BuildRequires:  jpackage-utils");
+        add_br("BuildRequires:  rpmbuild(macros) >= 1.294");
+    }
+
 }
 
 function format_configure(line,                n, a, s) {
@@ -1338,11 +1399,11 @@ function use_files_macros(      i, n, t, a)
        # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
        # attr not required, allow default 644 attr
        if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
-               if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
+               if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace/) {
                        gsub("%config", "%config(noreplace)")
                }
 
-               if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
+               if (/\/etc\/sysconfig\// && !/%config\(noreplace/) {
                        $NF = "%config(noreplace) " $NF
                }
 
@@ -1360,6 +1421,12 @@ function use_files_macros(       i, n, t, a)
                gsub("%attr\\(0", "%attr(")
        }
 
+    # kill default attrs
+    gsub(/%dir %attr\(755,root,root\)/, "%dir");
+    if (!/%dir/) {
+        gsub(/%attr\(644,root,root\) /, "");
+    }
+
        # sort %verify attrs
        if (match($0, /%verify\(not([^)]+)\)/)) {
                t = substr($0, RSTART, RLENGTH)
@@ -1540,3 +1607,40 @@ function use_tabs()
        # reverse vim: ts=4 sw=4 et
        gsub(/    /, "\t");
 }
+
+function add_br(br)
+{
+    BR[BR_count++] = br
+}
+
+# php virtual deps as discussed in devel-en
+function replace_php_virtual_deps()
+{
+    pkg = $2
+#    if (pkg == "php-program") {
+#        $0 = $1 "\t/usr/bin/php"
+#        return
+#    }
+
+    if (pkg ~ /^php-/ && pkg !~ /^php-(pear|common|cli|devel|fcgi|cgi|dirs|program|ZendOptimizer|pecl-)/) {
+        sub(/^php-/, "php(", pkg);
+        sub(/$/, ")", pkg);
+        $2 = pkg
+    }
+
+    if (pkg ~/^php$/) {
+        $2 = "webserver(php)";
+        if ($4 ~ /^[0-9]:/) {
+            $4 = substr($4, 3);
+        }
+    }
+
+    if (pkg ~/^php4$/) {
+        $2 = "webserver(php)";
+        if ($4 ~ /^[0-9]:/) {
+            $4 = substr($4, 3);
+        }
+    }
+}
+
+# vim:ts=4:sw=4:et
This page took 0.049976 seconds and 4 git commands to generate.