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"
27 # Is 'date' macro already defined?
28 if (is_there_line("%define date"))
32 "rpm --eval %_prefix" | getline prefix
33 "rpm --eval %_bindir" | getline bindir
34 "rpm --eval %_sbindir" | getline sbindir
35 "rpm --eval %_libdir" | getline libdir
36 "rpm --eval %_sysconfdir" | getline sysconfdir
37 "rpm --eval %_datadir" | getline datadir
38 "rpm --eval %_includedir" | getline includedir
39 "rpm --eval %_mandir" | getline mandir
40 "rpm --eval %_infodir" | getline infodir
43 # There should be a comment with CVS keywords on the first line of file.
45 if (!/# \$Revision:/) # If this line is already OK?
46 print "# $" "Revision:$, " "$" "Date:$" # No
49 next # It is enough for first line
53 # If the latest line matched /%files/
55 if ($0 !~ /defattr/) # If no %defattr
56 print "%defattr(644,root,root,755)" # Add it
58 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
62 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
64 if ($2 == "_applnkdir")
69 /^%description/, (/^%[a-z]+/ && !/^%description/) {
72 if (/^%description/) {
78 # Define _prefix and _mandir if it is X11 application
79 if (/^%description$/ && x11 == 1) {
80 print "%define\t\t_prefix\t\t/usr/X11R6"
81 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
87 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
89 format_flush(format_line, format_indent)
93 } else if (/^[ \t]*[-\*][ \t]*/) {
94 format_flush(format_line, format_indent)
96 format_indent = RLENGTH
97 match($0, /^[ \t]*[-\*][ \t]/)
98 format_line = substr($0, RLENGTH)
100 format_line = format_line " " $0
104 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
105 format_flush(format_line, format_indent)
118 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
122 if (/^%setup/ && !/-q/)
123 sub(/^%setup/, "%setup -q")
127 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
134 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
138 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_clean==0) {
140 print "rm -rf $RPM_BUILD_ROOT"
144 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_clean==0) {
145 print "rm -rf $RPM_BUILD_ROOT"
151 # 'install -d' instead 'mkdir -p'
153 sub(/mkdir -p/, "install -d")
155 # No '-u root' or '-g root' for 'install'
156 if (/^install/ && /-[ug][ \t]*root/)
157 gsub(/-[ug][ \t]*root /, "")
159 if (/^install/ && /-m[ \t]*644/)
160 gsub(/-m[ \t]*644 /, "")
162 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
163 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
166 # No lines contain 'chmod' if it sets the modes to '644'
167 if ($1 ~ /chmod/ && $2 ~ /644/)
170 # 'gzip -9nf' for compressing
171 if ($1 ~ /gzip|bzip2/) {
173 sub(/-[A-Za-z0-9]+ /, "", $0)
180 /^%pre/, (/^[a-z]+$/ && !/^%pre/) { script = 1 }
181 /^%preun/, (/^[a-z]+$/ && !/^%preun/) { script = 1 }
182 /^%post/, (/^[a-z]+$/ && !/^%post/) { script = 1 }
183 /^%postun/, (/^[a-z]+$/ && !/^%postun/) { script = 1 }
188 sub(/-[A-Za-z0-9]+ /, "", $0)
196 sub(/-[A-Za-z0-9]+ /, "", $0)
206 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
215 # %changelog section:
216 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
219 # There should be some CVS keywords on the first line of %changelog.
222 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
223 printf "All persons listed below can be reached at " > changelog_file
224 print "<cvs_login>@pld.org.pl\n" > changelog_file
225 print "$" "Log:$" > changelog_file
233 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
234 print " date +\"%a %b %d %Y\"`)" > changelog_file
239 if (!/^%[a-z]+$/ || /changelog/)
240 print > changelog_file
248 # There should not be a space after the name of field
249 # and before the colon.
254 if (field ~ /packager:|distribution:|docdir:|prefix:/)
257 if (field ~ /buildroot:/)
258 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
260 if (field ~ /group:/) {
268 if ($0 ~ /^X11/ && x11 == 0) # Is it X11 application?
271 next # Line is already formatted and printed
274 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
275 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
281 if (field ~ /version:/)
284 # Use %{name} and %{version} in the filenames in "Source:"
285 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
286 n = split($2, url, /\//)
288 sub(name, "%{name}", url[n])
289 sub(version, "%{version}", url[n])
290 sub(filename, url[n], $2)
293 if (field ~ /source:/)
296 if (field ~ /patch:/)
301 if ($1 ~ /%define/) {
302 # Do not add %define of _prefix if it already is.
303 if ($2 ~ /_prefix/) {
304 sub("^"prefix, $3, bindir)
305 sub("^"prefix, $3, sbindir)
306 sub("^"prefix, $3, libdir)
307 sub("^"prefix, $3, datadir)
308 sub("^"prefix, $3, includedir)
312 if ($2 ~ /_bindir/ && !/_sbindir/)
318 if ($2 ~ /_sysconfdir/)
322 if ($2 ~ /_includedir/)
341 close(changelog_file)
342 while ((getline < changelog_file) > 0)
344 system("rm -f " changelog_file)
348 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
353 print "* %{date} PLD Team <pld-list@pld.org.pl>"
354 printf "All persons listed below can be reached at "
355 print "<cvs_login>@pld.org.pl\n"
360 # This function uses grep to determine if there is line (in the current file)
361 # which matches regexp.
362 function is_there_line(line, l)
364 command = "grep \"" line "\" " ARGV[1]
374 # This function prints translated names of groups.
375 function translate_group(group)
378 result = getline line < groups_file
381 print "######\t\t" groups_file ": no such file"
386 print "######\t\t" "Unknown group!"
396 if (line ~ /\[[a-z][a-z]\]:/) {
397 split(line, g, /\[|\]|\:/)
398 if (!is_there_line("^Group(" g[2] "):"))
399 printf("Group(%s):%s\n", g[2], g[4])
407 # There should be one or two tabs after the colon.
408 function format_preamble()
411 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
419 # Replace directly specified directories with macros
420 function use_macros()
422 gsub(bindir, "%{_bindir}")
423 gsub("%{_prefix}/bin", "%{_bindir}")
424 gsub("%{prefix}/bin", "%{_bindir}")
426 for (c = 1; c <= NF; c++) {
427 if ($c ~ sbindir "/fix-info-dir")
429 gsub(sbindir, "%{_sbindir}", $c)
432 gsub("%{prefix}/sbin", "%{_sbindir}")
433 gsub("%{_prefix}/sbib", "%{_sbindir}")
435 gsub(libdir, "%{_libdir}")
436 gsub("%{prefix}/lib", "%{_libdir}")
437 gsub("%{_prefix}/lib", "%{_libdir}")
439 for (c = 1; c <= NF; c++) {
440 if ($c ~ sysconfdir "/cron.d")
442 if ($c ~ sysconfdir "/crontab.d")
444 if ($c ~ sysconfdir "/logrotate.d")
446 if ($c ~ sysconfdir "/pam.d")
448 if ($c ~ sysconfdir "/profile.d")
450 if ($c ~ sysconfdir "/rc.d")
452 if ($c ~ sysconfdir "/security")
454 if ($c ~ sysconfdir "/skel")
456 if ($c ~ sysconfdir "/sysconfig")
458 gsub(sysconfdir, "%{_sysconfdir}", $c)
461 gsub(datadir, "%{_datadir}")
462 gsub("%{prefix}/share", "%{_datadir}")
463 gsub("%{_prefix}/share", "%{_datadir}")
465 gsub(includedir, "%{_includedir}")
466 gsub("%{prefix}/include", "%{_includedir}")
467 gsub("%{_prefix}/include", "%{_includedir}")
469 gsub(mandir, "%{_mandir}")
470 gsub("%{_datadir}/man", "%{_mandir}")
471 gsub("%{_prefix}/share/man", "%{_mandir}")
472 gsub("%{prefix}/share/man", "%{_mandir}")
473 gsub("%{prefix}/man", "%{_mandir}")
474 gsub("%{_prefix}/man", "%{_mandir}")
476 gsub(infodir, "%{_infodir}")
477 gsub("%{prefix}/info", "%{_infodir}")
478 gsub("%{_prefix}/info", "%{_infodir}")
480 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
483 for (c = 1; c <= NF; c++) {
484 if ($c ~ prefix "/sbin/fix-info-dir")
486 gsub(prefix, "%{_prefix}", $c)
488 gsub("%{prefix}", "%{_prefix}")
491 gsub("%{PACKAGE_VERSION}", "%{version}")
492 gsub("%{PACKAGE_NAME}", "%{name}")
494 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
495 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
497 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
498 gsub("%{_datadir}/applnk", "%{_applnkdir}")
500 gsub("^make$", "%{__make}")
501 gsub("^make ", "%{__make} ")
504 function fill(ch, n, i) {
505 for (i = 0; i < n; i++)
509 function format_flush(line, indent, newline, word, first_word) {
511 if (format_indent == -1)
514 newline = fill(" ", format_indent) "- "
516 while (match(line, /[^\t ]+/)) {
517 word = substr(line, RSTART, RLENGTH)
518 if (length(newline) + length(word) + 1 > tw) {
521 if (format_indent == -1)
524 newline = fill(" ", format_indent + 2)
529 newline = newline word
532 newline = newline " " word
534 line = substr(line, RSTART + RLENGTH)
536 if (newline ~ /[^\t ]/) {