]> git.pld-linux.org Git - packages/adapter.git/blobdiff - adapter.awk
- simplified %setup
[packages/adapter.git] / adapter.awk
index 4a328c1b4508b7304bb0cdf4fe6ef2245cac7e2c..0c38cea064748e658f17f770b2d89f143aa6401d 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This is adapter v0.27. Adapter adapts .spec files for PLD.
 #
-# Copyright (C) 1999-2001 PLD-Team <feedback@pld.org.pl>
+# Copyright (C) 1999-2003 PLD-Team <feedback@pld-linux.org>
 # Authors:
 #      Micha³ Kuratczyk <kura@pld.org.pl>
 #      Sebastian Zagrodzki <s.zagrodzki@mimuw.edu.pl>
 #      Michal Kochanowicz <mkochano@pld.org.pl>
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 
+# TODO
+# - parse ../PLD-doc/BuildRequires.txt and setup proper BR epoches?
+# - add "-nc" option to skip CVS interaction
+# - sort Summary(XX)
+# - sort Requires, BuildRequires
+
 BEGIN {
        preamble = 1            # Is it part of preamble? Default - yes
        boc = 4                 # Beggining of %changelog
        bod = 0                 # Beggining of %description
-       tw = 70                 # Descriptions width
-       
+       tw = 70                 # Descriptions width
+
        # If variable removed, then 1 (for removing it from export)
        removed["LDFLAGS"] = 0
        removed["CFLAGS"] = 0
@@ -24,7 +30,7 @@ BEGIN {
 
        # If 1, we are inside of comment block (started with /^#%/)
        comment_block = 0
-       
+
        # File with rpm groups
        "rpm --eval %_sourcedir" | getline groups_file
        groups_file = groups_file "/rpm.groups"
@@ -43,6 +49,15 @@ BEGIN {
        "rpm --eval %_includedir" | getline includedir
        "rpm --eval %_mandir"   | getline mandir
        "rpm --eval %_infodir"  | getline infodir
+
+       "rpm --eval %perl_sitearch" | getline perl_sitearch
+       "rpm --eval %perl_archlib" | getline perl_archlib
+       "rpm --eval %perl_privlib" | getline perl_privlib
+       "rpm --eval %perl_archlib" | getline perl_archlib
+       "rpm --eval %perl_vendorlib" | getline perl_vendorlib
+       "rpm --eval %perl_vendorarch" | getline perl_vendorarch
+       "rpm --eval %perl_sitelib" | getline perl_sitelib
+       "rpm --eval %perl_sitearch" | getline perl_sitearch
 }
 
 # There should be a comment with CVS keywords on the first line of file.
@@ -88,10 +103,15 @@ defattr == 1 {
                date = 1
 }
 
+# Obsolete
+/^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
+       next
+}
+
 ################
 # %description #
 ################
-/^%description/, (/^%[a-z]+/ && !/^%description/) {
+/^%description/, (/^%[a-z]+/ && !/^%description/ && !/^%((end)?if|else)/) {
        preamble = 0
 
        if (/^%description/) {
@@ -100,14 +120,6 @@ defattr == 1 {
                format_indent = -1
        }
 
-       # Define _prefix and _mandir if it is X11 application
-#      if (/^%description$/ && x11 == 1) {
-#              print "%define\t\t_prefix\t\t/usr/X11R6"
-#              print "%define\t\t_mandir\t\t%{_prefix}/man\n"
-#              prefix = "/usr/X11R6"
-#              x11 = 2
-#      }
-       
        # Format description
        if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
                if (/^[ \t]*$/) {
@@ -117,15 +129,15 @@ defattr == 1 {
                        format_indent = -1
                } else if (/^[ \t]*[-\*][ \t]*/) {
                        format_flush(format_line, format_indent)
-                       match($0, /^[ \t]*/)    
+                       match($0, /^[ \t]*/)
                        format_indent = RLENGTH
                        match($0, /^[ \t]*[-\*][ \t]/)
                        format_line = substr($0, RLENGTH)
-               } else 
+               } else
                        format_line = format_line " " $0
                next
        }
+
        if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
                if (NF > 3 && $2 == "-l") {
                        ll = $1
@@ -148,22 +160,27 @@ defattr == 1 {
 #########
 # %prep #
 #########
-/^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
+/^%prep/, (/^%[a-z]+$/ && !/^%prep/ && !/^%((end)?if|else)/) {
        preamble = 0
-       
+
        # Add '-q' to %setup
-       if (/^%setup/ && !/-q/)
+       if (/^%setup/ && !/-q/) {
                sub(/^%setup/, "%setup -q")
+       }
+
+       if (/^%setup -q -n %{name}-%{version}$/) {
+               $0 = "%setup"
+       }
 }
 
 ##########
 # %build #
 ##########
-/^%build/, (/^%[a-z]+$/ && !/^%build/) {
+/^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
        preamble = 0
 
        use_macros()
-       
+
        if (/^automake$/)
                sub(/$/, " -a -c")
 
@@ -190,7 +207,7 @@ defattr == 1 {
        if (/CXXFLAGS=/)
                if (cflags("CXXFLAGS") == 0)
                        next
-       
+
        if (/^export /) {
                if (removed["LDFLAGS"])
                        sub(" LDFLAGS", "")
@@ -202,23 +219,23 @@ defattr == 1 {
                if (/^export[ ]*$/)
                        next
        }
-                       
+
 }
 
 ##########
 # %clean #
 ##########
-/^%clean/, (/^%[a-z]+$/ && !/^%clean/) {
+/^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
        did_clean = 1
 }
 
 ############
 # %install #
 ############
-/^%install/, (/^%[a-z]+$/ && !/^%install/) {
-       
+/^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
+
        preamble = 0
-       
+
        if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
                did_rmroot=1
                print "rm -rf $RPM_BUILD_ROOT"
@@ -229,24 +246,28 @@ defattr == 1 {
                print "rm -rf $RPM_BUILD_ROOT"
                did_rmroot=1
        }
-       
+
        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")
+
        # No '-u root' or '-g root' for 'install'
        if (/^install/ && /-[ug][ \t]*root/)
                gsub(/-[ug][ \t]*root /, "")
-       
+
        if (/^install/ && /-m[ \t]*644/)
                gsub(/-m[ \t]*644 /, "")
-       
+
        # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
        if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
                next
-       
+
        # No lines contain 'chmod' if it sets the modes to '644'
        if ($1 ~ /chmod/ && $2 ~ /644/)
                next
@@ -255,12 +276,12 @@ defattr == 1 {
 ##########
 # %files #
 ##########
-/^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
+/^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
        preamble = 0
-       
+
        if ($0 ~ /^%files/)
                defattr = 1
-       
+
        use_macros()
        use_files_macros()
 }
@@ -336,7 +357,7 @@ preamble == 1 {
        # There should not be a space after the name of field
        # and before the colon.
        sub(/[ \t]*:/, ":")
-       
+
        field = tolower($1)
        fieldnlower = $1
        if (field ~ /group(\([^)]+\)):/)
@@ -358,7 +379,7 @@ preamble == 1 {
 
                print "Group:\t\t" Grupa
                if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
-                      x11 = 1
+                       x11 = 1
 
                byl_plik_z_grupami = 0
                byl_opis_grupy = 0
@@ -374,21 +395,21 @@ preamble == 1 {
                        print "######\t\t" groups_file ": no such file"
                else if (!byl_opis_grupy)
                        print "######\t\t" "Unknown group!"
-               
+
                close(groups_file)
                next
        }
-       
+
        if (field ~ /packager:|distribution:|docdir:|prefix:/)
                next
-       
+
        if (field ~ /buildroot:/)
                $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
 
        # Use "License" instead of "Copyright" if it is (L)GPL or BSD
        if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
                $1 = "License:"
-       
+
        if (field ~ /name:/)
                name = $2
 
@@ -430,31 +451,50 @@ preamble == 1 {
                        sub(/\.pamd$/,"",url[n])
                }
 
+               # allow %{name} just in last url component
+               s = ""
+               for (i = 1; i <= n; i++) {
+                       url[i] = fixedsub("%{name}", name, url[i])
+                       if (s) {
+                               s = s "/" url[i]
+                       } else {
+                               s = url[i]
+                       }
+               }
+               $2 = s url[n+1]
+
                filename = url[n]
                url[n] = fixedsub(name, "%{name}", url[n])
-               if (field ~ /source/) 
+               if (field ~ /source/)
                        url[n] = fixedsub(version, "%{version}", url[n])
                $2 = fixedsub(filename, url[n], $2)
+
+               # sourceforge urls
+               sub("[?]use_mirror=.*$", "", $2);
+               sub("^http://prdownloads\.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)
        }
 
+
        if (field ~ /^source:/)
-               $1 = "Source0:" 
+               $1 = "Source0:"
 
        if (field ~ /patch:/)
                $1 = "Patch0:"
-       
+
        format_preamble()
-       
+
        if ($1 ~ /%define/) {
                # Do not add %define of _prefix if it already is.
-               if ($2 ~ /^_prefix/) {
+               if ($2 ~ /^_prefix/) {
                        sub("^"prefix, $3, bindir)
                        sub("^"prefix, $3, sbindir)
                        sub("^"prefix, $3, libdir)
                        sub("^"prefix, $3, datadir)
                        sub("^"prefix, $3, includedir)
                        prefix = $3
-                       x11 = 2
                }
                if ($2 ~ /_bindir/ && !/_sbindir/)
                        bindir = $3
@@ -462,7 +502,7 @@ preamble == 1 {
                        sbindir = $3
                if ($2 ~ /_libdir/)
                        libdir = $3
-               if ($2 ~ /_sysconfdir/)
+               if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
                        sysconfdir = $3
                if ($2 ~ /_datadir/)
                        datadir = $3
@@ -473,13 +513,20 @@ preamble == 1 {
                if ($2 ~ /_infodir/)
                        infodir = $3
        }
+
+       if (field ~ /buildrequires:/) {
+               # obsolete
+               if ($2 ~ /rpm-pythonprov/) {
+                       next
+               }
+       }
 }
 
 
-# main()  ;-)
+# main() ;-)
 {
        preamble = 1
-       
+
        sub(/[ \t]+$/, "")
        print
 }
@@ -488,7 +535,7 @@ preamble == 1 {
 END {
        if (do_not_touch_anything)
                exit 0
-       
+
        close(changelog_file)
        while ((getline < changelog_file) > 0)
                print
@@ -504,25 +551,25 @@ END {
                print ""
                print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
        }
-       
+
        if (has_changelog == 0)
                print "%changelog"
 
        if (boc > 2)
-               print "* %{date} PLD Team <feedback@pld.org.pl>"
+               print "* %{date} PLD Team <feedback@pld-linux.org>"
        if (boc > 1) {
                printf "All persons listed below can be reached at "
-               print "<cvs_login>@pld.org.pl\n"
+               print "<cvs_login>@pld-linux.org\n"
        }
        if (boc > 0)
                print "$" "Log:$"
 }
 
-function fixedsub(s1,s2,t,      ind) {
+function fixedsub(s1,s2,t, ind) {
 # substitutes fixed strings (not regexps)
-        if (ind = index(t,s1))
-                t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
-        return t
+       if (ind = index(t,s1))
+               t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
+       return t
 }
 
 # There should be one or two tabs after the colon.
@@ -540,6 +587,15 @@ function format_preamble()
 # Replace directly specified directories with macros
 function use_macros()
 {
+       gsub(perl_sitearch, "%{perl_sitearch}")
+       gsub(perl_archlib, "%{perl_archlib}")
+       gsub(perl_privlib, "%{perl_privlib}")
+       gsub(perl_archlib, "%{perl_archlib}")
+       gsub(perl_vendorlib, "%{perl_vendorlib}")
+       gsub(perl_vendorarch, "%{perl_vendorarch}")
+       gsub(perl_sitelib, "%{perl_sitelib}")
+       gsub(perl_sitearch, "%{perl_sitearch}")
+
        gsub(bindir, "%{_bindir}")
        gsub("%{prefix}/bin", "%{_bindir}")
        if(prefix"/bin" == bindir)
@@ -552,14 +608,9 @@ function use_macros()
        }
 
        gsub("%{prefix}/sbin", "%{_sbindir}")
-       if(prefix"/sbin" == sbindir)
+       if (prefix"/sbin" == sbindir)
                gsub("%{_prefix}/sbin", "%{_sbindir}")
 
-       gsub(libdir, "%{_libdir}")
-       gsub("%{prefix}/lib", "%{_libdir}")
-       if(prefix"/lib" == libdir)
-               gsub("%{_prefix}/lib", "%{_libdir}")
-
        for (c = 1; c <= NF; c++) {
                if ($c ~ sysconfdir "/{?cron.")
                        continue;
@@ -582,14 +633,22 @@ function use_macros()
                gsub(sysconfdir, "%{_sysconfdir}", $c)
        }
 
-       gsub(datadir, "%{_datadir}")
+       for (c = 1; c <= NF; c++) {
+               if ($c ~ datadir "/automake")
+                       continue;
+               if ($c ~ datadir "/unsermake")
+                       continue;
+               gsub(datadir, "%{_datadir}", $c)
+       }
+
+
        gsub("%{prefix}/share", "%{_datadir}")
-       if(prefix"/share" == datadir)
+       if (prefix"/share" == datadir)
                gsub("%{_prefix}/share", "%{_datadir}")
 
        gsub(includedir, "%{_includedir}")
        gsub("%{prefix}/include", "%{_includedir}")
-       if(prefix"/include" == includedir)
+       if (prefix"/include" == includedir)
                gsub("%{_prefix}/include", "%{_includedir}")
 
        gsub(mandir, "%{_mandir}")
@@ -612,6 +671,10 @@ function use_macros()
                for (c = 1; c <= NF; c++) {
                        if ($c ~ prefix "/sbin/fix-info-dir")
                                continue;
+                       if ($c ~ prefix "/share/automake")
+                               continue;
+                       if ($c ~ prefix "/share/unsermake")
+                               continue;
                        gsub(prefix, "%{_prefix}", $c)
                }
                gsub("%{prefix}", "%{_prefix}")
@@ -620,10 +683,9 @@ function use_macros()
        gsub("%{PACKAGE_VERSION}", "%{version}")
        gsub("%{PACKAGE_NAME}", "%{name}")
 
-       # we can move files between tge dirs below
+       # we can move files between the dirs below
        if ($0 !~ "%{_applnkdir}") {
                gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
-               gsub("%{_datadir}/applnk", "%{_applnkdir}")
        }
 
        gsub("^make$", "%{__make}")
@@ -632,11 +694,87 @@ function use_macros()
        gsub("/usr/src/linux", "%{_kernelsrcdir}")
        gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
 }
-       
-function use_files_macros()
+
+
+# insertion sort of A[1..n]
+# copied from mawk manual
+function isort(A,n,            i,j,hold) {
+       for (i = 2; i <= n; i++) {
+               hold = A[j = i]
+               while (A[j-1] > hold) {
+                       j-- ; A[j+1] = A[j]
+               }
+               A[j] = hold
+       }
+       # sentinel A[0] = "" will be created if needed
+}
+
+
+function use_files_macros(     i, n, t, a)
 {
        gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
        gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
+
+       gsub("%{_sysconfdir}\/rc\.d\/init.d", "/etc/rc.d/init.d")
+       gsub("%{_sysconfdir}\/init.d", "/etc/rc.d/init.d")
+       gsub("%{_sysconfdir}\/sysconfig", "/etc/sysconfig")
+
+       if (/\/etc\/rc\.d\/init\.d/) {
+               if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
+                       $0 = "%attr(754,root,root) " $0
+               }
+               if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
+                       gsub("^%attr\(... *,", "%attr(754,");
+               }
+       }
+
+
+       if (/lib.+\.so/ && !/^%attr.*/) {
+               $0 = "%attr(755,root,root) " $0
+       }
+
+       # /etc/sysconfig files
+       # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
+       # attr not required, allow default 644 attr
+       if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
+               gsub("%config", "%config(noreplace)")
+       }
+
+       if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
+               $NF = "%config(noreplace) " $NF
+       }
+
+       if (/\/etc\/sysconfig\// && /%attr\(755/) {
+               gsub("^%attr\(... *,", "%attr(640,");
+       }
+
+       if (/\/etc\/sysconfig\// && !/%verify/) {
+               gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
+       }
+
+
+       # kill leading zeros
+       gsub("%attr\(0", "%attr(")
+
+       # sort %verify attrs
+       if (match($0, /%verify\(not([^)]+)\)/)) {
+               t = substr($0, RSTART, RLENGTH)
+               gsub(/^%verify\(not |\)$/, "", t)
+               n = split(t, a, / /)
+               isort(a, n)
+
+               s = "%verify(not"
+               for (i = 1 ; i <= n; i++) {
+                       s = s " " a[i]
+               }
+               s = s ")"
+
+               gsub(/%verify\(not[^)]+\)/, s)
+       }
+
+       if (/%{_mandir}/) {
+               gsub("\.gz$", "*")
+       }
 }
 
 function fill(ch, n, i) {
@@ -646,7 +784,7 @@ function fill(ch, n, i) {
 
 function format_flush(line, indent, newline, word, first_word) {
        first_word = 1
-       if (format_indent == -1) 
+       if (format_indent == -1)
                newline = ""
        else
                newline = fill(" ", format_indent) "- "
@@ -655,7 +793,7 @@ function format_flush(line, indent, newline, word, first_word) {
                word = substr(line, RSTART, RLENGTH)
                if (length(newline) + length(word) + 1 > tw) {
                        print newline
-                       
+
                        if (format_indent == -1)
                                newline = ""
                        else
@@ -668,7 +806,7 @@ function format_flush(line, indent, newline, word, first_word) {
                        first_word = 0
                } else
                        newline = newline " " word
-                       
+
                line = substr(line, RSTART + RLENGTH)
        }
        if (newline ~ /[^\t ]/) {
@@ -682,9 +820,8 @@ function cflags(var)
                removed[var] = 1
                return 0
        }
-               
+
        if (!/!\?debug/)
                sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
        return 1
 }
-
This page took 0.074863 seconds and 4 git commands to generate.