3 # This is adapter v0.12. 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 /%description/, (/^%[a-z]+/ && !/%description/) {
57 # Define _prefix and _mandir if it is X11 application
58 if (/^%description$/ && x11 == 1) {
59 print "%define\t\t_prefix\t\t/usr/X11R6"
60 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
65 # Collect whole text of description
66 if (description == 1 && !/^%[a-z]+/ && !/%description/) {
67 description_text = description_text $0 " "
71 # Formt description to the length of tw (default == 77)
72 if (/^%[a-z]+/ && (!/%description/ || bod == 2)) {
73 n = split(description_text, dt, / /)
74 for (i = 1; i <= n; i++) {
75 if (length(line) + length(dt[i]) + 1 < tw)
78 sub(/[ ]+$/, "", line)
85 sub(/[ ]+$/, "", line)
102 /%prep/, (/^%[a-z]+$/ && !/%prep/) {
106 if (/%setup/ && !/-q/)
107 sub(/%setup/, "%setup -q")
111 /%build/, (/^%[a-z]+$/ && !/%build/) {
118 /%install/, (/^[a-z]+$/ && !/%install/) {
123 # 'install -d' instead 'mkdir -p'
125 sub(/mkdir -p/, "install -d")
127 # No '-u root' or '-g root' for 'install'
128 if (/^install/ && /-[ug][ \t]*root/)
129 gsub(/-[ug][ \t]*root /, "")
131 if (/^install/ && /-m[ \t]*644/)
132 gsub(/-m[ \t]*644 /, "")
134 # No lines contain 'chown' or 'chgrp', which changes
135 # owner/group to 'root'
136 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
139 # No lines contain 'chmod' if it sets the modes to '644'
140 if ($1 ~ /chmod/ && $2 ~ /644/)
143 # 'gzip -9nf' for compressing
144 if ($1 ~ /gzip|bzip2/) {
146 sub(/-[A-Za-z0-9]+ /, "", $0)
152 /%files/, (/^%[a-z \-]+$/ && !/%files/) {
161 # %changelog section:
162 /%changelog/, (/^%[a-z]+$/ && !/%changelog/) {
165 # There should be some CVS keywords on the first line of %changelog.
168 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
169 printf "All below listed persons can be reached on " > changelog_file
170 print "<cvs_login>@pld.org.pl\n" > changelog_file
171 print "$" "Log:$" > changelog_file
179 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
180 print " date +\"%a %b %d %Y\"`)" > changelog_file
185 if (!/^%[a-z]+$/ || /%changelog/)
186 print > changelog_file
194 # There should not be a space after the name of field
195 # and before the colon.
200 if (field ~ /packager:|distribution:|prefix:/)
203 if (field ~ /buildroot:/)
204 $2 = "/tmp/%{name}-%{version}-root"
206 if (field ~ /group:/) {
213 if ($2 ~ /^X11/ && x11 == 0) # Is it X11 application?
216 next # Line is already formatted and printed
219 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
220 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
226 if (field ~ /version:/)
229 # Use %{name} and %{version} in the filenames in "Source:"
230 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
231 n = split($2, url, /\//)
233 sub(name, "%{name}", url[n])
234 sub(version, "%{version}", url[n])
235 sub(filename, url[n], $2)
238 if (field ~ /source:/)
241 if (field ~ /patch:/)
246 if ($1 ~ /%define/) {
247 # Do not add %define of _prefix if it already is.
248 if ($2 ~ /_prefix/) {
252 if ($2 ~ /_bindir/ && !/_sbindir/)
258 if ($2 ~ /_sysconfdir/)
262 if ($2 ~ /_includedir/)
279 close(changelog_file)
282 print "* %{date} PLD Team <pld-list@pld.org.pl>"
283 printf "All below listed persons can be reached on "
284 print "<cvs_login>@pld.org.pl\n"
287 while ((getline < changelog_file) > 0)
292 system("rm -f " changelog_file)
295 # This function uses grep to determine if there is line (in the current file)
296 # which matches regexp.
297 function is_there_line(line, l)
299 command = "grep \"" line "\" " ARGV[1]
309 # This function prints translated names of groups.
310 function translate_group(group)
313 result = getline line < groups_file
316 print "######\t\t" groups_file ": no such file"
321 print "######\t\t" "Unknown group!"
331 if (line ~ /\[[a-z][a-z]\]:/) {
332 split(line, g, /\[|\]|\:/)
333 if (!is_there_line("^Group(" g[2] "):"))
334 printf("Group(%s):%s\n", g[2], g[4])
342 # There should be one or two tabs after the colon.
343 function format_preamble()
346 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
354 # Replace directly specified directories with macros
355 function use_macros()
357 gsub(bindir, "%{_bindir}")
358 gsub("%{_prefix}/bin", "%{_bindir}")
359 gsub("%{prefix}/bin", "%{_bindir}")
361 gsub(sbindir, "%{_sbindir}")
362 gsub("%{prefix}/sbin", "%{_sbindir}")
363 gsub("%{_prefix}/sbib", "%{_sbindir}")
365 gsub(libdir, "%{_libdir}")
366 gsub("%{prefix}/lib", "%{_libdir}")
367 gsub("%{_prefix}/lib", "%{_libdir}")
369 gsub(sysconfdir, "%{_sysconfdir}")
371 gsub(datadir, "%{_datadir}")
372 gsub("%{prefix}/share", "%{_datadir}")
373 gsub("%{_prefix}/share", "%{_datadir}")
375 gsub(includedir, "%{_includedir}")
376 gsub("%{prefix}/include", "%{_includedir}")
377 gsub("%{_prefix}/include", "%{_includedir}")
379 gsub(mandir, "%{_mandir}")
380 gsub("%{prefix}/man", "%{_mandir}")
381 gsub("%{_prefix}/man", "%{_mandir}")
383 gsub(infodir, "%{_infodir}")
384 gsub("%{prefix}/info", "%{_infodir}")
385 gsub("%{_prefix}/info", "%{_infodir}")
388 gsub(prefix, "%{_prefix}")
389 gsub("%{prefix}", "%{_prefix}")