]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - adapter.awk
- up from SPECS HEAD, rev 1.324
[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/ && /-n %{name}-%{version}( |$)/) {
210                 sub(/ -n %{name}-%{version}/, "")
211         }
212
213         # invalid in %prep
214         sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
215 }
216
217 ##########
218 # %build #
219 ##########
220 /^%build/, (/^%[a-z]+$/ && !/^%build/ && !/^%((end)?if|else)/) {
221         preamble = 0
222
223         use_macros()
224
225         if (/^automake$/)
226                 sub(/$/, " -a -c")
227
228         if (/LDFLAGS/) {
229                 if (/LDFLAGS="-s"/) {
230                         removed["LDFLAGS"] = 1
231                         next
232                 } else {
233                         split($0, tmp, "LDFLAGS=")
234                         count = split(tmp[2], flags, "\"")
235                         if (flags[1] != "" && flags[1] !~ "!?debug") {
236                                 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
237                                 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
238                                 for (i = 2; i < count; i++)
239                                         $0 = $0 flags[i] "\""
240                         }
241                 }
242         }
243
244         if (/CFLAGS=/)
245                 if (cflags("CFLAGS") == 0)
246                         next
247
248         if (/CXXFLAGS=/)
249                 if (cflags("CXXFLAGS") == 0)
250                         next
251
252         if (/^export /) {
253                 if (removed["LDFLAGS"])
254                         sub(" LDFLAGS", "")
255                 if (removed["CFLAGS"])
256                         sub(" CFLAGS", "")
257                 if (removed["CXXFLAGS"])
258                         sub(" CXXFLAGS", "")
259                 # Is there still something?
260                 if (/^export[ ]*$/)
261                         next
262         }
263
264 }
265
266 ##########
267 # %clean #
268 ##########
269 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
270         did_clean = 1
271         use_macros()
272 }
273
274 ############
275 # %install #
276 ############
277 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
278
279         preamble = 0
280
281         if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
282                 did_rmroot=1
283                 print "rm -rf $RPM_BUILD_ROOT"
284                 next
285         }
286
287         if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
288                 print "rm -rf $RPM_BUILD_ROOT"
289                 did_rmroot=1
290         }
291
292         use_macros()
293
294         # 'install -d' instead 'mkdir -p'
295         if (/mkdir -p/)
296                 sub(/mkdir -p/, "install -d")
297
298         # 'install' instead 'cp -p'
299         if (/cp -p\b/)
300                 sub(/cp -p/, "install")
301
302         # No '-u root' or '-g root' for 'install'
303         if (/^install/ && /-[ug][ \t]*root/)
304                 gsub(/-[ug][ \t]*root /, "")
305
306         if (/^install/ && /-m[ \t]*[0-9]+/)
307                 gsub(/-m[ \t]*[0-9]+ /, "")
308
309         # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
310         if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
311                 next
312
313         # No lines contain 'chmod' if it sets the modes to '644'
314         if ($1 ~ /chmod/ && $2 ~ /644/)
315                 next
316 }
317
318 ##########
319 # %files #
320 ##########
321 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
322         preamble = 0
323
324         if ($0 ~ /^%files/)
325                 defattr = 1
326
327         use_macros()
328         use_files_macros()
329 }
330
331 ##############
332 # %changelog #
333 ##############
334 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
335         preamble = 0
336         has_changelog = 1
337         skip = 0
338         # There should be some CVS keywords on the first line of %changelog.
339         if (boc == 3) {
340                 if (!/PLD Team/)
341                         print "* %{date} PLD Team <feedback@pld-linux.org>" > changelog_file
342                 else
343                         skip = 1
344                 boc = 2
345         }
346         if (boc == 2 && !skip) {
347                 if (!/All persons listed below/) {
348                         printf "All persons listed below can be reached at " > changelog_file
349                         print "<cvs_login>@pld-linux.org\n" > changelog_file
350                 } else
351                         skip = 1
352                 boc = 1
353         }
354         if (boc == 1 && !skip) {
355                 if (!/^$/) {
356                         if (!/\$.*Log:.*\$/)
357                                 print "$" "Log:$" > changelog_file
358                         boc = 0
359                 }
360         }
361         # Define date macro.
362         if (boc == 4) {
363                 if (date == 0) {
364                         printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
365                         print " date +\"%a %b %d %Y\"`)" > changelog_file
366                         date = 1
367                 }
368                 boc = 3
369         }
370
371         sub(/[ \t]+$/, "")
372         if (!/^%[a-z]+$/ || /changelog/)
373                 print > changelog_file
374         else
375                 print
376         next
377 }
378
379 ###########
380 # SCRIPTS #
381 ###########
382 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
383         preamble = 0
384 }
385 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
386         preamble = 0
387 }
388 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
389         preamble = 0
390 }
391 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
392         preamble = 0
393 }
394 /^%triggerin/, (/^%[a-z]+$/ && !/^%triggerin/) {
395         preamble = 0
396 }
397 /^%triggerun/, (/^%[a-z]+$/ && !/^%triggerun/) {
398         preamble = 0
399 }
400 /^%triggerpostun/, (/^%[a-z]+$/ && !/^%triggerpostun/) {
401         preamble = 0
402 }
403 /^%pretrans/, (/^%[a-z]+$/ && !/^%pretrans/) {
404         preamble = 0
405 }
406 /^%posttrans/, (/^%[a-z]+$/ && !/^%posttrans/) {
407         preamble = 0
408 }
409
410 #############
411 # PREAMBLES #
412 #############
413 preamble == 1 {
414         # There should not be a space after the name of field
415         # and before the colon.
416         sub(/[ \t]*:/, ":")
417
418         field = tolower($1)
419         fieldnlower = $1
420         if (field ~ /group(\([^)]+\)):/)
421                 next
422         if (field ~ /group:/) {
423                 format_preamble()
424                 sub(/^Utilities\//,"Applications/",$2)
425                 sub(/^Games/,"Applications/Games",$2)
426                 sub(/^X11\/Games/,"X11/Applications/Games",$2)
427                 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
428                 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
429                 sub(/^X11\/GNOME/,"X11/Applications",$2)
430                 sub(/^X11\/Utilities/,"X11/Applications",$2)
431                 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
432                 sub(/^Shells/,"Applications/Shells",$2)
433
434                 sub(/^[^ \t]*[ \t]*/,"")
435                 Grupa = $0
436
437                 print "Group:\t\t" Grupa
438                 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
439                         x11 = 1
440
441                 byl_plik_z_grupami = 0
442                 byl_opis_grupy = 0
443                 while ((getline linia_grup < groups_file) > 0) {
444                         byl_plik_z_grupami = 1
445                         if (linia_grup == Grupa) {
446                                 byl_opis_grupy = 1
447                                 break
448                         }
449                 }
450
451                 if (!byl_plik_z_grupami)
452                         print "######\t\t" groups_file ": no such file"
453                 else if (!byl_opis_grupy)
454                         print "######\t\t" "Unknown group!"
455
456                 close(groups_file)
457                 next
458         }
459
460         if (field ~ /prereq:/) {
461                 $1 = "Requires:"
462                 $(NF + 1) = " # FIXME add Requires(scriptlet) -adapter.awk"
463         }
464
465         if (field ~ /packager:|distribution:|docdir:|prefix:/)
466                 next
467
468         if (field ~ /buildroot:/)
469                 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
470
471         # Use "License" instead of "Copyright" if it is (L)GPL or BSD
472         if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
473                 $1 = "License:"
474
475         if (field ~ /name:/)
476                 name = $2
477
478         if (field ~ /version:/)
479                 version = $2
480
481         if (field ~ /serial:/)
482                 $1 = "Epoch:"
483
484         # Use %{name} and %{version} in the filenames in "Source:"
485         if (field ~ /^source/ || field ~ /patch/) {
486                 n = split($2, url, /\//)
487                 if (url[n] ~ /\.gz$/) {
488                         url[n+1] = ".gz" url[n+1]
489                         sub(/\.gz$/,"",url[n])
490                 }
491                 if (url[n] ~ /\.zip$/) {
492                         url[n+1] = ".zip" url[n+1]
493                         sub(/\.zip$/,"",url[n])
494                 }
495                 if (url[n] ~ /\.tar$/) {
496                         url[n+1] = ".tar" url[n+1]
497                         sub(/\.tar$/,"",url[n])
498                 }
499                 if (url[n] ~ /\.patch$/) {
500                         url[n+1] = ".patch" url[n+1]
501                         sub(/\.patch$/,"",url[n])
502                 }
503                 if (url[n] ~ /\.bz2$/) {
504                         url[n+1] = ".bz2" url[n+1]
505                         sub(/\.bz2$/,"",url[n])
506                 }
507                 if (url[n] ~ /\.logrotate$/) {
508                         url[n+1] = ".logrotate" url[n+1]
509                         sub(/\.logrotate$/,"",url[n])
510                 }
511                 if (url[n] ~ /\.pamd$/) {
512                         url[n+1] = ".pamd" url[n+1]
513                         sub(/\.pamd$/,"",url[n])
514                 }
515
516                 # allow %{name} just in last url component
517                 s = ""
518                 for (i = 1; i <= n; i++) {
519                         url[i] = fixedsub("%{name}", name, url[i])
520                         if (s) {
521                                 s = s "/" url[i]
522                         } else {
523                                 s = url[i]
524                         }
525                 }
526                 $2 = s url[n+1]
527
528                 filename = url[n]
529                 url[n] = fixedsub(name, "%{name}", url[n])
530                 if (field ~ /source/) {
531                         url[n] = fixedsub(version, "%{version}", url[n])
532                         if (_beta) {
533                                 url[n] = fixedsub(_beta, "%{_beta}", url[n])
534                         }
535                         if (_rc) {
536                                 url[n] = fixedsub(_rc, "%{_rc}", url[n])
537                         }
538                         if (_snap) {
539                                 url[n] = fixedsub(_snap, "%{_snap}", url[n])
540                         }
541                 }
542                 $2 = fixedsub(filename, url[n], $2)
543
544                 # sourceforge urls
545                 sub("[?]use_mirror=.*$", "", $2);
546                 sub("[?]download$", "", $2);
547                 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
548
549                 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
550                 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
551         }
552
553
554         if (field ~ /^source:/)
555                 $1 = "Source0:"
556
557         if (field ~ /patch:/)
558                 $1 = "Patch0:"
559
560         format_preamble()
561
562         if ($1 ~ /%define/) {
563                 # Do not add %define of _prefix if it already is.
564                 if ($2 ~ /^_prefix/) {
565                         sub("^"prefix, $3, bindir)
566                         sub("^"prefix, $3, sbindir)
567                         sub("^"prefix, $3, libdir)
568                         sub("^"prefix, $3, datadir)
569                         sub("^"prefix, $3, includedir)
570                         prefix = $3
571                 }
572                 if ($2 ~ /_bindir/ && !/_sbindir/)
573                         bindir = $3
574                 if ($2 ~ /_sbindir/)
575                         sbindir = $3
576                 if ($2 ~ /_libdir/)
577                         libdir = $3
578                 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
579                         sysconfdir = $3
580                 if ($2 ~ /_datadir/)
581                         datadir = $3
582                 if ($2 ~ /_includedir/)
583                         includedir = $3
584                 if ($2 ~ /_mandir/)
585                         mandir = $3
586                 if ($2 ~ /_infodir/)
587                         infodir = $3
588
589                 if ($2 ~ /_beta/)
590                         _beta = $3
591                 if ($2 ~ /_rc/)
592                         _rc = $3
593                 if ($2 ~ /_snap/)
594                         _snap = $3
595         }
596
597         if (field ~ /buildrequires:/) {
598                 # obsolete
599                 if ($2 ~ /rpm-pythonprov/) {
600                         next
601                 }
602         }
603 }
604
605 # main() ;-)
606 {
607         preamble = 1
608
609         sub(/[ \t]+$/, "")
610         print
611 }
612
613
614 END {
615         if (do_not_touch_anything)
616                 exit 0
617
618         close(changelog_file)
619         while ((getline < changelog_file) > 0)
620                 print
621         system("rm -f " changelog_file)
622
623         if (did_clean == 0) {
624                 print ""
625                 print "%clean"
626                 print "rm -rf $RPM_BUILD_ROOT"
627         }
628
629         if (date == 0) {
630                 print ""
631                 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
632         }
633
634         if (has_changelog == 0)
635                 print "%changelog"
636
637         if (boc > 2)
638                 print "* %{date} PLD Team <feedback@pld-linux.org>"
639         if (boc > 1) {
640                 printf "All persons listed below can be reached at "
641                 print "<cvs_login>@pld-linux.org\n"
642         }
643         if (boc > 0)
644                 print "$" "Log:$"
645 }
646
647 function fixedsub(s1,s2,t, ind) {
648 # substitutes fixed strings (not regexps)
649         if (ind = index(t,s1))
650                 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
651         return t
652 }
653
654 # There should be one or two tabs after the colon.
655 function format_preamble()
656 {
657         sub(/:[ \t]*/, ":")
658         if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
659                 if (RLENGTH < 8)
660                         sub(/:/, ":\t\t")
661                 else
662                         sub(/:/, ":\t")
663         }
664 }
665
666 # Replace directly specified directories with macros
667 function use_macros()
668 {
669         gsub(perl_sitearch, "%{perl_sitearch}")
670         gsub(perl_archlib, "%{perl_archlib}")
671         gsub(perl_privlib, "%{perl_privlib}")
672         gsub(perl_vendorlib, "%{perl_vendorlib}")
673         gsub(perl_vendorarch, "%{perl_vendorarch}")
674         gsub(perl_sitelib, "%{perl_sitelib}")
675         
676         gsub(py_sitescriptdir, "%{py_sitescriptdir}")
677
678         gsub(bindir, "%{_bindir}")
679         gsub("%{prefix}/bin", "%{_bindir}")
680         if(prefix"/bin" == bindir)
681                 gsub("%{_prefix}/bin", "%{_bindir}")
682
683         for (c = 1; c <= NF; c++) {
684                 if ($c ~ sbindir "/fix-info-dir")
685                         continue;
686                 gsub(sbindir, "%{_sbindir}", $c)
687         }
688
689         gsub("%{prefix}/sbin", "%{_sbindir}")
690         if (prefix"/sbin" == sbindir)
691                 gsub("%{_prefix}/sbin", "%{_sbindir}")
692
693         for (c = 1; c <= NF; c++) {
694                 if ($c ~ sysconfdir "/{?cron.")
695                         continue;
696                 if ($c ~ sysconfdir "/{?crontab.d")
697                         continue;
698                 if ($c ~ sysconfdir "/{?logrotate.d")
699                         continue;
700                 if ($c ~ sysconfdir "/{?pam.d")
701                         continue;
702                 if ($c ~ sysconfdir "/{?profile.d")
703                         continue;
704                 if ($c ~ sysconfdir "/{?rc.d")
705                         continue;
706                 if ($c ~ sysconfdir "/{?security")
707                         continue;
708                 if ($c ~ sysconfdir "/{?skel")
709                         continue;
710                 if ($c ~ sysconfdir "/{?sysconfig")
711                         continue;
712                 if ($c ~ sysconfdir "/{?certs")
713                         continue;
714                 gsub(sysconfdir, "%{_sysconfdir}", $c)
715         }
716
717         for (c = 1; c <= NF; c++) {
718                 if ($c ~ datadir "/automake")
719                         continue;
720                 if ($c ~ datadir "/unsermake")
721                         continue;
722                 gsub(datadir, "%{_datadir}", $c)
723         }
724
725
726         gsub("%{prefix}/share", "%{_datadir}")
727         if (prefix"/share" == datadir)
728                 gsub("%{_prefix}/share", "%{_datadir}")
729
730         gsub(includedir, "%{_includedir}")
731         gsub("%{prefix}/include", "%{_includedir}")
732         if (prefix"/include" == includedir)
733                 gsub("%{_prefix}/include", "%{_includedir}")
734
735         gsub(mandir, "%{_mandir}")
736         if ($0 !~ "%{_datadir}/manual")
737                 gsub("%{_datadir}/man", "%{_mandir}")
738         gsub("%{_prefix}/share/man", "%{_mandir}")
739         gsub("%{prefix}/share/man", "%{_mandir}")
740         gsub("%{prefix}/man", "%{_mandir}")
741         gsub("%{_prefix}/man", "%{_mandir}")
742
743         gsub(infodir, "%{_infodir}")
744         gsub("%{prefix}/info", "%{_infodir}")
745         gsub("%{_prefix}/info", "%{_infodir}")
746
747         if (prefix !~ "/X11R6") {
748                 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
749         }
750
751         gsub(examplesdir, "%{_examplesdir}")
752
753         if (prefix != "/") {
754                 for (c = 1; c <= NF; c++) {
755                         if ($c ~ prefix "/sbin/fix-info-dir")
756                                 continue;
757                         if ($c ~ prefix "/share/automake")
758                                 continue;
759                         if ($c ~ prefix "/share/unsermake")
760                                 continue;
761                         gsub(prefix, "%{_prefix}", $c)
762                 }
763                 gsub("%{prefix}", "%{_prefix}")
764         }
765
766         gsub("%{PACKAGE_VERSION}", "%{version}")
767         gsub("%{PACKAGE_NAME}", "%{name}")
768
769         # we can move files between the dirs below
770         if ($0 !~ "%{_applnkdir}") {
771                 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
772         }
773
774         gsub("^make$", "%{__make}")
775         gsub("^make ", "%{__make} ")
776
777         # mandrake specs
778         gsub("^%make$", "%{__make}")
779         gsub("^%make ", "%{__make} ")
780         gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
781         gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
782         gsub("%optflags", "%{rpmcflags}")
783         gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
784
785         gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
786         gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
787         gsub("%buildroot", "$RPM_BUILD_ROOT")
788         gsub("%_bindir", "%{_bindir}")
789         gsub("%_datadir", "%{_datadir}")
790         gsub("%_iconsdir", "%{_iconsdir}")
791
792         gsub("/usr/src/linux", "%{_kernelsrcdir}")
793         gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
794 }
795
796
797 # insertion sort of A[1..n]
798 # copied from mawk manual
799 function isort(A,n,             i,j,hold) {
800         for (i = 2; i <= n; i++) {
801                 hold = A[j = i]
802                 while (A[j-1] > hold) {
803                         j-- ; A[j+1] = A[j]
804                 }
805                 A[j] = hold
806         }
807         # sentinel A[0] = "" will be created if needed
808 }
809
810
811 function use_files_macros(      i, n, t, a)
812 {
813         gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
814         gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
815
816         # replace back
817         gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
818         gsub("%{_sysconfdir}/crontab\.d", "/etc/cron.d")
819         gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
820         gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
821         gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
822         gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
823         gsub("%{_sysconfdir}/security", "/etc/security")
824         gsub("%{_sysconfdir}/skel", "/etc/skel")
825         gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
826         gsub("%{_sysconfdir}/certs", "/etc/certs")
827         gsub("%{_sysconfdir}/init.d", "/etc/init.d")
828
829         # /etc/init.d -> /etc/rc.d/init.d
830         if (!/^\/etc\/init\.d$/) {
831                  gsub("/etc/init.d", "/etc/rc.d/init.d")
832         }
833
834         if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
835                 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
836                         $0 = "%attr(754,root,root) " $0
837                 }
838                 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
839                         gsub("^%attr\\(... *,", "%attr(754,");
840                 }
841         }
842
843         if (/lib.+\.so/ && !/^%attr.*/) {
844                 $0 = "%attr(755,root,root) " $0
845         }
846
847         # /etc/sysconfig files
848         # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
849         # attr not required, allow default 644 attr
850         if (!/network-scripts/) {
851                 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
852                         gsub("%config", "%config(noreplace)")
853                 }
854
855                 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
856                         $NF = "%config(noreplace) " $NF
857                 }
858
859                 if (/\/etc\/sysconfig\// && /%attr\(755/) {
860                         gsub("^%attr\\(... *,", "%attr(640,");
861                 }
862
863                 if (/\/etc\/sysconfig\// && !/%verify/) {
864                         gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
865                 }
866         }
867
868
869         # kill leading zeros
870         gsub("%attr\\(0", "%attr(")
871
872         # sort %verify attrs
873         if (match($0, /%verify\(not([^)]+)\)/)) {
874                 t = substr($0, RSTART, RLENGTH)
875                 gsub(/^%verify\(not |\)$/, "", t)
876                 n = split(t, a, / /)
877                 isort(a, n)
878
879                 s = "%verify(not"
880                 for (i = 1 ; i <= n; i++) {
881                         s = s " " a[i]
882                 }
883                 s = s ")"
884
885                 gsub(/%verify\(not[^)]+\)/, s)
886         }
887
888         if (/%{_mandir}/) {
889                 gsub("\.gz$", "*")
890         }
891 }
892
893 function fill(ch, n, i) {
894         for (i = 0; i < n; i++)
895                 printf("%c", ch)
896 }
897
898 function format_flush(line, indent, newline, word, first_word) {
899         first_word = 1
900         if (format_indent == -1)
901                 newline = ""
902         else
903                 newline = fill(" ", format_indent) "- "
904
905         while (match(line, /[^\t ]+/)) {
906                 word = substr(line, RSTART, RLENGTH)
907                 if (length(newline) + length(word) + 1 > tw) {
908                         print newline
909
910                         if (format_indent == -1)
911                                 newline = ""
912                         else
913                                 newline = fill(" ", format_indent + 2)
914                         first_word = 1
915                 }
916
917                 if (first_word) {
918                         newline = newline word
919                         first_word = 0
920                 } else
921                         newline = newline " " word
922
923                 line = substr(line, RSTART + RLENGTH)
924         }
925         if (newline ~ /[^\t ]/) {
926                 print newline
927         }
928 }
929
930 function cflags(var)
931 {
932         if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
933                 removed[var] = 1
934                 return 0
935         }
936
937         if (!/!\?debug/)
938                 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
939         return 1
940 }
This page took 0.134043 seconds and 3 git commands to generate.