3 # This is adapter v0.16. Adapter adapts .spec files for PLD.
4 # Copyright (C) 1999 Micha³ Kuratczyk <kura@pld.org.pl>
7 preamble = 1 # Is it part of preamble? Default - yes
8 boc = 2 # Beggining of %changelog
9 bod = 0 # Beggining of %description
10 tw = 77 # Descriptions width
12 groups_file = ENVIRON["HOME"] "/rpm/groups" # File with rpm groups
13 format_macro = ENVIRON["HOME"] "/tmp/format.vim"# File with format macro
15 # Create format macro file
16 system("rm -f " format_macro)
17 print ":set tw = " tw > format_macro
18 print "VGgq" >> format_macro
19 print ":wq!" >> format_macro
22 # Command to format the text
23 format_command = "vim -s " format_macro ">/dev/null 2>&1 "
25 # Temporary file for changelog section
26 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
27 description_file = ENVIRON["HOME"] "/tmp/adapter.description"
29 # Is 'date' macro already defined?
30 if (is_there_line("%define date"))
34 "rpm --eval %_prefix" | getline prefix
35 "rpm --eval %_bindir" | getline bindir
36 "rpm --eval %_sbindir" | getline sbindir
37 "rpm --eval %_libdir" | getline libdir
38 "rpm --eval %_sysconfdir" | getline sysconfdir
39 "rpm --eval %_datadir" | getline datadir
40 "rpm --eval %_includedir" | getline includedir
41 "rpm --eval %_mandir" | getline mandir
42 "rpm --eval %_infodir" | getline infodir
45 # There should be a comment with CVS keywords on the first line of file.
47 if (!/# \$Revision:/) # If this line is already OK?
48 print "# $" "Revision:$, " "$" "Date:$" # No
51 next # It is enough for first line
55 # If the latest line matched /%files/
57 if ($0 !~ /defattr/) # If no %defattr
58 print "%defattr(644,root,root,755)" # Add it
60 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
64 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
66 if ($2 == "_applnkdir")
71 /^%description/, (/^%[a-z]+/ && !/^%description/) {
77 # Define _prefix and _mandir if it is X11 application
78 if (/^%description$/ && x11 == 1) {
79 print "%define\t\t_prefix\t\t/usr/X11R6"
80 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
85 # Collect whole text of description in file
86 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
87 print $0 >> description_file
91 # Format description file and insert it
92 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
93 close(description_file)
94 system(format_command description_file)
96 while ((getline line < description_file) > 0)
98 system("rm -f " description_file)
112 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
116 if (/^%setup/ && !/-q/)
117 sub(/^%setup/, "%setup -q")
121 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
128 /^%install/, (/^[a-z]+$/ && !/^%install/) {
133 # 'install -d' instead 'mkdir -p'
135 sub(/mkdir -p/, "install -d")
137 # No '-u root' or '-g root' for 'install'
138 if (/^install/ && /-[ug][ \t]*root/)
139 gsub(/-[ug][ \t]*root /, "")
141 if (/^install/ && /-m[ \t]*644/)
142 gsub(/-m[ \t]*644 /, "")
144 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
145 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
148 # No lines contain 'chmod' if it sets the modes to '644'
149 if ($1 ~ /chmod/ && $2 ~ /644/)
152 # 'gzip -9nf' for compressing
153 if ($1 ~ /gzip|bzip2/) {
155 sub(/-[A-Za-z0-9]+ /, "", $0)
161 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
170 # %changelog section:
171 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
174 # There should be some CVS keywords on the first line of %changelog.
177 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
178 printf "All persons listed below can be reached at " > changelog_file
179 print "<cvs_login>@pld.org.pl\n" > changelog_file
180 print "$" "Log:$" > changelog_file
188 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
189 print " date +\"%a %b %d %Y\"`)" > changelog_file
194 if (!/^%[a-z]+$/ || /changelog/)
195 print > changelog_file
203 # There should not be a space after the name of field
204 # and before the colon.
209 if (field ~ /packager:|distribution:|docdir:|prefix:/)
212 if (field ~ /buildroot:/)
213 $2 = "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
215 if (field ~ /group:/) {
222 if ($2 ~ /^X11/ && x11 == 0) # Is it X11 application?
225 next # Line is already formatted and printed
228 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
229 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
235 if (field ~ /version:/)
238 # Use %{name} and %{version} in the filenames in "Source:"
239 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
240 n = split($2, url, /\//)
242 sub(name, "%{name}", url[n])
243 sub(version, "%{version}", url[n])
244 sub(filename, url[n], $2)
247 if (field ~ /source:/)
250 if (field ~ /patch:/)
255 if ($1 ~ /%define/) {
256 # Do not add %define of _prefix if it already is.
257 if ($2 ~ /_prefix/) {
261 if ($2 ~ /_bindir/ && !/_sbindir/)
267 if ($2 ~ /_sysconfdir/)
271 if ($2 ~ /_includedir/)
290 close(changelog_file)
291 while ((getline < changelog_file) > 0)
293 system("rm -f " changelog_file)
296 print "* %{date} PLD Team <pld-list@pld.org.pl>"
297 printf "All persons listed below can be reached at "
298 print "<cvs_login>@pld.org.pl\n"
303 # This function uses grep to determine if there is line (in the current file)
304 # which matches regexp.
305 function is_there_line(line, l)
307 command = "grep \"" line "\" " ARGV[1]
317 # This function prints translated names of groups.
318 function translate_group(group)
321 result = getline line < groups_file
324 print "######\t\t" groups_file ": no such file"
329 print "######\t\t" "Unknown group!"
339 if (line ~ /\[[a-z][a-z]\]:/) {
340 split(line, g, /\[|\]|\:/)
341 if (!is_there_line("^Group(" g[2] "):"))
342 printf("Group(%s):%s\n", g[2], g[4])
350 # There should be one or two tabs after the colon.
351 function format_preamble()
354 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
362 # Replace directly specified directories with macros
363 function use_macros()
365 gsub(bindir, "%{_bindir}")
366 gsub("%{_prefix}/bin", "%{_bindir}")
367 gsub("%{prefix}/bin", "%{_bindir}")
369 gsub(sbindir, "%{_sbindir}")
370 gsub("%{prefix}/sbin", "%{_sbindir}")
371 gsub("%{_prefix}/sbib", "%{_sbindir}")
373 gsub(libdir, "%{_libdir}")
374 gsub("%{prefix}/lib", "%{_libdir}")
375 gsub("%{_prefix}/lib", "%{_libdir}")
377 gsub(sysconfdir, "%{_sysconfdir}")
379 gsub(datadir, "%{_datadir}")
380 gsub("%{prefix}/share", "%{_datadir}")
381 gsub("%{_prefix}/share", "%{_datadir}")
383 gsub(includedir, "%{_includedir}")
384 gsub("%{prefix}/include", "%{_includedir}")
385 gsub("%{_prefix}/include", "%{_includedir}")
387 gsub(mandir, "%{_mandir}")
388 gsub("%{prefix}/man", "%{_mandir}")
389 gsub("%{_prefix}/man", "%{_mandir}")
391 gsub(infodir, "%{_infodir}")
392 gsub("%{prefix}/info", "%{_infodir}")
393 gsub("%{_prefix}/info", "%{_infodir}")
395 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
398 gsub(prefix, "%{_prefix}")
399 gsub("%{prefix}", "%{_prefix}")
402 gsub("%{PACKAGE_VERSION}", "%{version}")
403 gsub("%{PACKAGE_NAME}", "%{name}")