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