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