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