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