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