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_archlib" | getline perl_archlib
57 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
58 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
59 "rpm --eval %perl_sitelib" | getline perl_sitelib
60 "rpm --eval %perl_sitearch" | getline perl_sitearch
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")
174 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
183 if (/LDFLAGS="-s"/) {
184 removed["LDFLAGS"] = 1
187 split($0, tmp, "LDFLAGS=")
188 count = split(tmp[2], flags, "\"")
189 if (flags[1] != "" && flags[1] !~ "!?debug") {
190 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
191 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
192 for (i = 2; i < count; i++)
193 $0 = $0 flags[i] "\""
199 if (cflags("CFLAGS") == 0)
203 if (cflags("CXXFLAGS") == 0)
207 if (removed["LDFLAGS"])
209 if (removed["CFLAGS"])
211 if (removed["CXXFLAGS"])
213 # Is there still something?
223 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
230 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
234 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
236 print "rm -rf $RPM_BUILD_ROOT"
240 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
241 print "rm -rf $RPM_BUILD_ROOT"
247 # 'install -d' instead 'mkdir -p'
249 sub(/mkdir -p/, "install -d")
251 # 'install' instead 'cp -p'
253 sub(/cp -p/, "install")
255 # No '-u root' or '-g root' for 'install'
256 if (/^install/ && /-[ug][ \t]*root/)
257 gsub(/-[ug][ \t]*root /, "")
259 if (/^install/ && /-m[ \t]*644/)
260 gsub(/-m[ \t]*644 /, "")
262 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
263 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
266 # No lines contain 'chmod' if it sets the modes to '644'
267 if ($1 ~ /chmod/ && $2 ~ /644/)
274 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
287 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
291 # There should be some CVS keywords on the first line of %changelog.
294 print "* %{date} PLD Team <feedback@pld-linux.org>" > changelog_file
299 if (boc == 2 && !skip) {
300 if (!/All persons listed below/) {
301 printf "All persons listed below can be reached at " > changelog_file
302 print "<cvs_login>@pld-linux.org\n" > changelog_file
307 if (boc == 1 && !skip) {
310 print "$" "Log:$" > changelog_file
317 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
318 print " date +\"%a %b %d %Y\"`)" > changelog_file
325 if (!/^%[a-z]+$/ || /changelog/)
326 print > changelog_file
335 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
338 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
341 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
344 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
352 # There should not be a space after the name of field
353 # and before the colon.
358 if (field ~ /group(\([^)]+\)):/)
360 if (field ~ /group:/) {
362 sub(/^Utilities\//,"Applications/",$2)
363 sub(/^Games/,"Applications/Games",$2)
364 sub(/^X11\/Games/,"X11/Applications/Games",$2)
365 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
366 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
367 sub(/^X11\/GNOME/,"X11/Applications",$2)
368 sub(/^X11\/Utilities/,"X11/Applications",$2)
369 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
370 sub(/^Shells/,"Applications/Shells",$2)
372 sub(/^[^ \t]*[ \t]*/,"")
375 print "Group:\t\t" Grupa
376 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
379 byl_plik_z_grupami = 0
381 while ((getline linia_grup < groups_file) > 0) {
382 byl_plik_z_grupami = 1
383 if (linia_grup == Grupa) {
389 if (!byl_plik_z_grupami)
390 print "######\t\t" groups_file ": no such file"
391 else if (!byl_opis_grupy)
392 print "######\t\t" "Unknown group!"
398 if (field ~ /packager:|distribution:|docdir:|prefix:/)
401 if (field ~ /buildroot:/)
402 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
404 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
405 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
411 if (field ~ /version:/)
414 if (field ~ /serial:/)
417 # Use %{name} and %{version} in the filenames in "Source:"
418 if (field ~ /^source/ || field ~ /patch/) {
419 n = split($2, url, /\//)
420 if (url[n] ~ /\.gz$/) {
421 url[n+1] = ".gz" url[n+1]
422 sub(/\.gz$/,"",url[n])
424 if (url[n] ~ /\.zip$/) {
425 url[n+1] = ".zip" url[n+1]
426 sub(/\.zip$/,"",url[n])
428 if (url[n] ~ /\.tar$/) {
429 url[n+1] = ".tar" url[n+1]
430 sub(/\.tar$/,"",url[n])
432 if (url[n] ~ /\.patch$/) {
433 url[n+1] = ".patch" url[n+1]
434 sub(/\.patch$/,"",url[n])
436 if (url[n] ~ /\.bz2$/) {
437 url[n+1] = ".bz2" url[n+1]
438 sub(/\.bz2$/,"",url[n])
440 if (url[n] ~ /\.logrotate$/) {
441 url[n+1] = ".logrotate" url[n+1]
442 sub(/\.logrotate$/,"",url[n])
444 if (url[n] ~ /\.pamd$/) {
445 url[n+1] = ".pamd" url[n+1]
446 sub(/\.pamd$/,"",url[n])
449 # allow %{name} just in last url component
451 for (i = 1; i <= n; i++) {
452 url[i] = fixedsub("%{name}", name, url[i])
462 url[n] = fixedsub(name, "%{name}", url[n])
463 if (field ~ /source/)
464 url[n] = fixedsub(version, "%{version}", url[n])
465 $2 = fixedsub(filename, url[n], $2)
468 sub("[?]use_mirror=.*$", "", $2);
469 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
471 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
472 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
476 if (field ~ /^source:/)
479 if (field ~ /patch:/)
484 if ($1 ~ /%define/) {
485 # Do not add %define of _prefix if it already is.
486 if ($2 ~ /^_prefix/) {
487 sub("^"prefix, $3, bindir)
488 sub("^"prefix, $3, sbindir)
489 sub("^"prefix, $3, libdir)
490 sub("^"prefix, $3, datadir)
491 sub("^"prefix, $3, includedir)
494 if ($2 ~ /_bindir/ && !/_sbindir/)
500 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
504 if ($2 ~ /_includedir/)
512 if (field ~ /buildrequires:/) {
514 if ($2 ~ /rpm-pythonprov/) {
531 if (do_not_touch_anything)
534 close(changelog_file)
535 while ((getline < changelog_file) > 0)
537 system("rm -f " changelog_file)
539 if (did_clean == 0) {
542 print "rm -rf $RPM_BUILD_ROOT"
547 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
550 if (has_changelog == 0)
554 print "* %{date} PLD Team <feedback@pld-linux.org>"
556 printf "All persons listed below can be reached at "
557 print "<cvs_login>@pld-linux.org\n"
563 function fixedsub(s1,s2,t, ind) {
564 # substitutes fixed strings (not regexps)
565 if (ind = index(t,s1))
566 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
570 # There should be one or two tabs after the colon.
571 function format_preamble()
574 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
582 # Replace directly specified directories with macros
583 function use_macros()
585 gsub(perl_sitearch, "%{perl_sitearch}")
586 gsub(perl_archlib, "%{perl_archlib}")
587 gsub(perl_privlib, "%{perl_privlib}")
588 gsub(perl_archlib, "%{perl_archlib}")
589 gsub(perl_vendorlib, "%{perl_vendorlib}")
590 gsub(perl_vendorarch, "%{perl_vendorarch}")
591 gsub(perl_sitelib, "%{perl_sitelib}")
592 gsub(perl_sitearch, "%{perl_sitearch}")
594 gsub(bindir, "%{_bindir}")
595 gsub("%{prefix}/bin", "%{_bindir}")
596 if(prefix"/bin" == bindir)
597 gsub("%{_prefix}/bin", "%{_bindir}")
599 for (c = 1; c <= NF; c++) {
600 if ($c ~ sbindir "/fix-info-dir")
602 gsub(sbindir, "%{_sbindir}", $c)
605 gsub("%{prefix}/sbin", "%{_sbindir}")
606 if (prefix"/sbin" == sbindir)
607 gsub("%{_prefix}/sbin", "%{_sbindir}")
609 for (c = 1; c <= NF; c++) {
610 if ($c ~ sysconfdir "/{?cron.")
612 if ($c ~ sysconfdir "/{?crontab.d")
614 if ($c ~ sysconfdir "/{?logrotate.d")
616 if ($c ~ sysconfdir "/{?pam.d")
618 if ($c ~ sysconfdir "/{?profile.d")
620 if ($c ~ sysconfdir "/{?rc.d")
622 if ($c ~ sysconfdir "/{?security")
624 if ($c ~ sysconfdir "/{?skel")
626 if ($c ~ sysconfdir "/{?sysconfig")
628 gsub(sysconfdir, "%{_sysconfdir}", $c)
631 for (c = 1; c <= NF; c++) {
632 if ($c ~ datadir "/automake")
634 if ($c ~ datadir "/unsermake")
636 gsub(datadir, "%{_datadir}", $c)
640 gsub("%{prefix}/share", "%{_datadir}")
641 if (prefix"/share" == datadir)
642 gsub("%{_prefix}/share", "%{_datadir}")
644 gsub(includedir, "%{_includedir}")
645 gsub("%{prefix}/include", "%{_includedir}")
646 if (prefix"/include" == includedir)
647 gsub("%{_prefix}/include", "%{_includedir}")
649 gsub(mandir, "%{_mandir}")
650 if ($0 !~ "%{_datadir}/manual")
651 gsub("%{_datadir}/man", "%{_mandir}")
652 gsub("%{_prefix}/share/man", "%{_mandir}")
653 gsub("%{prefix}/share/man", "%{_mandir}")
654 gsub("%{prefix}/man", "%{_mandir}")
655 gsub("%{_prefix}/man", "%{_mandir}")
657 gsub(infodir, "%{_infodir}")
658 gsub("%{prefix}/info", "%{_infodir}")
659 gsub("%{_prefix}/info", "%{_infodir}")
661 if (prefix !~ "/X11R6") {
662 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
666 for (c = 1; c <= NF; c++) {
667 if ($c ~ prefix "/sbin/fix-info-dir")
669 if ($c ~ prefix "/share/automake")
671 if ($c ~ prefix "/share/unsermake")
673 gsub(prefix, "%{_prefix}", $c)
675 gsub("%{prefix}", "%{_prefix}")
678 gsub("%{PACKAGE_VERSION}", "%{version}")
679 gsub("%{PACKAGE_NAME}", "%{name}")
681 # we can move files between the dirs below
682 if ($0 !~ "%{_applnkdir}") {
683 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
686 gsub("^make$", "%{__make}")
687 gsub("^make ", "%{__make} ")
689 gsub("/usr/src/linux", "%{_kernelsrcdir}")
690 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
694 # insertion sort of A[1..n]
695 # copied from mawk manual
696 function isort(A,n, i,j,hold) {
697 for (i = 2; i <= n; i++) {
699 while (A[j-1] > hold) {
704 # sentinel A[0] = "" will be created if needed
708 function use_files_macros( i, n, t, a)
710 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
711 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
713 gsub("%{_sysconfdir}\/rc\.d\/init.d", "/etc/rc.d/init.d")
714 gsub("%{_sysconfdir}\/init.d", "/etc/rc.d/init.d")
715 gsub("%{_sysconfdir}\/sysconfig", "/etc/sysconfig")
717 if (/\/etc\/rc\.d\/init\.d/) {
718 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
719 $0 = "%attr(754,root,root) " $0
721 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
722 gsub("^%attr\(... *,", "%attr(754,");
727 if (/lib.+\.so/ && !/^%attr.*/) {
728 $0 = "%attr(755,root,root) " $0
731 # /etc/sysconfig files
732 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
733 # attr not required, allow default 644 attr
734 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
735 gsub("%config", "%config(noreplace)")
738 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
739 $NF = "%config(noreplace) " $NF
742 if (/\/etc\/sysconfig\// && /%attr\(755/) {
743 gsub("^%attr\(... *,", "%attr(640,");
746 if (/\/etc\/sysconfig\// && !/%verify/) {
747 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
752 gsub("%attr\(0", "%attr(")
755 if (match($0, /%verify\(not([^)]+)\)/)) {
756 t = substr($0, RSTART, RLENGTH)
757 gsub(/^%verify\(not |\)$/, "", t)
762 for (i = 1 ; i <= n; i++) {
767 gsub(/%verify\(not[^)]+\)/, s)
775 function fill(ch, n, i) {
776 for (i = 0; i < n; i++)
780 function format_flush(line, indent, newline, word, first_word) {
782 if (format_indent == -1)
785 newline = fill(" ", format_indent) "- "
787 while (match(line, /[^\t ]+/)) {
788 word = substr(line, RSTART, RLENGTH)
789 if (length(newline) + length(word) + 1 > tw) {
792 if (format_indent == -1)
795 newline = fill(" ", format_indent + 2)
800 newline = newline word
803 newline = newline " " word
805 line = substr(line, RSTART + RLENGTH)
807 if (newline ~ /[^\t ]/) {
814 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
820 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")