3 # This is adapter v0.24. 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 # File with rpm groups
26 "rpm --eval %_sourcedir" | getline groups_file
27 groups_file = groups_file "/rpm.groups"
28 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups 1>&2")
30 # Temporary file for changelog section
31 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
34 "rpm --eval %_prefix" | getline prefix
35 "rpm --eval %_bindir" | getline bindir
36 "rpm --eval %_sbindir" | getline sbindir
37 "rpm --eval %_libdir" | getline libdir
38 "rpm --eval %_sysconfdir" | getline sysconfdir
39 "rpm --eval %_datadir" | getline datadir
40 "rpm --eval %_includedir" | getline includedir
41 "rpm --eval %_mandir" | getline mandir
42 "rpm --eval %_infodir" | getline infodir
45 # There should be a comment with CVS keywords on the first line of file.
47 if (!/# \$Revision:/) # If this line is already OK?
48 print "# $" "Revision:$, " "$" "Date:$" # No
51 next # It is enough for first line
55 # If the latest line matched /%files/
57 if ($0 !~ /defattr/) # If no %defattr
58 print "%defattr(644,root,root,755)" # Add it
60 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
64 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
66 if ($2 == "_applnkdir")
73 /^%description/, (/^%[a-z]+/ && !/^%description/) {
76 if (/^%description/) {
82 # Define _prefix and _mandir if it is X11 application
83 if (/^%description$/ && x11 == 1) {
84 print "%define\t\t_prefix\t\t/usr/X11R6"
85 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
91 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
93 format_flush(format_line, format_indent)
97 } else if (/^[ \t]*[-\*][ \t]*/) {
98 format_flush(format_line, format_indent)
100 format_indent = RLENGTH
101 match($0, /^[ \t]*[-\*][ \t]/)
102 format_line = substr($0, RLENGTH)
104 format_line = format_line " " $0
108 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
109 format_flush(format_line, format_indent)
122 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
126 if (/^%setup/ && !/-q/)
127 sub(/^%setup/, "%setup -q")
131 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
140 if (/LDFLAGS="-s"/) {
141 removed["LDFLAGS"] = 1
144 split($0, tmp, "LDFLAGS=")
145 count = split(tmp[2], flags, "\"")
146 if (flags[1] != "" && flags[1] !~ "!?debug") {
147 sub(/-s[" ]?/, "%{!?debug:-s} ", flags[1])
148 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
149 for (i = 2; i < count; i++)
150 $0 = $0 flags[i] "\""
156 if (cflags("CFLAGS") == 0)
160 if (cflags("CXXFLAGS") == 0)
164 if (removed["LDFLAGS"])
166 if (removed["CFLAGS"])
168 if (removed["CXXFLAGS"])
170 # Is there still something?
178 /^%clean/, (/^%[a-z]+$/ && !/^%clean/) {
183 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
187 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
189 print "rm -rf $RPM_BUILD_ROOT"
193 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
194 print "rm -rf $RPM_BUILD_ROOT"
200 # 'install -d' instead 'mkdir -p'
202 sub(/mkdir -p/, "install -d")
204 # No '-u root' or '-g root' for 'install'
205 if (/^install/ && /-[ug][ \t]*root/)
206 gsub(/-[ug][ \t]*root /, "")
208 if (/^install/ && /-m[ \t]*644/)
209 gsub(/-m[ \t]*644 /, "")
211 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
212 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
215 # No lines contain 'chmod' if it sets the modes to '644'
216 if ($1 ~ /chmod/ && $2 ~ /644/)
222 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
231 # %changelog section:
232 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
235 # There should be some CVS keywords on the first line of %changelog.
238 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
239 printf "All persons listed below can be reached at " > changelog_file
240 print "<cvs_login>@pld.org.pl\n" > changelog_file
241 print "$" "Log:$" > changelog_file
249 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
250 print " date +\"%a %b %d %Y\"`)" > changelog_file
256 if (!/^%[a-z]+$/ || /changelog/)
257 print > changelog_file
265 # There should not be a space after the name of field
266 # and before the colon.
270 if (Byla_grupa == 1 && field ~ /^#/)
272 if (Byla_grupa == 1 && field !~ /group(\(..\))?:/) {
274 print "Group:\t\t" Grupa["en"]
275 if (Grupa["en"] ~ /^X11/ && x11 == 0) # Is it X11 application?
278 byl_plik_z_grupami = 0
280 while ((getline linia_grup < groups_file) > 0) {
281 byl_plik_z_grupami = 1
282 if (linia_grup == Grupa["en"]) {
288 if (!byl_plik_z_grupami)
289 print "######\t\t" groups_file ": no such file"
290 else if (!byl_opis_grupy)
291 print "######\t\t" "Unknown group!"
293 while (getline linia_grup < groups_file) {
294 if (linia_grup == "")
296 split(linia_grup, g, /[\[\]:]/)
297 sub(/^[ \t]*/,"",g[4])
304 for (jezyk in Grupa) {
305 print "Group(" jezyk "):\t" Grupa[jezyk] | "sort"
311 if (field ~ /packager:|distribution:|docdir:|prefix:/)
314 if (field ~ /buildroot:/)
315 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
317 if (field ~ /group(\(..\))?:/) {
319 sub(/^Utilities\//,"Applications/",$2)
320 sub(/^Games/,"Applications/Games",$2)
321 sub(/^X11\/Games/,"Applications\/Games",$2)
322 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
323 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
324 sub(/^X11\/GNOME/,"X11/Applications",$2)
325 sub(/^X11\/Utilities/,"X11\/Applications",$2)
326 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
327 sub(/^Shells/,"Applications/Shells",$2)
329 if (!match(field,/\(..\):/))
332 glang=substr(field,RSTART+1,2)
333 sub(/^[^ \t]*[ \t]*/,"")
337 next # Line is already formatted and printed
340 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
341 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
347 if (field ~ /version:/)
350 if (field ~ /serial:/)
353 # Use %{name} and %{version} in the filenames in "Source:"
354 if (field ~ /source/ || field ~ /patch/) {
355 n = split($2, url, /\//)
356 if (url[n] ~ /\.gz$/) {
357 url[n+1] = ".gz" url[n+1]
358 sub(/\.gz$/,"",url[n])
360 if (url[n] ~ /\.zip$/) {
361 url[n+1] = ".zip" url[n+1]
362 sub(/\.zip$/,"",url[n])
364 if (url[n] ~ /\.tar$/) {
365 url[n+1] = ".tar" url[n+1]
366 sub(/\.tar$/,"",url[n])
368 if (url[n] ~ /\.patch$/) {
369 url[n+1] = ".patch" url[n+1]
370 sub(/\.patch$/,"",url[n])
372 if (url[n] ~ /\.bz2$/) {
373 url[n+1] = ".bz2" url[n+1]
374 sub(/\.bz2$/,"",url[n])
376 if (url[n] ~ /\.logrotate$/) {
377 url[n+1] = ".logrotate" url[n+1]
378 sub(/\.logrotate$/,"",url[n])
380 if (url[n] ~ /\.pamd$/) {
381 url[n+1] = ".pamd" url[n+1]
382 sub(/\.pamd$/,"",url[n])
386 url[n] = fixedsub(name, "%{name}", url[n])
387 if (field ~ /source/)
388 url[n] = fixedsub(version, "%{version}", url[n])
389 $2 = fixedsub(filename, url[n], $2)
392 if (field ~ /source:/)
395 if (field ~ /patch:/)
400 if ($1 ~ /%define/) {
401 # Do not add %define of _prefix if it already is.
402 if ($2 ~ /_prefix/) {
403 sub("^"prefix, $3, bindir)
404 sub("^"prefix, $3, sbindir)
405 sub("^"prefix, $3, libdir)
406 sub("^"prefix, $3, datadir)
407 sub("^"prefix, $3, includedir)
411 if ($2 ~ /_bindir/ && !/_sbindir/)
417 if ($2 ~ /_sysconfdir/)
421 if ($2 ~ /_includedir/)
440 close(changelog_file)
441 while ((getline < changelog_file) > 0)
443 system("rm -f " changelog_file)
445 if (did_clean == 0) {
448 print "rm -rf $RPM_BUILD_ROOT"
453 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
456 if (has_changelog == 0)
460 print "* %{date} PLD Team <pld-list@pld.org.pl>"
461 printf "All persons listed below can be reached at "
462 print "<cvs_login>@pld.org.pl\n"
467 function fixedsub(s1,s2,t, ind) {
468 # substitutes fixed strings (not regexps)
469 if (ind = index(t,s1))
470 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
474 # There should be one or two tabs after the colon.
475 function format_preamble()
478 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
486 # Replace directly specified directories with macros
487 function use_macros()
489 gsub(bindir, "%{_bindir}")
490 gsub("%{_prefix}/bin", "%{_bindir}")
491 gsub("%{prefix}/bin", "%{_bindir}")
493 for (c = 1; c <= NF; c++) {
494 if ($c ~ sbindir "/fix-info-dir")
496 gsub(sbindir, "%{_sbindir}", $c)
499 gsub("%{prefix}/sbin", "%{_sbindir}")
500 gsub("%{_prefix}/sbib", "%{_sbindir}")
502 gsub(libdir, "%{_libdir}")
503 gsub("%{prefix}/lib", "%{_libdir}")
504 gsub("%{_prefix}/lib", "%{_libdir}")
506 for (c = 1; c <= NF; c++) {
507 if ($c ~ sysconfdir "/cron.d")
509 if ($c ~ sysconfdir "/crontab.d")
511 if ($c ~ sysconfdir "/logrotate.d")
513 if ($c ~ sysconfdir "/pam.d")
515 if ($c ~ sysconfdir "/profile.d")
517 if ($c ~ sysconfdir "/rc.d")
519 if ($c ~ sysconfdir "/security")
521 if ($c ~ sysconfdir "/skel")
523 if ($c ~ sysconfdir "/sysconfig")
525 gsub(sysconfdir, "%{_sysconfdir}", $c)
528 gsub(datadir, "%{_datadir}")
529 gsub("%{prefix}/share", "%{_datadir}")
530 gsub("%{_prefix}/share", "%{_datadir}")
532 gsub(includedir, "%{_includedir}")
533 gsub("%{prefix}/include", "%{_includedir}")
534 gsub("%{_prefix}/include", "%{_includedir}")
536 gsub(mandir, "%{_mandir}")
537 gsub("%{_datadir}/man", "%{_mandir}")
538 gsub("%{_prefix}/share/man", "%{_mandir}")
539 gsub("%{prefix}/share/man", "%{_mandir}")
540 gsub("%{prefix}/man", "%{_mandir}")
541 gsub("%{_prefix}/man", "%{_mandir}")
543 gsub(infodir, "%{_infodir}")
544 gsub("%{prefix}/info", "%{_infodir}")
545 gsub("%{_prefix}/info", "%{_infodir}")
547 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
550 for (c = 1; c <= NF; c++) {
551 if ($c ~ prefix "/sbin/fix-info-dir")
553 gsub(prefix, "%{_prefix}", $c)
555 gsub("%{prefix}", "%{_prefix}")
558 gsub("%{PACKAGE_VERSION}", "%{version}")
559 gsub("%{PACKAGE_NAME}", "%{name}")
561 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
562 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
564 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
565 gsub("%{_datadir}/applnk", "%{_applnkdir}")
567 gsub("^make$", "%{__make}")
568 gsub("^make ", "%{__make} ")
571 function fill(ch, n, i) {
572 for (i = 0; i < n; i++)
576 function format_flush(line, indent, newline, word, first_word) {
578 if (format_indent == -1)
581 newline = fill(" ", format_indent) "- "
583 while (match(line, /[^\t ]+/)) {
584 word = substr(line, RSTART, RLENGTH)
585 if (length(newline) + length(word) + 1 > tw) {
588 if (format_indent == -1)
591 newline = fill(" ", format_indent + 2)
596 newline = newline word
599 newline = newline " " word
601 line = substr(line, RSTART + RLENGTH)
603 if (newline ~ /[^\t ]/) {
610 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
615 sub("\$RPM_OPT_FLAGS", "%{!?debug:$RPM_OPT_FLAGS}%{?debug:-O0 -g}")