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
52 "rpm --eval %_examplesdir" | getline examplesdir
54 "rpm --eval %perl_sitearch" | getline perl_sitearch
55 "rpm --eval %perl_archlib" | getline perl_archlib
56 "rpm --eval %perl_privlib" | getline perl_privlib
57 "rpm --eval %perl_vendorlib" | getline perl_vendorlib
58 "rpm --eval %perl_vendorarch" | getline perl_vendorarch
59 "rpm --eval %perl_sitelib" | getline perl_sitelib
61 "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
64 # There should be a comment with CVS keywords on the first line of file.
66 if (!/# \$Revision:/) # If this line is already OK?
67 print "# $" "Revision:$, " "$" "Date:$" # No
70 next # It is enough for first line
74 # If the latest line matched /%files/
76 if ($0 !~ /defattr/) # If no %defattr
77 print "%defattr(644,root,root,755)" # Add it
79 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
84 /^#/ && (description == 0) {
85 if (/This file does not like to be adapterized!/) {
86 print # print this message
87 while (getline) # print the rest of spec as it is
89 do_not_touch_anything = 1 # do not touch anything in END()
93 # Generally, comments are printed without touching
99 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
101 if ($2 == "_applnkdir")
108 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
115 /^%description/, (/^%[a-z]+/ && !/^%description/ && !/^%((end)?if|else)/) {
118 if (/^%description/) {
125 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
127 format_flush(format_line, format_indent)
131 } else if (/^[ \t]*[-\*][ \t]*/) {
132 format_flush(format_line, format_indent)
134 format_indent = RLENGTH
135 match($0, /^[ \t]*[-\*][ \t]/)
136 format_line = substr($0, RLENGTH)
138 format_line = format_line " " $0
142 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
143 if (NF > 3 && $2 == "-l") {
145 for (i = 4; i <= NF; i++)
149 format_flush(format_line, format_indent)
164 /^%prep/, (/^%[a-z]+$/ && !/^%prep/ && !/^%((end)?if|else)/) {
170 if (/^%setup/ && !/-q/) {
171 sub(/^%setup/, "%setup -q")
174 if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
175 sub(/ -n %{name}-%{version}/, "")
179 sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
185 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
194 if (/LDFLAGS="-s"/) {
195 removed["LDFLAGS"] = 1
198 split($0, tmp, "LDFLAGS=")
199 count = split(tmp[2], flags, "\"")
200 if (flags[1] != "" && flags[1] !~ "!?debug") {
201 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
202 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
203 for (i = 2; i < count; i++)
204 $0 = $0 flags[i] "\""
210 if (cflags("CFLAGS") == 0)
214 if (cflags("CXXFLAGS") == 0)
218 if (removed["LDFLAGS"])
220 if (removed["CFLAGS"])
222 if (removed["CXXFLAGS"])
224 # Is there still something?
234 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
242 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
246 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
248 print "rm -rf $RPM_BUILD_ROOT"
252 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
253 print "rm -rf $RPM_BUILD_ROOT"
259 # 'install -d' instead 'mkdir -p'
261 sub(/mkdir -p/, "install -d")
263 # 'install' instead 'cp -p'
265 sub(/cp -p/, "install")
267 # No '-u root' or '-g root' for 'install'
268 if (/^install/ && /-[ug][ \t]*root/)
269 gsub(/-[ug][ \t]*root /, "")
271 if (/^install/ && /-m[ \t]*[0-9]+/)
272 gsub(/-m[ \t]*[0-9]+ /, "")
274 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
275 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
278 # No lines contain 'chmod' if it sets the modes to '644'
279 if ($1 ~ /chmod/ && $2 ~ /644/)
286 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
299 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
303 # There should be some CVS keywords on the first line of %changelog.
306 print "* %{date} PLD Team <feedback@pld-linux.org>" > changelog_file
311 if (boc == 2 && !skip) {
312 if (!/All persons listed below/) {
313 printf "All persons listed below can be reached at " > changelog_file
314 print "<cvs_login>@pld-linux.org\n" > changelog_file
319 if (boc == 1 && !skip) {
322 print "$" "Log:$" > changelog_file
329 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
330 print " date +\"%a %b %d %Y\"`)" > changelog_file
337 if (!/^%[a-z]+$/ || /changelog/)
338 print > changelog_file
347 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
350 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
354 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
357 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
360 /^%triggerin/, (/^%[a-z]+$/ && !/^%triggerin/) {
363 /^%triggerun/, (/^%[a-z]+$/ && !/^%triggerun/) {
366 /^%triggerpostun/, (/^%[a-z]+$/ && !/^%triggerpostun/) {
369 /^%pretrans/, (/^%[a-z]+$/ && !/^%pretrans/) {
372 /^%posttrans/, (/^%[a-z]+$/ && !/^%posttrans/) {
380 # There should not be a space after the name of field
381 # and before the colon.
386 if (field ~ /group(\([^)]+\)):/)
388 if (field ~ /group:/) {
390 sub(/^Utilities\//,"Applications/",$2)
391 sub(/^Games/,"Applications/Games",$2)
392 sub(/^X11\/Games/,"X11/Applications/Games",$2)
393 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
394 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
395 sub(/^X11\/GNOME/,"X11/Applications",$2)
396 sub(/^X11\/Utilities/,"X11/Applications",$2)
397 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
398 sub(/^Shells/,"Applications/Shells",$2)
400 sub(/^[^ \t]*[ \t]*/,"")
403 print "Group:\t\t" Grupa
404 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
407 byl_plik_z_grupami = 0
409 while ((getline linia_grup < groups_file) > 0) {
410 byl_plik_z_grupami = 1
411 if (linia_grup == Grupa) {
417 if (!byl_plik_z_grupami)
418 print "######\t\t" groups_file ": no such file"
419 else if (!byl_opis_grupy)
420 print "######\t\t" "Unknown group!"
426 if (field ~ /prereq:/) {
430 if (field ~ /packager:|distribution:|docdir:|prefix:/)
433 if (field ~ /buildroot:/)
434 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
436 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
437 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
443 if (field ~ /version:/)
446 if (field ~ /serial:/)
449 # Use %{name} and %{version} in the filenames in "Source:"
450 if (field ~ /^source/ || field ~ /patch/) {
451 n = split($2, url, /\//)
452 if (url[n] ~ /\.gz$/) {
453 url[n+1] = ".gz" url[n+1]
454 sub(/\.gz$/,"",url[n])
456 if (url[n] ~ /\.zip$/) {
457 url[n+1] = ".zip" url[n+1]
458 sub(/\.zip$/,"",url[n])
460 if (url[n] ~ /\.tar$/) {
461 url[n+1] = ".tar" url[n+1]
462 sub(/\.tar$/,"",url[n])
464 if (url[n] ~ /\.patch$/) {
465 url[n+1] = ".patch" url[n+1]
466 sub(/\.patch$/,"",url[n])
468 if (url[n] ~ /\.bz2$/) {
469 url[n+1] = ".bz2" url[n+1]
470 sub(/\.bz2$/,"",url[n])
472 if (url[n] ~ /\.logrotate$/) {
473 url[n+1] = ".logrotate" url[n+1]
474 sub(/\.logrotate$/,"",url[n])
476 if (url[n] ~ /\.pamd$/) {
477 url[n+1] = ".pamd" url[n+1]
478 sub(/\.pamd$/,"",url[n])
481 # allow %{name} just in last url component
483 for (i = 1; i <= n; i++) {
484 url[i] = fixedsub("%{name}", name, url[i])
494 url[n] = fixedsub(name, "%{name}", url[n])
495 if (field ~ /source/) {
496 url[n] = fixedsub(version, "%{version}", url[n])
498 url[n] = fixedsub(_beta, "%{_beta}", url[n])
501 url[n] = fixedsub(_rc, "%{_rc}", url[n])
504 url[n] = fixedsub(_snap, "%{_snap}", url[n])
507 $2 = fixedsub(filename, url[n], $2)
510 sub("[?]use_mirror=.*$", "", $2);
511 sub("[?]download$", "", $2);
512 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
514 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
515 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
519 if (field ~ /^source:/)
522 if (field ~ /patch:/)
527 if ($1 ~ /%define/) {
528 # Do not add %define of _prefix if it already is.
529 if ($2 ~ /^_prefix/) {
530 sub("^"prefix, $3, bindir)
531 sub("^"prefix, $3, sbindir)
532 sub("^"prefix, $3, libdir)
533 sub("^"prefix, $3, datadir)
534 sub("^"prefix, $3, includedir)
537 if ($2 ~ /_bindir/ && !/_sbindir/)
543 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
547 if ($2 ~ /_includedir/)
562 if (field ~ /buildrequires:/) {
564 if ($2 ~ /rpm-pythonprov/) {
581 if (do_not_touch_anything)
584 close(changelog_file)
585 while ((getline < changelog_file) > 0)
587 system("rm -f " changelog_file)
589 if (did_clean == 0) {
592 print "rm -rf $RPM_BUILD_ROOT"
597 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
600 if (has_changelog == 0)
604 print "* %{date} PLD Team <feedback@pld-linux.org>"
606 printf "All persons listed below can be reached at "
607 print "<cvs_login>@pld-linux.org\n"
613 function fixedsub(s1,s2,t, ind) {
614 # substitutes fixed strings (not regexps)
615 if (ind = index(t,s1))
616 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
620 # There should be one or two tabs after the colon.
621 function format_preamble()
624 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
632 # Replace directly specified directories with macros
633 function use_macros()
635 gsub(perl_sitearch, "%{perl_sitearch}")
636 gsub(perl_archlib, "%{perl_archlib}")
637 gsub(perl_privlib, "%{perl_privlib}")
638 gsub(perl_vendorlib, "%{perl_vendorlib}")
639 gsub(perl_vendorarch, "%{perl_vendorarch}")
640 gsub(perl_sitelib, "%{perl_sitelib}")
642 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
644 gsub(bindir, "%{_bindir}")
645 gsub("%{prefix}/bin", "%{_bindir}")
646 if(prefix"/bin" == bindir)
647 gsub("%{_prefix}/bin", "%{_bindir}")
649 for (c = 1; c <= NF; c++) {
650 if ($c ~ sbindir "/fix-info-dir")
652 gsub(sbindir, "%{_sbindir}", $c)
655 gsub("%{prefix}/sbin", "%{_sbindir}")
656 if (prefix"/sbin" == sbindir)
657 gsub("%{_prefix}/sbin", "%{_sbindir}")
659 for (c = 1; c <= NF; c++) {
660 if ($c ~ sysconfdir "/{?cron.")
662 if ($c ~ sysconfdir "/{?crontab.d")
664 if ($c ~ sysconfdir "/{?logrotate.d")
666 if ($c ~ sysconfdir "/{?pam.d")
668 if ($c ~ sysconfdir "/{?profile.d")
670 if ($c ~ sysconfdir "/{?rc.d")
672 if ($c ~ sysconfdir "/{?security")
674 if ($c ~ sysconfdir "/{?skel")
676 if ($c ~ sysconfdir "/{?sysconfig")
678 if ($c ~ sysconfdir "/{?certs")
680 gsub(sysconfdir, "%{_sysconfdir}", $c)
683 for (c = 1; c <= NF; c++) {
684 if ($c ~ datadir "/automake")
686 if ($c ~ datadir "/unsermake")
688 gsub(datadir, "%{_datadir}", $c)
692 gsub("%{prefix}/share", "%{_datadir}")
693 if (prefix"/share" == datadir)
694 gsub("%{_prefix}/share", "%{_datadir}")
696 gsub(includedir, "%{_includedir}")
697 gsub("%{prefix}/include", "%{_includedir}")
698 if (prefix"/include" == includedir)
699 gsub("%{_prefix}/include", "%{_includedir}")
701 gsub(mandir, "%{_mandir}")
702 if ($0 !~ "%{_datadir}/manual")
703 gsub("%{_datadir}/man", "%{_mandir}")
704 gsub("%{_prefix}/share/man", "%{_mandir}")
705 gsub("%{prefix}/share/man", "%{_mandir}")
706 gsub("%{prefix}/man", "%{_mandir}")
707 gsub("%{_prefix}/man", "%{_mandir}")
709 gsub(infodir, "%{_infodir}")
710 gsub("%{prefix}/info", "%{_infodir}")
711 gsub("%{_prefix}/info", "%{_infodir}")
713 if (prefix !~ "/X11R6") {
714 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
717 gsub(examplesdir, "%{_examplesdir}")
720 for (c = 1; c <= NF; c++) {
721 if ($c ~ prefix "/sbin/fix-info-dir")
723 if ($c ~ prefix "/share/automake")
725 if ($c ~ prefix "/share/unsermake")
727 gsub(prefix, "%{_prefix}", $c)
729 gsub("%{prefix}", "%{_prefix}")
732 gsub("%{PACKAGE_VERSION}", "%{version}")
733 gsub("%{PACKAGE_NAME}", "%{name}")
735 # we can move files between the dirs below
736 if ($0 !~ "%{_applnkdir}") {
737 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
740 gsub("^make$", "%{__make}")
741 gsub("^make ", "%{__make} ")
744 gsub("^%make$", "%{__make}")
745 gsub("^%make ", "%{__make} ")
746 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
747 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
748 gsub("%optflags", "%{rpmcflags}")
749 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
751 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
752 gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
753 gsub("%buildroot", "$RPM_BUILD_ROOT")
754 gsub("%_bindir", "%{_bindir}")
755 gsub("%_datadir", "%{_datadir}")
756 gsub("%_iconsdir", "%{_iconsdir}")
758 gsub("/usr/src/linux", "%{_kernelsrcdir}")
759 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
763 # insertion sort of A[1..n]
764 # copied from mawk manual
765 function isort(A,n, i,j,hold) {
766 for (i = 2; i <= n; i++) {
768 while (A[j-1] > hold) {
773 # sentinel A[0] = "" will be created if needed
777 function use_files_macros( i, n, t, a)
779 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
780 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
783 gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
784 gsub("%{_sysconfdir}/crontab\.d", "/etc/cron.d")
785 gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
786 gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
787 gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
788 gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
789 gsub("%{_sysconfdir}/security", "/etc/security")
790 gsub("%{_sysconfdir}/skel", "/etc/skel")
791 gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
792 gsub("%{_sysconfdir}/certs", "/etc/certs")
793 gsub("%{_sysconfdir}/init.d", "/etc/init.d")
795 # /etc/init.d -> /etc/rc.d/init.d
796 if (!/^\/etc\/init\.d$/) {
797 gsub("/etc/init.d", "/etc/rc.d/init.d")
800 if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
801 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
802 $0 = "%attr(754,root,root) " $0
804 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
805 gsub("^%attr\(... *,", "%attr(754,");
809 if (/lib.+\.so/ && !/^%attr.*/) {
810 $0 = "%attr(755,root,root) " $0
813 # /etc/sysconfig files
814 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
815 # attr not required, allow default 644 attr
816 if (!/network-scripts/) {
817 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
818 gsub("%config", "%config(noreplace)")
821 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
822 $NF = "%config(noreplace) " $NF
825 if (/\/etc\/sysconfig\// && /%attr\(755/) {
826 gsub("^%attr\(... *,", "%attr(640,");
829 if (/\/etc\/sysconfig\// && !/%verify/) {
830 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
836 gsub("%attr\(0", "%attr(")
839 if (match($0, /%verify\(not([^)]+)\)/)) {
840 t = substr($0, RSTART, RLENGTH)
841 gsub(/^%verify\(not |\)$/, "", t)
846 for (i = 1 ; i <= n; i++) {
851 gsub(/%verify\(not[^)]+\)/, s)
859 function fill(ch, n, i) {
860 for (i = 0; i < n; i++)
864 function format_flush(line, indent, newline, word, first_word) {
866 if (format_indent == -1)
869 newline = fill(" ", format_indent) "- "
871 while (match(line, /[^\t ]+/)) {
872 word = substr(line, RSTART, RLENGTH)
873 if (length(newline) + length(word) + 1 > tw) {
876 if (format_indent == -1)
879 newline = fill(" ", format_indent + 2)
884 newline = newline word
887 newline = newline " " word
889 line = substr(line, RSTART + RLENGTH)
891 if (newline ~ /[^\t ]/) {
898 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
904 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")