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 preamble = 1 # Is it part of preamble? Default - yes
16 boc = 4 # Beggining of %changelog
17 bod = 0 # Beggining of %description
18 tw = 70 # Descriptions width
20 # If variable removed, then 1 (for removing it from export)
21 removed["LDFLAGS"] = 0
23 removed["CXXFLAGS"] = 0
25 # If 1, we are inside of comment block (started with /^#%/)
28 # File with rpm groups
29 "rpm --eval %_sourcedir" | getline groups_file
30 groups_file = groups_file "/rpm.groups"
31 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups >/dev/null")
33 # Temporary file for changelog section
34 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
37 "rpm --eval %_prefix" | getline prefix
38 "rpm --eval %_bindir" | getline bindir
39 "rpm --eval %_sbindir" | getline sbindir
40 "rpm --eval %_libdir" | getline libdir
41 "rpm --eval %_sysconfdir" | getline sysconfdir
42 "rpm --eval %_datadir" | getline datadir
43 "rpm --eval %_includedir" | getline includedir
44 "rpm --eval %_mandir" | getline mandir
45 "rpm --eval %_infodir" | getline infodir
48 # There should be a comment with CVS keywords on the first line of file.
50 if (!/# \$Revision:/) # If this line is already OK?
51 print "# $" "Revision:$, " "$" "Date:$" # No
54 next # It is enough for first line
58 # If the latest line matched /%files/
60 if ($0 !~ /defattr/) # If no %defattr
61 print "%defattr(644,root,root,755)" # Add it
63 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
68 /^#/ && (description == 0) {
69 if (/This file does not like to be adapterized!/) {
70 print # print this message
71 while (getline) # print the rest of spec as it is
73 do_not_touch_anything = 1 # do not touch anything in END()
77 # Generally, comments are printed without touching
83 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
85 if ($2 == "_applnkdir")
94 /^%description/, (/^%[a-z]+/ && !/^%description/) {
97 if (/^%description/) {
104 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
106 format_flush(format_line, format_indent)
110 } else if (/^[ \t]*[-\*][ \t]*/) {
111 format_flush(format_line, format_indent)
113 format_indent = RLENGTH
114 match($0, /^[ \t]*[-\*][ \t]/)
115 format_line = substr($0, RLENGTH)
117 format_line = format_line " " $0
121 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
122 if (NF > 3 && $2 == "-l") {
124 for (i = 4; i <= NF; i++)
128 format_flush(format_line, format_indent)
143 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
147 if (/^%setup/ && !/-q/)
148 sub(/^%setup/, "%setup -q")
154 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
163 if (/LDFLAGS="-s"/) {
164 removed["LDFLAGS"] = 1
167 split($0, tmp, "LDFLAGS=")
168 count = split(tmp[2], flags, "\"")
169 if (flags[1] != "" && flags[1] !~ "!?debug") {
170 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
171 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
172 for (i = 2; i < count; i++)
173 $0 = $0 flags[i] "\""
179 if (cflags("CFLAGS") == 0)
183 if (cflags("CXXFLAGS") == 0)
187 if (removed["LDFLAGS"])
189 if (removed["CFLAGS"])
191 if (removed["CXXFLAGS"])
193 # Is there still something?
203 /^%clean/, (/^%[a-z]+$/ && !/^%clean/) {
210 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
214 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
216 print "rm -rf $RPM_BUILD_ROOT"
220 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
221 print "rm -rf $RPM_BUILD_ROOT"
227 # 'install -d' instead 'mkdir -p'
229 sub(/mkdir -p/, "install -d")
231 # 'install' instead 'cp -p'
233 sub(/cp -p/, "install")
235 # No '-u root' or '-g root' for 'install'
236 if (/^install/ && /-[ug][ \t]*root/)
237 gsub(/-[ug][ \t]*root /, "")
239 if (/^install/ && /-m[ \t]*644/)
240 gsub(/-m[ \t]*644 /, "")
242 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
243 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
246 # No lines contain 'chmod' if it sets the modes to '644'
247 if ($1 ~ /chmod/ && $2 ~ /644/)
254 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
267 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
271 # There should be some CVS keywords on the first line of %changelog.
274 print "* %{date} PLD Team <feedback@pld-linux.org>" > changelog_file
279 if (boc == 2 && !skip) {
280 if (!/All persons listed below/) {
281 printf "All persons listed below can be reached at " > changelog_file
282 print "<cvs_login>@pld-linux.org\n" > changelog_file
287 if (boc == 1 && !skip) {
290 print "$" "Log:$" > changelog_file
297 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
298 print " date +\"%a %b %d %Y\"`)" > changelog_file
305 if (!/^%[a-z]+$/ || /changelog/)
306 print > changelog_file
315 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
318 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
321 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
324 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
332 # There should not be a space after the name of field
333 # and before the colon.
338 if (field ~ /group(\([^)]+\)):/)
340 if (field ~ /group:/) {
342 sub(/^Utilities\//,"Applications/",$2)
343 sub(/^Games/,"Applications/Games",$2)
344 sub(/^X11\/Games/,"X11/Applications/Games",$2)
345 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
346 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
347 sub(/^X11\/GNOME/,"X11/Applications",$2)
348 sub(/^X11\/Utilities/,"X11/Applications",$2)
349 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
350 sub(/^Shells/,"Applications/Shells",$2)
352 sub(/^[^ \t]*[ \t]*/,"")
355 print "Group:\t\t" Grupa
356 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
359 byl_plik_z_grupami = 0
361 while ((getline linia_grup < groups_file) > 0) {
362 byl_plik_z_grupami = 1
363 if (linia_grup == Grupa) {
369 if (!byl_plik_z_grupami)
370 print "######\t\t" groups_file ": no such file"
371 else if (!byl_opis_grupy)
372 print "######\t\t" "Unknown group!"
378 if (field ~ /packager:|distribution:|docdir:|prefix:/)
381 if (field ~ /buildroot:/)
382 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
384 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
385 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
391 if (field ~ /version:/)
394 if (field ~ /serial:/)
397 # Use %{name} and %{version} in the filenames in "Source:"
398 if (field ~ /^source/ || field ~ /patch/) {
399 n = split($2, url, /\//)
400 if (url[n] ~ /\.gz$/) {
401 url[n+1] = ".gz" url[n+1]
402 sub(/\.gz$/,"",url[n])
404 if (url[n] ~ /\.zip$/) {
405 url[n+1] = ".zip" url[n+1]
406 sub(/\.zip$/,"",url[n])
408 if (url[n] ~ /\.tar$/) {
409 url[n+1] = ".tar" url[n+1]
410 sub(/\.tar$/,"",url[n])
412 if (url[n] ~ /\.patch$/) {
413 url[n+1] = ".patch" url[n+1]
414 sub(/\.patch$/,"",url[n])
416 if (url[n] ~ /\.bz2$/) {
417 url[n+1] = ".bz2" url[n+1]
418 sub(/\.bz2$/,"",url[n])
420 if (url[n] ~ /\.logrotate$/) {
421 url[n+1] = ".logrotate" url[n+1]
422 sub(/\.logrotate$/,"",url[n])
424 if (url[n] ~ /\.pamd$/) {
425 url[n+1] = ".pamd" url[n+1]
426 sub(/\.pamd$/,"",url[n])
430 url[n] = fixedsub(name, "%{name}", url[n])
431 if (field ~ /source/)
432 url[n] = fixedsub(version, "%{version}", url[n])
433 $2 = fixedsub(filename, url[n], $2)
436 if (field ~ /^source:/)
439 if (field ~ /patch:/)
444 if ($1 ~ /%define/) {
445 # Do not add %define of _prefix if it already is.
446 if ($2 ~ /^_prefix/) {
447 sub("^"prefix, $3, bindir)
448 sub("^"prefix, $3, sbindir)
449 sub("^"prefix, $3, libdir)
450 sub("^"prefix, $3, datadir)
451 sub("^"prefix, $3, includedir)
454 if ($2 ~ /_bindir/ && !/_sbindir/)
460 if ($2 ~ /_sysconfdir/)
464 if ($2 ~ /_includedir/)
484 if (do_not_touch_anything)
487 close(changelog_file)
488 while ((getline < changelog_file) > 0)
490 system("rm -f " changelog_file)
492 if (did_clean == 0) {
495 print "rm -rf $RPM_BUILD_ROOT"
500 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
503 if (has_changelog == 0)
507 print "* %{date} PLD Team <feedback@pld-linux.org>"
509 printf "All persons listed below can be reached at "
510 print "<cvs_login>@pld-linux.org\n"
516 function fixedsub(s1,s2,t, ind) {
517 # substitutes fixed strings (not regexps)
518 if (ind = index(t,s1))
519 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
523 # There should be one or two tabs after the colon.
524 function format_preamble()
527 if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
535 # Replace directly specified directories with macros
536 function use_macros()
538 gsub(bindir, "%{_bindir}")
539 gsub("%{prefix}/bin", "%{_bindir}")
540 if(prefix"/bin" == bindir)
541 gsub("%{_prefix}/bin", "%{_bindir}")
543 for (c = 1; c <= NF; c++) {
544 if ($c ~ sbindir "/fix-info-dir")
546 gsub(sbindir, "%{_sbindir}", $c)
549 gsub("%{prefix}/sbin", "%{_sbindir}")
550 if(prefix"/sbin" == sbindir)
551 gsub("%{_prefix}/sbin", "%{_sbindir}")
553 for (c = 1; c <= NF; c++) {
554 if ($c ~ sysconfdir "/{?cron.")
556 if ($c ~ sysconfdir "/{?crontab.d")
558 if ($c ~ sysconfdir "/{?logrotate.d")
560 if ($c ~ sysconfdir "/{?pam.d")
562 if ($c ~ sysconfdir "/{?profile.d")
564 if ($c ~ sysconfdir "/{?rc.d")
566 if ($c ~ sysconfdir "/{?security")
568 if ($c ~ sysconfdir "/{?skel")
570 if ($c ~ sysconfdir "/{?sysconfig")
572 gsub(sysconfdir, "%{_sysconfdir}", $c)
575 gsub(datadir, "%{_datadir}")
576 gsub("%{prefix}/share", "%{_datadir}")
577 if(prefix"/share" == datadir)
578 gsub("%{_prefix}/share", "%{_datadir}")
580 gsub(includedir, "%{_includedir}")
581 gsub("%{prefix}/include", "%{_includedir}")
582 if(prefix"/include" == includedir)
583 gsub("%{_prefix}/include", "%{_includedir}")
585 gsub(mandir, "%{_mandir}")
586 if ($0 !~ "%{_datadir}/manual")
587 gsub("%{_datadir}/man", "%{_mandir}")
588 gsub("%{_prefix}/share/man", "%{_mandir}")
589 gsub("%{prefix}/share/man", "%{_mandir}")
590 gsub("%{prefix}/man", "%{_mandir}")
591 gsub("%{_prefix}/man", "%{_mandir}")
593 gsub(infodir, "%{_infodir}")
594 gsub("%{prefix}/info", "%{_infodir}")
595 gsub("%{_prefix}/info", "%{_infodir}")
597 if (prefix !~ "/X11R6") {
598 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
602 for (c = 1; c <= NF; c++) {
603 if ($c ~ prefix "/sbin/fix-info-dir")
605 gsub(prefix, "%{_prefix}", $c)
607 gsub("%{prefix}", "%{_prefix}")
610 gsub("%{PACKAGE_VERSION}", "%{version}")
611 gsub("%{PACKAGE_NAME}", "%{name}")
613 # we can move files between the dirs below
614 if ($0 !~ "%{_applnkdir}") {
615 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
618 gsub("^make$", "%{__make}")
619 gsub("^make ", "%{__make} ")
621 gsub("/usr/src/linux", "%{_kernelsrcdir}")
622 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
625 function use_files_macros()
627 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
628 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
631 function fill(ch, n, i) {
632 for (i = 0; i < n; i++)
636 function format_flush(line, indent, newline, word, first_word) {
638 if (format_indent == -1)
641 newline = fill(" ", format_indent) "- "
643 while (match(line, /[^\t ]+/)) {
644 word = substr(line, RSTART, RLENGTH)
645 if (length(newline) + length(word) + 1 > tw) {
648 if (format_indent == -1)
651 newline = fill(" ", format_indent + 2)
656 newline = newline word
659 newline = newline " " word
661 line = substr(line, RSTART + RLENGTH)
663 if (newline ~ /[^\t ]/) {
670 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
676 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")