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