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