3 # This is adapter v0.14. Adapter adapts .spec files for PLD.
4 # Copyright (C) 1999 Micha³ Kuratczyk <kura@pld.org.pl>
8 boc = 2 # Beggining of %changelog
9 bod = 0 # Beggining of %description
10 tw = 77 # Descriptions width
11 groups_file = ENVIRON["HOME"] "/rpm/groups" # File with rpm groups
13 # Temporary file for changelog section
14 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
16 # Is 'date' macro already defined?
17 if (is_there_line("%define date"))
20 "rpm --eval %_prefix" | getline prefix
21 "rpm --eval %_bindir" | getline bindir
22 "rpm --eval %_sbindir" | getline sbindir
23 "rpm --eval %_libdir" | getline libdir
24 "rpm --eval %_sysconfdir" | getline sysconfdir
25 "rpm --eval %_datadir" | getline datadir
26 "rpm --eval %_includedir" | getline includedir
27 "rpm --eval %_mandir" | getline mandir
28 "rpm --eval %_infodir" | getline infodir
31 # There should be a comment with CVS keywords on the first line of file.
33 if (!/# \$Revision:/) # If this line is already OK?
34 print "# $" "Revision:$, " "$" "Date:$" # No
37 next # It is enough for first line
41 # If the latest line matched /%files/
43 if ($0 !~ /defattr/) # If no %defattr
44 print "%defattr(644,root,root,755)" # Add it
46 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
51 if ($2 == "_applnkdir")
56 /^%description/, (/^%[a-z]+/ && !/^%description/) {
62 # Define _prefix and _mandir if it is X11 application
63 if (/^%description$/ && x11 == 1) {
64 print "%define\t\t_prefix\t\t/usr/X11R6"
65 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
70 # Collect whole text of description
71 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
72 description_text = description_text $0 " "
76 # Formt description to the length of tw (default == 77)
77 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
78 n = split(description_text, dt, / /)
79 for (i = 1; i <= n; i++) {
80 if (length(line) + length(dt[i]) + 1 < tw)
83 sub(/[ ]+$/, "", line)
90 sub(/[ ]+$/, "", line)
107 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
111 if (/^%setup/ && !/-q/)
112 sub(/^%setup/, "%setup -q")
116 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
123 /^%install/, (/^[a-z]+$/ && !/^%install/) {
128 # 'install -d' instead 'mkdir -p'
130 sub(/mkdir -p/, "install -d")
132 # No '-u root' or '-g root' for 'install'
133 if (/^install/ && /-[ug][ \t]*root/)
134 gsub(/-[ug][ \t]*root /, "")
136 if (/^install/ && /-m[ \t]*644/)
137 gsub(/-m[ \t]*644 /, "")
139 # No lines contain 'chown' or 'chgrp', which changes
140 # owner/group to 'root'
141 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
144 # No lines contain 'chmod' if it sets the modes to '644'
145 if ($1 ~ /chmod/ && $2 ~ /644/)
148 # 'gzip -9nf' for compressing
149 if ($1 ~ /gzip|bzip2/) {
151 sub(/-[A-Za-z0-9]+ /, "", $0)
157 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
166 # %changelog section:
167 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
170 # There should be some CVS keywords on the first line of %changelog.
173 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
174 printf "All persons listed below can be reached at " > changelog_file
175 print "<cvs_login>@pld.org.pl\n" > changelog_file
176 print "$" "Log:$" > changelog_file
184 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
185 print " date +\"%a %b %d %Y\"`)" > changelog_file
190 if (!/^%[a-z]+$/ || /changelog/)
191 print > changelog_file
199 # There should not be a space after the name of field
200 # and before the colon.
205 if (field ~ /packager:|distribution:|prefix:/)
208 if (field ~ /buildroot:/)
209 $2 = "/tmp/%{name}-%{version}-root-%(id -u -n)"
211 if (field ~ /group:/) {
218 if ($2 ~ /^X11/ && x11 == 0) # Is it X11 application?
221 next # Line is already formatted and printed
224 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
225 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
231 if (field ~ /version:/)
234 # Use %{name} and %{version} in the filenames in "Source:"
235 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
236 n = split($2, url, /\//)
238 sub(name, "%{name}", url[n])
239 sub(version, "%{version}", url[n])
240 sub(filename, url[n], $2)
243 if (field ~ /source:/)
246 if (field ~ /patch:/)
249 if (fiels ~ /buildroot:/)
250 $2 = "%{tmpdir}/%{name}-%{dir}"
254 if ($1 ~ /%define/) {
255 # Do not add %define of _prefix if it already is.
256 if ($2 ~ /_prefix/) {
260 if ($2 ~ /_bindir/ && !/_sbindir/)
266 if ($2 ~ /_sysconfdir/)
270 if ($2 ~ /_includedir/)
286 if (changelog_file) {
287 close(changelog_file)
288 while ((getline < changelog_file) > 0)
290 system("rm -f " changelog_file)
294 print "* %{date} PLD Team <pld-list@pld.org.pl>"
295 printf "All below listed persons can be reached on "
296 print "<cvs_login>@pld.org.pl\n"
301 # This function uses grep to determine if there is line (in the current file)
302 # which matches regexp.
303 function is_there_line(line, l)
305 command = "grep \"" line "\" " ARGV[1]
315 # This function prints translated names of groups.
316 function translate_group(group)
319 result = getline line < groups_file
322 print "######\t\t" groups_file ": no such file"
327 print "######\t\t" "Unknown group!"
337 if (line ~ /\[[a-z][a-z]\]:/) {
338 split(line, g, /\[|\]|\:/)
339 if (!is_there_line("^Group(" g[2] "):"))
340 printf("Group(%s):%s\n", g[2], g[4])
348 # There should be one or two tabs after the colon.
349 function format_preamble()
352 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
360 # Replace directly specified directories with macros
361 function use_macros()
363 gsub(bindir, "%{_bindir}")
364 gsub("%{_prefix}/bin", "%{_bindir}")
365 gsub("%{prefix}/bin", "%{_bindir}")
367 gsub(sbindir, "%{_sbindir}")
368 gsub("%{prefix}/sbin", "%{_sbindir}")
369 gsub("%{_prefix}/sbib", "%{_sbindir}")
371 gsub(libdir, "%{_libdir}")
372 gsub("%{prefix}/lib", "%{_libdir}")
373 gsub("%{_prefix}/lib", "%{_libdir}")
375 gsub(sysconfdir, "%{_sysconfdir}")
377 gsub(datadir, "%{_datadir}")
378 gsub("%{prefix}/share", "%{_datadir}")
379 gsub("%{_prefix}/share", "%{_datadir}")
381 gsub(includedir, "%{_includedir}")
382 gsub("%{prefix}/include", "%{_includedir}")
383 gsub("%{_prefix}/include", "%{_includedir}")
385 gsub(mandir, "%{_mandir}")
386 gsub("%{prefix}/man", "%{_mandir}")
387 gsub("%{_prefix}/man", "%{_mandir}")
389 gsub(infodir, "%{_infodir}")
390 gsub("%{prefix}/info", "%{_infodir}")
391 gsub("%{_prefix}/info", "%{_infodir}")
394 gsub(prefix, "%{_prefix}")
395 gsub("%{prefix}", "%{_prefix}")