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