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