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