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