3 # This is adapter v1.0. 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 # Is 'date' macro already defined?
14 if (is_there_line("%define date"))
17 "rpm --eval %_prefix" | getline prefix
18 "rpm --eval %_bindir" | getline bindir
19 "rpm --eval %_sbindir" | getline sbindir
20 "rpm --eval %_libdir" | getline libdir
21 "rpm --eval %_sysconfdir" | getline sysconfdir
22 "rpm --eval %_datadir" | getline datadir
23 "rpm --eval %_includedir" | getline includedir
24 "rpm --eval %_mandir" | getline mandir
25 "rpm --eval %_infodir" | getline infodir
28 # There should be a comment with CVS keywords on the first line of file.
30 if (!/# \$Revision:/) # If this line is already OK?
31 print "# $" "Revision:$, " "$" "Date:$" # No
34 next # It is enough for first line
38 # If the latest line matched /%files/
40 if ($0 !~ /defattr/) # If no %defattr
41 print "%defattr(644,root,root,755)" # Add it
43 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
48 /%description/, (/^%[a-z]+/ && !/%description/) {
54 # Define _prefix and _mandir if it is X11 application
55 if (/^%description$/ && x11 == 1) {
56 print "%define\t\t_prefix\t\t/usr/X11R6"
57 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
62 # Collect whole text of description
63 if (description == 1 && !/^%[a-z]+/ && !/%description/) {
64 description_text = description_text $0 " "
68 # Formt description to the length of tw (default == 77)
69 if (/^%[a-z]+/ && (!/%description/ || bod == 2)) {
70 n = split(description_text, dt, / /)
71 for (i = 1; i <= n; i++) {
72 if (length(line) + length(dt[i]) + 1 < tw)
75 sub(/[ ]+$/, "", line)
82 sub(/[ ]+$/, "", line)
99 /%prep/, (/^%[a-z]+$/ && !/%prep/) {
103 if (/%setup/ && !/-q/)
104 sub(/%setup/, "%setup -q")
108 /%build/, (/^%[a-z]+$/ && !/%build/) {
115 /%install/, (/^[a-z]+$/ && !/%install/) {
120 # 'install -d' instead 'mkdir -p'
122 sub(/mkdir -p/, "install -d")
124 # No '-u root' or '-g root' for 'install'
125 if (/^install/ && /-[ug][ \t]*root/)
126 gsub(/-[ug][ \t]*root /, "")
128 if (/^install/ && /-m[ \t]*644/)
129 gsub(/-m[ \t]*644 /, "")
131 # No lines contain 'chown' or 'chgrp', which changes
132 # owner/group to 'root'
133 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
136 # No lines contain 'chmod' if it sets the modes to '644'
137 if ($1 ~ /chmod/ && $2 ~ /644/)
140 # 'gzip -9nf' for compressing
141 if ($1 ~ /gzip|bzip2/) {
143 sub(/-[A-Za-z0-9]+ /, "", $0)
149 /%files/, (/^%[a-z \-]+$/ && !/%files/) {
158 # %changelog section:
159 /%changelog/, (/^%[a-z]+$/ && !/%changelog/) {
162 # There should be some CVS keywords on the first line of %changelog.
165 print "* %{date} PLD Team <pld-list@pld.org.pl>"
166 printf "All below listed persons can be reached on "
167 print "<cvs_login>@pld.org.pl\n"
176 printf "%%define date\t%%(echo `LC_ALL=\"C\""
177 print " date +\"%a %b %d %Y\"`)"
185 # There should not be a space after the name of field
186 # and before the colon.
191 if (field ~ /packager:|distribution:|prefix:/)
194 if (field ~ /buildroot:/)
195 $2 = "/tmp/%{name}-%{version}-root"
197 if (field ~ /group:/) {
204 if ($2 ~ /^X11/ && x11 == 0) # Is it X11 application?
207 next # Line is already formatted and printed
210 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
211 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
217 if (field ~ /version:/)
220 # Use %{name} and %{version} in the filenames in "Source:"
221 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
222 n = split($2, url, /\//)
224 sub(name, "%{name}", url[n])
225 sub(version, "%{version}", url[n])
226 sub(filename, url[n], $2)
229 if (field ~ /source:/)
232 if (field ~ /patch:/)
237 if ($1 ~ /%define/) {
238 # Do not add %define of _prefix if it already is.
239 if ($2 ~ /_prefix/) {
243 if ($2 ~ /_bindir/ && !/_sbindir/)
249 if ($2 ~ /_sysconfdir/)
253 if ($2 ~ /_includedir/)
270 print "* %{date} PLD Team <pld-list@pld.org.pl>"
271 printf "All below listed persons can be reached on "
272 print "<cvs_login>@pld.org.pl\n"
277 # This function uses grep to determine if there is line (in the current file)
278 # which matches regexp.
279 function is_there_line(line, l)
281 command = "grep \"" line "\" " ARGV[1]
291 # This function prints translated names of groups.
292 function translate_group(group)
295 result = getline line < groups_file
298 print "######\t\t" groups_file ": no such file"
303 print "######\t\t" "Unknown group!"
313 if (line ~ /\[[a-z][a-z]\]:/) {
314 split(line, g, /\[|\]|\:/)
315 if (!is_there_line("^Group(" g[2] "):"))
316 printf("Group(%s):%s\n", g[2], g[4])
324 # There should be one or two tabs after the colon.
325 function format_preamble()
328 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
336 # Replace directly specified directories with macros
337 function use_macros()
339 gsub(bindir, "%{_bindir}")
340 gsub("%{_prefix}/bin", "%{_bindir}")
341 gsub("%{prefix}/bin", "%{_bindir}")
343 gsub(sbindir, "%{_sbindir}")
344 gsub("%{prefix}/sbin", "%{_sbindir}")
345 gsub("%{_prefix}/sbib", "%{_sbindir}")
347 gsub(libdir, "%{_libdir}")
348 gsub("%{prefix}/lib", "%{_libdir}")
349 gsub("%{_prefix}/lib", "%{_libdir}")
351 gsub(sysconfdir, "%{_sysconfdir}")
353 gsub(datadir, "%{_datadir}")
354 gsub("%{prefix}/share", "%{_datadir}")
355 gsub("%{_prefix}/share", "%{_datadir}")
357 gsub(includedir, "%{_includedir}")
358 gsub("%{prefix}/include", "%{_includedir}")
359 gsub("%{_prefix}/include", "%{_includedir}")
361 gsub(mandir, "%{_mandir}")
362 gsub("%{prefix}/man", "%{_mandir}")
363 gsub("%{_prefix}/man", "%{_mandir}")
365 gsub(infodir, "%{_infodir}")
366 gsub("%{prefix}/info", "%{_infodir}")
367 gsub("%{_prefix}/info", "%{_infodir}")
369 gsub(prefix, "%{_prefix}")
370 gsub("%{prefix}", "%{_prefix}")