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