]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - adapter.awk
- Development/Docs -> Documentation group trans
[packages/rpm-build-tools.git] / adapter.awk
1 #!/bin/awk -f
2 #
3 # This is adapter v0.27. Adapter adapts .spec files for PLD.
4 #
5 # Copyright (C) 1999-2003 PLD-Team <feedback@pld-linux.org>
6 # Authors:
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-linux.org>
11 #       Michal Kochanowicz <mkochano@pld.org.pl>
12 #       Elan Ruusamäe <glen@pld-linux.org>
13 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
14
15 # TODO
16 # - parse ../PLD-doc/BuildRequires.txt and setup proper BR epoches?
17 # - add "-nc" option to skip CVS interaction
18 # - sort Summary(XX)
19 # - sort Requires, BuildRequires
20 # - check if %description (lang=C) contains 8bit
21 # - desc wrapping is totally fucked up on global.spec,1.25, dosemu.spec,1.115-
22
23 BEGIN {
24         preamble = 1            # Is it part of preamble? Default - yes
25         boc = 4                 # Beginning of %changelog
26         bod = 0                 # Beginning of %description
27         tw = 70                 # Descriptions width
28
29         b_idx = 0               # index of BR/R arrays
30
31         # If variable removed, then 1 (for removing it from export)
32         removed["LDFLAGS"] = 0
33         removed["CFLAGS"] = 0
34         removed["CXXFLAGS"] = 0
35
36         # get cvsaddress for changelog section
37         # using rpm macros as too lazy to add ~/.adapterrc parsing support.
38         "rpm --eval '%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'" | getline _cvsmaildomain
39         "rpm --eval '%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'" | getline _cvsmailfeedback
40
41         # If 1, we are inside of comment block (started with /^#%/)
42         comment_block = 0
43
44         # File with rpm groups
45         "rpm --eval %_sourcedir" | getline groups_file
46         groups_file = groups_file "/rpm.groups"
47         system("cd `rpm --eval %_sourcedir`; cvs up rpm.groups >/dev/null")
48
49         # Temporary file for changelog section
50         changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
51
52         # Load rpm macros
53         "rpm --eval %_prefix"   | getline prefix
54         "rpm --eval %_bindir"   | getline bindir
55         "rpm --eval %_sbindir"  | getline sbindir
56         "rpm --eval %_libdir"   | getline libdir
57         "rpm --eval %_sysconfdir" | getline sysconfdir
58         "rpm --eval %_datadir"  | getline datadir
59         "rpm --eval %_includedir" | getline includedir
60         "rpm --eval %_mandir"   | getline mandir
61         "rpm --eval %_infodir"  | getline infodir
62         "rpm --eval %_examplesdir"      | getline examplesdir
63
64         "rpm --eval %perl_sitearch" | getline perl_sitearch
65         "rpm --eval %perl_archlib" | getline perl_archlib
66         "rpm --eval %perl_privlib" | getline perl_privlib
67         "rpm --eval %perl_vendorlib" | getline perl_vendorlib
68         "rpm --eval %perl_vendorarch" | getline perl_vendorarch
69         "rpm --eval %perl_sitelib" | getline perl_sitelib
70
71         "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
72 }
73
74 # There should be a comment with CVS keywords on the first line of file.
75 FNR == 1 {
76         if (!/# \$Revision:/)   # If this line is already OK?
77                 print "# $" "Revision:$, " "$" "Date:$" # No
78         else {
79                 print $0                                # Yes
80                 next            # It is enough for first line
81         }
82 }
83
84 # If the latest line matched /%files/
85 defattr == 1 {
86         if ($0 !~ /defattr/)    # If no %defattr
87                 print "%defattr(644,root,root,755)"     # Add it
88         else
89                 $0 = "%defattr(644,root,root,755)"      # Correct mistakes (if any)
90         defattr = 0
91 }
92
93 function b_makekey(a, b,        s) {
94         s = a "" b;
95         # kill bcond
96     gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
97         return s;
98 }
99
100 # sort BR/R!
101 #
102 # NOTES:
103 # - mixing BR/R and anything else confuses this (all will be sorted together)
104 #   so don't do that.
105 # - comments leading the BR/R can not be associated,
106 #   so don't adapterize when the BR/R are mixed with comments
107 ENVIRON["SORTBR"] == 1 && preamble == 1 && /(Build)?Requires/, /(Build)?Requires/ { # && !/^%/) {
108         b_idx++;
109         l = substr($0, index($0, $2));
110         b_ktmp = b_makekey($1, l);
111         b_key[b_idx] = b_ktmp;
112         b_val[b_ktmp] = $0;
113
114         next;
115 }
116
117 /^%bcond_/ {
118         # do nothing
119         print
120         next
121 }
122
123 preamble == 1 {
124         if (b_idx > 0) {
125                 isort(b_key, b_idx);
126                 for (i = 1; i <= b_idx; i++) {
127                         print "" b_val[b_key[i]];
128                 }
129                 b_idx = 0
130         }
131 }
132
133 # Comments
134 /^#/ && (description == 0) {
135         if (/This file does not like to be adapterized!/) {
136                 print                   # print this message
137                 while (getline)         # print the rest of spec as it is
138                         print
139                 do_not_touch_anything = 1 # do not touch anything in END()
140                 exit 0
141         }
142
143         # Generally, comments are printed without touching
144         sub(/[ \t]+$/, "")
145         print $0
146         next
147 }
148
149 # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
150 /^%define/ {
151         if ($2 == "_applnkdir") {
152                 next
153         }
154         if ($2 == "date") {
155                 date = 1
156         }
157
158         # Do not add %define of _prefix if it already is.
159         if ($2 ~ /^_prefix/) {
160                 sub("^"prefix, $3, bindir)
161                 sub("^"prefix, $3, sbindir)
162                 sub("^"prefix, $3, libdir)
163                 sub("^"prefix, $3, datadir)
164                 sub("^"prefix, $3, includedir)
165                 prefix = $3
166         }
167
168         if ($2 ~ /_bindir/ && !/_sbindir/)
169                 bindir = $3
170         if ($2 ~ /_sbindir/)
171                 sbindir = $3
172         if ($2 ~ /_libdir/)
173                 libdir = $3
174         if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
175                 sysconfdir = $3
176         if ($2 ~ /_datadir/)
177                 datadir = $3
178         if ($2 ~ /_includedir/)
179                 includedir = $3
180         if ($2 ~ /_mandir/)
181                 mandir = $3
182         if ($2 ~ /_infodir/)
183                 infodir = $3
184
185         # version related macros
186         if ($2 ~ /^_beta$/)
187                 _beta = $3
188         if ($2 ~ /^_rc$/)
189                 _rc = $3
190         if ($2 ~ /^_snap$/)
191                 _snap = $3
192
193         # these are used usually when adapterizing external spec
194         if ($2 ~ /^name$/)
195                 name = $3
196         if ($2 ~ /^version$/)
197                 version = $3
198         if ($2 ~ /^release$/)
199                 release = $3
200
201         # do nothing further, otherwise adapter thinks we're at preamble
202         print
203         next
204 }
205
206 # Obsolete
207 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
208         next
209 }
210
211 ################
212 # %description #
213 ################
214 /^%description/, (/^%[a-z]+/ && !/^%description/ && !/^%((end)?if|else)/) {
215         preamble = 0
216
217         if (/^%description/) {
218                 bod++
219                 format_line = ""
220                 format_indent = -1
221         }
222
223         # Format description
224         if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
225                 if (/^[ \t]*$/) {
226                         format_flush(format_line, format_indent)
227                         print ""
228                         format_line = ""
229                         format_indent = -1
230                 } else if (/^[ \t]*[-\*][ \t]*/) {
231                         format_flush(format_line, format_indent)
232                         match($0, /^[ \t]*/)
233                         format_indent = RLENGTH
234                         match($0, /^[ \t]*[-\*][ \t]/)
235                         format_line = substr($0, RLENGTH)
236                 } else
237                         format_line = format_line " " $0
238                 next
239         }
240
241         if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
242                 if (NF > 3 && $2 == "-l") {
243                         ll = $1
244                         for (i = 4; i <= NF; i++)
245                                 ll = ll " " $i
246                         $0 = ll " -l " $3
247                 }
248                 format_flush(format_line, format_indent)
249                 if (bod == 2) {
250                         bod = 1
251                         description = 1
252                 } else {
253                         bod = 0
254                         description = 0
255                 }
256         } else
257                 description = 1
258 }
259
260 #########
261 # %prep #
262 #########
263 /^%prep/, (/^%[a-z]+$/ && !/^%prep/ && !/^%((end)?if|else)/) {
264         preamble = 0
265
266         use_macros()
267
268         # Add '-q' to %setup
269         if (/^%setup/ && !/-q/) {
270                 sub(/^%setup/, "%setup -q")
271         }
272
273         if (/^%setup/) {
274                 gsub(name, "%{name}");
275                 gsub(version, "%{version}");
276                 if (_beta) {
277                         gsub(_beta, "%{_beta}");
278                 }
279                 if (_rc) {
280                         gsub(_rc, "%{_rc}");
281                 }
282                 if (_snap) {
283                         gsub(_snap, "%{_snap}");
284                 }
285         }
286
287         if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
288                 sub(/ -n %{name}-%{version}/, "")
289         }
290
291         # invalid in %prep
292         sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
293 }
294
295 ##########
296 # %build #
297 ##########
298 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
299         preamble = 0
300
301         use_macros()
302
303         if (/^automake$/)
304                 sub(/$/, " -a -c")
305
306         if (/LDFLAGS/) {
307                 if (/LDFLAGS="-s"/) {
308                         removed["LDFLAGS"] = 1
309                         next
310                 } else {
311                         split($0, tmp, "LDFLAGS=")
312                         count = split(tmp[2], flags, "\"")
313                         if (flags[1] != "" && flags[1] !~ "!?debug") {
314                                 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
315                                 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
316                                 for (i = 2; i < count; i++)
317                                         $0 = $0 flags[i] "\""
318                         }
319                 }
320         }
321
322         if (/CFLAGS=/)
323                 if (cflags("CFLAGS") == 0)
324                         next
325
326         if (/CXXFLAGS=/)
327                 if (cflags("CXXFLAGS") == 0)
328                         next
329
330         if (/^export /) {
331                 if (removed["LDFLAGS"])
332                         sub(" LDFLAGS", "")
333                 if (removed["CFLAGS"])
334                         sub(" CFLAGS", "")
335                 if (removed["CXXFLAGS"])
336                         sub(" CXXFLAGS", "")
337                 # Is there still something?
338                 if (/^export[ ]*$/)
339                         next
340         }
341
342         # quote CC
343         if (/CC=%{__cc} /) {
344                 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
345         }
346         
347         # use PLD Linux macros
348         $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
349         $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
350         $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
351
352         sub(/^aclocal$/, "%{__aclocal}");
353         sub(/^autoheader$/, "%{__autoheader}");
354         sub(/^autoconf$/, "%{__autoconf}");
355         sub(/^automake$/, "%{__automake}");
356
357         # atrpms
358         $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
359         $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
360 }
361
362 ##########
363 # %clean #
364 ##########
365 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
366         did_clean = 1
367
368         # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
369         if (!/^%/) {
370                 use_macros()
371         }
372 }
373
374 ############
375 # %install #
376 ############
377 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
378
379         preamble = 0
380
381         if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
382                 did_rmroot=1
383                 print "rm -rf $RPM_BUILD_ROOT"
384                 next
385         }
386
387         if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
388                 print "rm -rf $RPM_BUILD_ROOT"
389                 did_rmroot=1
390         }
391
392         use_macros()
393
394         # 'install -d' instead 'mkdir -p'
395         if (/mkdir -p/)
396                 sub(/mkdir -p/, "install -d")
397
398         # 'install' instead 'cp -p'
399         if (/cp -p\b/)
400                 sub(/cp -p/, "install")
401
402         # No '-u root' or '-g root' for 'install'
403         if (/^install/ && /-[ug][ \t]*root/)
404                 gsub(/-[ug][ \t]*root /, "")
405
406         if (/^install/ && /-m[ \t]*[0-9]+/)
407                 gsub(/-m[ \t]*[0-9]+ /, "")
408
409         # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
410         if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
411                 next
412
413         # No lines contain 'chmod' if it sets the modes to '644'
414         if ($1 ~ /chmod/ && $2 ~ /644/)
415                 next
416
417         # foreign rpms
418         $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
419         $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
420
421         # atrpms
422         $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
423 }
424
425 ##########
426 # %files #
427 ##########
428 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
429         preamble = 0
430
431         if ($0 ~ /^%files/)
432                 defattr = 1
433
434         use_files_macros()
435 }
436
437 ##############
438 # %changelog #
439 ##############
440 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
441         preamble = 0
442         has_changelog = 1
443         skip = 0
444         # There should be some CVS keywords on the first line of %changelog.
445         if (boc == 3) {
446                 if ($0 !~ _cvsmailfeedback)
447                         print "* %{date} " _cvsmailfeedback > changelog_file
448                 else
449                         skip = 1
450                 boc = 2
451         }
452         if (boc == 2 && !skip) {
453                 if (!/All persons listed below/) {
454                         printf "All persons listed below can be reached at " > changelog_file
455                         print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
456                 } else
457                         skip = 1
458                 boc = 1
459         }
460         if (boc == 1 && !skip) {
461                 if (!/^$/) {
462                         if (!/\$.*Log:.*\$/)
463                                 print "$" "Log:$" > changelog_file
464                         boc = 0
465                 }
466         }
467         # Define date macro.
468         if (boc == 4) {
469                 if (date == 0) {
470                         printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
471                         print " date +\"%a %b %d %Y\"`)" > changelog_file
472                         date = 1
473                 }
474                 boc = 3
475         }
476
477         sub(/[ \t]+$/, "")
478         if (!/^%[a-z]+$/ || /changelog/)
479                 print > changelog_file
480         else
481                 print
482         next
483 }
484
485 ###########
486 # SCRIPTS #
487 ###########
488 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
489         preamble = 0
490
491         # %useradd and %groupadd may not be wrapped
492         if (/%(useradd|groupadd).*\\$/) {
493                 a = $0; getline;
494                 sub(/^[\s\t]*/, "");
495                 $0 = substr(a, 1, length(a) - 1) $0;
496         }
497 }
498
499 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
500         preamble = 0
501 }
502 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
503         preamble = 0
504 }
505 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
506         preamble = 0
507 }
508 /^%triggerin/, (/^%[a-z]+$/ && !/^%triggerin/) {
509         preamble = 0
510 }
511 /^%triggerun/, (/^%[a-z]+$/ && !/^%triggerun/) {
512         preamble = 0
513 }
514 /^%triggerpostun/, (/^%[a-z]+$/ && !/^%triggerpostun/) {
515         preamble = 0
516 }
517 /^%pretrans/, (/^%[a-z]+$/ && !/^%pretrans/) {
518         preamble = 0
519 }
520 /^%posttrans/, (/^%[a-z]+$/ && !/^%posttrans/) {
521         preamble = 0
522 }
523
524 #############
525 # PREAMBLES #
526 #############
527 preamble == 1 {
528         # There should not be a space after the name of field
529         # and before the colon.
530         sub(/[ \t]*:/, ":")
531
532         if (/^%perl_module_wo_prefix/) {
533                 name = $2
534                 version = $3
535                 release = "0." fixedsub(".%{disttag}.at", "", $4)
536         }
537
538         field = tolower($1)
539         fieldnlower = $1
540         if (field ~ /summary:/) {
541                 sub(/\.$/, "", $0);
542         }
543         if (field ~ /group(\([^)]+\)):/)
544                 next
545         if (field ~ /group:/) {
546                 format_preamble()
547                 sub(/^Utilities\//,"Applications/",$2)
548                 sub(/^Games/,"Applications/Games",$2)
549                 sub(/^X11\/Games/,"X11/Applications/Games",$2)
550                 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
551                 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
552                 sub(/^X11\/GNOME/,"X11/Applications",$2)
553                 sub(/^X11\/Utilities/,"X11/Applications",$2)
554                 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
555                 sub(/^Shells/,"Applications/Shells",$2)
556
557                 sub(/^[^ \t]*[ \t]*/,"")
558                 Grupa = $0
559
560                 sub(/^System Environment\/Libraries$/, "Libraries", Grupa)
561                 sub(/^System Environment\/Daemons$/, "Daemons", Grupa)
562                 sub(/^Applications\/Internet$/, "Applications/Networking", Grupa)
563                 sub(/^System\/Servers$/, "Daemons", Grupa)
564                 sub(/^X11\/Xserver$/, "X11/Servers", Grupa)
565                 sub(/^X11\/XFree86$/, "X11", Grupa)
566                 sub(/^Applications\/Compilers$/, "Development/Languages", Grupa)
567                 sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", Grupa)
568                 sub(/^Networking\/Deamons$/, "Networking/Daemons", Grupa)
569                 sub(/^Development\/Docs$/, "Documentation", Grupa)
570
571                 print "Group:\t\t" Grupa
572                 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
573                         x11 = 1
574
575                 byl_plik_z_grupami = 0
576                 byl_opis_grupy = 0
577                 while ((getline linia_grup < groups_file) > 0) {
578                         byl_plik_z_grupami = 1
579                         if (linia_grup == Grupa) {
580                                 byl_opis_grupy = 1
581                                 break
582                         }
583                 }
584
585                 if (!byl_plik_z_grupami)
586                         print "######\t\t" groups_file ": no such file"
587                 else if (!byl_opis_grupy)
588                         print "######\t\t" "Unknown group!"
589
590                 close(groups_file)
591                 next
592         }
593
594         if (field ~ /prereq:/) {
595                 sub(/PreReq:/, "Requires:", $1);
596         }
597
598         # split (build)requires, obsoletes on commas
599         if (field ~ /(obsoletes|requires):/ && $0 ~ /,/) {
600                 l = substr($0, index($0, $2));
601                 n = split(l, p, / *, */);
602                 for (i in p) {
603                         printf("%s\t%s\n", $1, p[i]);
604                 }
605                 next;
606         }
607
608         if (field ~ /packager:|distribution:|docdir:|prefix:/)
609                 next
610
611         if (field ~ /buildroot:/)
612                 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
613
614         # Use "License" instead of "Copyright" if it is (L)GPL or BSD
615         if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
616                 $1 = "License:"
617
618         if (field ~ /name:/) {
619                 if ($2 == "%{name}" && name) {
620                         $2 = name
621                 }
622                 name = $2
623                 name_seen = 1;
624         }
625
626         if (field ~ /version:/) {
627                 if ($2 == "%{version}" && version) {
628                         $2 = version
629                 }
630                 version = $2
631                 version_seen = 1;
632         }
633
634         if (field ~ /release:/) {
635                 if ($2 == "%{release}" && release) {
636                         $2 = release
637                 }
638                 release = $2
639                 release_seen = 1;
640         }
641
642         if (field ~ /serial:/)
643                 $1 = "Epoch:"
644
645         # proper caps
646         if (field ~ /^url:$/)
647                 $1 = "URL:"
648
649         # Use %{name} and %{version} in the filenames in "Source:"
650         if (field ~ /^source/ || field ~ /patch/) {
651                 n = split($2, url, /\//)
652                 if (url[n] ~ /\.gz$/) {
653                         url[n+1] = ".gz" url[n+1]
654                         sub(/\.gz$/,"",url[n])
655                 }
656                 if (url[n] ~ /\.zip$/) {
657                         url[n+1] = ".zip" url[n+1]
658                         sub(/\.zip$/,"",url[n])
659                 }
660                 if (url[n] ~ /\.tar$/) {
661                         url[n+1] = ".tar" url[n+1]
662                         sub(/\.tar$/,"",url[n])
663                 }
664                 if (url[n] ~ /\.patch$/) {
665                         url[n+1] = ".patch" url[n+1]
666                         sub(/\.patch$/,"",url[n])
667                 }
668                 if (url[n] ~ /\.bz2$/) {
669                         url[n+1] = ".bz2" url[n+1]
670                         sub(/\.bz2$/,"",url[n])
671                 }
672                 if (url[n] ~ /\.logrotate$/) {
673                         url[n+1] = ".logrotate" url[n+1]
674                         sub(/\.logrotate$/,"",url[n])
675                 }
676                 if (url[n] ~ /\.pamd$/) {
677                         url[n+1] = ".pamd" url[n+1]
678                         sub(/\.pamd$/,"",url[n])
679                 }
680
681                 # allow %{name} just in last url component
682                 s = ""
683                 for (i = 1; i <= n; i++) {
684                         url[i] = fixedsub("%{name}", name, url[i])
685                         if (s) {
686                                 s = s "/" url[i]
687                         } else {
688                                 s = url[i]
689                         }
690                 }
691                 $2 = s url[n+1]
692
693                 filename = url[n]
694                 if (name) {
695                         url[n] = fixedsub(name, "%{name}", url[n])
696                 }
697                 if (field ~ /source/) {
698                         if (version) {
699                                 url[n] = fixedsub(version, "%{version}", url[n])
700                         }
701                         if (_beta) {
702                                 url[n] = fixedsub(_beta, "%{_beta}", url[n])
703                         }
704                         if (_rc) {
705                                 url[n] = fixedsub(_rc, "%{_rc}", url[n])
706                         }
707                         if (_snap) {
708                                 url[n] = fixedsub(_snap, "%{_snap}", url[n])
709                         }
710                 }
711                 $2 = fixedsub(filename, url[n], $2)
712
713                 # sourceforge urls
714                 sub("[?]use_mirror=.*$", "", $2);
715                 sub("[?]download$", "", $2);
716                 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
717
718                 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
719                 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
720                 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
721         }
722
723
724         if (field ~ /^source:/)
725                 $1 = "Source0:"
726
727         if (field ~ /patch:/)
728                 $1 = "Patch0:"
729
730         format_preamble()
731
732
733         if (field ~ /requires/) {
734                 # atrpms
735                 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
736         }
737 }
738
739 # main() ;-)
740 {
741         preamble = 1
742
743         sub(/[ \t]+$/, "")
744         print
745
746         if (name_seen == 0 && name) {
747                 print "Name:\t" name
748                 name_seen = 1
749         }
750
751         if (version_seen == 0 && version) {
752                 print "Version:\t" version
753                 version_seen = 1
754         }
755
756         if (release_seen == 0 && release) {
757                 print "Release:\t" release
758                 release_seen = 1
759         }
760 }
761
762
763 END {
764         if (do_not_touch_anything)
765                 exit 0
766
767         close(changelog_file)
768         while ((getline < changelog_file) > 0)
769                 print
770         system("rm -f " changelog_file)
771
772
773
774         if (did_clean == 0) {
775                 print ""
776                 print "%clean"
777                 print "rm -rf $RPM_BUILD_ROOT"
778         }
779
780         if (date == 0) {
781                 print ""
782                 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
783         }
784
785         if (has_changelog == 0)
786                 print "%changelog"
787
788         if (boc > 2)
789                 print "* %{date} PLD Team <feedback@pld-linux.org>"
790         if (boc > 1) {
791                 printf "All persons listed below can be reached at "
792                 print "<cvs_login>@pld-linux.org\n"
793         }
794         if (boc > 0)
795                 print "$" "Log:$"
796 }
797
798 function fixedsub(s1,s2,t, ind) {
799 # substitutes fixed strings (not regexps)
800         if (ind = index(t,s1))
801                 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
802         return t
803 }
804
805 # There should be one or two tabs after the colon.
806 function format_preamble()
807 {
808         sub(/:[ \t]*/, ":")
809         if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
810                 if (RLENGTH < 8)
811                         sub(/:/, ":\t\t")
812                 else
813                         sub(/:/, ":\t")
814         }
815 }
816
817 # Replace directly specified directories with macros
818 function use_macros()
819 {
820         gsub(perl_sitearch, "%{perl_sitearch}")
821         gsub(perl_archlib, "%{perl_archlib}")
822         gsub(perl_privlib, "%{perl_privlib}")
823         gsub(perl_vendorlib, "%{perl_vendorlib}")
824         gsub(perl_vendorarch, "%{perl_vendorarch}")
825         gsub(perl_sitelib, "%{perl_sitelib}")
826         
827         gsub(py_sitescriptdir, "%{py_sitescriptdir}")
828
829         gsub(bindir, "%{_bindir}")
830         gsub("%{prefix}/bin", "%{_bindir}")
831         if(prefix"/bin" == bindir)
832                 gsub("%{_prefix}/bin", "%{_bindir}")
833
834         for (c = 1; c <= NF; c++) {
835                 if ($c ~ sbindir "/fix-info-dir")
836                         continue;
837                 if ($c ~ sbindir "/webapp")
838                         continue;
839                 if ($c ~ sbindir "/chsh")
840                         continue;
841                 if ($c ~ sbindir "/usermod")
842                         continue;
843                 gsub(sbindir, "%{_sbindir}", $c)
844         }
845
846         gsub("%{prefix}/sbin", "%{_sbindir}")
847         if (prefix"/sbin" == sbindir)
848                 gsub("%{_prefix}/sbin", "%{_sbindir}")
849
850         for (c = 1; c <= NF; c++) {
851                 if ($c ~ sysconfdir "/{?cron.")
852                         continue;
853                 if ($c ~ sysconfdir "/{?crontab.d")
854                         continue;
855                 if ($c ~ sysconfdir "/{?env.d")
856                         continue;
857                 if ($c ~ sysconfdir "/{?logrotate.d")
858                         continue;
859                 if ($c ~ sysconfdir "/{?pam.d")
860                         continue;
861                 if ($c ~ sysconfdir "/{?profile.d")
862                         continue;
863                 if ($c ~ sysconfdir "/{?rc.d")
864                         continue;
865                 if ($c ~ sysconfdir "/{?security")
866                         continue;
867                 if ($c ~ sysconfdir "/{?skel")
868                         continue;
869                 if ($c ~ sysconfdir "/{?sysconfig")
870                         continue;
871                 if ($c ~ sysconfdir "/{?shrc.d")
872                         continue;
873                 if ($c ~ sysconfdir "/{?certs")
874                         continue;
875                 if ($c ~ sysconfdir "/{?X11")
876                         continue;
877                 if ($c ~ sysconfdir "/{?ld.so.conf.d")
878                         continue;
879                 if ($c ~ sysconfdir "/{?httpd") # temp
880                         continue;
881                 gsub(sysconfdir, "%{_sysconfdir}", $c)
882         }
883
884         for (c = 1; c <= NF; c++) {
885                 if ($c ~ datadir "/automake")
886                         continue;
887                 if ($c ~ datadir "/unsermake")
888                         continue;
889                 if ($c ~ datadir "/file/magic.mime")
890                         continue;
891                 gsub(datadir, "%{_datadir}", $c)
892         }
893
894         gsub("%_sbindir", "%{_sbindir}")
895         gsub("%_mandir", "%{_mandir}")
896         gsub("%name", "%{name}")
897
898         gsub("%{prefix}/share", "%{_datadir}")
899         if (prefix"/share" == datadir)
900                 gsub("%{_prefix}/share", "%{_datadir}")
901
902         gsub(includedir, "%{_includedir}")
903         gsub("%{prefix}/include", "%{_includedir}")
904         if (prefix"/include" == includedir)
905                 gsub("%{_prefix}/include", "%{_includedir}")
906
907         gsub(mandir, "%{_mandir}")
908         if ($0 !~ "%{_datadir}/manual")
909                 gsub("%{_datadir}/man", "%{_mandir}")
910         gsub("%{_prefix}/share/man", "%{_mandir}")
911         gsub("%{prefix}/share/man", "%{_mandir}")
912         gsub("%{prefix}/man", "%{_mandir}")
913         gsub("%{_prefix}/man", "%{_mandir}")
914
915         gsub(infodir, "%{_infodir}")
916         gsub("%{prefix}/info", "%{_infodir}")
917         gsub("%{_prefix}/info", "%{_infodir}")
918
919         if (prefix !~ "/X11R6") {
920                 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
921         }
922
923         gsub(examplesdir, "%{_examplesdir}")
924
925         if (prefix != "/") {
926                 # leave --with-foo=/usr alone
927                 if ($0 !~ "--with.*=.*" prefix) {
928                         for (c = 1; c <= NF; c++) {
929                                 if ($c ~ prefix "/sbin/fix-info-dir")
930                                         continue;
931                                 if ($c ~ prefix "/sbin/webapp")
932                                         continue;
933                                 if ($c ~ prefix "/sbin/chsh")
934                                         continue;
935                                 if ($c ~ prefix "/sbin/usermod")
936                                         continue;
937                                 if ($c ~ prefix "/share/automake")
938                                         continue;
939                                 if ($c ~ prefix "/share/unsermake")
940                                         continue;
941                                 if ($c ~ prefix "/lib/sendmail")
942                                         continue;
943                                 if ($c ~ prefix "/lib/pkgconfig")
944                                         continue;
945                                 gsub(prefix, "%{_prefix}", $c)
946                         }
947                 }
948                 gsub("%{prefix}", "%{_prefix}")
949         }
950
951         gsub("%{PACKAGE_VERSION}", "%{version}")
952         gsub("%{PACKAGE_NAME}", "%{name}")
953
954         gsub("^make$", "%{__make}")
955         gsub("^make ", "%{__make} ")
956         gsub("^gcc ", "%{__cc} ")
957
958         # mandrake specs
959         gsub("^%make$", "%{__make}")
960         gsub("^%make ", "%{__make} ")
961         gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
962         gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
963         gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
964         gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
965         gsub("^%{__install}", "install")
966         gsub("^%{__rm}", "rm")
967         gsub("%optflags", "%{rpmcflags}")
968         gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
969
970         gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
971         gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
972         $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
973         $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
974         $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
975
976         gsub("%_bindir", "%{_bindir}")
977         gsub("%_datadir", "%{_datadir}")
978         gsub("%_iconsdir", "%{_iconsdir}")
979
980         gsub("/usr/src/linux", "%{_kernelsrcdir}")
981         gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
982 }
983
984
985 # insertion sort of A[1..n]
986 # copied from mawk manual
987 function isort(A,n,             i,j,hold) {
988         for (i = 2; i <= n; i++) {
989                 hold = A[j = i]
990                 while (A[j-1] > hold) {
991                         j-- ; A[j+1] = A[j]
992                 }
993                 A[j] = hold
994         }
995         # sentinel A[0] = "" will be created if needed
996 }
997
998
999 function use_files_macros(      i, n, t, a)
1000 {
1001         use_macros()
1002
1003         gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1004         gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1005
1006         # uid/gid nobody is not valid in %files
1007         if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1008                 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1009         }
1010
1011         # replace back
1012         gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1013         gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1014         gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1015         gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1016         gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1017         gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1018         gsub("%{_sysconfdir}/security", "/etc/security")
1019         gsub("%{_sysconfdir}/skel", "/etc/skel")
1020         gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1021         gsub("%{_sysconfdir}/certs", "/etc/certs")
1022         gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1023
1024         # /etc/init.d -> /etc/rc.d/init.d
1025         if (!/^\/etc\/init\.d$/) {
1026                  gsub("/etc/init.d", "/etc/rc.d/init.d")
1027         }
1028
1029         if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1030                 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1031                         $0 = "%attr(754,root,root) " $0
1032                 }
1033                 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1034                         gsub("^%attr\\(... *,", "%attr(754,");
1035                 }
1036         }
1037
1038         if (/lib.+\.so/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1039                 $0 = "%attr(755,root,root) " $0
1040         }
1041
1042         # /etc/sysconfig files
1043         # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1044         # attr not required, allow default 644 attr
1045         if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1046                 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1047                         gsub("%config", "%config(noreplace)")
1048                 }
1049
1050                 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1051                         $NF = "%config(noreplace) " $NF
1052                 }
1053
1054                 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1055                         gsub("^%attr\\(... *,", "%attr(640,");
1056                 }
1057
1058                 if (/\/etc\/sysconfig\// && !/%verify/) {
1059                         gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1060                 }
1061         }
1062
1063         # kill leading zeros
1064         if (/%attr\(0[1-9]/) {
1065                 gsub("%attr\\(0", "%attr(")
1066         }
1067
1068         # sort %verify attrs
1069         if (match($0, /%verify\(not([^)]+)\)/)) {
1070                 t = substr($0, RSTART, RLENGTH)
1071                 gsub(/^%verify\(not |\)$/, "", t)
1072                 n = split(t, a, / /)
1073                 isort(a, n)
1074
1075                 s = "%verify(not"
1076                 for (i = 1 ; i <= n; i++) {
1077                         s = s " " a[i]
1078                 }
1079                 s = s ")"
1080
1081                 gsub(/%verify\(not[^)]+\)/, s)
1082         }
1083
1084         if (/%{_mandir}/) {
1085                 gsub("\.gz$", "*")
1086         }
1087
1088         # locale dir and no %lang -> bad
1089         if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1090                 $(NF + 1) = "# FIXME consider using %find_lang"
1091         }
1092
1093         # atrpms
1094         $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1095         $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1096         $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1097
1098         gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1099         gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1100         gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1101
1102         gsub("%{_datadir}/applications", "%{_desktopdir}");
1103         gsub("%{_datadir}/icons", "%{_iconsdir}");
1104         gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1105 }
1106
1107 function fill(ch, n, i) {
1108         for (i = 0; i < n; i++)
1109                 printf("%c", ch)
1110 }
1111
1112 function format_flush(line, indent, newline, word, first_word) {
1113         first_word = 1
1114         if (format_indent == -1)
1115                 newline = ""
1116         else
1117                 newline = fill(" ", format_indent) "- "
1118
1119         while (match(line, /[^\t ]+/)) {
1120                 word = substr(line, RSTART, RLENGTH)
1121                 if (length(newline) + length(word) + 1 > tw) {
1122                         print newline
1123
1124                         if (format_indent == -1)
1125                                 newline = ""
1126                         else
1127                                 newline = fill(" ", format_indent + 2)
1128                         first_word = 1
1129                 }
1130
1131                 if (first_word) {
1132                         newline = newline word
1133                         first_word = 0
1134                 } else
1135                         newline = newline " " word
1136
1137                 line = substr(line, RSTART + RLENGTH)
1138         }
1139         if (newline ~ /[^\t ]/) {
1140                 print newline
1141         }
1142 }
1143
1144 function cflags(var)
1145 {
1146         if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1147                 removed[var] = 1
1148                 return 0
1149         }
1150
1151         if (!/!\?debug/)
1152                 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
1153         return 1
1154 }
This page took 0.12003 seconds and 4 git commands to generate.