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