]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - adapter.awk
- adapterize mandrake specs
[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 }
347 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
348         preamble = 0
349 }
350 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
351         preamble = 0
352 }
353
354 #############
355 # PREAMBLES #
356 #############
357 preamble == 1 {
358         # There should not be a space after the name of field
359         # and before the colon.
360         sub(/[ \t]*:/, ":")
361
362         field = tolower($1)
363         fieldnlower = $1
364         if (field ~ /group(\([^)]+\)):/)
365                 next
366         if (field ~ /group:/) {
367                 format_preamble()
368                 sub(/^Utilities\//,"Applications/",$2)
369                 sub(/^Games/,"Applications/Games",$2)
370                 sub(/^X11\/Games/,"X11/Applications/Games",$2)
371                 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
372                 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
373                 sub(/^X11\/GNOME/,"X11/Applications",$2)
374                 sub(/^X11\/Utilities/,"X11/Applications",$2)
375                 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
376                 sub(/^Shells/,"Applications/Shells",$2)
377
378                 sub(/^[^ \t]*[ \t]*/,"")
379                 Grupa = $0
380
381                 print "Group:\t\t" Grupa
382                 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
383                         x11 = 1
384
385                 byl_plik_z_grupami = 0
386                 byl_opis_grupy = 0
387                 while ((getline linia_grup < groups_file) > 0) {
388                         byl_plik_z_grupami = 1
389                         if (linia_grup == Grupa) {
390                                 byl_opis_grupy = 1
391                                 break
392                         }
393                 }
394
395                 if (!byl_plik_z_grupami)
396                         print "######\t\t" groups_file ": no such file"
397                 else if (!byl_opis_grupy)
398                         print "######\t\t" "Unknown group!"
399
400                 close(groups_file)
401                 next
402         }
403
404         if (field ~ /packager:|distribution:|docdir:|prefix:/)
405                 next
406
407         if (field ~ /buildroot:/)
408                 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
409
410         # Use "License" instead of "Copyright" if it is (L)GPL or BSD
411         if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
412                 $1 = "License:"
413
414         if (field ~ /name:/)
415                 name = $2
416
417         if (field ~ /version:/)
418                 version = $2
419
420         if (field ~ /serial:/)
421                 $1 = "Epoch:"
422
423         # Use %{name} and %{version} in the filenames in "Source:"
424         if (field ~ /^source/ || field ~ /patch/) {
425                 n = split($2, url, /\//)
426                 if (url[n] ~ /\.gz$/) {
427                         url[n+1] = ".gz" url[n+1]
428                         sub(/\.gz$/,"",url[n])
429                 }
430                 if (url[n] ~ /\.zip$/) {
431                         url[n+1] = ".zip" url[n+1]
432                         sub(/\.zip$/,"",url[n])
433                 }
434                 if (url[n] ~ /\.tar$/) {
435                         url[n+1] = ".tar" url[n+1]
436                         sub(/\.tar$/,"",url[n])
437                 }
438                 if (url[n] ~ /\.patch$/) {
439                         url[n+1] = ".patch" url[n+1]
440                         sub(/\.patch$/,"",url[n])
441                 }
442                 if (url[n] ~ /\.bz2$/) {
443                         url[n+1] = ".bz2" url[n+1]
444                         sub(/\.bz2$/,"",url[n])
445                 }
446                 if (url[n] ~ /\.logrotate$/) {
447                         url[n+1] = ".logrotate" url[n+1]
448                         sub(/\.logrotate$/,"",url[n])
449                 }
450                 if (url[n] ~ /\.pamd$/) {
451                         url[n+1] = ".pamd" url[n+1]
452                         sub(/\.pamd$/,"",url[n])
453                 }
454
455                 # allow %{name} just in last url component
456                 s = ""
457                 for (i = 1; i <= n; i++) {
458                         url[i] = fixedsub("%{name}", name, url[i])
459                         if (s) {
460                                 s = s "/" url[i]
461                         } else {
462                                 s = url[i]
463                         }
464                 }
465                 $2 = s url[n+1]
466
467                 filename = url[n]
468                 url[n] = fixedsub(name, "%{name}", url[n])
469                 if (field ~ /source/)
470                         url[n] = fixedsub(version, "%{version}", url[n])
471                 $2 = fixedsub(filename, url[n], $2)
472
473                 # sourceforge urls
474                 sub("[?]use_mirror=.*$", "", $2);
475                 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
476
477                 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
478                 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
479         }
480
481
482         if (field ~ /^source:/)
483                 $1 = "Source0:"
484
485         if (field ~ /patch:/)
486                 $1 = "Patch0:"
487
488         format_preamble()
489
490         if ($1 ~ /%define/) {
491                 # Do not add %define of _prefix if it already is.
492                 if ($2 ~ /^_prefix/) {
493                         sub("^"prefix, $3, bindir)
494                         sub("^"prefix, $3, sbindir)
495                         sub("^"prefix, $3, libdir)
496                         sub("^"prefix, $3, datadir)
497                         sub("^"prefix, $3, includedir)
498                         prefix = $3
499                 }
500                 if ($2 ~ /_bindir/ && !/_sbindir/)
501                         bindir = $3
502                 if ($2 ~ /_sbindir/)
503                         sbindir = $3
504                 if ($2 ~ /_libdir/)
505                         libdir = $3
506                 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
507                         sysconfdir = $3
508                 if ($2 ~ /_datadir/)
509                         datadir = $3
510                 if ($2 ~ /_includedir/)
511                         includedir = $3
512                 if ($2 ~ /_mandir/)
513                         mandir = $3
514                 if ($2 ~ /_infodir/)
515                         infodir = $3
516         }
517
518         if (field ~ /buildrequires:/) {
519                 # obsolete
520                 if ($2 ~ /rpm-pythonprov/) {
521                         next
522                 }
523         }
524 }
525
526
527 # main() ;-)
528 {
529         preamble = 1
530
531         sub(/[ \t]+$/, "")
532         print
533 }
534
535
536 END {
537         if (do_not_touch_anything)
538                 exit 0
539
540         close(changelog_file)
541         while ((getline < changelog_file) > 0)
542                 print
543         system("rm -f " changelog_file)
544
545         if (did_clean == 0) {
546                 print ""
547                 print "%clean"
548                 print "rm -rf $RPM_BUILD_ROOT"
549         }
550
551         if (date == 0) {
552                 print ""
553                 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
554         }
555
556         if (has_changelog == 0)
557                 print "%changelog"
558
559         if (boc > 2)
560                 print "* %{date} PLD Team <feedback@pld-linux.org>"
561         if (boc > 1) {
562                 printf "All persons listed below can be reached at "
563                 print "<cvs_login>@pld-linux.org\n"
564         }
565         if (boc > 0)
566                 print "$" "Log:$"
567 }
568
569 function fixedsub(s1,s2,t, ind) {
570 # substitutes fixed strings (not regexps)
571         if (ind = index(t,s1))
572                 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
573         return t
574 }
575
576 # There should be one or two tabs after the colon.
577 function format_preamble()
578 {
579         sub(/:[ \t]*/, ":")
580         if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
581                 if (RLENGTH < 8)
582                         sub(/:/, ":\t\t")
583                 else
584                         sub(/:/, ":\t")
585         }
586 }
587
588 # Replace directly specified directories with macros
589 function use_macros()
590 {
591         gsub(perl_sitearch, "%{perl_sitearch}")
592         gsub(perl_archlib, "%{perl_archlib}")
593         gsub(perl_privlib, "%{perl_privlib}")
594         gsub(perl_vendorlib, "%{perl_vendorlib}")
595         gsub(perl_vendorarch, "%{perl_vendorarch}")
596         gsub(perl_sitelib, "%{perl_sitelib}")
597         
598         gsub(py_sitescriptdir, "%{py_sitescriptdir}")
599
600         gsub(bindir, "%{_bindir}")
601         gsub("%{prefix}/bin", "%{_bindir}")
602         if(prefix"/bin" == bindir)
603                 gsub("%{_prefix}/bin", "%{_bindir}")
604
605         for (c = 1; c <= NF; c++) {
606                 if ($c ~ sbindir "/fix-info-dir")
607                         continue;
608                 gsub(sbindir, "%{_sbindir}", $c)
609         }
610
611         gsub("%{prefix}/sbin", "%{_sbindir}")
612         if (prefix"/sbin" == sbindir)
613                 gsub("%{_prefix}/sbin", "%{_sbindir}")
614
615         for (c = 1; c <= NF; c++) {
616                 if ($c ~ sysconfdir "/{?cron.")
617                         continue;
618                 if ($c ~ sysconfdir "/{?crontab.d")
619                         continue;
620                 if ($c ~ sysconfdir "/{?logrotate.d")
621                         continue;
622                 if ($c ~ sysconfdir "/{?pam.d")
623                         continue;
624                 if ($c ~ sysconfdir "/{?profile.d")
625                         continue;
626                 if ($c ~ sysconfdir "/{?rc.d")
627                         continue;
628                 if ($c ~ sysconfdir "/{?security")
629                         continue;
630                 if ($c ~ sysconfdir "/{?skel")
631                         continue;
632                 if ($c ~ sysconfdir "/{?sysconfig")
633                         continue;
634                 if ($c ~ sysconfdir "/{?certs")
635                         continue;
636                 gsub(sysconfdir, "%{_sysconfdir}", $c)
637         }
638
639         for (c = 1; c <= NF; c++) {
640                 if ($c ~ datadir "/automake")
641                         continue;
642                 if ($c ~ datadir "/unsermake")
643                         continue;
644                 gsub(datadir, "%{_datadir}", $c)
645         }
646
647
648         gsub("%{prefix}/share", "%{_datadir}")
649         if (prefix"/share" == datadir)
650                 gsub("%{_prefix}/share", "%{_datadir}")
651
652         gsub(includedir, "%{_includedir}")
653         gsub("%{prefix}/include", "%{_includedir}")
654         if (prefix"/include" == includedir)
655                 gsub("%{_prefix}/include", "%{_includedir}")
656
657         gsub(mandir, "%{_mandir}")
658         if ($0 !~ "%{_datadir}/manual")
659                 gsub("%{_datadir}/man", "%{_mandir}")
660         gsub("%{_prefix}/share/man", "%{_mandir}")
661         gsub("%{prefix}/share/man", "%{_mandir}")
662         gsub("%{prefix}/man", "%{_mandir}")
663         gsub("%{_prefix}/man", "%{_mandir}")
664
665         gsub(infodir, "%{_infodir}")
666         gsub("%{prefix}/info", "%{_infodir}")
667         gsub("%{_prefix}/info", "%{_infodir}")
668
669         if (prefix !~ "/X11R6") {
670                 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
671         }
672
673         if (prefix != "/") {
674                 for (c = 1; c <= NF; c++) {
675                         if ($c ~ prefix "/sbin/fix-info-dir")
676                                 continue;
677                         if ($c ~ prefix "/share/automake")
678                                 continue;
679                         if ($c ~ prefix "/share/unsermake")
680                                 continue;
681                         gsub(prefix, "%{_prefix}", $c)
682                 }
683                 gsub("%{prefix}", "%{_prefix}")
684         }
685
686         gsub("%{PACKAGE_VERSION}", "%{version}")
687         gsub("%{PACKAGE_NAME}", "%{name}")
688
689         # we can move files between the dirs below
690         if ($0 !~ "%{_applnkdir}") {
691                 gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
692         }
693
694         gsub("^make$", "%{__make}")
695         gsub("^make ", "%{__make} ")
696
697         # mandrake specs
698         gsub("^%make$", "%{__make}")
699         gsub("^%make ", "%{__make} ")
700         gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
701         gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
702         gsub("%optflags", "%{rpmcflags}")
703         gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
704
705         gsub("/usr/src/linux", "%{_kernelsrcdir}")
706         gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
707 }
708
709
710 # insertion sort of A[1..n]
711 # copied from mawk manual
712 function isort(A,n,             i,j,hold) {
713         for (i = 2; i <= n; i++) {
714                 hold = A[j = i]
715                 while (A[j-1] > hold) {
716                         j-- ; A[j+1] = A[j]
717                 }
718                 A[j] = hold
719         }
720         # sentinel A[0] = "" will be created if needed
721 }
722
723
724 function use_files_macros(      i, n, t, a)
725 {
726         gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
727         gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
728
729         gsub("%{_sysconfdir}\/rc\.d\/init.d", "/etc/rc.d/init.d")
730         gsub("%{_sysconfdir}\/init.d", "/etc/rc.d/init.d")
731         gsub("%{_sysconfdir}\/sysconfig", "/etc/sysconfig")
732
733         if (/\/etc\/rc\.d\/init\.d/) {
734                 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
735                         $0 = "%attr(754,root,root) " $0
736                 }
737                 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
738                         gsub("^%attr\(... *,", "%attr(754,");
739                 }
740         }
741
742
743         if (/lib.+\.so/ && !/^%attr.*/) {
744                 $0 = "%attr(755,root,root) " $0
745         }
746
747         # /etc/sysconfig files
748         # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
749         # attr not required, allow default 644 attr
750         if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
751                 gsub("%config", "%config(noreplace)")
752         }
753
754         if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
755                 $NF = "%config(noreplace) " $NF
756         }
757
758         if (/\/etc\/sysconfig\// && /%attr\(755/) {
759                 gsub("^%attr\(... *,", "%attr(640,");
760         }
761
762         if (/\/etc\/sysconfig\// && !/%verify/) {
763                 gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
764         }
765
766
767         # kill leading zeros
768         gsub("%attr\(0", "%attr(")
769
770         # sort %verify attrs
771         if (match($0, /%verify\(not([^)]+)\)/)) {
772                 t = substr($0, RSTART, RLENGTH)
773                 gsub(/^%verify\(not |\)$/, "", t)
774                 n = split(t, a, / /)
775                 isort(a, n)
776
777                 s = "%verify(not"
778                 for (i = 1 ; i <= n; i++) {
779                         s = s " " a[i]
780                 }
781                 s = s ")"
782
783                 gsub(/%verify\(not[^)]+\)/, s)
784         }
785
786         if (/%{_mandir}/) {
787                 gsub("\.gz$", "*")
788         }
789 }
790
791 function fill(ch, n, i) {
792         for (i = 0; i < n; i++)
793                 printf("%c", ch)
794 }
795
796 function format_flush(line, indent, newline, word, first_word) {
797         first_word = 1
798         if (format_indent == -1)
799                 newline = ""
800         else
801                 newline = fill(" ", format_indent) "- "
802
803         while (match(line, /[^\t ]+/)) {
804                 word = substr(line, RSTART, RLENGTH)
805                 if (length(newline) + length(word) + 1 > tw) {
806                         print newline
807
808                         if (format_indent == -1)
809                                 newline = ""
810                         else
811                                 newline = fill(" ", format_indent + 2)
812                         first_word = 1
813                 }
814
815                 if (first_word) {
816                         newline = newline word
817                         first_word = 0
818                 } else
819                         newline = newline " " word
820
821                 line = substr(line, RSTART + RLENGTH)
822         }
823         if (newline ~ /[^\t ]/) {
824                 print newline
825         }
826 }
827
828 function cflags(var)
829 {
830         if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
831                 removed[var] = 1
832                 return 0
833         }
834
835         if (!/!\?debug/)
836                 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
837         return 1
838 }
This page took 0.137819 seconds and 4 git commands to generate.