3 # This is adapter v0.18. Adapter adapts .spec files for PLD.
4 # Copyright (C) 1999 Micha³ Kuratczyk <kura@pld.org.pl>
6 function fill(ch, n, i) {
7 for (i=0; i<n; i++) printf("%c",ch)
10 function format_flush(linia, wciecie, newlinia, slowo, pierwszeslowo) {
12 if (format_wciecie==-1)
15 newlinia=(fill(" ",format_wciecie) "- ")
16 while (match(linia,/[^\t ]+/)) {
17 slowo=substr(linia,RSTART,RLENGTH)
18 if (length(newlinia)+length(slowo)+1 > tw) {
21 if (format_wciecie==-1)
24 newlinia=fill(" ",format_wciecie+2)
29 newlinia=(newlinia slowo)
32 newlinia=(newlinia " " slowo)
34 linia=substr(linia,RSTART+RLENGTH)
36 if (newlinia ~ /[^\t ]/) {
42 preamble = 1 # Is it part of preamble? Default - yes
43 boc = 2 # Beggining of %changelog
44 bod = 0 # Beggining of %description
45 tw = 75 # Descriptions width
47 groups_file = ENVIRON["HOME"] "/rpm/groups" # File with rpm groups
49 # Temporary file for changelog section
50 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
52 # Is 'date' macro already defined?
53 if (is_there_line("%define date"))
57 "rpm --eval %_prefix" | getline prefix
58 "rpm --eval %_bindir" | getline bindir
59 "rpm --eval %_sbindir" | getline sbindir
60 "rpm --eval %_libdir" | getline libdir
61 "rpm --eval %_sysconfdir" | getline sysconfdir
62 "rpm --eval %_datadir" | getline datadir
63 "rpm --eval %_includedir" | getline includedir
64 "rpm --eval %_mandir" | getline mandir
65 "rpm --eval %_infodir" | getline infodir
68 # There should be a comment with CVS keywords on the first line of file.
70 if (!/# \$Revision:/) # If this line is already OK?
71 print "# $" "Revision:$, " "$" "Date:$" # No
74 next # It is enough for first line
78 # If the latest line matched /%files/
80 if ($0 !~ /defattr/) # If no %defattr
81 print "%defattr(644,root,root,755)" # Add it
83 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
87 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
89 if ($2 == "_applnkdir")
94 /^%description/, (/^%[a-z]+/ && !/^%description/) {
97 if (/^%description/) {
103 # Define _prefix and _mandir if it is X11 application
104 if (/^%description$/ && x11 == 1) {
105 print "%define\t\t_prefix\t\t/usr/X11R6"
106 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
107 prefix = "/usr/X11R6"
111 # formatter (c) 2000 by Sebastian Zagrodzki
113 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
115 format_flush(format_linia, format_wciecie)
119 } else if (/^[ \t]*[-\*][ \t]*/) {
120 format_flush(format_linia, format_wciecie)
122 format_wciecie=RLENGTH
123 match($0,/^[ \t]*[-\*][ \t]/)
124 format_linia=substr($0,RLENGTH)
126 format_linia=(format_linia " " $0)
130 # Format description file and insert it
131 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
132 format_flush(format_linia, format_wciecie)
145 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
149 if (/^%setup/ && !/-q/)
150 sub(/^%setup/, "%setup -q")
154 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
161 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
166 # 'install -d' instead 'mkdir -p'
168 sub(/mkdir -p/, "install -d")
170 # No '-u root' or '-g root' for 'install'
171 if (/^install/ && /-[ug][ \t]*root/)
172 gsub(/-[ug][ \t]*root /, "")
174 if (/^install/ && /-m[ \t]*644/)
175 gsub(/-m[ \t]*644 /, "")
177 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
178 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
181 # No lines contain 'chmod' if it sets the modes to '644'
182 if ($1 ~ /chmod/ && $2 ~ /644/)
185 # 'gzip -9nf' for compressing
186 if ($1 ~ /gzip|bzip2/) {
188 sub(/-[A-Za-z0-9]+ /, "", $0)
194 /^%pre /, (/^[a-z]+$/ && !/^%pre /) { preamble = 0 }
195 /^%preun/, (/^[a-z]+$/ && !/^%preun/) { preamble = 0 }
196 /^%post /, (/^[a-z]+$/ && !/^%post /) { preamble = 0 }
197 /^%postun/, (/^[a-z]+$/ && !/^%postun/) { preamble = 0 }
200 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
209 # %changelog section:
210 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
213 # There should be some CVS keywords on the first line of %changelog.
216 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
217 printf "All persons listed below can be reached at " > changelog_file
218 print "<cvs_login>@pld.org.pl\n" > changelog_file
219 print "$" "Log:$" > changelog_file
227 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
228 print " date +\"%a %b %d %Y\"`)" > changelog_file
233 if (!/^%[a-z]+$/ || /changelog/)
234 print > changelog_file
242 # There should not be a space after the name of field
243 # and before the colon.
248 if (field ~ /packager:|distribution:|docdir:|prefix:/)
251 if (field ~ /buildroot:/)
252 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
254 if (field ~ /group:/) {
261 if ($2 ~ /^X11/ && x11 == 0) # Is it X11 application?
264 next # Line is already formatted and printed
267 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
268 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
274 if (field ~ /version:/)
277 # Use %{name} and %{version} in the filenames in "Source:"
278 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
279 n = split($2, url, /\//)
281 sub(name, "%{name}", url[n])
282 sub(version, "%{version}", url[n])
283 sub(filename, url[n], $2)
286 if (field ~ /source:/)
289 if (field ~ /patch:/)
294 if ($1 ~ /%define/) {
295 # Do not add %define of _prefix if it already is.
296 if ($2 ~ /_prefix/) {
300 if ($2 ~ /_bindir/ && !/_sbindir/)
306 if ($2 ~ /_sysconfdir/)
310 if ($2 ~ /_includedir/)
329 close(changelog_file)
330 while ((getline < changelog_file) > 0)
332 system("rm -f " changelog_file)
335 print "* %{date} PLD Team <pld-list@pld.org.pl>"
336 printf "All persons listed below can be reached at "
337 print "<cvs_login>@pld.org.pl\n"
342 # This function uses grep to determine if there is line (in the current file)
343 # which matches regexp.
344 function is_there_line(line, l)
346 command = "grep \"" line "\" " ARGV[1]
356 # This function prints translated names of groups.
357 function translate_group(group)
360 result = getline line < groups_file
363 print "######\t\t" groups_file ": no such file"
368 print "######\t\t" "Unknown group!"
378 if (line ~ /\[[a-z][a-z]\]:/) {
379 split(line, g, /\[|\]|\:/)
380 if (!is_there_line("^Group(" g[2] "):"))
381 printf("Group(%s):%s\n", g[2], g[4])
389 # There should be one or two tabs after the colon.
390 function format_preamble()
393 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
401 # Replace directly specified directories with macros
402 function use_macros()
404 gsub(bindir, "%{_bindir}")
405 gsub("%{_prefix}/bin", "%{_bindir}")
406 gsub("%{prefix}/bin", "%{_bindir}")
408 gsub(sbindir, "%{_sbindir}")
409 gsub("%{prefix}/sbin", "%{_sbindir}")
410 gsub("%{_prefix}/sbib", "%{_sbindir}")
412 gsub(libdir, "%{_libdir}")
413 gsub("%{prefix}/lib", "%{_libdir}")
414 gsub("%{_prefix}/lib", "%{_libdir}")
416 gsub(sysconfdir, "%{_sysconfdir}")
418 gsub(datadir, "%{_datadir}")
419 gsub("%{prefix}/share", "%{_datadir}")
420 gsub("%{_prefix}/share", "%{_datadir}")
422 gsub(includedir, "%{_includedir}")
423 gsub("%{prefix}/include", "%{_includedir}")
424 gsub("%{_prefix}/include", "%{_includedir}")
426 gsub(mandir, "%{_mandir}")
427 gsub("%{prefix}/man", "%{_mandir}")
428 gsub("%{_prefix}/man", "%{_mandir}")
430 gsub(infodir, "%{_infodir}")
431 gsub("%{prefix}/info", "%{_infodir}")
432 gsub("%{_prefix}/info", "%{_infodir}")
434 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
437 gsub(prefix, "%{_prefix}")
438 gsub("%{prefix}", "%{_prefix}")
441 gsub("%{PACKAGE_VERSION}", "%{version}")
442 gsub("%{PACKAGE_NAME}", "%{name}")