3 # This is adapter v0.18. 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 /^%pre /, (/^[a-z]+$/ && !/^%pre /) { preamble = 0 }
162 /^%preun/, (/^[a-z]+$/ && !/^%preun/) { preamble = 0 }
163 /^%post /, (/^[a-z]+$/ && !/^%post /) { preamble = 0 }
164 /^%postun/, (/^[a-z]+$/ && !/^%postun/) { preamble = 0 }
167 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
176 # %changelog section:
177 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
180 # There should be some CVS keywords on the first line of %changelog.
183 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
184 printf "All persons listed below can be reached at " > changelog_file
185 print "<cvs_login>@pld.org.pl\n" > changelog_file
186 print "$" "Log:$" > changelog_file
194 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
195 print " date +\"%a %b %d %Y\"`)" > changelog_file
200 if (!/^%[a-z]+$/ || /changelog/)
201 print > changelog_file
209 # There should not be a space after the name of field
210 # and before the colon.
215 if (field ~ /packager:|distribution:|docdir:|prefix:/)
218 if (field ~ /buildroot:/)
219 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
221 if (field ~ /group:/) {
228 if ($2 ~ /^X11/ && x11 == 0) # Is it X11 application?
231 next # Line is already formatted and printed
234 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
235 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
241 if (field ~ /version:/)
244 # Use %{name} and %{version} in the filenames in "Source:"
245 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
246 n = split($2, url, /\//)
248 sub(name, "%{name}", url[n])
249 sub(version, "%{version}", url[n])
250 sub(filename, url[n], $2)
253 if (field ~ /source:/)
256 if (field ~ /patch:/)
261 if ($1 ~ /%define/) {
262 # Do not add %define of _prefix if it already is.
263 if ($2 ~ /_prefix/) {
267 if ($2 ~ /_bindir/ && !/_sbindir/)
273 if ($2 ~ /_sysconfdir/)
277 if ($2 ~ /_includedir/)
296 close(changelog_file)
297 while ((getline < changelog_file) > 0)
299 system("rm -f " changelog_file)
302 print "* %{date} PLD Team <pld-list@pld.org.pl>"
303 printf "All persons listed below can be reached at "
304 print "<cvs_login>@pld.org.pl\n"
309 # This function uses grep to determine if there is line (in the current file)
310 # which matches regexp.
311 function is_there_line(line, l)
313 command = "grep \"" line "\" " ARGV[1]
323 # This function prints translated names of groups.
324 function translate_group(group)
327 result = getline line < groups_file
330 print "######\t\t" groups_file ": no such file"
335 print "######\t\t" "Unknown group!"
345 if (line ~ /\[[a-z][a-z]\]:/) {
346 split(line, g, /\[|\]|\:/)
347 if (!is_there_line("^Group(" g[2] "):"))
348 printf("Group(%s):%s\n", g[2], g[4])
356 # There should be one or two tabs after the colon.
357 function format_preamble()
360 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
368 # Replace directly specified directories with macros
369 function use_macros()
371 gsub(bindir, "%{_bindir}")
372 gsub("%{_prefix}/bin", "%{_bindir}")
373 gsub("%{prefix}/bin", "%{_bindir}")
375 gsub(sbindir, "%{_sbindir}")
376 gsub("%{prefix}/sbin", "%{_sbindir}")
377 gsub("%{_prefix}/sbib", "%{_sbindir}")
379 gsub(libdir, "%{_libdir}")
380 gsub("%{prefix}/lib", "%{_libdir}")
381 gsub("%{_prefix}/lib", "%{_libdir}")
383 gsub(sysconfdir, "%{_sysconfdir}")
385 gsub(datadir, "%{_datadir}")
386 gsub("%{prefix}/share", "%{_datadir}")
387 gsub("%{_prefix}/share", "%{_datadir}")
389 gsub(includedir, "%{_includedir}")
390 gsub("%{prefix}/include", "%{_includedir}")
391 gsub("%{_prefix}/include", "%{_includedir}")
393 gsub(mandir, "%{_mandir}")
394 gsub("%{prefix}/man", "%{_mandir}")
395 gsub("%{_prefix}/man", "%{_mandir}")
397 gsub(infodir, "%{_infodir}")
398 gsub("%{prefix}/info", "%{_infodir}")
399 gsub("%{_prefix}/info", "%{_infodir}")
401 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
404 gsub(prefix, "%{_prefix}")
405 gsub("%{prefix}", "%{_prefix}")
408 gsub("%{PACKAGE_VERSION}", "%{version}")
409 gsub("%{PACKAGE_NAME}", "%{name}")