]> 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 32141d2623f9cc2310aefdfa7b3050d5e677541c..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,10 +82,18 @@ 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
 }
 
 # There should be a comment with CVS keywords on the first line of file.
@@ -189,8 +198,14 @@ function b_makekey(a, b,   s) {
                bindir = $3
        if ($2 ~ /_sbindir/)
                sbindir = $3
-       if ($2 ~ /_libdir/)
-               libdir = $3
+       if ($2 ~ /_libdir/) {
+               if ($3 ~ /^%\(/) {
+                       # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
+                       libdir = "%%%%%%%%%%%%%%"
+               } else {
+                       libdir = $3
+               }
+       }
        if ($2 ~ /_sysconfdir/) {
                if ($3 ~ /^%\(/) {
                        # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
@@ -199,8 +214,14 @@ function b_makekey(a, b,   s) {
                        sysconfdir = $3
                }
        }
-       if ($2 ~ /_datadir/)
-               datadir = $3
+       if ($2 ~ /_datadir/) {
+               if ($3 ~ /^%\(/) {
+                       # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
+                       datadir = "%%%%%%%%%%%%%%"
+               } else {
+                       datadir = $3
+               }
+       }
        if ($2 ~ /_includedir/)
                includedir = $3
        if ($2 ~ /_mandir/)
@@ -255,7 +276,7 @@ function b_makekey(a, b,    s) {
        }
 
        # Format description
-       if (ENVIRON["SKIP_DESC"] != 1 && description == 1 && !$0 ~ SECTIONS && !/^%description/) {
+       if (ENVIRON["SKIP_DESC"] != 1 && description == 1 && !/^%[a-z]+/ && !/^%description/) {
                if (/^[ \t]*$/) {
                        format_flush(format_line, format_indent)
                        print ""
@@ -305,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) {
@@ -325,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.*", "");
@@ -343,6 +365,7 @@ function b_makekey(a, b,    s) {
        }
 
        use_macros()
+       use_tabs()
 
        if (/^automake$/)
                sub(/$/, " -a -c")
@@ -413,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 (!/^%/) {
-               use_macros()
-       }
+    use_macros()
 }
 
 ############
@@ -426,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
@@ -437,15 +462,23 @@ function b_makekey(a, b,  s) {
                did_rmroot=1
        }
 
+    if (tmpdir) {
+        buildroot = tmpdir "/" name "-" version "-root-" ENVIRON["USER"]
+               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/)
@@ -462,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);
 }
@@ -626,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)
@@ -639,7 +670,15 @@ preamble == 1 {
                sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", group)
                sub(/^Networking\/Deamons$/, "Networking/Daemons", group)
                sub(/^Development\/Docs$/, "Documentation", group)
+               sub(/^Development\/Documentation$/, "Documentation", group)
                sub(/^System Environment\/Kernel$/, "Base/Kernel", group)
+               sub(/^Development\/Libraries\/Java$/, "Development/Languages/Java", group)
+               sub(/^Development\/Java/, "Development/Languages/Java", group)
+               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
 
@@ -670,34 +709,53 @@ preamble == 1 {
        }
 
        # split (build)requires, obsoletes on commas
-       if (field ~ /(obsoletes|requires|conflicts):/ && NF > 2) {
+       if (field ~ /(obsoletes|requires|provides|conflicts):/ && NF > 2) {
                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:/) {
-               if ($2 == "awk" ||
-                       $2 == "binutils" ||
-                       $2 == "bzip2" ||
-                       $2 == "cpio" ||
-                       $2 == "diffutils" ||
-                       $2 == "elfutils" ||
-                       $2 == "fileutils" ||
-                       $2 == "findutils" ||
-                       $2 == "glibc-devel" ||
-                       $2 == "grep" ||
-                       $2 == "gzip" ||
-                       $2 == "make" ||
-                       $2 == "patch" ||
-                       $2 == "sed" ||
-                       $2 == "sh-utils" ||
-                       $2 == "tar" ||
-                       $2 == "textutils") {
+               l = substr($0, index($0, $2));
+               if (l == "awk" ||
+                       l == "binutils" ||
+                       l == "bzip2" ||
+                       l == "cpio" ||
+                       l == "diffutils" ||
+                       l == "elfutils" ||
+                       l == "fileutils" ||
+                       l == "findutils" ||
+                       l == "glibc-devel" ||
+                       l == "grep" ||
+                       l == "gzip" ||
+                       l == "make" ||
+                       l == "patch" ||
+                       l == "sed" ||
+                       l == "sh-utils" ||
+                       l == "tar" ||
+                       l == "textutils") {
                        next
                }
+
+        # perhaps we have common known name?
+
+        # jpackages
+               sub(/^java-devel$/, "jdk", $2);
+               sub(/^log4j$/, "jakarta-log4j", $2);
+               sub(/^oro$/, "jakarta-oro", $2);
+               sub(/^xerces-j2$/, "xerces-j", $2);
+               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
@@ -830,9 +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)
@@ -855,6 +919,11 @@ preamble == 1 {
        }
 }
 
+/^%bcond_/ {
+       # do nothing
+       print
+       next
+}
 
 # sort BR/R!
 #
@@ -879,12 +948,6 @@ ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && $0 ~ PREAMBLE_TAGS, $0 ~ PREAMBL
        next;
 }
 
-/^%bcond_/ {
-       # do nothing
-       print
-       next
-}
-
 preamble == 1 {
        if (b_idx > 0) {
                isort(b_key, b_idx);
@@ -905,7 +968,7 @@ preamble == 1 {
        print
 
        if (name_seen == 0 && name) {
-               print "Name:\t" name
+               print "Name:\t\t" name
                name_seen = 1
        }
 
@@ -934,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
@@ -950,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) {
@@ -998,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}")
@@ -1009,6 +1088,14 @@ function use_macros()
        gsub(py_sitedir, "%{py_sitedir}")
        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}")
 
@@ -1022,18 +1109,23 @@ function use_macros()
                        continue;
                if ($c ~ sbindir "/webapp")
                        continue;
+               if ($c ~ sbindir "/ldconfig")
+                       continue;
                if ($c ~ sbindir "/chsh")
                        continue;
                if ($c ~ sbindir "/usermod")
                        continue;
                if ($c ~ sbindir "/chkconfig")
                        continue;
+               if ($c ~ sbindir "/installzope(product|3package)")
+                       continue;
                gsub(sbindir, "%{_sbindir}", $c)
        }
 
        gsub("%{prefix}/sbin", "%{_sbindir}")
-       if (prefix"/sbin" == sbindir)
+       if (prefix"/sbin" == sbindir) {
                gsub("%{_prefix}/sbin", "%{_sbindir}")
+       }
 
        for (c = 1; c <= NF; c++) {
                if ($c ~ sysconfdir "/{?cron.")
@@ -1042,6 +1134,10 @@ function use_macros()
                        continue;
                if ($c ~ sysconfdir "/{?env.d")
                        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")
@@ -1070,6 +1166,8 @@ function use_macros()
                        continue;
                if ($c ~ sysconfdir "/{?samba")
                        continue;
+               if ($c ~ sysconfdir "/shells")
+                       continue;
                gsub(sysconfdir, "%{_sysconfdir}", $c)
        }
 
@@ -1131,6 +1229,8 @@ function use_macros()
                                        continue;
                                if ($c ~ prefix "/sbin/usermod")
                                        continue;
+                               if ($c ~ prefix "/sbin/installzope(product|3package)")
+                                       continue;
                                if ($c ~ prefix "/share/automake")
                                        continue;
                                if ($c ~ prefix "/share/unsermake")
@@ -1193,9 +1293,23 @@ function use_macros()
        gsub("%_sbindir", "%{_sbindir}")
        gsub("%_mandir", "%{_mandir}")
        gsub("%name", "%{name}")
+    gsub(/%__rm/, "rm");
+    gsub(/%__mkdir_p/, "install -d");
+    gsub(/%__cp/, "cp");
+    gsub(/%__ln_s/, "ln -s");
+    gsub(/%__sed/, "%{__sed}");
+    gsub(/%__cat/, "cat");
+    gsub(/%__chmod/, "chmod");
 
        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) {
@@ -1231,6 +1345,8 @@ function use_files_macros(        i, n, t, a)
                return;
        }
 
+       sub("^%doc %{_mandir}", "%{_mandir}")
+
        gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
        gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
 
@@ -1283,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
                }
 
@@ -1305,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)
@@ -1479,3 +1601,46 @@ function format_requires(tag, value,     n, p, i, deps, ndeps) {
        }
        return substr(s, 1, length(s)-1);
 }
+
+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.049626 seconds and 4 git commands to generate.