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