3 # This is adapter v0.21. Adapter adapts .spec files for PLD.
5 # Copyright (C) 1999, 2000 PLD-Team <pld-list@pld.org.pl>
7 # Micha³ Kuratczyk <kura@pld.org.pl>
8 # Sebastian Zagrodzki <s.zagrodzki@mimuw.edu.pl>
9 # Tomasz K³oczko <kloczek@rudy.mif.pg.gda.pl>
10 # Artur Frysiak <wiget@pld.org.pl>
11 # Michal Kochanowicz <mkochano@ee.pw.edu.pl>
12 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
15 preamble = 1 # Is it part of preamble? Default - yes
16 boc = 2 # Beggining of %changelog
17 bod = 0 # Beggining of %description
18 tw = 70 # Descriptions width
20 # File with rpm groups
21 "rpm --eval %_sourcedir" | getline groups_file
22 groups_file = groups_file "/rpm.groups"
23 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups")
25 # Temporary file for changelog section
26 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
29 "rpm --eval %_prefix" | getline prefix
30 "rpm --eval %_bindir" | getline bindir
31 "rpm --eval %_sbindir" | getline sbindir
32 "rpm --eval %_libdir" | getline libdir
33 "rpm --eval %_sysconfdir" | getline sysconfdir
34 "rpm --eval %_datadir" | getline datadir
35 "rpm --eval %_includedir" | getline includedir
36 "rpm --eval %_mandir" | getline mandir
37 "rpm --eval %_infodir" | getline infodir
40 # There should be a comment with CVS keywords on the first line of file.
42 if (!/# \$Revision:/) # If this line is already OK?
43 print "# $" "Revision:$, " "$" "Date:$" # No
46 next # It is enough for first line
50 # If the latest line matched /%files/
52 if ($0 !~ /defattr/) # If no %defattr
53 print "%defattr(644,root,root,755)" # Add it
55 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
59 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
61 if ($2 == "_applnkdir")
68 /^%description/, (/^%[a-z]+/ && !/^%description/) {
71 if (/^%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"
86 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
88 format_flush(format_line, format_indent)
92 } else if (/^[ \t]*[-\*][ \t]*/) {
93 format_flush(format_line, format_indent)
95 format_indent = RLENGTH
96 match($0, /^[ \t]*[-\*][ \t]/)
97 format_line = substr($0, RLENGTH)
99 format_line = format_line " " $0
103 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
104 format_flush(format_line, format_indent)
117 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
121 if (/^%setup/ && !/-q/)
122 sub(/^%setup/, "%setup -q")
126 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
133 /^%clean/, (/^%[a-z]+$/ && !/^%clean/) {
138 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
142 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
144 print "rm -rf $RPM_BUILD_ROOT"
148 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
149 print "rm -rf $RPM_BUILD_ROOT"
155 # 'install -d' instead 'mkdir -p'
157 sub(/mkdir -p/, "install -d")
159 # No '-u root' or '-g root' for 'install'
160 if (/^install/ && /-[ug][ \t]*root/)
161 gsub(/-[ug][ \t]*root /, "")
163 if (/^install/ && /-m[ \t]*644/)
164 gsub(/-m[ \t]*644 /, "")
166 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
167 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
170 # No lines contain 'chmod' if it sets the modes to '644'
171 if ($1 ~ /chmod/ && $2 ~ /644/)
174 # 'gzip -9nf' for compressing
175 if ($1 ~ /gzip|bzip2/) {
177 sub(/-[A-Za-z0-9]+ /, "", $0)
186 sub(/-[A-Za-z0-9]+ /, "", $0)
194 sub(/-[A-Za-z0-9]+ /, "", $0)
204 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
213 # %changelog section:
214 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
217 # There should be some CVS keywords on the first line of %changelog.
220 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
221 printf "All persons listed below can be reached at " > changelog_file
222 print "<cvs_login>@pld.org.pl\n" > changelog_file
223 print "$" "Log:$" > changelog_file
231 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
232 print " date +\"%a %b %d %Y\"`)" > changelog_file
238 if (!/^%[a-z]+$/ || /changelog/)
239 print > changelog_file
247 # There should not be a space after the name of field
248 # and before the colon.
252 if (Byla_grupa == 1 && field ~ /^#/)
254 if (Byla_grupa == 1 && field !~ /group(\(..\))?:/) {
256 print "Group:\t\t" Grupa["en"]
257 if (Grupa["en"] ~ /^X11/ && x11 == 0) # Is it X11 application?
260 byl_plik_z_grupami = 0
262 while ((getline linia_grup < groups_file) > 0) {
263 byl_plik_z_grupami = 1
264 if (linia_grup == Grupa["en"]) {
270 if (!byl_plik_z_grupami)
271 print "######\t\t" groups_file ": no such file"
272 else if (!byl_opis_grupy)
273 print "######\t\t" "Unknown group!"
275 while (getline linia_grup < groups_file) {
276 if (linia_grup == "")
278 split(linia_grup, g, /[\[\]:]/)
279 sub(/^[ \t]*/,"",g[4])
286 for (jezyk in Grupa) {
287 print "Group(" jezyk "):\t" Grupa[jezyk]
292 if (field ~ /packager:|distribution:|docdir:|prefix:/)
295 if (field ~ /buildroot:/)
296 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
298 if (field ~ /group(\(..\))?:/) {
300 sub(/^Utilities\//,"Applications/",$2)
301 if (!match(field,/\(..\):/))
304 glang=substr(field,RSTART+1,2)
305 sub(/^[^ \t]*[ \t]*/,"")
309 next # Line is already formatted and printed
312 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
313 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
319 if (field ~ /version:/)
322 if (field ~ /serial:/)
325 # Use %{name} and %{version} in the filenames in "Source:"
326 if (field ~ /source/ || field ~ /patch/) {
327 n = split($2, url, /\//)
328 if (url[n] ~ /\.gz$/) {
329 url[n+1] = ".gz" url[n+1]
330 sub(/\.gz$/,"",url[n])
332 if (url[n] ~ /\.zip$/) {
333 url[n+1] = ".zip" url[n+1]
334 sub(/\.zip$/,"",url[n])
336 if (url[n] ~ /\.tar$/) {
337 url[n+1] = ".tar" url[n+1]
338 sub(/\.tar$/,"",url[n])
340 if (url[n] ~ /\.patch$/) {
341 url[n+1] = ".patch" url[n+1]
342 sub(/\.patch$/,"",url[n])
344 if (url[n] ~ /\.bz2$/) {
345 url[n+1] = ".bz2" url[n+1]
346 sub(/\.bz2$/,"",url[n])
348 if (url[n] ~ /\.logrotate$/) {
349 url[n+1] = ".logrotate" url[n+1]
350 sub(/\.logrotate$/,"",url[n])
352 if (url[n] ~ /\.pamd$/) {
353 url[n+1] = ".pamd" url[n+1]
354 sub(/\.pamd$/,"",url[n])
358 url[n] = fixedsub(name, "%{name}", url[n])
359 if (field ~ /source/)
360 url[n] = fixedsub(version, "%{version}", url[n])
361 $2 = fixedsub(filename, url[n], $2)
364 if (field ~ /source:/)
367 if (field ~ /patch:/)
372 if ($1 ~ /%define/) {
373 # Do not add %define of _prefix if it already is.
374 if ($2 ~ /_prefix/) {
375 sub("^"prefix, $3, bindir)
376 sub("^"prefix, $3, sbindir)
377 sub("^"prefix, $3, libdir)
378 sub("^"prefix, $3, datadir)
379 sub("^"prefix, $3, includedir)
383 if ($2 ~ /_bindir/ && !/_sbindir/)
389 if ($2 ~ /_sysconfdir/)
393 if ($2 ~ /_includedir/)
412 close(changelog_file)
413 while ((getline < changelog_file) > 0)
415 system("rm -f " changelog_file)
417 if (did_clean == 0) {
420 print "rm -rf $RPM_BUILD_ROOT"
425 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
428 if (has_changelog == 0)
432 print "* %{date} PLD Team <pld-list@pld.org.pl>"
433 printf "All persons listed below can be reached at "
434 print "<cvs_login>@pld.org.pl\n"
439 function fixedsub(s1,s2,t, ind) {
440 # substitutes fixed strings (not regexps)
441 if (ind = index(t,s1))
442 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
446 # There should be one or two tabs after the colon.
447 function format_preamble()
450 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
458 # Replace directly specified directories with macros
459 function use_macros()
461 gsub(bindir, "%{_bindir}")
462 gsub("%{_prefix}/bin", "%{_bindir}")
463 gsub("%{prefix}/bin", "%{_bindir}")
465 for (c = 1; c <= NF; c++) {
466 if ($c ~ sbindir "/fix-info-dir")
468 gsub(sbindir, "%{_sbindir}", $c)
471 gsub("%{prefix}/sbin", "%{_sbindir}")
472 gsub("%{_prefix}/sbib", "%{_sbindir}")
474 gsub(libdir, "%{_libdir}")
475 gsub("%{prefix}/lib", "%{_libdir}")
476 gsub("%{_prefix}/lib", "%{_libdir}")
478 for (c = 1; c <= NF; c++) {
479 if ($c ~ sysconfdir "/cron.d")
481 if ($c ~ sysconfdir "/crontab.d")
483 if ($c ~ sysconfdir "/logrotate.d")
485 if ($c ~ sysconfdir "/pam.d")
487 if ($c ~ sysconfdir "/profile.d")
489 if ($c ~ sysconfdir "/rc.d")
491 if ($c ~ sysconfdir "/security")
493 if ($c ~ sysconfdir "/skel")
495 if ($c ~ sysconfdir "/sysconfig")
497 gsub(sysconfdir, "%{_sysconfdir}", $c)
500 gsub(datadir, "%{_datadir}")
501 gsub("%{prefix}/share", "%{_datadir}")
502 gsub("%{_prefix}/share", "%{_datadir}")
504 gsub(includedir, "%{_includedir}")
505 gsub("%{prefix}/include", "%{_includedir}")
506 gsub("%{_prefix}/include", "%{_includedir}")
508 gsub(mandir, "%{_mandir}")
509 gsub("%{_datadir}/man", "%{_mandir}")
510 gsub("%{_prefix}/share/man", "%{_mandir}")
511 gsub("%{prefix}/share/man", "%{_mandir}")
512 gsub("%{prefix}/man", "%{_mandir}")
513 gsub("%{_prefix}/man", "%{_mandir}")
515 gsub(infodir, "%{_infodir}")
516 gsub("%{prefix}/info", "%{_infodir}")
517 gsub("%{_prefix}/info", "%{_infodir}")
519 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
522 for (c = 1; c <= NF; c++) {
523 if ($c ~ prefix "/sbin/fix-info-dir")
525 gsub(prefix, "%{_prefix}", $c)
527 gsub("%{prefix}", "%{_prefix}")
530 gsub("%{PACKAGE_VERSION}", "%{version}")
531 gsub("%{PACKAGE_NAME}", "%{name}")
533 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
534 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
536 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
537 gsub("%{_datadir}/applnk", "%{_applnkdir}")
539 gsub("^make$", "%{__make}")
540 gsub("^make ", "%{__make} ")
543 function fill(ch, n, i) {
544 for (i = 0; i < n; i++)
548 function format_flush(line, indent, newline, word, first_word) {
550 if (format_indent == -1)
553 newline = fill(" ", format_indent) "- "
555 while (match(line, /[^\t ]+/)) {
556 word = substr(line, RSTART, RLENGTH)
557 if (length(newline) + length(word) + 1 > tw) {
560 if (format_indent == -1)
563 newline = fill(" ", format_indent + 2)
568 newline = newline word
571 newline = newline " " word
573 line = substr(line, RSTART + RLENGTH)
575 if (newline ~ /[^\t ]/) {