3 # This is adapter v0.27. Adapter adapts .spec files for PLD.
5 # Copyright (C) 1999-2001 PLD-Team <feedback@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@pld.org.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 # If variable removed, then 1 (for removing it from export)
21 removed["LDFLAGS"] = 0
23 removed["CXXFLAGS"] = 0
25 # If 1, we are inside of comment block (started with /^#%/)
28 # File with rpm groups
29 "rpm --eval %_sourcedir" | getline groups_file
30 groups_file = groups_file "/rpm.groups"
31 system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups >/dev/null")
33 # Temporary file for changelog section
34 changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
37 "rpm --eval %_prefix" | getline prefix
38 "rpm --eval %_bindir" | getline bindir
39 "rpm --eval %_sbindir" | getline sbindir
40 "rpm --eval %_libdir" | getline libdir
41 "rpm --eval %_sysconfdir" | getline sysconfdir
42 "rpm --eval %_datadir" | getline datadir
43 "rpm --eval %_includedir" | getline includedir
44 "rpm --eval %_mandir" | getline mandir
45 "rpm --eval %_infodir" | getline infodir
48 # There should be a comment with CVS keywords on the first line of file.
50 if (!/# \$Revision:/) # If this line is already OK?
51 print "# $" "Revision:$, " "$" "Date:$" # No
54 next # It is enough for first line
58 # If the latest line matched /%files/
60 if ($0 !~ /defattr/) # If no %defattr
61 print "%defattr(644,root,root,755)" # Add it
63 $0 = "%defattr(644,root,root,755)" # Correct mistakes (if any)
68 /^#/ && (description == 0) {
69 if (/This file does not like to be adapterized!/) {
70 print # print this message
71 while (getline) # print the rest of spec as it is
73 do_not_touch_anything = 1 # do not touch anything in END()
77 # Generally, comments are printed without touching
83 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
85 if ($2 == "_applnkdir")
94 /^%description/, (/^%[a-z]+/ && !/^%description/) {
97 if (/^%description/) {
103 # Define _prefix and _mandir if it is X11 application
104 if (/^%description$/ && x11 == 1) {
105 print "%define\t\t_prefix\t\t/usr/X11R6"
106 print "%define\t\t_mandir\t\t%{_prefix}/man\n"
107 prefix = "/usr/X11R6"
112 if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
114 format_flush(format_line, format_indent)
118 } else if (/^[ \t]*[-\*][ \t]*/) {
119 format_flush(format_line, format_indent)
121 format_indent = RLENGTH
122 match($0, /^[ \t]*[-\*][ \t]/)
123 format_line = substr($0, RLENGTH)
125 format_line = format_line " " $0
129 if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
130 if (NF > 3 && $2 == "-l") {
132 for (i = 4; i <= NF; i++)
136 format_flush(format_line, format_indent)
151 /^%prep/, (/^%[a-z]+$/ && !/^%prep/) {
155 if (/^%setup/ && !/-q/)
156 sub(/^%setup/, "%setup -q")
162 /^%build/, (/^%[a-z]+$/ && !/^%build/) {
171 if (/LDFLAGS="-s"/) {
172 removed["LDFLAGS"] = 1
175 split($0, tmp, "LDFLAGS=")
176 count = split(tmp[2], flags, "\"")
177 if (flags[1] != "" && flags[1] !~ "!?debug") {
178 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
179 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
180 for (i = 2; i < count; i++)
181 $0 = $0 flags[i] "\""
187 if (cflags("CFLAGS") == 0)
191 if (cflags("CXXFLAGS") == 0)
195 if (removed["LDFLAGS"])
197 if (removed["CFLAGS"])
199 if (removed["CXXFLAGS"])
201 # Is there still something?
211 /^%clean/, (/^%[a-z]+$/ && !/^%clean/) {
218 /^%install/, (/^%[a-z]+$/ && !/^%install/) {
222 if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
224 print "rm -rf $RPM_BUILD_ROOT"
228 if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
229 print "rm -rf $RPM_BUILD_ROOT"
235 # 'install -d' instead 'mkdir -p'
237 sub(/mkdir -p/, "install -d")
239 # No '-u root' or '-g root' for 'install'
240 if (/^install/ && /-[ug][ \t]*root/)
241 gsub(/-[ug][ \t]*root /, "")
243 if (/^install/ && /-m[ \t]*644/)
244 gsub(/-m[ \t]*644 /, "")
246 # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
247 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
250 # No lines contain 'chmod' if it sets the modes to '644'
251 if ($1 ~ /chmod/ && $2 ~ /644/)
258 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
271 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
274 # There should be some CVS keywords on the first line of %changelog.
277 print "* %{date} PLD Team <feedback@pld.org.pl>" > changelog_file
278 printf "All persons listed below can be reached at " > changelog_file
279 print "<cvs_login>@pld.org.pl\n" > changelog_file
280 print "$" "Log:$" > changelog_file
288 printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
289 print " date +\"%a %b %d %Y\"`)" > changelog_file
296 if (!/^%[a-z]+$/ || /changelog/)
297 print > changelog_file
306 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
309 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
312 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
315 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
323 # There should not be a space after the name of field
324 # and before the colon.
329 if (field ~ /group(\([^)]+\)):/)
331 if (field ~ /group:/) {
333 sub(/^Utilities\//,"Applications/",$2)
334 sub(/^Games/,"Applications/Games",$2)
335 sub(/^X11\/Games/,"X11/Applications/Games",$2)
336 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
337 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
338 sub(/^X11\/GNOME/,"X11/Applications",$2)
339 sub(/^X11\/Utilities/,"X11/Applications",$2)
340 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
341 sub(/^Shells/,"Applications/Shells",$2)
343 sub(/^[^ \t]*[ \t]*/,"")
346 print "Group:\t\t" Grupa
347 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
350 byl_plik_z_grupami = 0
352 while ((getline linia_grup < groups_file) > 0) {
353 byl_plik_z_grupami = 1
354 if (linia_grup == Grupa) {
360 if (!byl_plik_z_grupami)
361 print "######\t\t" groups_file ": no such file"
362 else if (!byl_opis_grupy)
363 print "######\t\t" "Unknown group!"
369 if (field ~ /packager:|distribution:|docdir:|prefix:/)
372 if (field ~ /buildroot:/)
373 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
375 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
376 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
382 if (field ~ /version:/)
385 if (field ~ /serial:/)
388 # Use %{name} and %{version} in the filenames in "Source:"
389 if (field ~ /^source/ || field ~ /patch/) {
390 n = split($2, url, /\//)
391 if (url[n] ~ /\.gz$/) {
392 url[n+1] = ".gz" url[n+1]
393 sub(/\.gz$/,"",url[n])
395 if (url[n] ~ /\.zip$/) {
396 url[n+1] = ".zip" url[n+1]
397 sub(/\.zip$/,"",url[n])
399 if (url[n] ~ /\.tar$/) {
400 url[n+1] = ".tar" url[n+1]
401 sub(/\.tar$/,"",url[n])
403 if (url[n] ~ /\.patch$/) {
404 url[n+1] = ".patch" url[n+1]
405 sub(/\.patch$/,"",url[n])
407 if (url[n] ~ /\.bz2$/) {
408 url[n+1] = ".bz2" url[n+1]
409 sub(/\.bz2$/,"",url[n])
411 if (url[n] ~ /\.logrotate$/) {
412 url[n+1] = ".logrotate" url[n+1]
413 sub(/\.logrotate$/,"",url[n])
415 if (url[n] ~ /\.pamd$/) {
416 url[n+1] = ".pamd" url[n+1]
417 sub(/\.pamd$/,"",url[n])
421 url[n] = fixedsub(name, "%{name}", url[n])
422 if (field ~ /source/)
423 url[n] = fixedsub(version, "%{version}", url[n])
424 $2 = fixedsub(filename, url[n], $2)
427 if (field ~ /^source:/)
430 if (field ~ /patch:/)
435 if ($1 ~ /%define/) {
436 # Do not add %define of _prefix if it already is.
437 if ($2 ~ /^_prefix/) {
438 sub("^"prefix, $3, bindir)
439 sub("^"prefix, $3, sbindir)
440 sub("^"prefix, $3, libdir)
441 sub("^"prefix, $3, datadir)
442 sub("^"prefix, $3, includedir)
446 if ($2 ~ /_bindir/ && !/_sbindir/)
452 if ($2 ~ /_sysconfdir/)
456 if ($2 ~ /_includedir/)
476 if (do_not_touch_anything)
479 close(changelog_file)
480 while ((getline < changelog_file) > 0)
482 system("rm -f " changelog_file)
484 if (did_clean == 0) {
487 print "rm -rf $RPM_BUILD_ROOT"
492 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
495 if (has_changelog == 0)
499 print "* %{date} PLD Team <feedback@pld.org.pl>"
500 printf "All persons listed below can be reached at "
501 print "<cvs_login>@pld.org.pl\n"
506 function fixedsub(s1,s2,t, ind) {
507 # substitutes fixed strings (not regexps)
508 if (ind = index(t,s1))
509 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
513 # There should be one or two tabs after the colon.
514 function format_preamble()
517 if (match($0, /[A-Za-z0-9()#_ \t]+[ \t]*:[ \t]*/) == 1) {
525 # Replace directly specified directories with macros
526 function use_macros()
528 gsub(bindir, "%{_bindir}")
529 gsub("%{prefix}/bin", "%{_bindir}")
530 if(prefix"/bin" == bindir)
531 gsub("%{_prefix}/bin", "%{_bindir}")
533 for (c = 1; c <= NF; c++) {
534 if ($c ~ sbindir "/fix-info-dir")
536 gsub(sbindir, "%{_sbindir}", $c)
539 gsub("%{prefix}/sbin", "%{_sbindir}")
540 if(prefix"/sbin" == sbindir)
541 gsub("%{_prefix}/sbin", "%{_sbindir}")
543 gsub(libdir, "%{_libdir}")
544 gsub("%{prefix}/lib", "%{_libdir}")
545 if(prefix"/lib" == libdir)
546 gsub("%{_prefix}/lib", "%{_libdir}")
548 for (c = 1; c <= NF; c++) {
549 if ($c ~ sysconfdir "/{?cron.d")
551 if ($c ~ sysconfdir "/{?crontab.d")
553 if ($c ~ sysconfdir "/{?logrotate.d")
555 if ($c ~ sysconfdir "/{?pam.d")
557 if ($c ~ sysconfdir "/{?profile.d")
559 if ($c ~ sysconfdir "/{?rc.d")
561 if ($c ~ sysconfdir "/{?security")
563 if ($c ~ sysconfdir "/{?skel")
565 if ($c ~ sysconfdir "/{?sysconfig")
567 gsub(sysconfdir, "%{_sysconfdir}", $c)
570 gsub(datadir, "%{_datadir}")
571 gsub("%{prefix}/share", "%{_datadir}")
572 if(prefix"/share" == datadir)
573 gsub("%{_prefix}/share", "%{_datadir}")
575 gsub(includedir, "%{_includedir}")
576 gsub("%{prefix}/include", "%{_includedir}")
577 if(prefix"/include" == includedir)
578 gsub("%{_prefix}/include", "%{_includedir}")
580 gsub(mandir, "%{_mandir}")
581 if ($0 !~ "%{_datadir}/manual")
582 gsub("%{_datadir}/man", "%{_mandir}")
583 gsub("%{_prefix}/share/man", "%{_mandir}")
584 gsub("%{prefix}/share/man", "%{_mandir}")
585 gsub("%{prefix}/man", "%{_mandir}")
586 gsub("%{_prefix}/man", "%{_mandir}")
588 gsub(infodir, "%{_infodir}")
589 gsub("%{prefix}/info", "%{_infodir}")
590 gsub("%{_prefix}/info", "%{_infodir}")
592 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
595 for (c = 1; c <= NF; c++) {
596 if ($c ~ prefix "/sbin/fix-info-dir")
598 gsub(prefix, "%{_prefix}", $c)
600 gsub("%{prefix}", "%{_prefix}")
603 gsub("%{PACKAGE_VERSION}", "%{version}")
604 gsub("%{PACKAGE_NAME}", "%{name}")
606 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
607 gsub("%{_datadir}/applnk", "%{_applnkdir}")
609 gsub("^make$", "%{__make}")
610 gsub("^make ", "%{__make} ")
612 gsub("/usr/src/linux", "%{_kernelsrcdir}")
613 gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
616 function use_files_macros()
618 gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
619 gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
622 function fill(ch, n, i) {
623 for (i = 0; i < n; i++)
627 function format_flush(line, indent, newline, word, first_word) {
629 if (format_indent == -1)
632 newline = fill(" ", format_indent) "- "
634 while (match(line, /[^\t ]+/)) {
635 word = substr(line, RSTART, RLENGTH)
636 if (length(newline) + length(word) + 1 > tw) {
639 if (format_indent == -1)
642 newline = fill(" ", format_indent + 2)
647 newline = newline word
650 newline = newline " " word
652 line = substr(line, RSTART + RLENGTH)
654 if (newline ~ /[^\t ]/) {
661 if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
667 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")