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