3 # This is adapter v0.27. Adapter adapts .spec files for PLD.
5 # Copyright (C) 1999-2003 PLD-Team <feedback@pld-linux.org>
7 # Micha³ Kuratczyk <kura@pld.org.pl>
8 # Sebastian Zagrodzki <s.zagrodzki@mimuw.edu.pl>
9 # Tomasz K³oczko <kloczek@rudy.mif.pg.gda.pl>
10 # Artur Frysiak <wiget@pld.org.pl>
11 # Michal Kochanowicz <mkochano@pld.org.pl>
12 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
15 # - parse ../PLD-doc/BuildRequires.txt and setup proper BR epoches?
16 # - add "-nc" option to skip CVS interaction
18 # - sort Requires, BuildRequires
21 preamble = 1 # Is it part of preamble? Default - yes
22 boc = 4 # Beggining of %changelog
23 bod = 0 # Beggining of %description
24 tw = 70 # Descriptions width
26 # If variable removed, then 1 (for removing it from export)
27 removed["LDFLAGS"] = 0
29 removed["CXXFLAGS"] = 0
31 # If 1, we are inside of comment block (started with /^#%/)
34 # File with rpm groups
35 "rpm --eval %_sourcedir" | getline groups_file
36 groups_file = groups_file "/rpm.groups"
37 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups >/dev/null")
39 # Temporary file for changelog section
40 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
43 "rpm --eval %_prefix" | getline prefix
44 "rpm --eval %_bindir" | getline bindir
45 "rpm --eval %_sbindir" | getline sbindir
46 "rpm --eval %_libdir" | getline libdir
47 "rpm --eval %_sysconfdir" | getline sysconfdir
48 "rpm --eval %_datadir" | getline datadir
49 "rpm --eval %_includedir" | getline includedir
50 "rpm --eval %_mandir" | getline mandir
51 "rpm --eval %_infodir" | getline infodir
53 "rpm --eval %perl_sitearch" | getline perl_sitearch
54 "rpm --eval %perl_archlib" | getline perl_archlib
55 "rpm --eval %perl_privlib" | getline perl_privlib
56 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
57 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
58 "rpm --eval %perl_sitelib" | getline perl_sitelib
60 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
63 # There should be a comment with CVS keywords on the first line of file.
65 if (!/# \$Revision:/) # If this line is already OK?
66 print "# $" "Revision:$, " "$" "Date:$" # No
69 next # It is enough for first line
73 # If the latest line matched /%files/
75 if ($0 !~ /defattr/) # If no %defattr
76 print "%defattr(644,root,root,755)" # Add it
78 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
83 /^#/ && (description == 0) {
84 if (/This file does not like to be adapterized!/) {
85 print # print this message
86 while (getline) # print the rest of spec as it is
88 do_not_touch_anything = 1 # do not touch anything in END()
92 # Generally, comments are printed without touching
98 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
100 if ($2 == "_applnkdir")
107 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
114 /^%description/, (/^%[a-z]+/ && !/^%description/ && !/^%((end)?if|else)/) {
117 if (/^%description/) {
124 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
126 format_flush(format_line, format_indent)
130 } else if (/^[ \t]*[-\*][ \t]*/) {
131 format_flush(format_line, format_indent)
133 format_indent = RLENGTH
134 match($0, /^[ \t]*[-\*][ \t]/)
135 format_line = substr($0, RLENGTH)
137 format_line = format_line " " $0
141 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
142 if (NF > 3 && $2 == "-l") {
144 for (i = 4; i <= NF; i++)
148 format_flush(format_line, format_indent)
163 /^%prep/, (/^%[a-z]+$/ && !/^%prep/ && !/^%((end)?if|else)/) {
167 if (/^%setup/ && !/-q/) {
168 sub(/^%setup/, "%setup -q")
171 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
172 sub(/ -n %{name}-%{version}/, "")
179 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
188 if (/LDFLAGS="-s"/) {
189 removed["LDFLAGS"] = 1
192 split($0, tmp, "LDFLAGS=")
193 count = split(tmp[2], flags, "\"")
194 if (flags[1] != "" && flags[1] !~ "!?debug") {
195 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
196 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
197 for (i = 2; i < count; i++)
198 $0 = $0 flags[i] "\""
204 if (cflags("CFLAGS") == 0)
208 if (cflags("CXXFLAGS") == 0)
212 if (removed["LDFLAGS"])
214 if (removed["CFLAGS"])
216 if (removed["CXXFLAGS"])
218 # Is there still something?
228 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
236 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
240 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
242 print "rm -rf $RPM_BUILD_ROOT"
246 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
247 print "rm -rf $RPM_BUILD_ROOT"
253 # 'install -d' instead 'mkdir -p'
255 sub(/mkdir -p/, "install -d")
257 # 'install' instead 'cp -p'
259 sub(/cp -p/, "install")
261 # No '-u root' or '-g root' for 'install'
262 if (/^install/ && /-[ug][ \t]*root/)
263 gsub(/-[ug][ \t]*root /, "")
265 if (/^install/ && /-m[ \t]*[0-9]+/)
266 gsub(/-m[ \t]*[0-9]+ /, "")
268 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
269 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
272 # No lines contain 'chmod' if it sets the modes to '644'
273 if ($1 ~ /chmod/ && $2 ~ /644/)
280 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
293 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
297 # There should be some CVS keywords on the first line of %changelog.
300 print "* %{date} PLD Team <feedback@pld-linux.org>" > changelog_file
305 if (boc == 2 && !skip) {
306 if (!/All persons listed below/) {
307 printf "All persons listed below can be reached at " > changelog_file
308 print "<cvs_login>@pld-linux.org\n" > changelog_file
313 if (boc == 1 && !skip) {
316 print "$" "Log:$" > changelog_file
323 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
324 print " date +\"%a %b %d %Y\"`)" > changelog_file
331 if (!/^%[a-z]+$/ || /changelog/)
332 print > changelog_file
341 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
344 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
348 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
351 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
359 # There should not be a space after the name of field
360 # and before the colon.
365 if (field ~ /group(\([^)]+\)):/)
367 if (field ~ /group:/) {
369 sub(/^Utilities\//,"Applications/",$2)
370 sub(/^Games/,"Applications/Games",$2)
371 sub(/^X11\/Games/,"X11/Applications/Games",$2)
372 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
373 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
374 sub(/^X11\/GNOME/,"X11/Applications",$2)
375 sub(/^X11\/Utilities/,"X11/Applications",$2)
376 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
377 sub(/^Shells/,"Applications/Shells",$2)
379 sub(/^[^ \t]*[ \t]*/,"")
382 print "Group:\t\t" Grupa
383 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
386 byl_plik_z_grupami = 0
388 while ((getline linia_grup < groups_file) > 0) {
389 byl_plik_z_grupami = 1
390 if (linia_grup == Grupa) {
396 if (!byl_plik_z_grupami)
397 print "######\t\t" groups_file ": no such file"
398 else if (!byl_opis_grupy)
399 print "######\t\t" "Unknown group!"
405 if (field ~ /packager:|distribution:|docdir:|prefix:/)
408 if (field ~ /buildroot:/)
409 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
411 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
412 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
418 if (field ~ /version:/)
421 if (field ~ /serial:/)
424 # Use %{name} and %{version} in the filenames in "Source:"
425 if (field ~ /^source/ || field ~ /patch/) {
426 n = split($2, url, /\//)
427 if (url[n] ~ /\.gz$/) {
428 url[n+1] = ".gz" url[n+1]
429 sub(/\.gz$/,"",url[n])
431 if (url[n] ~ /\.zip$/) {
432 url[n+1] = ".zip" url[n+1]
433 sub(/\.zip$/,"",url[n])
435 if (url[n] ~ /\.tar$/) {
436 url[n+1] = ".tar" url[n+1]
437 sub(/\.tar$/,"",url[n])
439 if (url[n] ~ /\.patch$/) {
440 url[n+1] = ".patch" url[n+1]
441 sub(/\.patch$/,"",url[n])
443 if (url[n] ~ /\.bz2$/) {
444 url[n+1] = ".bz2" url[n+1]
445 sub(/\.bz2$/,"",url[n])
447 if (url[n] ~ /\.logrotate$/) {
448 url[n+1] = ".logrotate" url[n+1]
449 sub(/\.logrotate$/,"",url[n])
451 if (url[n] ~ /\.pamd$/) {
452 url[n+1] = ".pamd" url[n+1]
453 sub(/\.pamd$/,"",url[n])
456 # allow %{name} just in last url component
458 for (i = 1; i <= n; i++) {
459 url[i] = fixedsub("%{name}", name, url[i])
469 url[n] = fixedsub(name, "%{name}", url[n])
470 if (field ~ /source/)
471 url[n] = fixedsub(version, "%{version}", url[n])
472 $2 = fixedsub(filename, url[n], $2)
475 sub("[?]use_mirror=.*$", "", $2);
476 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
478 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
479 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
483 if (field ~ /^source:/)
486 if (field ~ /patch:/)
491 if ($1 ~ /%define/) {
492 # Do not add %define of _prefix if it already is.
493 if ($2 ~ /^_prefix/) {
494 sub("^"prefix, $3, bindir)
495 sub("^"prefix, $3, sbindir)
496 sub("^"prefix, $3, libdir)
497 sub("^"prefix, $3, datadir)
498 sub("^"prefix, $3, includedir)
501 if ($2 ~ /_bindir/ && !/_sbindir/)
507 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
511 if ($2 ~ /_includedir/)
519 if (field ~ /buildrequires:/) {
521 if ($2 ~ /rpm-pythonprov/) {
538 if (do_not_touch_anything)
541 close(changelog_file)
542 while ((getline < changelog_file) > 0)
544 system("rm -f " changelog_file)
546 if (did_clean == 0) {
549 print "rm -rf $RPM_BUILD_ROOT"
554 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
557 if (has_changelog == 0)
561 print "* %{date} PLD Team <feedback@pld-linux.org>"
563 printf "All persons listed below can be reached at "
564 print "<cvs_login>@pld-linux.org\n"
570 function fixedsub(s1,s2,t, ind) {
571 # substitutes fixed strings (not regexps)
572 if (ind = index(t,s1))
573 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
577 # There should be one or two tabs after the colon.
578 function format_preamble()
581 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
589 # Replace directly specified directories with macros
590 function use_macros()
592 gsub(perl_sitearch, "%{perl_sitearch}")
593 gsub(perl_archlib, "%{perl_archlib}")
594 gsub(perl_privlib, "%{perl_privlib}")
595 gsub(perl_vendorlib, "%{perl_vendorlib}")
596 gsub(perl_vendorarch, "%{perl_vendorarch}")
597 gsub(perl_sitelib, "%{perl_sitelib}")
599 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
601 gsub(bindir, "%{_bindir}")
602 gsub("%{prefix}/bin", "%{_bindir}")
603 if(prefix"/bin" == bindir)
604 gsub("%{_prefix}/bin", "%{_bindir}")
606 for (c = 1; c <= NF; c++) {
607 if ($c ~ sbindir "/fix-info-dir")
609 gsub(sbindir, "%{_sbindir}", $c)
612 gsub("%{prefix}/sbin", "%{_sbindir}")
613 if (prefix"/sbin" == sbindir)
614 gsub("%{_prefix}/sbin", "%{_sbindir}")
616 for (c = 1; c <= NF; c++) {
617 if ($c ~ sysconfdir "/{?cron.")
619 if ($c ~ sysconfdir "/{?crontab.d")
621 if ($c ~ sysconfdir "/{?logrotate.d")
623 if ($c ~ sysconfdir "/{?pam.d")
625 if ($c ~ sysconfdir "/{?profile.d")
627 if ($c ~ sysconfdir "/{?rc.d")
629 if ($c ~ sysconfdir "/{?security")
631 if ($c ~ sysconfdir "/{?skel")
633 if ($c ~ sysconfdir "/{?sysconfig")
635 if ($c ~ sysconfdir "/{?certs")
637 gsub(sysconfdir, "%{_sysconfdir}", $c)
640 for (c = 1; c <= NF; c++) {
641 if ($c ~ datadir "/automake")
643 if ($c ~ datadir "/unsermake")
645 gsub(datadir, "%{_datadir}", $c)
649 gsub("%{prefix}/share", "%{_datadir}")
650 if (prefix"/share" == datadir)
651 gsub("%{_prefix}/share", "%{_datadir}")
653 gsub(includedir, "%{_includedir}")
654 gsub("%{prefix}/include", "%{_includedir}")
655 if (prefix"/include" == includedir)
656 gsub("%{_prefix}/include", "%{_includedir}")
658 gsub(mandir, "%{_mandir}")
659 if ($0 !~ "%{_datadir}/manual")
660 gsub("%{_datadir}/man", "%{_mandir}")
661 gsub("%{_prefix}/share/man", "%{_mandir}")
662 gsub("%{prefix}/share/man", "%{_mandir}")
663 gsub("%{prefix}/man", "%{_mandir}")
664 gsub("%{_prefix}/man", "%{_mandir}")
666 gsub(infodir, "%{_infodir}")
667 gsub("%{prefix}/info", "%{_infodir}")
668 gsub("%{_prefix}/info", "%{_infodir}")
670 if (prefix !~ "/X11R6") {
671 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
675 for (c = 1; c <= NF; c++) {
676 if ($c ~ prefix "/sbin/fix-info-dir")
678 if ($c ~ prefix "/share/automake")
680 if ($c ~ prefix "/share/unsermake")
682 gsub(prefix, "%{_prefix}", $c)
684 gsub("%{prefix}", "%{_prefix}")
687 gsub("%{PACKAGE_VERSION}", "%{version}")
688 gsub("%{PACKAGE_NAME}", "%{name}")
690 # we can move files between the dirs below
691 if ($0 !~ "%{_applnkdir}") {
692 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
695 gsub("^make$", "%{__make}")
696 gsub("^make ", "%{__make} ")
699 gsub("^%make$", "%{__make}")
700 gsub("^%make ", "%{__make} ")
701 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
702 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
703 gsub("%optflags", "%{rpmcflags}")
704 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
706 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
707 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
709 gsub("/usr/src/linux", "%{_kernelsrcdir}")
710 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
714 # insertion sort of A[1..n]
715 # copied from mawk manual
716 function isort(A,n, i,j,hold) {
717 for (i = 2; i <= n; i++) {
719 while (A[j-1] > hold) {
724 # sentinel A[0] = "" will be created if needed
728 function use_files_macros( i, n, t, a)
730 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
731 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
733 gsub("%{_sysconfdir}\/rc\.d\/init.d", "/etc/rc.d/init.d")
734 gsub("%{_sysconfdir}\/init.d", "/etc/rc.d/init.d")
735 gsub("%{_sysconfdir}\/sysconfig", "/etc/sysconfig")
737 if (/\/etc\/rc\.d\/init\.d/) {
738 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
739 $0 = "%attr(754,root,root) " $0
741 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
742 gsub("^%attr\(... *,", "%attr(754,");
747 if (/lib.+\.so/ && !/^%attr.*/) {
748 $0 = "%attr(755,root,root) " $0
751 # /etc/sysconfig files
752 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
753 # attr not required, allow default 644 attr
754 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
755 gsub("%config", "%config(noreplace)")
758 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
759 $NF = "%config(noreplace) " $NF
762 if (/\/etc\/sysconfig\// && /%attr\(755/) {
763 gsub("^%attr\(... *,", "%attr(640,");
766 if (/\/etc\/sysconfig\// && !/%verify/) {
767 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
772 gsub("%attr\(0", "%attr(")
775 if (match($0, /%verify\(not([^)]+)\)/)) {
776 t = substr($0, RSTART, RLENGTH)
777 gsub(/^%verify\(not |\)$/, "", t)
782 for (i = 1 ; i <= n; i++) {
787 gsub(/%verify\(not[^)]+\)/, s)
795 function fill(ch, n, i) {
796 for (i = 0; i < n; i++)
800 function format_flush(line, indent, newline, word, first_word) {
802 if (format_indent == -1)
805 newline = fill(" ", format_indent) "- "
807 while (match(line, /[^\t ]+/)) {
808 word = substr(line, RSTART, RLENGTH)
809 if (length(newline) + length(word) + 1 > tw) {
812 if (format_indent == -1)
815 newline = fill(" ", format_indent + 2)
820 newline = newline word
823 newline = newline " " word
825 line = substr(line, RSTART + RLENGTH)
827 if (newline ~ /[^\t ]/) {
834 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
840 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")