3 # This is adapter v0.22. 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 # File with rpm groups
21 "rpm --eval %_sourcedir" | getline groups_file
22 groups_file = groups_file "/rpm.groups"
23 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups 1>&2")
25 # Temporary file for changelog section
26 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
29 "rpm --eval %_prefix" | getline prefix
30 "rpm --eval %_bindir" | getline bindir
31 "rpm --eval %_sbindir" | getline sbindir
32 "rpm --eval %_libdir" | getline libdir
33 "rpm --eval %_sysconfdir" | getline sysconfdir
34 "rpm --eval %_datadir" | getline datadir
35 "rpm --eval %_includedir" | getline includedir
36 "rpm --eval %_mandir" | getline mandir
37 "rpm --eval %_infodir" | getline infodir
40 # There should be a comment with CVS keywords on the first line of file.
42 if (!/# \$Revision:/) # If this line is already OK?
43 print "# $" "Revision:$, " "$" "Date:$" # No
46 next # It is enough for first line
50 # If the latest line matched /%files/
52 if ($0 !~ /defattr/) # If no %defattr
53 print "%defattr(644,root,root,755)" # Add it
55 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
59 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
61 if ($2 == "_applnkdir")
68 /^%description/, (/^%[a-z]+/ && !/^%description/) {
71 if (/^%description/) {
77 # Define _prefix and _mandir if it is X11 application
78 if (/^%description$/ && x11 == 1) {
79 print "%define\t\t_prefix\t\t/usr/X11R6"
80 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
86 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
88 format_flush(format_line, format_indent)
92 } else if (/^[ \t]*[-\*][ \t]*/) {
93 format_flush(format_line, format_indent)
95 format_indent = RLENGTH
96 match($0, /^[ \t]*[-\*][ \t]/)
97 format_line = substr($0, RLENGTH)
99 format_line = format_line " " $0
103 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
104 format_flush(format_line, format_indent)
117 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
121 if (/^%setup/ && !/-q/)
122 sub(/^%setup/, "%setup -q")
126 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
133 sub(/LDFLAGS="-s"[ ]*/, "")
135 split($0, tmp, "LDFLAGS=\"")
136 count = split(tmp[2], flags, "\"")
137 sub(/-s[" ]?/, "%{!?debug:-s} ", flags[1])
138 $0 = tmp[1] line[1] "LDFLAGS=\"" flags[1] "\""
139 for (i = 2; i < count; i++)
140 $0 = $0 flags[i] "\""
145 if (cflags("CFLAGS") == 0)
149 if (cflags("CXXFLAGS") == 0)
154 /^%clean/, (/^%[a-z]+$/ && !/^%clean/) {
159 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
163 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
165 print "rm -rf $RPM_BUILD_ROOT"
169 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
170 print "rm -rf $RPM_BUILD_ROOT"
176 # 'install -d' instead 'mkdir -p'
178 sub(/mkdir -p/, "install -d")
180 # No '-u root' or '-g root' for 'install'
181 if (/^install/ && /-[ug][ \t]*root/)
182 gsub(/-[ug][ \t]*root /, "")
184 if (/^install/ && /-m[ \t]*644/)
185 gsub(/-m[ \t]*644 /, "")
187 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
188 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
191 # No lines contain 'chmod' if it sets the modes to '644'
192 if ($1 ~ /chmod/ && $2 ~ /644/)
195 # 'gzip -9nf' for compressing
196 if ($1 ~ /gzip|bzip2/)
202 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
211 # %changelog section:
212 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
215 # There should be some CVS keywords on the first line of %changelog.
218 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
219 printf "All persons listed below can be reached at " > changelog_file
220 print "<cvs_login>@pld.org.pl\n" > changelog_file
221 print "$" "Log:$" > changelog_file
229 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
230 print " date +\"%a %b %d %Y\"`)" > changelog_file
236 if (!/^%[a-z]+$/ || /changelog/)
237 print > changelog_file
245 # There should not be a space after the name of field
246 # and before the colon.
250 if (Byla_grupa == 1 && field ~ /^#/)
252 if (Byla_grupa == 1 && field !~ /group(\(..\))?:/) {
254 print "Group:\t\t" Grupa["en"]
255 if (Grupa["en"] ~ /^X11/ && x11 == 0) # Is it X11 application?
258 byl_plik_z_grupami = 0
260 while ((getline linia_grup < groups_file) > 0) {
261 byl_plik_z_grupami = 1
262 if (linia_grup == Grupa["en"]) {
268 if (!byl_plik_z_grupami)
269 print "######\t\t" groups_file ": no such file"
270 else if (!byl_opis_grupy)
271 print "######\t\t" "Unknown group!"
273 while (getline linia_grup < groups_file) {
274 if (linia_grup == "")
276 split(linia_grup, g, /[\[\]:]/)
277 sub(/^[ \t]*/,"",g[4])
284 for (jezyk in Grupa) {
285 print "Group(" jezyk "):\t" Grupa[jezyk] | "sort"
291 if (field ~ /packager:|distribution:|docdir:|prefix:/)
294 if (field ~ /buildroot:/)
295 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
297 if (field ~ /group(\(..\))?:/) {
299 sub(/^Utilities\//,"Applications/",$2)
300 sub(/^Games/,"Applications/Games",$2)
301 sub(/^X11\/Games/,"Applications\/Games",$2)
302 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
303 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
304 sub(/^X11\/GNOME/,"X11/Applications",$2)
305 sub(/^X11\/Utilities/,"X11\/Applications",$2)
306 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
307 sub(/^Shells/,"Applications/Shells",$2)
309 if (!match(field,/\(..\):/))
312 glang=substr(field,RSTART+1,2)
313 sub(/^[^ \t]*[ \t]*/,"")
317 next # Line is already formatted and printed
320 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
321 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
327 if (field ~ /version:/)
330 if (field ~ /serial:/)
333 # Use %{name} and %{version} in the filenames in "Source:"
334 if (field ~ /source/ || field ~ /patch/) {
335 n = split($2, url, /\//)
336 if (url[n] ~ /\.gz$/) {
337 url[n+1] = ".gz" url[n+1]
338 sub(/\.gz$/,"",url[n])
340 if (url[n] ~ /\.zip$/) {
341 url[n+1] = ".zip" url[n+1]
342 sub(/\.zip$/,"",url[n])
344 if (url[n] ~ /\.tar$/) {
345 url[n+1] = ".tar" url[n+1]
346 sub(/\.tar$/,"",url[n])
348 if (url[n] ~ /\.patch$/) {
349 url[n+1] = ".patch" url[n+1]
350 sub(/\.patch$/,"",url[n])
352 if (url[n] ~ /\.bz2$/) {
353 url[n+1] = ".bz2" url[n+1]
354 sub(/\.bz2$/,"",url[n])
356 if (url[n] ~ /\.logrotate$/) {
357 url[n+1] = ".logrotate" url[n+1]
358 sub(/\.logrotate$/,"",url[n])
360 if (url[n] ~ /\.pamd$/) {
361 url[n+1] = ".pamd" url[n+1]
362 sub(/\.pamd$/,"",url[n])
366 url[n] = fixedsub(name, "%{name}", url[n])
367 if (field ~ /source/)
368 url[n] = fixedsub(version, "%{version}", url[n])
369 $2 = fixedsub(filename, url[n], $2)
372 if (field ~ /source:/)
375 if (field ~ /patch:/)
380 if ($1 ~ /%define/) {
381 # Do not add %define of _prefix if it already is.
382 if ($2 ~ /_prefix/) {
383 sub("^"prefix, $3, bindir)
384 sub("^"prefix, $3, sbindir)
385 sub("^"prefix, $3, libdir)
386 sub("^"prefix, $3, datadir)
387 sub("^"prefix, $3, includedir)
391 if ($2 ~ /_bindir/ && !/_sbindir/)
397 if ($2 ~ /_sysconfdir/)
401 if ($2 ~ /_includedir/)
420 close(changelog_file)
421 while ((getline < changelog_file) > 0)
423 system("rm -f " changelog_file)
425 if (did_clean == 0) {
428 print "rm -rf $RPM_BUILD_ROOT"
433 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
436 if (has_changelog == 0)
440 print "* %{date} PLD Team <pld-list@pld.org.pl>"
441 printf "All persons listed below can be reached at "
442 print "<cvs_login>@pld.org.pl\n"
447 function fixedsub(s1,s2,t, ind) {
448 # substitutes fixed strings (not regexps)
449 if (ind = index(t,s1))
450 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
454 # There should be one or two tabs after the colon.
455 function format_preamble()
458 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
466 # Replace directly specified directories with macros
467 function use_macros()
469 gsub(bindir, "%{_bindir}")
470 gsub("%{_prefix}/bin", "%{_bindir}")
471 gsub("%{prefix}/bin", "%{_bindir}")
473 for (c = 1; c <= NF; c++) {
474 if ($c ~ sbindir "/fix-info-dir")
476 gsub(sbindir, "%{_sbindir}", $c)
479 gsub("%{prefix}/sbin", "%{_sbindir}")
480 gsub("%{_prefix}/sbib", "%{_sbindir}")
482 gsub(libdir, "%{_libdir}")
483 gsub("%{prefix}/lib", "%{_libdir}")
484 gsub("%{_prefix}/lib", "%{_libdir}")
486 for (c = 1; c <= NF; c++) {
487 if ($c ~ sysconfdir "/cron.d")
489 if ($c ~ sysconfdir "/crontab.d")
491 if ($c ~ sysconfdir "/logrotate.d")
493 if ($c ~ sysconfdir "/pam.d")
495 if ($c ~ sysconfdir "/profile.d")
497 if ($c ~ sysconfdir "/rc.d")
499 if ($c ~ sysconfdir "/security")
501 if ($c ~ sysconfdir "/skel")
503 if ($c ~ sysconfdir "/sysconfig")
505 gsub(sysconfdir, "%{_sysconfdir}", $c)
508 gsub(datadir, "%{_datadir}")
509 gsub("%{prefix}/share", "%{_datadir}")
510 gsub("%{_prefix}/share", "%{_datadir}")
512 gsub(includedir, "%{_includedir}")
513 gsub("%{prefix}/include", "%{_includedir}")
514 gsub("%{_prefix}/include", "%{_includedir}")
516 gsub(mandir, "%{_mandir}")
517 gsub("%{_datadir}/man", "%{_mandir}")
518 gsub("%{_prefix}/share/man", "%{_mandir}")
519 gsub("%{prefix}/share/man", "%{_mandir}")
520 gsub("%{prefix}/man", "%{_mandir}")
521 gsub("%{_prefix}/man", "%{_mandir}")
523 gsub(infodir, "%{_infodir}")
524 gsub("%{prefix}/info", "%{_infodir}")
525 gsub("%{_prefix}/info", "%{_infodir}")
527 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
530 for (c = 1; c <= NF; c++) {
531 if ($c ~ prefix "/sbin/fix-info-dir")
533 gsub(prefix, "%{_prefix}", $c)
535 gsub("%{prefix}", "%{_prefix}")
538 gsub("%{PACKAGE_VERSION}", "%{version}")
539 gsub("%{PACKAGE_NAME}", "%{name}")
541 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
542 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
544 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
545 gsub("%{_datadir}/applnk", "%{_applnkdir}")
547 gsub("^make$", "%{__make}")
548 gsub("^make ", "%{__make} ")
551 function fill(ch, n, i) {
552 for (i = 0; i < n; i++)
556 function format_flush(line, indent, newline, word, first_word) {
558 if (format_indent == -1)
561 newline = fill(" ", format_indent) "- "
563 while (match(line, /[^\t ]+/)) {
564 word = substr(line, RSTART, RLENGTH)
565 if (length(newline) + length(word) + 1 > tw) {
568 if (format_indent == -1)
571 newline = fill(" ", format_indent + 2)
576 newline = newline word
579 newline = newline " " word
581 line = substr(line, RSTART + RLENGTH)
583 if (newline ~ /[^\t ]/) {
590 if ($0 == var "=\"$RPM_OPT_FLAGS\"")
593 sub("\$RPM_OPT_FLAGS", "%{!?debug:$RPM_OPT_FLAGS}%{?debug:-O -g}")