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 1>&2")
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)
185 gsub(/LDFLAGS="?.*?"?[ \t]*;?/,"");
187 gsub(/LDFLAGS(="?.*?"?)?[ \t]*/,"");
188 gsub("export[ \t]*(;|$)","");
196 sub(/-[A-Za-z0-9]+ /, "", $0)
204 sub(/-[A-Za-z0-9]+ /, "", $0)
214 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
223 # %changelog section:
224 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
227 # There should be some CVS keywords on the first line of %changelog.
230 print "* %{date} PLD Team <pld-list@pld.org.pl>" > changelog_file
231 printf "All persons listed below can be reached at " > changelog_file
232 print "<cvs_login>@pld.org.pl\n" > changelog_file
233 print "$" "Log:$" > changelog_file
241 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
242 print " date +\"%a %b %d %Y\"`)" > changelog_file
248 if (!/^%[a-z]+$/ || /changelog/)
249 print > changelog_file
257 # There should not be a space after the name of field
258 # and before the colon.
262 if (Byla_grupa == 1 && field ~ /^#/)
264 if (Byla_grupa == 1 && field !~ /group(\(..\))?:/) {
266 print "Group:\t\t" Grupa["en"]
267 if (Grupa["en"] ~ /^X11/ && x11 == 0) # Is it X11 application?
270 byl_plik_z_grupami = 0
272 while ((getline linia_grup < groups_file) > 0) {
273 byl_plik_z_grupami = 1
274 if (linia_grup == Grupa["en"]) {
280 if (!byl_plik_z_grupami)
281 print "######\t\t" groups_file ": no such file"
282 else if (!byl_opis_grupy)
283 print "######\t\t" "Unknown group!"
285 while (getline linia_grup < groups_file) {
286 if (linia_grup == "")
288 split(linia_grup, g, /[\[\]:]/)
289 sub(/^[ \t]*/,"",g[4])
296 for (jezyk in Grupa) {
297 print "Group(" jezyk "):\t" Grupa[jezyk] | "sort"
303 if (field ~ /packager:|distribution:|docdir:|prefix:/)
306 if (field ~ /buildroot:/)
307 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
309 if (field ~ /group(\(..\))?:/) {
311 sub(/^Utilities\//,"Applications/",$2)
312 sub(/^Games/,"Applications/Games",$2)
313 sub(/^X11\/Games/,"Applications\/Games",$2)
314 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
315 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
316 sub(/^X11\/GNOME/,"X11/Applications",$2)
317 sub(/^X11\/Utilities/,"X11\/Applications",$2)
318 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
319 sub(/^Shells/,"Applications/Shells",$2)
321 if (!match(field,/\(..\):/))
324 glang=substr(field,RSTART+1,2)
325 sub(/^[^ \t]*[ \t]*/,"")
329 next # Line is already formatted and printed
332 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
333 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
339 if (field ~ /version:/)
342 if (field ~ /serial:/)
345 # Use %{name} and %{version} in the filenames in "Source:"
346 if (field ~ /source/ || field ~ /patch/) {
347 n = split($2, url, /\//)
348 if (url[n] ~ /\.gz$/) {
349 url[n+1] = ".gz" url[n+1]
350 sub(/\.gz$/,"",url[n])
352 if (url[n] ~ /\.zip$/) {
353 url[n+1] = ".zip" url[n+1]
354 sub(/\.zip$/,"",url[n])
356 if (url[n] ~ /\.tar$/) {
357 url[n+1] = ".tar" url[n+1]
358 sub(/\.tar$/,"",url[n])
360 if (url[n] ~ /\.patch$/) {
361 url[n+1] = ".patch" url[n+1]
362 sub(/\.patch$/,"",url[n])
364 if (url[n] ~ /\.bz2$/) {
365 url[n+1] = ".bz2" url[n+1]
366 sub(/\.bz2$/,"",url[n])
368 if (url[n] ~ /\.logrotate$/) {
369 url[n+1] = ".logrotate" url[n+1]
370 sub(/\.logrotate$/,"",url[n])
372 if (url[n] ~ /\.pamd$/) {
373 url[n+1] = ".pamd" url[n+1]
374 sub(/\.pamd$/,"",url[n])
378 url[n] = fixedsub(name, "%{name}", url[n])
379 if (field ~ /source/)
380 url[n] = fixedsub(version, "%{version}", url[n])
381 $2 = fixedsub(filename, url[n], $2)
384 if (field ~ /source:/)
387 if (field ~ /patch:/)
392 if ($1 ~ /%define/) {
393 # Do not add %define of _prefix if it already is.
394 if ($2 ~ /_prefix/) {
395 sub("^"prefix, $3, bindir)
396 sub("^"prefix, $3, sbindir)
397 sub("^"prefix, $3, libdir)
398 sub("^"prefix, $3, datadir)
399 sub("^"prefix, $3, includedir)
403 if ($2 ~ /_bindir/ && !/_sbindir/)
409 if ($2 ~ /_sysconfdir/)
413 if ($2 ~ /_includedir/)
432 close(changelog_file)
433 while ((getline < changelog_file) > 0)
435 system("rm -f " changelog_file)
437 if (did_clean == 0) {
440 print "rm -rf $RPM_BUILD_ROOT"
445 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
448 if (has_changelog == 0)
452 print "* %{date} PLD Team <pld-list@pld.org.pl>"
453 printf "All persons listed below can be reached at "
454 print "<cvs_login>@pld.org.pl\n"
459 function fixedsub(s1,s2,t, ind) {
460 # substitutes fixed strings (not regexps)
461 if (ind = index(t,s1))
462 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
466 # There should be one or two tabs after the colon.
467 function format_preamble()
470 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
478 # Replace directly specified directories with macros
479 function use_macros()
481 gsub(bindir, "%{_bindir}")
482 gsub("%{_prefix}/bin", "%{_bindir}")
483 gsub("%{prefix}/bin", "%{_bindir}")
485 for (c = 1; c <= NF; c++) {
486 if ($c ~ sbindir "/fix-info-dir")
488 gsub(sbindir, "%{_sbindir}", $c)
491 gsub("%{prefix}/sbin", "%{_sbindir}")
492 gsub("%{_prefix}/sbib", "%{_sbindir}")
494 gsub(libdir, "%{_libdir}")
495 gsub("%{prefix}/lib", "%{_libdir}")
496 gsub("%{_prefix}/lib", "%{_libdir}")
498 for (c = 1; c <= NF; c++) {
499 if ($c ~ sysconfdir "/cron.d")
501 if ($c ~ sysconfdir "/crontab.d")
503 if ($c ~ sysconfdir "/logrotate.d")
505 if ($c ~ sysconfdir "/pam.d")
507 if ($c ~ sysconfdir "/profile.d")
509 if ($c ~ sysconfdir "/rc.d")
511 if ($c ~ sysconfdir "/security")
513 if ($c ~ sysconfdir "/skel")
515 if ($c ~ sysconfdir "/sysconfig")
517 gsub(sysconfdir, "%{_sysconfdir}", $c)
520 gsub(datadir, "%{_datadir}")
521 gsub("%{prefix}/share", "%{_datadir}")
522 gsub("%{_prefix}/share", "%{_datadir}")
524 gsub(includedir, "%{_includedir}")
525 gsub("%{prefix}/include", "%{_includedir}")
526 gsub("%{_prefix}/include", "%{_includedir}")
528 gsub(mandir, "%{_mandir}")
529 gsub("%{_datadir}/man", "%{_mandir}")
530 gsub("%{_prefix}/share/man", "%{_mandir}")
531 gsub("%{prefix}/share/man", "%{_mandir}")
532 gsub("%{prefix}/man", "%{_mandir}")
533 gsub("%{_prefix}/man", "%{_mandir}")
535 gsub(infodir, "%{_infodir}")
536 gsub("%{prefix}/info", "%{_infodir}")
537 gsub("%{_prefix}/info", "%{_infodir}")
539 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
542 for (c = 1; c <= NF; c++) {
543 if ($c ~ prefix "/sbin/fix-info-dir")
545 gsub(prefix, "%{_prefix}", $c)
547 gsub("%{prefix}", "%{_prefix}")
550 gsub("%{PACKAGE_VERSION}", "%{version}")
551 gsub("%{PACKAGE_NAME}", "%{name}")
553 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
554 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
556 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
557 gsub("%{_datadir}/applnk", "%{_applnkdir}")
559 gsub("^make$", "%{__make}")
560 gsub("^make ", "%{__make} ")
563 function fill(ch, n, i) {
564 for (i = 0; i < n; i++)
568 function format_flush(line, indent, newline, word, first_word) {
570 if (format_indent == -1)
573 newline = fill(" ", format_indent) "- "
575 while (match(line, /[^\t ]+/)) {
576 word = substr(line, RSTART, RLENGTH)
577 if (length(newline) + length(word) + 1 > tw) {
580 if (format_indent == -1)
583 newline = fill(" ", format_indent + 2)
588 newline = newline word
591 newline = newline " " word
593 line = substr(line, RSTART + RLENGTH)
595 if (newline ~ /[^\t ]/) {