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