]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - adapter.awk
- fix Groups
[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         if (/CC=%{__cc} /) {
293                 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
294         }
295         
296         # use macros
297         $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
298         $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
299
300         # atrpms
301         $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
302         $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
303 }
304
305 ##########
306 # %clean #
307 ##########
308 /^%clean/, (/^%[a-z]+$/ && !/^%clean/ && !/^%((end)?if|else)/) {
309         did_clean = 1
310         use_macros()
311 }
312
313 ############
314 # %install #
315 ############
316 /^%install/, (/^%[a-z]+$/ && !/^%install/ && !/^%((end)?if|else)/) {
317
318         preamble = 0
319
320         if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+\${?RPM_BUILD_ROOT}?/ && did_rmroot==0) {
321                 did_rmroot=1
322                 print "rm -rf $RPM_BUILD_ROOT"
323                 next
324         }
325
326         if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
327                 print "rm -rf $RPM_BUILD_ROOT"
328                 did_rmroot=1
329         }
330
331         use_macros()
332
333         # 'install -d' instead 'mkdir -p'
334         if (/mkdir -p/)
335                 sub(/mkdir -p/, "install -d")
336
337         # 'install' instead 'cp -p'
338         if (/cp -p\b/)
339                 sub(/cp -p/, "install")
340
341         # No '-u root' or '-g root' for 'install'
342         if (/^install/ && /-[ug][ \t]*root/)
343                 gsub(/-[ug][ \t]*root /, "")
344
345         if (/^install/ && /-m[ \t]*[0-9]+/)
346                 gsub(/-m[ \t]*[0-9]+ /, "")
347
348         # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
349         if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
350                 next
351
352         # No lines contain 'chmod' if it sets the modes to '644'
353         if ($1 ~ /chmod/ && $2 ~ /644/)
354                 next
355
356         # foreign rpms
357         $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
358         $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
359
360         # atrpms
361         $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
362 }
363
364 ##########
365 # %files #
366 ##########
367 /^%files/, (/^%[a-z \-]+$/ && !/^%files/ && !/^%((end)?if|else)/) {
368         preamble = 0
369
370         if ($0 ~ /^%files/)
371                 defattr = 1
372
373         use_macros()
374         use_files_macros()
375 }
376
377 ##############
378 # %changelog #
379 ##############
380 /^%changelog/, (/^%[a-z]+$/ && !/^%changelog/) {
381         preamble = 0
382         has_changelog = 1
383         skip = 0
384         # There should be some CVS keywords on the first line of %changelog.
385         if (boc == 3) {
386                 if ($0 !~ _cvsmailfeedback)
387                         print "* %{date} " _cvsmailfeedback > changelog_file
388                 else
389                         skip = 1
390                 boc = 2
391         }
392         if (boc == 2 && !skip) {
393                 if (!/All persons listed below/) {
394                         printf "All persons listed below can be reached at " > changelog_file
395                         print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
396                 } else
397                         skip = 1
398                 boc = 1
399         }
400         if (boc == 1 && !skip) {
401                 if (!/^$/) {
402                         if (!/\$.*Log:.*\$/)
403                                 print "$" "Log:$" > changelog_file
404                         boc = 0
405                 }
406         }
407         # Define date macro.
408         if (boc == 4) {
409                 if (date == 0) {
410                         printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
411                         print " date +\"%a %b %d %Y\"`)" > changelog_file
412                         date = 1
413                 }
414                 boc = 3
415         }
416
417         sub(/[ \t]+$/, "")
418         if (!/^%[a-z]+$/ || /changelog/)
419                 print > changelog_file
420         else
421                 print
422         next
423 }
424
425 ###########
426 # SCRIPTS #
427 ###########
428 /^%pre/, (/^%[a-z]+$/ && !/^%pre/) {
429         preamble = 0
430
431         # %useradd and %groupadd may not be wrapped
432         if (/%(useradd|groupadd).*\\$/) {
433                 a = $0; getline;
434                 sub(/^[\s\t]*/, "");
435                 $0 = substr(a, 1, length(a) - 1) $0;
436         }
437 }
438
439 /^%post/, (/^%[a-z]+$/ && !/^%post/) {
440         preamble = 0
441 }
442 /^%preun/, (/^%[a-z]+$/ && !/^%preun/) {
443         preamble = 0
444 }
445 /^%postun/, (/^%[a-z]+$/ && !/^%postun/) {
446         preamble = 0
447 }
448 /^%triggerin/, (/^%[a-z]+$/ && !/^%triggerin/) {
449         preamble = 0
450 }
451 /^%triggerun/, (/^%[a-z]+$/ && !/^%triggerun/) {
452         preamble = 0
453 }
454 /^%triggerpostun/, (/^%[a-z]+$/ && !/^%triggerpostun/) {
455         preamble = 0
456 }
457 /^%pretrans/, (/^%[a-z]+$/ && !/^%pretrans/) {
458         preamble = 0
459 }
460 /^%posttrans/, (/^%[a-z]+$/ && !/^%posttrans/) {
461         preamble = 0
462 }
463
464 #############
465 # PREAMBLES #
466 #############
467 preamble == 1 {
468         # There should not be a space after the name of field
469         # and before the colon.
470         sub(/[ \t]*:/, ":")
471
472         if (/^%perl_module_wo_prefix/) {
473                 name = $2
474                 version = $3
475                 release = "0." fixedsub(".%{disttag}.at", "", $4)
476         }
477
478         field = tolower($1)
479         fieldnlower = $1
480         if (field ~ /summary:/) {
481                 sub(/\.$/, "", $0);
482         }
483         if (field ~ /group(\([^)]+\)):/)
484                 next
485         if (field ~ /group:/) {
486                 format_preamble()
487                 sub(/^Utilities\//,"Applications/",$2)
488                 sub(/^Games/,"Applications/Games",$2)
489                 sub(/^X11\/Games/,"X11/Applications/Games",$2)
490                 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries",$2)
491                 sub(/^X11\/GNOME\/Applications/,"X11/Applications",$2)
492                 sub(/^X11\/GNOME/,"X11/Applications",$2)
493                 sub(/^X11\/Utilities/,"X11/Applications",$2)
494                 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy",$2)
495                 sub(/^Shells/,"Applications/Shells",$2)
496
497                 sub(/^[^ \t]*[ \t]*/,"")
498                 Grupa = $0
499
500                 sub(/^System Environment\/Libraries/, "Libraries", Grupa)
501                 sub(/^System Environment\/Daemons/, "Daemons", Grupa)
502
503                 print "Group:\t\t" Grupa
504                 if (Grupa ~ /^X11/ && x11 == 0) # Is it X11 application?
505                         x11 = 1
506
507                 byl_plik_z_grupami = 0
508                 byl_opis_grupy = 0
509                 while ((getline linia_grup < groups_file) > 0) {
510                         byl_plik_z_grupami = 1
511                         if (linia_grup == Grupa) {
512                                 byl_opis_grupy = 1
513                                 break
514                         }
515                 }
516
517                 if (!byl_plik_z_grupami)
518                         print "######\t\t" groups_file ": no such file"
519                 else if (!byl_opis_grupy)
520                         print "######\t\t" "Unknown group!"
521
522                 close(groups_file)
523                 next
524         }
525
526         if (field ~ /prereq:/) {
527                 $1 = "Requires:"
528                 $(NF + 1) = " # FIXME add Requires(scriptlet) -adapter.awk"
529         }
530
531         # split (build)requires on commas
532         if (field ~ /requires:/ && $0 ~ /,/) {
533                 l = substr($0, index($0, $2));
534                 n = split(l, p, / *, */);
535                 for (i in p) {
536                         printf("%s\t%s\n", $1, p[i]);
537                 }
538                 next;
539         }
540
541         if (field ~ /packager:|distribution:|docdir:|prefix:/)
542                 next
543
544         if (field ~ /buildroot:/)
545                 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
546
547         # Use "License" instead of "Copyright" if it is (L)GPL or BSD
548         if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
549                 $1 = "License:"
550
551         if (field ~ /name:/) {
552                 if ($2 == "%{name}" && name) {
553                         $2 = name
554                 }
555                 name = $2
556                 name_seen = 1;
557         }
558
559         if (field ~ /version:/) {
560                 if ($2 == "%{version}" && version) {
561                         $2 = version
562                 }
563                 version = $2
564                 version_seen = 1;
565         }
566
567         if (field ~ /release:/) {
568                 if ($2 == "%{release}" && release) {
569                         $2 = release
570                 }
571                 release = $2
572                 release_seen = 1;
573         }
574
575         if (field ~ /serial:/)
576                 $1 = "Epoch:"
577
578         # proper caps
579         if (field ~ /^url:$/)
580                 $1 = "URL:"
581
582         # Use %{name} and %{version} in the filenames in "Source:"
583         if (field ~ /^source/ || field ~ /patch/) {
584                 n = split($2, url, /\//)
585                 if (url[n] ~ /\.gz$/) {
586                         url[n+1] = ".gz" url[n+1]
587                         sub(/\.gz$/,"",url[n])
588                 }
589                 if (url[n] ~ /\.zip$/) {
590                         url[n+1] = ".zip" url[n+1]
591                         sub(/\.zip$/,"",url[n])
592                 }
593                 if (url[n] ~ /\.tar$/) {
594                         url[n+1] = ".tar" url[n+1]
595                         sub(/\.tar$/,"",url[n])
596                 }
597                 if (url[n] ~ /\.patch$/) {
598                         url[n+1] = ".patch" url[n+1]
599                         sub(/\.patch$/,"",url[n])
600                 }
601                 if (url[n] ~ /\.bz2$/) {
602                         url[n+1] = ".bz2" url[n+1]
603                         sub(/\.bz2$/,"",url[n])
604                 }
605                 if (url[n] ~ /\.logrotate$/) {
606                         url[n+1] = ".logrotate" url[n+1]
607                         sub(/\.logrotate$/,"",url[n])
608                 }
609                 if (url[n] ~ /\.pamd$/) {
610                         url[n+1] = ".pamd" url[n+1]
611                         sub(/\.pamd$/,"",url[n])
612                 }
613
614                 # allow %{name} just in last url component
615                 s = ""
616                 for (i = 1; i <= n; i++) {
617                         url[i] = fixedsub("%{name}", name, url[i])
618                         if (s) {
619                                 s = s "/" url[i]
620                         } else {
621                                 s = url[i]
622                         }
623                 }
624                 $2 = s url[n+1]
625
626                 filename = url[n]
627                 if (name) {
628                         url[n] = fixedsub(name, "%{name}", url[n])
629                 }
630                 if (field ~ /source/) {
631                         if (version) {
632                                 url[n] = fixedsub(version, "%{version}", url[n])
633                         }
634                         if (_beta) {
635                                 url[n] = fixedsub(_beta, "%{_beta}", url[n])
636                         }
637                         if (_rc) {
638                                 url[n] = fixedsub(_rc, "%{_rc}", url[n])
639                         }
640                         if (_snap) {
641                                 url[n] = fixedsub(_snap, "%{_snap}", url[n])
642                         }
643                 }
644                 $2 = fixedsub(filename, url[n], $2)
645
646                 # sourceforge urls
647                 sub("[?]use_mirror=.*$", "", $2);
648                 sub("[?]download$", "", $2);
649                 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
650
651                 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
652                 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
653                 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
654         }
655
656
657         if (field ~ /^source:/)
658                 $1 = "Source0:"
659
660         if (field ~ /patch:/)
661                 $1 = "Patch0:"
662
663         format_preamble()
664
665         if ($1 ~ /%define/) {
666                 # Do not add %define of _prefix if it already is.
667                 if ($2 ~ /^_prefix/) {
668                         sub("^"prefix, $3, bindir)
669                         sub("^"prefix, $3, sbindir)
670                         sub("^"prefix, $3, libdir)
671                         sub("^"prefix, $3, datadir)
672                         sub("^"prefix, $3, includedir)
673                         prefix = $3
674                 }
675
676                 if ($2 ~ /_bindir/ && !/_sbindir/)
677                         bindir = $3
678                 if ($2 ~ /_sbindir/)
679                         sbindir = $3
680                 if ($2 ~ /_libdir/)
681                         libdir = $3
682                 if ($2 ~ /_sysconfdir/ && $3 !~ /^%\(/)
683                         sysconfdir = $3
684                 if ($2 ~ /_datadir/)
685                         datadir = $3
686                 if ($2 ~ /_includedir/)
687                         includedir = $3
688                 if ($2 ~ /_mandir/)
689                         mandir = $3
690                 if ($2 ~ /_infodir/)
691                         infodir = $3
692
693                 if ($2 ~ /^_beta$/)
694                         _beta = $3
695                 if ($2 ~ /^_rc$/)
696                         _rc = $3
697                 if ($2 ~ /^_snap$/)
698                         _snap = $3
699
700                 if ($2 ~ /^name$/)
701                         name = $3
702                 if ($2 ~ /^version$/)
703                         version = $3
704                 if ($2 ~ /^release$/)
705                         release = $3
706         }
707
708         if (field ~ /requires/) {
709                 # atrpms
710                 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
711         }
712 }
713
714 # main() ;-)
715 {
716         preamble = 1
717
718         sub(/[ \t]+$/, "")
719         print
720
721         if (name_seen == 0 && name) {
722                 print "Name:\t" name
723                 name_seen = 1
724         }
725
726         if (version_seen == 0 && version) {
727                 print "Version:\t" version
728                 version_seen = 1
729         }
730
731         if (release_seen == 0 && release) {
732                 print "Release:\t" release
733                 release_seen = 1
734         }
735 }
736
737
738 END {
739         if (do_not_touch_anything)
740                 exit 0
741
742         close(changelog_file)
743         while ((getline < changelog_file) > 0)
744                 print
745         system("rm -f " changelog_file)
746
747
748
749         if (did_clean == 0) {
750                 print ""
751                 print "%clean"
752                 print "rm -rf $RPM_BUILD_ROOT"
753         }
754
755         if (date == 0) {
756                 print ""
757                 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
758         }
759
760         if (has_changelog == 0)
761                 print "%changelog"
762
763         if (boc > 2)
764                 print "* %{date} PLD Team <feedback@pld-linux.org>"
765         if (boc > 1) {
766                 printf "All persons listed below can be reached at "
767                 print "<cvs_login>@pld-linux.org\n"
768         }
769         if (boc > 0)
770                 print "$" "Log:$"
771 }
772
773 function fixedsub(s1,s2,t, ind) {
774 # substitutes fixed strings (not regexps)
775         if (ind = index(t,s1))
776                 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
777         return t
778 }
779
780 # There should be one or two tabs after the colon.
781 function format_preamble()
782 {
783         sub(/:[ \t]*/, ":")
784         if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
785                 if (RLENGTH < 8)
786                         sub(/:/, ":\t\t")
787                 else
788                         sub(/:/, ":\t")
789         }
790 }
791
792 # Replace directly specified directories with macros
793 function use_macros()
794 {
795         gsub(perl_sitearch, "%{perl_sitearch}")
796         gsub(perl_archlib, "%{perl_archlib}")
797         gsub(perl_privlib, "%{perl_privlib}")
798         gsub(perl_vendorlib, "%{perl_vendorlib}")
799         gsub(perl_vendorarch, "%{perl_vendorarch}")
800         gsub(perl_sitelib, "%{perl_sitelib}")
801         
802         gsub(py_sitescriptdir, "%{py_sitescriptdir}")
803
804         gsub(bindir, "%{_bindir}")
805         gsub("%{prefix}/bin", "%{_bindir}")
806         if(prefix"/bin" == bindir)
807                 gsub("%{_prefix}/bin", "%{_bindir}")
808
809         for (c = 1; c <= NF; c++) {
810                 if ($c ~ sbindir "/fix-info-dir")
811                         continue;
812                 gsub(sbindir, "%{_sbindir}", $c)
813         }
814
815         gsub("%{prefix}/sbin", "%{_sbindir}")
816         if (prefix"/sbin" == sbindir)
817                 gsub("%{_prefix}/sbin", "%{_sbindir}")
818
819         for (c = 1; c <= NF; c++) {
820                 if ($c ~ sysconfdir "/{?cron.")
821                         continue;
822                 if ($c ~ sysconfdir "/{?crontab.d")
823                         continue;
824                 if ($c ~ sysconfdir "/{?env.d")
825                         continue;
826                 if ($c ~ sysconfdir "/{?logrotate.d")
827                         continue;
828                 if ($c ~ sysconfdir "/{?pam.d")
829                         continue;
830                 if ($c ~ sysconfdir "/{?profile.d")
831                         continue;
832                 if ($c ~ sysconfdir "/{?rc.d")
833                         continue;
834                 if ($c ~ sysconfdir "/{?security")
835                         continue;
836                 if ($c ~ sysconfdir "/{?skel")
837                         continue;
838                 if ($c ~ sysconfdir "/{?sysconfig")
839                         continue;
840                 if ($c ~ sysconfdir "/{?certs")
841                         continue;
842                 gsub(sysconfdir, "%{_sysconfdir}", $c)
843         }
844
845         for (c = 1; c <= NF; c++) {
846                 if ($c ~ datadir "/automake")
847                         continue;
848                 if ($c ~ datadir "/unsermake")
849                         continue;
850                 if ($c ~ datadir "/file/magic.mime")
851                         continue;
852                 gsub(datadir, "%{_datadir}", $c)
853         }
854
855         gsub("%_sbindir", "%{_sbindir}")
856         gsub("%_mandir", "%{_mandir}")
857         gsub("%name", "%{name}")
858
859         gsub("%{prefix}/share", "%{_datadir}")
860         if (prefix"/share" == datadir)
861                 gsub("%{_prefix}/share", "%{_datadir}")
862
863         gsub(includedir, "%{_includedir}")
864         gsub("%{prefix}/include", "%{_includedir}")
865         if (prefix"/include" == includedir)
866                 gsub("%{_prefix}/include", "%{_includedir}")
867
868         gsub(mandir, "%{_mandir}")
869         if ($0 !~ "%{_datadir}/manual")
870                 gsub("%{_datadir}/man", "%{_mandir}")
871         gsub("%{_prefix}/share/man", "%{_mandir}")
872         gsub("%{prefix}/share/man", "%{_mandir}")
873         gsub("%{prefix}/man", "%{_mandir}")
874         gsub("%{_prefix}/man", "%{_mandir}")
875
876         gsub(infodir, "%{_infodir}")
877         gsub("%{prefix}/info", "%{_infodir}")
878         gsub("%{_prefix}/info", "%{_infodir}")
879
880         if (prefix !~ "/X11R6") {
881                 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
882         }
883
884         gsub(examplesdir, "%{_examplesdir}")
885
886         if (prefix != "/") {
887                 # leave --with-foo=/usr alone
888                 if ($0 !~ "--with.*=.*" prefix) {
889                         for (c = 1; c <= NF; c++) {
890                                 if ($c ~ prefix "/sbin/fix-info-dir")
891                                         continue;
892                                 if ($c ~ prefix "/share/automake")
893                                         continue;
894                                 if ($c ~ prefix "/share/unsermake")
895                                         continue;
896                                 if ($c ~ prefix "/lib/sendmail")
897                                         continue;
898                                 if ($c ~ prefix "/lib/pkgconfig")
899                                         continue;
900                                 gsub(prefix, "%{_prefix}", $c)
901                         }
902                 }
903                 gsub("%{prefix}", "%{_prefix}")
904         }
905
906         gsub("%{PACKAGE_VERSION}", "%{version}")
907         gsub("%{PACKAGE_NAME}", "%{name}")
908
909         gsub("^make$", "%{__make}")
910         gsub("^make ", "%{__make} ")
911         gsub("^gcc ", "%{__cc} ")
912
913         # mandrake specs
914         gsub("^%make$", "%{__make}")
915         gsub("^%make ", "%{__make} ")
916         gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
917         gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
918         gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
919         gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
920         gsub("^%{__install}", "install")
921         gsub("^%{__rm}", "rm")
922         gsub("%optflags", "%{rpmcflags}")
923         gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
924
925         gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
926         gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
927         $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
928         $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
929         $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
930
931         gsub("%_bindir", "%{_bindir}")
932         gsub("%_datadir", "%{_datadir}")
933         gsub("%_iconsdir", "%{_iconsdir}")
934
935         gsub("/usr/src/linux", "%{_kernelsrcdir}")
936         gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
937 }
938
939
940 # insertion sort of A[1..n]
941 # copied from mawk manual
942 function isort(A,n,             i,j,hold) {
943         for (i = 2; i <= n; i++) {
944                 hold = A[j = i]
945                 while (A[j-1] > hold) {
946                         j-- ; A[j+1] = A[j]
947                 }
948                 A[j] = hold
949         }
950         # sentinel A[0] = "" will be created if needed
951 }
952
953
954 function use_files_macros(      i, n, t, a)
955 {
956         gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
957         gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
958
959         # uid/gid nobody is not valid in %files
960         if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
961                 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
962         }
963
964         # replace back
965         gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
966         gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
967         gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
968         gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
969         gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
970         gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
971         gsub("%{_sysconfdir}/security", "/etc/security")
972         gsub("%{_sysconfdir}/skel", "/etc/skel")
973         gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
974         gsub("%{_sysconfdir}/certs", "/etc/certs")
975         gsub("%{_sysconfdir}/init.d", "/etc/init.d")
976
977         # /etc/init.d -> /etc/rc.d/init.d
978         if (!/^\/etc\/init\.d$/) {
979                  gsub("/etc/init.d", "/etc/rc.d/init.d")
980         }
981
982         if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
983                 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
984                         $0 = "%attr(754,root,root) " $0
985                 }
986                 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
987                         gsub("^%attr\\(... *,", "%attr(754,");
988                 }
989         }
990
991         if (/lib.+\.so/ && !/^%attr.*/) {
992                 $0 = "%attr(755,root,root) " $0
993         }
994
995         # /etc/sysconfig files
996         # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
997         # attr not required, allow default 644 attr
998         if (!/network-scripts/) {
999                 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1000                         gsub("%config", "%config(noreplace)")
1001                 }
1002
1003                 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1004                         $NF = "%config(noreplace) " $NF
1005                 }
1006
1007                 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1008                         gsub("^%attr\\(... *,", "%attr(640,");
1009                 }
1010
1011                 if (/\/etc\/sysconfig\// && !/%verify/) {
1012                         gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1013                 }
1014         }
1015
1016         # kill leading zeros
1017         if (/%attr\(0[1-9]/) {
1018                 gsub("%attr\\(0", "%attr(")
1019         }
1020
1021         # sort %verify attrs
1022         if (match($0, /%verify\(not([^)]+)\)/)) {
1023                 t = substr($0, RSTART, RLENGTH)
1024                 gsub(/^%verify\(not |\)$/, "", t)
1025                 n = split(t, a, / /)
1026                 isort(a, n)
1027
1028                 s = "%verify(not"
1029                 for (i = 1 ; i <= n; i++) {
1030                         s = s " " a[i]
1031                 }
1032                 s = s ")"
1033
1034                 gsub(/%verify\(not[^)]+\)/, s)
1035         }
1036
1037         if (/%{_mandir}/) {
1038                 gsub("\.gz$", "*")
1039         }
1040
1041         # atrpms
1042         $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1043         $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1044         $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1045
1046         gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1047         gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1048         gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1049 }
1050
1051 function fill(ch, n, i) {
1052         for (i = 0; i < n; i++)
1053                 printf("%c", ch)
1054 }
1055
1056 function format_flush(line, indent, newline, word, first_word) {
1057         first_word = 1
1058         if (format_indent == -1)
1059                 newline = ""
1060         else
1061                 newline = fill(" ", format_indent) "- "
1062
1063         while (match(line, /[^\t ]+/)) {
1064                 word = substr(line, RSTART, RLENGTH)
1065                 if (length(newline) + length(word) + 1 > tw) {
1066                         print newline
1067
1068                         if (format_indent == -1)
1069                                 newline = ""
1070                         else
1071                                 newline = fill(" ", format_indent + 2)
1072                         first_word = 1
1073                 }
1074
1075                 if (first_word) {
1076                         newline = newline word
1077                         first_word = 0
1078                 } else
1079                         newline = newline " " word
1080
1081                 line = substr(line, RSTART + RLENGTH)
1082         }
1083         if (newline ~ /[^\t ]/) {
1084                 print newline
1085         }
1086 }
1087
1088 function cflags(var)
1089 {
1090         if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1091                 removed[var] = 1
1092                 return 0
1093         }
1094
1095         if (!/!\?debug/)
1096                 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
1097         return 1
1098 }
This page took 0.158713 seconds and 4 git commands to generate.