3 # This is adapter v0.25. Adapter adapts .spec files for PLD.
5 # Copyright (C) 1999-2001 PLD-Team <pld-list@pld.org.pl>
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@ee.pw.edu.pl>
12 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
15 preamble = 1 # Is it part of preamble? Default - yes
16 boc = 2 # 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 1>&2")
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)
67 # Do not touch commented sections!
81 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
83 if ($2 == "_applnkdir")
92 /^%description/, (/^%[a-z]+/ && !/^%description/) {
95 if (/^%description/) {
101 # Define _prefix and _mandir if it is X11 application
102 if (/^%description$/ && x11 == 1) {
103 print "%define\t\t_prefix\t\t/usr/X11R6"
104 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
105 prefix = "/usr/X11R6"
110 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
112 format_flush(format_line, format_indent)
116 } else if (/^[ \t]*[-\*][ \t]*/) {
117 format_flush(format_line, format_indent)
119 format_indent = RLENGTH
120 match($0, /^[ \t]*[-\*][ \t]/)
121 format_line = substr($0, RLENGTH)
123 format_line = format_line " " $0
127 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
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 # No '-u root' or '-g root' for 'install'
232 if (/^install/ && /-[ug][ \t]*root/)
233 gsub(/-[ug][ \t]*root /, "")
235 if (/^install/ && /-m[ \t]*644/)
236 gsub(/-m[ \t]*644 /, "")
238 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
239 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
242 # No lines contain 'chmod' if it sets the modes to '644'
243 if ($1 ~ /chmod/ && $2 ~ /644/)
250 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
262 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
265 # There should be some CVS keywords on the first line of %changelog.
268 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
269 printf "All persons listed below can be reached at " > changelog_file
270 print "<cvs_login>@pld.org.pl\n" > changelog_file
271 print "$" "Log:$" > changelog_file
279 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
280 print " date +\"%a %b %d %Y\"`)" > changelog_file
286 if (!/^%[a-z]+$/ || /changelog/)
287 print > changelog_file
296 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
299 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
302 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
305 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
313 # There should not be a space after the name of field
314 # and before the colon.
318 if (Byla_grupa == 1 && field ~ /^#/)
320 if (Byla_grupa == 1 && field !~ /group(\(..\))?:/) {
322 print "Group:\t\t" Grupa["en"]
323 if (Grupa["en"] ~ /^X11/ && x11 == 0) # Is it X11 application?
326 byl_plik_z_grupami = 0
328 while ((getline linia_grup < groups_file) > 0) {
329 byl_plik_z_grupami = 1
330 if (linia_grup == Grupa["en"]) {
336 if (!byl_plik_z_grupami)
337 print "######\t\t" groups_file ": no such file"
338 else if (!byl_opis_grupy)
339 print "######\t\t" "Unknown group!"
341 while (getline linia_grup < groups_file) {
342 if (linia_grup == "")
344 split(linia_grup, g, /[\[\]:]/)
345 sub(/^[ \t]*/,"",g[4])
352 for (jezyk in Grupa) {
353 print "Group(" jezyk "):\t" Grupa[jezyk] | "sort"
359 if (field ~ /packager:|distribution:|docdir:|prefix:/)
362 if (field ~ /buildroot:/)
363 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
365 if (field ~ /group(\(..\))?:/) {
367 sub(/^Utilities\//,"Applications/",$2)
368 sub(/^Games/,"Applications/Games",$2)
369 sub(/^X11\/Games/,"Applications\/Games",$2)
370 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
371 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
372 sub(/^X11\/GNOME/,"X11/Applications",$2)
373 sub(/^X11\/Utilities/,"X11\/Applications",$2)
374 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
375 sub(/^Shells/,"Applications/Shells",$2)
377 if (!match(field,/\(..\):/))
380 glang=substr(field,RSTART+1,2)
381 sub(/^[^ \t]*[ \t]*/,"")
385 next # Line is already formatted and printed
388 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
389 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
395 if (field ~ /version:/)
398 if (field ~ /serial:/)
401 # Use %{name} and %{version} in the filenames in "Source:"
402 if (field ~ /source/ || field ~ /patch/) {
403 n = split($2, url, /\//)
404 if (url[n] ~ /\.gz$/) {
405 url[n+1] = ".gz" url[n+1]
406 sub(/\.gz$/,"",url[n])
408 if (url[n] ~ /\.zip$/) {
409 url[n+1] = ".zip" url[n+1]
410 sub(/\.zip$/,"",url[n])
412 if (url[n] ~ /\.tar$/) {
413 url[n+1] = ".tar" url[n+1]
414 sub(/\.tar$/,"",url[n])
416 if (url[n] ~ /\.patch$/) {
417 url[n+1] = ".patch" url[n+1]
418 sub(/\.patch$/,"",url[n])
420 if (url[n] ~ /\.bz2$/) {
421 url[n+1] = ".bz2" url[n+1]
422 sub(/\.bz2$/,"",url[n])
424 if (url[n] ~ /\.logrotate$/) {
425 url[n+1] = ".logrotate" url[n+1]
426 sub(/\.logrotate$/,"",url[n])
428 if (url[n] ~ /\.pamd$/) {
429 url[n+1] = ".pamd" url[n+1]
430 sub(/\.pamd$/,"",url[n])
434 url[n] = fixedsub(name, "%{name}", url[n])
435 if (field ~ /source/)
436 url[n] = fixedsub(version, "%{version}", url[n])
437 $2 = fixedsub(filename, url[n], $2)
440 if (field ~ /source:/)
443 if (field ~ /patch:/)
448 if ($1 ~ /%define/) {
449 # Do not add %define of _prefix if it already is.
450 if ($2 ~ /_prefix/) {
451 sub("^"prefix, $3, bindir)
452 sub("^"prefix, $3, sbindir)
453 sub("^"prefix, $3, libdir)
454 sub("^"prefix, $3, datadir)
455 sub("^"prefix, $3, includedir)
459 if ($2 ~ /_bindir/ && !/_sbindir/)
465 if ($2 ~ /_sysconfdir/)
469 if ($2 ~ /_includedir/)
488 close(changelog_file)
489 while ((getline < changelog_file) > 0)
491 system("rm -f " changelog_file)
493 if (did_clean == 0) {
496 print "rm -rf $RPM_BUILD_ROOT"
501 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
504 if (has_changelog == 0)
508 print "* %{date} PLD Team <pld-list@pld.org.pl>"
509 printf "All persons listed below can be reached at "
510 print "<cvs_login>@pld.org.pl\n"
515 function fixedsub(s1,s2,t, ind) {
516 # substitutes fixed strings (not regexps)
517 if (ind = index(t,s1))
518 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
522 # There should be one or two tabs after the colon.
523 function format_preamble()
526 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
534 # Replace directly specified directories with macros
535 function use_macros()
537 gsub(bindir, "%{_bindir}")
538 gsub("%{_prefix}/bin", "%{_bindir}")
539 gsub("%{prefix}/bin", "%{_bindir}")
541 for (c = 1; c <= NF; c++) {
542 if ($c ~ sbindir "/fix-info-dir")
544 gsub(sbindir, "%{_sbindir}", $c)
547 gsub("%{prefix}/sbin", "%{_sbindir}")
548 gsub("%{_prefix}/sbib", "%{_sbindir}")
550 gsub(libdir, "%{_libdir}")
551 gsub("%{prefix}/lib", "%{_libdir}")
552 gsub("%{_prefix}/lib", "%{_libdir}")
554 for (c = 1; c <= NF; c++) {
555 if ($c ~ sysconfdir "/cron.d")
557 if ($c ~ sysconfdir "/crontab.d")
559 if ($c ~ sysconfdir "/logrotate.d")
561 if ($c ~ sysconfdir "/pam.d")
563 if ($c ~ sysconfdir "/profile.d")
565 if ($c ~ sysconfdir "/rc.d")
567 if ($c ~ sysconfdir "/security")
569 if ($c ~ sysconfdir "/skel")
571 if ($c ~ sysconfdir "/sysconfig")
573 gsub(sysconfdir, "%{_sysconfdir}", $c)
576 gsub(datadir, "%{_datadir}")
577 gsub("%{prefix}/share", "%{_datadir}")
578 gsub("%{_prefix}/share", "%{_datadir}")
580 gsub(includedir, "%{_includedir}")
581 gsub("%{prefix}/include", "%{_includedir}")
582 gsub("%{_prefix}/include", "%{_includedir}")
584 gsub(mandir, "%{_mandir}")
585 gsub("%{_datadir}/man", "%{_mandir}")
586 gsub("%{_prefix}/share/man", "%{_mandir}")
587 gsub("%{prefix}/share/man", "%{_mandir}")
588 gsub("%{prefix}/man", "%{_mandir}")
589 gsub("%{_prefix}/man", "%{_mandir}")
591 gsub(infodir, "%{_infodir}")
592 gsub("%{prefix}/info", "%{_infodir}")
593 gsub("%{_prefix}/info", "%{_infodir}")
595 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
598 for (c = 1; c <= NF; c++) {
599 if ($c ~ prefix "/sbin/fix-info-dir")
601 gsub(prefix, "%{_prefix}", $c)
603 gsub("%{prefix}", "%{_prefix}")
606 gsub("%{PACKAGE_VERSION}", "%{version}")
607 gsub("%{PACKAGE_NAME}", "%{name}")
609 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
610 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
612 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
613 gsub("%{_datadir}/applnk", "%{_applnkdir}")
615 gsub("^make$", "%{__make}")
616 gsub("^make ", "%{__make} ")
619 function fill(ch, n, i) {
620 for (i = 0; i < n; i++)
624 function format_flush(line, indent, newline, word, first_word) {
626 if (format_indent == -1)
629 newline = fill(" ", format_indent) "- "
631 while (match(line, /[^\t ]+/)) {
632 word = substr(line, RSTART, RLENGTH)
633 if (length(newline) + length(word) + 1 > tw) {
636 if (format_indent == -1)
639 newline = fill(" ", format_indent + 2)
644 newline = newline word
647 newline = newline " " word
649 line = substr(line, RSTART + RLENGTH)
651 if (newline ~ /[^\t ]/) {
658 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
664 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")