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/) {
347 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
350 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
358 # There should not be a space after the name of field
359 # and before the colon.
364 if (field ~ /group(\([^)]+\)):/)
366 if (field ~ /group:/) {
368 sub(/^Utilities\//,"Applications/",$2)
369 sub(/^Games/,"Applications/Games",$2)
370 sub(/^X11\/Games/,"X11/Applications/Games",$2)
371 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
372 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
373 sub(/^X11\/GNOME/,"X11/Applications",$2)
374 sub(/^X11\/Utilities/,"X11/Applications",$2)
375 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
376 sub(/^Shells/,"Applications/Shells",$2)
378 sub(/^[^ \t]*[ \t]*/,"")
381 print "Group:\t\t" Grupa
382 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
385 byl_plik_z_grupami = 0
387 while ((getline linia_grup < groups_file) > 0) {
388 byl_plik_z_grupami = 1
389 if (linia_grup == Grupa) {
395 if (!byl_plik_z_grupami)
396 print "######\t\t" groups_file ": no such file"
397 else if (!byl_opis_grupy)
398 print "######\t\t" "Unknown group!"
404 if (field ~ /packager:|distribution:|docdir:|prefix:/)
407 if (field ~ /buildroot:/)
408 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
410 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
411 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
417 if (field ~ /version:/)
420 if (field ~ /serial:/)
423 # Use %{name} and %{version} in the filenames in "Source:"
424 if (field ~ /^source/ || field ~ /patch/) {
425 n = split($2, url, /\//)
426 if (url[n] ~ /\.gz$/) {
427 url[n+1] = ".gz" url[n+1]
428 sub(/\.gz$/,"",url[n])
430 if (url[n] ~ /\.zip$/) {
431 url[n+1] = ".zip" url[n+1]
432 sub(/\.zip$/,"",url[n])
434 if (url[n] ~ /\.tar$/) {
435 url[n+1] = ".tar" url[n+1]
436 sub(/\.tar$/,"",url[n])
438 if (url[n] ~ /\.patch$/) {
439 url[n+1] = ".patch" url[n+1]
440 sub(/\.patch$/,"",url[n])
442 if (url[n] ~ /\.bz2$/) {
443 url[n+1] = ".bz2" url[n+1]
444 sub(/\.bz2$/,"",url[n])
446 if (url[n] ~ /\.logrotate$/) {
447 url[n+1] = ".logrotate" url[n+1]
448 sub(/\.logrotate$/,"",url[n])
450 if (url[n] ~ /\.pamd$/) {
451 url[n+1] = ".pamd" url[n+1]
452 sub(/\.pamd$/,"",url[n])
455 # allow %{name} just in last url component
457 for (i = 1; i <= n; i++) {
458 url[i] = fixedsub("%{name}", name, url[i])
468 url[n] = fixedsub(name, "%{name}", url[n])
469 if (field ~ /source/)
470 url[n] = fixedsub(version, "%{version}", url[n])
471 $2 = fixedsub(filename, url[n], $2)
474 sub("[?]use_mirror=.*$", "", $2);
475 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
477 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
478 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
482 if (field ~ /^source:/)
485 if (field ~ /patch:/)
490 if ($1 ~ /%define/) {
491 # Do not add %define of _prefix if it already is.
492 if ($2 ~ /^_prefix/) {
493 sub("^"prefix, $3, bindir)
494 sub("^"prefix, $3, sbindir)
495 sub("^"prefix, $3, libdir)
496 sub("^"prefix, $3, datadir)
497 sub("^"prefix, $3, includedir)
500 if ($2 ~ /_bindir/ && !/_sbindir/)
506 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
510 if ($2 ~ /_includedir/)
518 if (field ~ /buildrequires:/) {
520 if ($2 ~ /rpm-pythonprov/) {
537 if (do_not_touch_anything)
540 close(changelog_file)
541 while ((getline < changelog_file) > 0)
543 system("rm -f " changelog_file)
545 if (did_clean == 0) {
548 print "rm -rf $RPM_BUILD_ROOT"
553 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
556 if (has_changelog == 0)
560 print "* %{date} PLD Team <feedback@pld-linux.org>"
562 printf "All persons listed below can be reached at "
563 print "<cvs_login>@pld-linux.org\n"
569 function fixedsub(s1,s2,t, ind) {
570 # substitutes fixed strings (not regexps)
571 if (ind = index(t,s1))
572 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
576 # There should be one or two tabs after the colon.
577 function format_preamble()
580 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
588 # Replace directly specified directories with macros
589 function use_macros()
591 gsub(perl_sitearch, "%{perl_sitearch}")
592 gsub(perl_archlib, "%{perl_archlib}")
593 gsub(perl_privlib, "%{perl_privlib}")
594 gsub(perl_vendorlib, "%{perl_vendorlib}")
595 gsub(perl_vendorarch, "%{perl_vendorarch}")
596 gsub(perl_sitelib, "%{perl_sitelib}")
598 gsub(py_sitescriptdir, "%{py_sitescriptdir}")
600 gsub(bindir, "%{_bindir}")
601 gsub("%{prefix}/bin", "%{_bindir}")
602 if(prefix"/bin" == bindir)
603 gsub("%{_prefix}/bin", "%{_bindir}")
605 for (c = 1; c <= NF; c++) {
606 if ($c ~ sbindir "/fix-info-dir")
608 gsub(sbindir, "%{_sbindir}", $c)
611 gsub("%{prefix}/sbin", "%{_sbindir}")
612 if (prefix"/sbin" == sbindir)
613 gsub("%{_prefix}/sbin", "%{_sbindir}")
615 for (c = 1; c <= NF; c++) {
616 if ($c ~ sysconfdir "/{?cron.")
618 if ($c ~ sysconfdir "/{?crontab.d")
620 if ($c ~ sysconfdir "/{?logrotate.d")
622 if ($c ~ sysconfdir "/{?pam.d")
624 if ($c ~ sysconfdir "/{?profile.d")
626 if ($c ~ sysconfdir "/{?rc.d")
628 if ($c ~ sysconfdir "/{?security")
630 if ($c ~ sysconfdir "/{?skel")
632 if ($c ~ sysconfdir "/{?sysconfig")
634 if ($c ~ sysconfdir "/{?certs")
636 gsub(sysconfdir, "%{_sysconfdir}", $c)
639 for (c = 1; c <= NF; c++) {
640 if ($c ~ datadir "/automake")
642 if ($c ~ datadir "/unsermake")
644 gsub(datadir, "%{_datadir}", $c)
648 gsub("%{prefix}/share", "%{_datadir}")
649 if (prefix"/share" == datadir)
650 gsub("%{_prefix}/share", "%{_datadir}")
652 gsub(includedir, "%{_includedir}")
653 gsub("%{prefix}/include", "%{_includedir}")
654 if (prefix"/include" == includedir)
655 gsub("%{_prefix}/include", "%{_includedir}")
657 gsub(mandir, "%{_mandir}")
658 if ($0 !~ "%{_datadir}/manual")
659 gsub("%{_datadir}/man", "%{_mandir}")
660 gsub("%{_prefix}/share/man", "%{_mandir}")
661 gsub("%{prefix}/share/man", "%{_mandir}")
662 gsub("%{prefix}/man", "%{_mandir}")
663 gsub("%{_prefix}/man", "%{_mandir}")
665 gsub(infodir, "%{_infodir}")
666 gsub("%{prefix}/info", "%{_infodir}")
667 gsub("%{_prefix}/info", "%{_infodir}")
669 if (prefix !~ "/X11R6") {
670 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
674 for (c = 1; c <= NF; c++) {
675 if ($c ~ prefix "/sbin/fix-info-dir")
677 if ($c ~ prefix "/share/automake")
679 if ($c ~ prefix "/share/unsermake")
681 gsub(prefix, "%{_prefix}", $c)
683 gsub("%{prefix}", "%{_prefix}")
686 gsub("%{PACKAGE_VERSION}", "%{version}")
687 gsub("%{PACKAGE_NAME}", "%{name}")
689 # we can move files between the dirs below
690 if ($0 !~ "%{_applnkdir}") {
691 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
694 gsub("^make$", "%{__make}")
695 gsub("^make ", "%{__make} ")
698 gsub("^%make$", "%{__make}")
699 gsub("^%make ", "%{__make} ")
700 gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
701 gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
702 gsub("%optflags", "%{rpmcflags}")
703 gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
705 gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
707 gsub("/usr/src/linux", "%{_kernelsrcdir}")
708 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
712 # insertion sort of A[1..n]
713 # copied from mawk manual
714 function isort(A,n, i,j,hold) {
715 for (i = 2; i <= n; i++) {
717 while (A[j-1] > hold) {
722 # sentinel A[0] = "" will be created if needed
726 function use_files_macros( i, n, t, a)
728 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
729 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
731 gsub("%{_sysconfdir}\/rc\.d\/init.d", "/etc/rc.d/init.d")
732 gsub("%{_sysconfdir}\/init.d", "/etc/rc.d/init.d")
733 gsub("%{_sysconfdir}\/sysconfig", "/etc/sysconfig")
735 if (/\/etc\/rc\.d\/init\.d/) {
736 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
737 $0 = "%attr(754,root,root) " $0
739 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
740 gsub("^%attr\(... *,", "%attr(754,");
745 if (/lib.+\.so/ && !/^%attr.*/) {
746 $0 = "%attr(755,root,root) " $0
749 # /etc/sysconfig files
750 # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
751 # attr not required, allow default 644 attr
752 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
753 gsub("%config", "%config(noreplace)")
756 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
757 $NF = "%config(noreplace) " $NF
760 if (/\/etc\/sysconfig\// && /%attr\(755/) {
761 gsub("^%attr\(... *,", "%attr(640,");
764 if (/\/etc\/sysconfig\// && !/%verify/) {
765 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
770 gsub("%attr\(0", "%attr(")
773 if (match($0, /%verify\(not([^)]+)\)/)) {
774 t = substr($0, RSTART, RLENGTH)
775 gsub(/^%verify\(not |\)$/, "", t)
780 for (i = 1 ; i <= n; i++) {
785 gsub(/%verify\(not[^)]+\)/, s)
793 function fill(ch, n, i) {
794 for (i = 0; i < n; i++)
798 function format_flush(line, indent, newline, word, first_word) {
800 if (format_indent == -1)
803 newline = fill(" ", format_indent) "- "
805 while (match(line, /[^\t ]+/)) {
806 word = substr(line, RSTART, RLENGTH)
807 if (length(newline) + length(word) + 1 > tw) {
810 if (format_indent == -1)
813 newline = fill(" ", format_indent + 2)
818 newline = newline word
821 newline = newline " " word
823 line = substr(line, RSTART + RLENGTH)
825 if (newline ~ /[^\t ]/) {
832 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
838 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")