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