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