3 # This is adapter v0.19. 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@sith.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 = 75 # Descriptions width
20 groups_file = ENVIRON["HOME"] "/rpm/groups" # File with rpm groups
22 # Temporary file for changelog section
23 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
25 # Is 'date' macro already defined?
26 if (is_there_line("%define date"))
30 "rpm --eval %_prefix" | getline prefix
31 "rpm --eval %_bindir" | getline bindir
32 "rpm --eval %_sbindir" | getline sbindir
33 "rpm --eval %_libdir" | getline libdir
34 "rpm --eval %_sysconfdir" | getline sysconfdir
35 "rpm --eval %_datadir" | getline datadir
36 "rpm --eval %_includedir" | getline includedir
37 "rpm --eval %_mandir" | getline mandir
38 "rpm --eval %_infodir" | getline infodir
41 # There should be a comment with CVS keywords on the first line of file.
43 if (!/# \$Revision:/) # If this line is already OK?
44 print "# $" "Revision:$, " "$" "Date:$" # No
47 next # It is enough for first line
51 # If the latest line matched /%files/
53 if ($0 !~ /defattr/) # If no %defattr
54 print "%defattr(644,root,root,755)" # Add it
56 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
60 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
62 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 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
137 # 'install -d' instead 'mkdir -p'
139 sub(/mkdir -p/, "install -d")
141 # No '-u root' or '-g root' for 'install'
142 if (/^install/ && /-[ug][ \t]*root/)
143 gsub(/-[ug][ \t]*root /, "")
145 if (/^install/ && /-m[ \t]*644/)
146 gsub(/-m[ \t]*644 /, "")
148 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
149 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
152 # No lines contain 'chmod' if it sets the modes to '644'
153 if ($1 ~ /chmod/ && $2 ~ /644/)
156 # 'gzip -9nf' for compressing
157 if ($1 ~ /gzip|bzip2/) {
159 sub(/-[A-Za-z0-9]+ /, "", $0)
165 /^%pre /, (/^[a-z]+$/ && !/^%pre /) { preamble = 0 }
166 /^%preun/, (/^[a-z]+$/ && !/^%preun/) { preamble = 0 }
167 /^%post /, (/^[a-z]+$/ && !/^%post /) { preamble = 0 }
168 /^%postun/, (/^[a-z]+$/ && !/^%postun/) { preamble = 0 }
171 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
180 # %changelog section:
181 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
184 # There should be some CVS keywords on the first line of %changelog.
187 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
188 printf "All persons listed below can be reached at " > changelog_file
189 print "<cvs_login>@pld.org.pl\n" > changelog_file
190 print "$" "Log:$" > changelog_file
198 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
199 print " date +\"%a %b %d %Y\"`)" > changelog_file
204 if (!/^%[a-z]+$/ || /changelog/)
205 print > changelog_file
213 # There should not be a space after the name of field
214 # and before the colon.
219 if (field ~ /packager:|distribution:|docdir:|prefix:/)
222 if (field ~ /buildroot:/)
223 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
225 if (field ~ /group:/) {
232 if ($2 ~ /^X11/ && x11 == 0) # Is it X11 application?
235 next # Line is already formatted and printed
238 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
239 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
245 if (field ~ /version:/)
248 # Use %{name} and %{version} in the filenames in "Source:"
249 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
250 n = split($2, url, /\//)
252 sub(name, "%{name}", url[n])
253 sub(version, "%{version}", url[n])
254 sub(filename, url[n], $2)
257 if (field ~ /source:/)
260 if (field ~ /patch:/)
265 if ($1 ~ /%define/) {
266 # Do not add %define of _prefix if it already is.
267 if ($2 ~ /_prefix/) {
271 if ($2 ~ /_bindir/ && !/_sbindir/)
277 if ($2 ~ /_sysconfdir/)
281 if ($2 ~ /_includedir/)
300 close(changelog_file)
301 while ((getline < changelog_file) > 0)
303 system("rm -f " changelog_file)
306 print "* %{date} PLD Team <pld-list@pld.org.pl>"
307 printf "All persons listed below can be reached at "
308 print "<cvs_login>@pld.org.pl\n"
313 # This function uses grep to determine if there is line (in the current file)
314 # which matches regexp.
315 function is_there_line(line, l)
317 command = "grep \"" line "\" " ARGV[1]
327 # This function prints translated names of groups.
328 function translate_group(group)
331 result = getline line < groups_file
334 print "######\t\t" groups_file ": no such file"
339 print "######\t\t" "Unknown group!"
349 if (line ~ /\[[a-z][a-z]\]:/) {
350 split(line, g, /\[|\]|\:/)
351 if (!is_there_line("^Group(" g[2] "):"))
352 printf("Group(%s):%s\n", g[2], g[4])
360 # There should be one or two tabs after the colon.
361 function format_preamble()
364 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
372 # Replace directly specified directories with macros
373 function use_macros()
375 gsub(bindir, "%{_bindir}")
376 gsub("%{_prefix}/bin", "%{_bindir}")
377 gsub("%{prefix}/bin", "%{_bindir}")
379 gsub(sbindir, "%{_sbindir}")
380 gsub("%{prefix}/sbin", "%{_sbindir}")
381 gsub("%{_prefix}/sbib", "%{_sbindir}")
383 gsub(libdir, "%{_libdir}")
384 gsub("%{prefix}/lib", "%{_libdir}")
385 gsub("%{_prefix}/lib", "%{_libdir}")
387 gsub(sysconfdir, "%{_sysconfdir}")
389 gsub(datadir, "%{_datadir}")
390 gsub("%{prefix}/share", "%{_datadir}")
391 gsub("%{_prefix}/share", "%{_datadir}")
393 gsub(includedir, "%{_includedir}")
394 gsub("%{prefix}/include", "%{_includedir}")
395 gsub("%{_prefix}/include", "%{_includedir}")
397 gsub(mandir, "%{_mandir}")
398 gsub("%{prefix}/man", "%{_mandir}")
399 gsub("%{_prefix}/man", "%{_mandir}")
401 gsub(infodir, "%{_infodir}")
402 gsub("%{prefix}/info", "%{_infodir}")
403 gsub("%{_prefix}/info", "%{_infodir}")
405 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
408 gsub(prefix, "%{_prefix}")
409 gsub("%{prefix}", "%{_prefix}")
412 gsub("%{PACKAGE_VERSION}", "%{version}")
413 gsub("%{PACKAGE_NAME}", "%{name}")
415 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
416 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
418 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
421 function fill(ch, n, i) {
422 for (i = 0; i < n; i++)
426 function format_flush(line, indent, newline, word, first_word) {
428 if (format_indent == -1)
431 newline = fill(" ", format_indent) "- "
433 while (match(line, /[^\t ]+/)) {
434 word = substr(line, RSTART, RLENGTH)
435 if (length(newline) + length(word) + 1 > tw) {
438 if (format_indent == -1)
441 newline = fill(" ", format_indent + 2)
446 newline = newline word
449 newline = newline " " word
451 line = substr(line, RSTART + RLENGTH)
453 if (newline ~ /[^\t ]/) {