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