3 # This is adapter v0.21. Adapter adapts .spec files for PLD.
5 # Copyright (C) 1999, 2000 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 %_topdir" | getline groups_file
22 groups_file = groups_file "/groups"
24 # Temporary file for changelog section
25 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
28 "rpm --eval %_prefix" | getline prefix
29 "rpm --eval %_bindir" | getline bindir
30 "rpm --eval %_sbindir" | getline sbindir
31 "rpm --eval %_libdir" | getline libdir
32 "rpm --eval %_sysconfdir" | getline sysconfdir
33 "rpm --eval %_datadir" | getline datadir
34 "rpm --eval %_includedir" | getline includedir
35 "rpm --eval %_mandir" | getline mandir
36 "rpm --eval %_infodir" | getline infodir
39 # There should be a comment with CVS keywords on the first line of file.
41 if (!/# \$Revision:/) # If this line is already OK?
42 print "# $" "Revision:$, " "$" "Date:$" # No
45 next # It is enough for first line
49 # If the latest line matched /%files/
51 if ($0 !~ /defattr/) # If no %defattr
52 print "%defattr(644,root,root,755)" # Add it
54 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
58 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
60 if ($2 == "_applnkdir")
67 /^%description/, (/^%[a-z]+/ && !/^%description/) {
70 if (/^%description/) {
76 # Define _prefix and _mandir if it is X11 application
77 if (/^%description$/ && x11 == 1) {
78 print "%define\t\t_prefix\t\t/usr/X11R6"
79 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
85 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
87 format_flush(format_line, format_indent)
91 } else if (/^[ \t]*[-\*][ \t]*/) {
92 format_flush(format_line, format_indent)
94 format_indent = RLENGTH
95 match($0, /^[ \t]*[-\*][ \t]/)
96 format_line = substr($0, RLENGTH)
98 format_line = format_line " " $0
102 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
103 format_flush(format_line, format_indent)
116 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
120 if (/^%setup/ && !/-q/)
121 sub(/^%setup/, "%setup -q")
125 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
132 /^%clean/, (/^%[a-z]+$/ && !/^%clean/) {
137 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
141 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
143 print "rm -rf $RPM_BUILD_ROOT"
147 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
148 print "rm -rf $RPM_BUILD_ROOT"
154 # 'install -d' instead 'mkdir -p'
156 sub(/mkdir -p/, "install -d")
158 # No '-u root' or '-g root' for 'install'
159 if (/^install/ && /-[ug][ \t]*root/)
160 gsub(/-[ug][ \t]*root /, "")
162 if (/^install/ && /-m[ \t]*644/)
163 gsub(/-m[ \t]*644 /, "")
165 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
166 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
169 # No lines contain 'chmod' if it sets the modes to '644'
170 if ($1 ~ /chmod/ && $2 ~ /644/)
173 # 'gzip -9nf' for compressing
174 if ($1 ~ /gzip|bzip2/) {
176 sub(/-[A-Za-z0-9]+ /, "", $0)
183 /^%pre/, (/^[a-z]+$/ && !/^%pre/) { script = 1 }
184 /^%preun/, (/^[a-z]+$/ && !/^%preun/) { script = 1 }
185 /^%post/, (/^[a-z]+$/ && !/^%post/) { script = 1 }
186 /^%postun/, (/^[a-z]+$/ && !/^%postun/) { script = 1 }
191 sub(/-[A-Za-z0-9]+ /, "", $0)
199 sub(/-[A-Za-z0-9]+ /, "", $0)
209 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
218 # %changelog section:
219 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
222 # There should be some CVS keywords on the first line of %changelog.
225 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
226 printf "All persons listed below can be reached at " > changelog_file
227 print "<cvs_login>@pld.org.pl\n" > changelog_file
228 print "$" "Log:$" > changelog_file
236 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
237 print " date +\"%a %b %d %Y\"`)" > changelog_file
243 if (!/^%[a-z]+$/ || /changelog/)
244 print > changelog_file
252 # There should not be a space after the name of field
253 # and before the colon.
258 if (Byla_grupa == 1 && field !~ /group(\(..\))?:/) {
260 print "Group:\t\t" Grupa["en"]
261 if (Grupa["en"] ~ /^X11/ && x11 == 0) # Is it X11 application?
264 byl_plik_z_grupami = 0
266 while ((getline linia_grup < groups_file) > 0) {
267 byl_plik_z_grupami = 1
268 if (linia_grup == Grupa["en"]) {
274 if (!byl_plik_z_grupami)
275 print "######\t\t" groups_file ": no such file"
276 else if (!byl_opis_grupy)
277 print "######\t\t" "Unknown group!"
279 while (getline linia_grup < groups_file) {
280 if (linia_grup == "")
282 split(linia_grup, g, /[\[\]:]/)
283 sub(/^[ \t]*/,"",g[4])
290 for (jezyk in Grupa) {
291 print "Group(" jezyk "):\t" Grupa[jezyk]
296 if (field ~ /packager:|distribution:|docdir:|prefix:/)
299 if (field ~ /buildroot:/)
300 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
302 if (field ~ /group(\(..\))?:/) {
305 if (!match(field,/\(..\):/))
308 glang=substr(field,RSTART+1,2)
309 sub(/^[^ \t]*[ \t]*/,"")
313 next # Line is already formatted and printed
316 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
317 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
323 if (field ~ /version:/)
326 if (field ~ /serial:/)
329 # Use %{name} and %{version} in the filenames in "Source:"
330 if (field ~ /source/ || field ~ /patch/) {
331 n = split($2, url, /\//)
332 if (url[n] ~ /\.gz$/) {
333 url[n+1] = ".gz" url[n+1]
334 sub(/\.gz$/,"",url[n])
336 if (url[n] ~ /\.zip$/) {
337 url[n+1] = ".zip" url[n+1]
338 sub(/\.zip$/,"",url[n])
340 if (url[n] ~ /\.tar$/) {
341 url[n+1] = ".tar" url[n+1]
342 sub(/\.tar$/,"",url[n])
344 if (url[n] ~ /\.patch$/) {
345 url[n+1] = ".patch" url[n+1]
346 sub(/\.patch$/,"",url[n])
348 if (url[n] ~ /\.bz2$/) {
349 url[n+1] = ".bz2" url[n+1]
350 sub(/\.bz2$/,"",url[n])
353 url[n] = fixedsub(name, "%{name}", url[n])
354 if (field ~ /source/)
355 url[n] = fixedsub(version, "%{version}", url[n])
356 $2 = fixedsub(filename, url[n], $2)
359 if (field ~ /source:/)
362 if (field ~ /patch:/)
367 if ($1 ~ /%define/) {
368 # Do not add %define of _prefix if it already is.
369 if ($2 ~ /_prefix/) {
370 sub("^"prefix, $3, bindir)
371 sub("^"prefix, $3, sbindir)
372 sub("^"prefix, $3, libdir)
373 sub("^"prefix, $3, datadir)
374 sub("^"prefix, $3, includedir)
378 if ($2 ~ /_bindir/ && !/_sbindir/)
384 if ($2 ~ /_sysconfdir/)
388 if ($2 ~ /_includedir/)
407 close(changelog_file)
408 while ((getline < changelog_file) > 0)
410 system("rm -f " changelog_file)
412 if (did_clean == 0) {
415 print "rm -rf $RPM_BUILD_ROOT"
420 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
423 if (has_changelog == 0)
427 print "* %{date} PLD Team <pld-list@pld.org.pl>"
428 printf "All persons listed below can be reached at "
429 print "<cvs_login>@pld.org.pl\n"
434 function fixedsub(s1,s2,t, ind) {
435 # substitutes fixed strings (not regexps)
436 if (ind = index(t,s1))
437 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
441 # There should be one or two tabs after the colon.
442 function format_preamble()
445 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
453 # Replace directly specified directories with macros
454 function use_macros()
456 gsub(bindir, "%{_bindir}")
457 gsub("%{_prefix}/bin", "%{_bindir}")
458 gsub("%{prefix}/bin", "%{_bindir}")
460 for (c = 1; c <= NF; c++) {
461 if ($c ~ sbindir "/fix-info-dir")
463 gsub(sbindir, "%{_sbindir}", $c)
466 gsub("%{prefix}/sbin", "%{_sbindir}")
467 gsub("%{_prefix}/sbib", "%{_sbindir}")
469 gsub(libdir, "%{_libdir}")
470 gsub("%{prefix}/lib", "%{_libdir}")
471 gsub("%{_prefix}/lib", "%{_libdir}")
473 for (c = 1; c <= NF; c++) {
474 if ($c ~ sysconfdir "/cron.d")
476 if ($c ~ sysconfdir "/crontab.d")
478 if ($c ~ sysconfdir "/logrotate.d")
480 if ($c ~ sysconfdir "/pam.d")
482 if ($c ~ sysconfdir "/profile.d")
484 if ($c ~ sysconfdir "/rc.d")
486 if ($c ~ sysconfdir "/security")
488 if ($c ~ sysconfdir "/skel")
490 if ($c ~ sysconfdir "/sysconfig")
492 gsub(sysconfdir, "%{_sysconfdir}", $c)
495 gsub(datadir, "%{_datadir}")
496 gsub("%{prefix}/share", "%{_datadir}")
497 gsub("%{_prefix}/share", "%{_datadir}")
499 gsub(includedir, "%{_includedir}")
500 gsub("%{prefix}/include", "%{_includedir}")
501 gsub("%{_prefix}/include", "%{_includedir}")
503 gsub(mandir, "%{_mandir}")
504 gsub("%{_datadir}/man", "%{_mandir}")
505 gsub("%{_prefix}/share/man", "%{_mandir}")
506 gsub("%{prefix}/share/man", "%{_mandir}")
507 gsub("%{prefix}/man", "%{_mandir}")
508 gsub("%{_prefix}/man", "%{_mandir}")
510 gsub(infodir, "%{_infodir}")
511 gsub("%{prefix}/info", "%{_infodir}")
512 gsub("%{_prefix}/info", "%{_infodir}")
514 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
517 for (c = 1; c <= NF; c++) {
518 if ($c ~ prefix "/sbin/fix-info-dir")
520 gsub(prefix, "%{_prefix}", $c)
522 gsub("%{prefix}", "%{_prefix}")
525 gsub("%{PACKAGE_VERSION}", "%{version}")
526 gsub("%{PACKAGE_NAME}", "%{name}")
528 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
529 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
531 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
532 gsub("%{_datadir}/applnk", "%{_applnkdir}")
534 gsub("^make$", "%{__make}")
535 gsub("^make ", "%{__make} ")
538 function fill(ch, n, i) {
539 for (i = 0; i < n; i++)
543 function format_flush(line, indent, newline, word, first_word) {
545 if (format_indent == -1)
548 newline = fill(" ", format_indent) "- "
550 while (match(line, /[^\t ]+/)) {
551 word = substr(line, RSTART, RLENGTH)
552 if (length(newline) + length(word) + 1 > tw) {
555 if (format_indent == -1)
558 newline = fill(" ", format_indent + 2)
563 newline = newline word
566 newline = newline " " word
568 line = substr(line, RSTART + RLENGTH)
570 if (newline ~ /[^\t ]/) {