]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - adapter.awk
- 2 tabs after Name:
[packages/rpm-build-tools.git] / adapter.awk
1 #!/bin/awk -f
2 #
3 # This is adapter v0.27. Adapter adapts .spec files for PLD Linux.
4 # $Id$
5 #
6 # Copyright (C) 1999-2006 PLD-Team <feedback@pld-linux.org>
7 # Authors:
8 #       Micha³ Kuratczyk <kura@pld.org.pl>
9 #       Sebastian Zagrodzki <s.zagrodzki@mimuw.edu.pl>
10 #       Tomasz K³oczko <kloczek@rudy.mif.pg.gda.pl>
11 #       Artur Frysiak <wiget@pld-linux.org>
12 #       Michal Kochanowicz <mkochano@pld.org.pl>
13 #       Elan Ruusamä¤e <glen@pld-linux.org>
14 #
15 # See cvs log adapter{,.awk} for list of contributors
16 #
17 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
18
19 # TODO
20 # - parse ../PLD-doc/BuildRequires.txt and setup proper BR epoches?
21 # - add "-nc" option to skip CVS interaction
22 # - sort Summary(XX)
23 # - sort Requires, BuildRequires
24 # - check if %description (lang=C) contains 8bit
25 # - desc wrapping is totally fucked up on global.spec,1.25, dosemu.spec,1.115-
26
27 BEGIN {
28         RPM_SECTIONS = "package|build|changelog|clean|description|install|post|posttrans|postun|pre|prep|pretrans|preun|triggerin|triggerpostun|triggerun|verifyscript|check"
29         SECTIONS = "^%(" RPM_SECTIONS ")"
30
31         PREAMBLE_TAGS = "(Summary|Name|Version|Release|Epoch|License|Group|URL|BuildArch|BuildRoot|Obsoletes|Conflicts|Provides|ExclusiveArch|ExcludeArch|Pre[Rr]eq|(Build)?Requires)"
32
33         preamble = 1            # Is it part of preamble? Default - yes
34         boc = 4                 # Beginning of %changelog
35         bod = 0                 # Beginning of %description
36         tw = 70                 # Descriptions width
37
38         b_idx = 0               # index of BR/R arrays
39
40         # If variable removed, then 1 (for removing it from export)
41         removed["LDFLAGS"] = 0
42         removed["CFLAGS"] = 0
43         removed["CXXFLAGS"] = 0
44
45         # get cvsaddress for changelog section
46         # using rpm macros as too lazy to add ~/.adapterrc parsing support.
47         "rpm --eval '%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'" | getline _cvsmaildomain
48         "rpm --eval '%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'" | getline _cvsmailfeedback
49
50         # If 1, we are inside of comment block (started with /^#%/)
51         comment_block = 0
52
53         # File with rpm groups
54         "rpm --eval %_sourcedir" | getline groups_file
55         groups_file = groups_file "/rpm.groups"
56         system("cd `rpm --eval %_sourcedir`; [ -f rpm.groups ] || cvs up rpm.groups >/dev/null")
57         system("[ -d ../PLD-doc ] && cd ../PLD-doc && ([ -f BuildRequires.txt ] || cvs up BuildRequires.txt >/dev/null)");
58
59         # Temporary file for changelog section
60         changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
61
62         # Load rpm macros
63         "rpm --eval %_prefix"   | getline prefix
64         "rpm --eval %_bindir"   | getline bindir
65         "rpm --eval %_sbindir"  | getline sbindir
66         "rpm --eval %_libdir"   | getline libdir
67         "rpm --eval %_sysconfdir" | getline sysconfdir
68         "rpm --eval %_datadir"  | getline datadir
69         "rpm --eval %_includedir" | getline includedir
70         "rpm --eval %_mandir"   | getline mandir
71         "rpm --eval %_infodir"  | getline infodir
72         "rpm --eval %_examplesdir"      | getline examplesdir
73         "rpm --eval %_defaultdocdir"    | getline docdir
74         "rpm --eval %_desktopdir" | getline desktopdir
75         "rpm --eval %_pixmapsdir" | getline pixmapsdir
76
77         "rpm --eval %perl_sitearch" | getline perl_sitearch
78         "rpm --eval %perl_archlib" | getline perl_archlib
79         "rpm --eval %perl_privlib" | getline perl_privlib
80         "rpm --eval %perl_vendorlib" | getline perl_vendorlib
81         "rpm --eval %perl_vendorarch" | getline perl_vendorarch
82         "rpm --eval %perl_sitelib" | getline perl_sitelib
83
84         "rpm --eval %py_sitescriptdir" | getline py_sitescriptdir
85         "rpm --eval %py_sitedir" | getline py_sitedir
86         "rpm --eval %py_scriptdir " | getline py_scriptdir
87         "rpm --eval %php_pear_dir" | getline php_pear_dir
88         "rpm --eval %tmpdir" | getline tmpdir
89 }
90
91 # There should be a comment with CVS keywords on the first line of file.
92 FNR == 1 {
93         if (!/# \$Revision:/)   # If this line is already OK?
94                 print "# $" "Revision:$, " "$" "Date:$" # No
95         else {
96                 print $0                                # Yes
97                 next            # It is enough for first line
98         }
99 }
100
101 # If the latest line matched /%files/
102 defattr == 1 {
103         if (ENVIRON["SKIP_DEFATTR"] != 1) {
104                 if ($0 !~ /defattr/) {  # If no %defattr
105                         print "%defattr(644,root,root,755)"     # Add it
106                 } else {
107                         $0 = "%defattr(644,root,root,755)"      # Correct mistakes (if any)
108                 }
109         }
110         defattr = 0
111 }
112
113 function b_makekey(a, b,        s) {
114         s = a "" b;
115         # kill bcond
116     gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
117
118         # kill commented out items
119     gsub(/^#[ \t]*/, "", s);
120
121         # force order
122     gsub(/^Summary\(/, "11Summary(", s);
123     gsub(/^Summary/, "10Summary", s);
124     gsub(/^Name/, "2Name", s);
125     gsub(/^Version/, "3Version", s);
126     gsub(/^Release/, "4Release", s);
127     gsub(/^Epoch/, "5Epoch", s);
128     gsub(/^License/, "5License", s);
129     gsub(/^Group/, "6Group", s);
130     gsub(/^URL/, "7URL", s);
131
132     gsub(/^BuildRequires/, "B1BuildRequires", s);
133     gsub(/^BuildConflicts/, "B2BuildConflicts", s);
134     gsub(/^Provides/, "X1Provides", s);
135     gsub(/^Obsoletes/, "X2Obsoletes", s);
136     gsub(/^Conflicts/, "X3Conflicts", s);
137     gsub(/^BuildArch/, "X4BuildArch", s);
138     gsub(/^ExclusiveArch/, "X6ExclusiveArch", s);
139     gsub(/^ExcludeArch/, "X7ExcludeArch", s);
140     gsub(/^BuildRoot/, "X9BuildRoot", s);
141
142 #       printf("%s -> %s\n", a""b, s);
143         return s;
144 }
145
146 # Comments
147 /^#/ && (description == 0) {
148         if (/This file does not like to be adapterized!/) {
149                 print                   # print this message
150                 while (getline)         # print the rest of spec as it is
151                         print
152                 do_not_touch_anything = 1 # do not touch anything in END()
153                 exit 0
154         }
155
156         # Generally, comments are printed without touching
157         sub(/[ \t]+$/, "")
158
159         if (/Source.*md5/) {
160                 print $0
161                 next
162         }
163 }
164
165 /^%define/ {
166         # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
167         if ($2 == "_applnkdir") {
168                 next
169         }
170         if ($2 == "date") {
171                 date = 1
172                 if (did_files == 0) {
173                         print "%files"
174                         print ""
175                         did_files = 1
176                 }
177         }
178
179         # Do not add %define of _prefix if it already is.
180         if ($2 ~ /^_prefix/) {
181                 sub("^"prefix, $3, bindir)
182                 sub("^"prefix, $3, sbindir)
183                 sub("^"prefix, $3, libdir)
184                 sub("^"prefix, $3, datadir)
185                 sub("^"prefix, $3, includedir)
186                 prefix = $3
187         }
188
189         if ($2 ~ /_bindir/ && !/_sbindir/)
190                 bindir = $3
191         if ($2 ~ /_sbindir/)
192                 sbindir = $3
193         if ($2 ~ /_libdir/) {
194                 if ($3 ~ /^%\(/) {
195                         # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
196                         libdir = "%%%%%%%%%%%%%%"
197                 } else {
198                         libdir = $3
199                 }
200         }
201         if ($2 ~ /_sysconfdir/) {
202                 if ($3 ~ /^%\(/) {
203                         # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
204                         sysconfdir = "%%%%%%%%%%%%%%"
205                 } else {
206                         sysconfdir = $3
207                 }
208         }
209         if ($2 ~ /_datadir/) {
210                 if ($3 ~ /^%\(/) {
211                         # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
212                         datadir = "%%%%%%%%%%%%%%"
213                 } else {
214                         datadir = $3
215                 }
216         }
217         if ($2 ~ /_includedir/)
218                 includedir = $3
219         if ($2 ~ /_mandir/)
220                 mandir = $3
221         if ($2 ~ /_infodir/)
222                 infodir = $3
223         if ($2 ~ /_docdir/)
224                 docdir = $3
225
226         # version related macros
227         if ($2 ~ /^_beta$/)
228                 _beta = $3
229         if ($2 ~ /^_rc$/)
230                 _rc = $3
231         if ($2 ~ /^_pre$/)
232                 _pre = $3
233         if ($2 ~ /^_snap$/)
234                 _snap = $3
235
236         # these are used usually when adapterizing external spec
237         if ($2 ~ /^name$/)
238                 name = $3
239         if ($2 ~ /^version$/)
240                 version = $3
241         if ($2 ~ /^release$/)
242                 release = $3
243
244         if ($2 ~ /^mod_name$/)
245                 mod_name = $3
246
247         sub(/[ \t]+$/, "");
248         # do nothing further, otherwise adapter thinks we're at preamble
249         print
250         next
251 }
252
253 # Obsolete
254 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
255         next
256 }
257
258 ################
259 # %description #
260 ################
261 /^%description/, (!/^%description/ && $0 ~ SECTIONS) {
262         preamble = 0
263
264         if (/^%description/) {
265                 bod++
266                 format_line = ""
267                 format_indent = -1
268         }
269
270         # Format description
271         if (ENVIRON["SKIP_DESC"] != 1 && description == 1 && !/^%[a-z]+/ && !/^%description/) {
272                 if (/^[ \t]*$/) {
273                         format_flush(format_line, format_indent)
274                         print ""
275                         format_line = ""
276                         format_indent = -1
277                 } else if (/^[ \t]*[-\*][ \t]*/) {
278                         format_flush(format_line, format_indent)
279                         match($0, /^[ \t]*/)
280                         format_indent = RLENGTH
281                         match($0, /^[ \t]*[-\*][ \t]/)
282                         format_line = substr($0, RLENGTH)
283                 } else
284                         format_line = format_line " " $0
285                 next
286         }
287
288         if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
289                 if (NF > 3 && $2 == "-l") {
290                         ll = $1
291                         for (i = 4; i <= NF; i++)
292                                 ll = ll " " $i
293                         $0 = ll " -l " $3
294                 }
295                 format_flush(format_line, format_indent)
296                 if (bod == 2) {
297                         bod = 1
298                         description = 1
299                 } else {
300                         bod = 0
301                         description = 0
302                 }
303         } else
304                 description = 1
305 }
306
307 #########
308 # %prep #
309 #########
310 /^%prep/, (!/^%prep/ && $0 ~ SECTIONS) {
311         preamble = 0
312         did_prep = 1
313
314         use_macros()
315
316         # Add '-q' to %setup
317         if (/^%setup/ && !/-q/) {
318                 sub(/^%setup/, "%setup -q")
319         }
320
321         if (/^%setup/) {
322                 $0 = fixedsub(name, "%{name}", $0);
323                 $0 = fixedsub(version, "%{version}", $0);
324                 if (_beta) {
325                         $0 = fixedsub(_beta, "%{_beta}", $0);
326                 }
327                 if (_rc) {
328                         $0 = fixedsub(_rc, "%{_rc}", $0);
329                 }
330                 if (_pre) {
331                         $0 = fixedsub(_pre, "%{_pre}", $0);
332                 }
333                 if (_snap) {
334                         $0 = fixedsub(_snap, "%{_snap}", $0);
335                 }
336         }
337
338         if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
339                 $0 = fixedsub(" -n %{name}-%{version}", "", $0)
340         }
341
342         # invalid in %prep
343         sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
344 }
345
346 ##########
347 # %build #
348 ##########
349 /^%build/, (!/^%build/ && $0 ~ SECTIONS) {
350         preamble = 0
351
352         if (did_prep == 0) {
353                 print "%prep"
354                 print ""
355                 did_prep = 1
356         }
357
358         use_macros()
359         use_tabs()
360
361         if (/^automake$/)
362                 sub(/$/, " -a -c")
363
364         if (/LDFLAGS/) {
365                 if (/LDFLAGS="-s"/) {
366                         removed["LDFLAGS"] = 1
367                         next
368                 } else {
369                         split($0, tmp, "LDFLAGS=")
370                         count = split(tmp[2], flags, "\"")
371                         if (flags[1] != "" && flags[1] !~ "!?debug") {
372                                 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
373                                 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
374                                 for (i = 2; i < count; i++)
375                                         $0 = $0 flags[i] "\""
376                         }
377                 }
378         }
379
380         if (/CFLAGS=/)
381                 if (cflags("CFLAGS") == 0)
382                         next
383
384         if (/CXXFLAGS=/)
385                 if (cflags("CXXFLAGS") == 0)
386                         next
387
388         if (/^export /) {
389                 if (removed["LDFLAGS"])
390                         sub(" LDFLAGS", "")
391                 if (removed["CFLAGS"])
392                         sub(" CFLAGS", "")
393                 if (removed["CXXFLAGS"])
394                         sub(" CXXFLAGS", "")
395                 # Is there still something?
396                 if (/^export[ ]*$/)
397                         next
398         }
399
400         # quote CC
401         if (/CC=%{__cc} /) {
402                 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
403         }
404         
405         # use PLD Linux macros
406         $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
407         $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
408         $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
409         $0 = fixedsub("automake -a --foreign --copy", "%{__automake}", $0);
410         $0 = fixedsub("automake -a -c --foreign", "%{__automake}", $0);
411         $0 = fixedsub("libtoolize --force --automake --copy", "%{__libtoolize}", $0);
412         $0 = fixedsub("libtoolize -c -f --automake", "%{__libtoolize}", $0);
413
414         sub(/^aclocal$/, "%{__aclocal}");
415         sub(/^autoheader$/, "%{__autoheader}");
416         sub(/^autoconf$/, "%{__autoconf}");
417         sub(/^automake$/, "%{__automake}");
418
419         # atrpms
420         $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
421         $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
422 }
423
424 ##########
425 # %clean #
426 ##########
427 /^%clean/, (!/^%clean/ && $0 ~ SECTIONS) {
428         did_clean = 1
429
430         # prevent next section header like "%post -p /sbin/ldconfig" being adapterized
431         if (!/^%post/) {
432                 use_macros()
433         }
434 }
435
436 ############
437 # %install #
438 ############
439 /^%install/, (!/^%install/ && $0 ~ SECTIONS) {
440
441         preamble = 0
442
443         # foreign rpms
444         sub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
445     sub("%buildroot", "$RPM_BUILD_ROOT");
446     sub("%{buildroot}", "$RPM_BUILD_ROOT");
447
448         if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+(\${?RPM_BUILD_ROOT}?|%{?buildroot}?)/ && did_rmroot==0) {
449                 did_rmroot=1
450                 print "rm -rf $RPM_BUILD_ROOT"
451                 next
452         }
453
454         if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
455                 print "rm -rf $RPM_BUILD_ROOT"
456                 did_rmroot=1
457         }
458
459     if (tmpdir) {
460         buildroot = tmpdir "/" name "-" version "-root-" ENVIRON["USER"]
461                 gsub(buildroot, "$RPM_BUILD_ROOT")
462     }
463
464         use_macros()
465
466         # 'install -d' instead 'mkdir -p'
467         if (/mkdir -p/)
468                 sub(/mkdir -p/, "install -d")
469
470         # 'install' instead 'cp -p'
471         if (/cp -p\b/)
472                 sub(/cp -p/, "install")
473
474         # No '-u root' or '-g root' for 'install'
475         if (/^install/ && /-[ug][ \t]*root/)
476                 gsub(/-[ug][ \t]*root /, "")
477
478         if (/^install/ && /-m[ \t]*[0-9]+/)
479                 gsub(/-m[ \t]*[0-9]+ /, "")
480
481         # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
482         if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
483                 next
484
485         # No lines contain 'chmod' if it sets the modes to '644'
486         if ($1 ~ /chmod/ && $2 ~ /644/)
487                 next
488
489         # atrpms
490         $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
491 }
492
493 ##########
494 # %files #
495 ##########
496 /^%files/, (!/^%files/ && $0 ~ SECTIONS) {
497         preamble = 0
498         did_files = 1
499
500         if ($0 ~ /^%files/)
501                 defattr = 1
502
503         use_files_macros()
504 }
505
506 ##############
507 # %changelog #
508 ##############
509 /^%changelog/, (!/^%changelog/ && $0 ~ SECTIONS) {
510         preamble = 0
511         has_changelog = 1
512         skip = 0
513         # There should be some CVS keywords on the first line of %changelog.
514         if (boc == 3) {
515                 if ($0 !~ _cvsmailfeedback)
516                         print "* %{date} " _cvsmailfeedback > changelog_file
517                 else
518                         skip = 1
519                 boc = 2
520         }
521         if (boc == 2 && !skip) {
522                 if (!/All persons listed below/) {
523                         printf "All persons listed below can be reached at " > changelog_file
524                         print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
525                 } else
526                         skip = 1
527                 boc = 1
528         }
529         if (boc == 1 && !skip) {
530                 if (!/^$/) {
531                         if (!/\$.*Log:.*\$/)
532                                 print "$" "Log:$" > changelog_file
533                         boc = 0
534                 }
535         }
536         # Define date macro.
537         if (boc == 4) {
538                 if (date == 0) {
539                         printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
540                         print " date +\"%a %b %d %Y\"`)" > changelog_file
541                         date = 1
542                 }
543                 boc = 3
544         }
545
546         sub(/[ \t]+$/, "")
547         if (!/^%[a-z]+$/ || /changelog/)
548                 print > changelog_file
549         else
550                 print
551         next
552 }
553
554 ###########
555 # SCRIPTS #
556 ###########
557 /^%pre/, (!/^%pre/ && $0 ~ SECTIONS) {
558         preamble = 0
559
560         if (gsub("/usr/sbin/useradd", "%useradd")) {
561                 sub(" 2> /dev/null \|\| :", "");
562                 sub(" >/dev/null 2>&1 \|\|:", "");
563         }
564
565         # %useradd and %groupadd may not be wrapped
566         if (/%(useradd|groupadd).*\\$/) {
567                 a = $0; getline;
568                 sub(/^[\s\t]*/, "");
569                 $0 = substr(a, 1, length(a) - 1) $0;
570         }
571         use_script_macros()
572 }
573
574 /^%post/, (!/^%post/ && $0 ~ SECTIONS) {
575         preamble = 0
576         use_macros()
577 }
578 /^%preun/, (!/^%preun/ && $0 ~ SECTIONS) {
579         preamble = 0
580         use_script_macros()
581 }
582 /^%postun/, (!/^%postun/ && $0 ~ SECTIONS) {
583         preamble = 0
584         use_script_macros()
585 }
586 /^%triggerin/, (!/^%triggerin/ && $0 ~ SECTIONS) {
587         preamble = 0
588         use_script_macros()
589 }
590 /^%triggerun/, (!/^%triggerun/ && $0 ~ SECTIONS) {
591         preamble = 0
592         use_script_macros()
593 }
594 /^%triggerpostun/, (!/^%triggerpostun/ && $0 ~ SECTIONS) {
595         preamble = 0
596         use_script_macros()
597 }
598 /^%pretrans/, (!/^%pretrans/ && $0 ~ SECTIONS) {
599         preamble = 0
600         use_script_macros()
601 }
602 /^%posttrans/, (!/^%posttrans/ && $0 ~ SECTIONS) {
603         preamble = 0
604         use_script_macros()
605 }
606 /^%verifyscript/, (!/^%verifyscript/ && $0 ~ SECTIONS) {
607         preamble = 0
608         use_script_macros()
609 }
610 /^%check/, (!/^%check/ && $0 ~ SECTIONS) {
611         preamble = 0
612         use_script_macros()
613 }
614
615 #############
616 # PREAMBLES #
617 #############
618 preamble == 1 {
619         # There should not be a space after the name of field
620         # and before the colon.
621         sub(/[ \t]*:/, ":")
622
623         if (/^%perl_module_wo_prefix/) {
624                 name = $2
625                 version = $3
626                 release = "0." fixedsub(".%{disttag}.at", "", $4)
627         }
628
629         field = tolower($1)
630         fieldnlower = $1
631         if (field ~ /summary:/ && !/etc\.$/) {
632                 sub(/\.$/, "", $0);
633         }
634         if (field ~ /group(\([^)]+\)):/)
635                 next
636         if (field ~ /group:/) {
637                 format_preamble()
638                 group = $0;
639                 sub(/^[^ \t]*[ \t]*/, "", group);
640
641                 sub(/^Utilities\//,"Applications/", group)
642                 sub(/^Games/,"Applications/Games", group)
643                 sub(/^X11\/Games/,"X11/Applications/Games", group)
644                 sub(/^X11\/GNOME\/Development\/Libraries/,"X11/Development/Libraries", group)
645                 sub(/^X11\/GNOME\/Applications/,"X11/Applications", group)
646                 sub(/^X11\/GNOME/,"X11/Applications", group)
647                 sub(/^X11\/Utilities/,"X11/Applications", group)
648                 sub(/^X11\/Games\/Strategy/,"X11/Applications/Games/Strategy", group)
649                 sub(/^Shells/,"Applications/Shells", group)
650                 sub(/^System Environment\/Libraries$/, "Libraries", group)
651                 sub(/^System Environment\/Daemons$/, "Daemons", group)
652                 sub(/^Applications\/Internet$/, "Applications/Networking", group)
653                 sub(/^Applications\/Daemons$/, "Daemons", group)
654                 sub(/^Application\/Multimedia$/, "Applications/Multimedia", group)
655                 sub(/^System\/Servers$/, "Daemons", group)
656                 sub(/^X11\/Xserver$/, "X11/Servers", group)
657                 sub(/^X11\/XFree86/, "X11", group)
658                 sub(/^Applications\/Compilers$/, "Development/Languages", group)
659                 sub(/^Applications\/Internet\/Peer to Peer/, "Applications/Networking", group)
660                 sub(/^Networking\/Deamons$/, "Networking/Daemons", group)
661                 sub(/^Development\/Docs$/, "Documentation", group)
662                 sub(/^Development\/Documentation$/, "Documentation", group)
663                 sub(/^System Environment\/Kernel$/, "Base/Kernel", group)
664                 sub(/^Development\/Libraries\/Java$/, "Development/Languages/Java", group)
665                 sub(/^Development\/Java/, "Development/Languages/Java", group)
666                 sub(/^Development\/Testing$/, "Development", group)
667                 sub(/^Text Processing\/Markup\/HTML$/, "Applications/Text", group)
668                 sub(/^Text Processing\/Markup\/XML$/, "Applications/Text", group)
669                 sub(/^Web\/Database$/, "Applications/WWW", group)
670                 sub(/^System Environment\/Base$/, "Base", group)
671
672                 $0 = "Group:\t\t" group
673
674                 if (group ~ /^X11/ && x11 == 0) # Is it X11 application?
675                         x11 = 1
676
677                 byl_plik_z_groupmi = 0
678                 byl_opis_grupy = 0
679                 while ((getline linia_grup < groups_file) > 0) {
680                         byl_plik_z_groupmi = 1
681                         if (linia_grup == group) {
682                                 byl_opis_grupy = 1
683                                 break
684                         }
685                 }
686
687                 if (!byl_plik_z_groupmi)
688                         print "######\t\t" groups_file ": no such file"
689                 else if (!byl_opis_grupy)
690                         print "######\t\t" "Unknown group!"
691
692                 close(groups_file)
693                 did_groups = 1
694         }
695
696         if (field ~ /prereq:/) {
697                 sub(/Pre[Rr]eq:/, "Requires:", $1);
698         }
699
700         # split (build)requires, obsoletes on commas
701         if (field ~ /(obsoletes|requires|provides|conflicts):/ && NF > 2) {
702                 value = substr($0, index($0, $2));
703                 $0 = format_requires($1, value);
704         }
705
706         # BR: tar (and others) is to common (rpm-build requires it)
707         if (field ~ /^buildrequires:/) {
708                 l = substr($0, index($0, $2));
709                 if (l == "awk" ||
710                         l == "binutils" ||
711                         l == "bzip2" ||
712                         l == "cpio" ||
713                         l == "diffutils" ||
714                         l == "elfutils" ||
715                         l == "fileutils" ||
716                         l == "findutils" ||
717                         l == "glibc-devel" ||
718                         l == "grep" ||
719                         l == "gzip" ||
720                         l == "make" ||
721                         l == "patch" ||
722                         l == "sed" ||
723                         l == "sh-utils" ||
724                         l == "tar" ||
725                         l == "textutils") {
726                         next
727                 }
728
729         # perhaps we have common known name?
730
731         # jpackages
732                 sub(/^java-devel$/, "jdk", $2);
733                 sub(/^log4j$/, "jakarta-log4j", $2);
734                 sub(/^oro$/, "jakarta-oro", $2);
735                 sub(/^xerces-j2$/, "xerces-j", $2);
736                 sub(/^ant-junit$/, "jakarta-ant", $2);
737                 sub(/^ldapjdk$/, "ldapsdk", $2);
738                 sub(/^saxon-scripts$/, "saxon", $2);
739         }
740
741         # obsolete/unwanted tags
742         if (field ~ /vendor:|packager:|distribution:|docdir:|prefix:|icon:|author:|author-email:|metadata-version:/) {
743                 next
744         }
745
746         if (field ~ /buildroot:/) {
747                 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
748                 did_build_root = 1
749         }
750
751         # Use "License" instead of "Copyright" if it is (L)GPL or BSD
752         if (field ~ /copyright:/ && $2 ~ /GPL|BSD/) {
753                 $1 = "License:"
754         }
755
756         if (field ~ /license:/) {
757                 l = substr($0, index($0, $2));
758                 if (l == "Python Software Foundation License") {
759                         l = "PSF"
760                 }
761                 $0 = "License:\t" l;
762         }
763
764
765         if (field ~ /name:/) {
766                 if ($2 == "%{name}" && name) {
767                         $2 = name
768                 }
769                 name = $2
770                 name_seen = 1;
771         }
772
773         if (field ~ /version:/) {
774                 if ($2 == "%{version}" && version) {
775                         $2 = version
776                 }
777                 version = $2
778                 version_seen = 1;
779         }
780
781         if (field ~ /release:/) {
782                 if ($2 == "%{release}" && release) {
783                         $2 = release
784                 }
785                 sub(/%atrelease /, "0.", $0)
786                 release = $2
787                 release_seen = 1;
788         }
789
790
791         if (field ~ /serial:/)
792                 $1 = "Epoch:"
793
794         if (field ~ /home-page:/)
795                 $1 = "URL:"
796
797         # proper caps
798         if (field ~ /^url:$/)
799                 $1 = "URL:"
800
801         if (field ~ /^description:$/)
802                 $1 = "\n%description\n"
803
804         # Use %{name} and %{version} in the filenames in "Source:"
805         if (field ~ /^source/ || field ~ /patch/) {
806                 n = split($2, url, /\//)
807                 if (url[n] ~ /\.gz$/) {
808                         url[n+1] = ".gz" url[n+1]
809                         sub(/\.gz$/,"",url[n])
810                 }
811                 if (url[n] ~ /\.zip$/) {
812                         url[n+1] = ".zip" url[n+1]
813                         sub(/\.zip$/,"",url[n])
814                 }
815                 if (url[n] ~ /\.tar$/) {
816                         url[n+1] = ".tar" url[n+1]
817                         sub(/\.tar$/,"",url[n])
818                 }
819                 if (url[n] ~ /\.patch$/) {
820                         url[n+1] = ".patch" url[n+1]
821                         sub(/\.patch$/,"",url[n])
822                 }
823                 if (url[n] ~ /\.bz2$/) {
824                         url[n+1] = ".bz2" url[n+1]
825                         sub(/\.bz2$/,"",url[n])
826                 }
827                 if (url[n] ~ /\.logrotate$/) {
828                         url[n+1] = ".logrotate" url[n+1]
829                         sub(/\.logrotate$/,"",url[n])
830                 }
831                 if (url[n] ~ /\.pamd$/) {
832                         url[n+1] = ".pamd" url[n+1]
833                         sub(/\.pamd$/,"",url[n])
834                 }
835
836                 # allow %{name} only in last url component
837                 s = ""
838                 for (i = 1; i <= n; i++) {
839                         url[i] = fixedsub("%{name}", name, url[i])
840                         if (s) {
841                                 s = s "/" url[i]
842                         } else {
843                                 s = url[i]
844                         }
845                 }
846                 $2 = s url[n+1]
847
848                 filename = url[n]
849                 if (name) {
850                         url[n] = fixedsub(name, "%{name}", url[n])
851                 }
852                 if (field ~ /source/) {
853                         if (version) {
854                                 url[n] = fixedsub(version, "%{version}", url[n])
855                         }
856                         if (_beta) {
857                                 url[n] = fixedsub(_beta, "%{_beta}", url[n])
858                         }
859                         if (_rc) {
860                                 url[n] = fixedsub(_rc, "%{_rc}", url[n])
861                         }
862                         if (_pre) {
863                                 url[n] = fixedsub(_pre, "%{_pre}", url[n])
864                         }
865                         if (_snap) {
866                                 url[n] = fixedsub(_snap, "%{_snap}", url[n])
867                         }
868                 }
869                 # assigning to $2 kills preamble formatting
870                 $2 = fixedsub(filename, url[n], $2)
871
872                 # sourceforge urls
873                 sub("[?]use_mirror=.*$", "", $2);
874                 sub("[?]download$", "", $2);
875                 sub("^http://prdownloads\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
876                 sub("^http://download\.sf\.net/", "http://dl.sourceforge.net/", $2)
877
878                 sub("^http://.*\.dl\.sourceforge\.net/", "http://dl.sourceforge.net/", $2)
879                 sub("^http://dl\.sourceforge\.net/sourceforge/", "http://dl.sourceforge.net/", $2)
880                 sub("^http://dl\.sf\.net/", "http://dl.sourceforge.net/", $2)
881         }
882
883
884         if (field ~ /^source:/)
885                 $1 = "Source0:"
886
887         if (field ~ /^patch:/)
888                 $1 = "Patch0:"
889
890         kill_preamble_macros();
891         format_preamble()
892
893         if (field ~ /requires/) {
894                 # atrpms
895                 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
896         }
897 }
898
899 /^%bcond_/ {
900         # do nothing
901         print
902         next
903 }
904
905 # sort BR/R!
906 #
907 # NOTES:
908 # - mixing BR/R and anything else confuses this (all will be sorted together)
909 #   so don't do that.
910 # - comments leading the BR/R can not be associated,
911 #   so don't adapterize when the BR/R are mixed with comments
912 ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && $0 ~ PREAMBLE_TAGS, $0 ~ PREAMBLE_TAGS {
913         if ($1 ~ /Pre[Rr]eq:/) {
914                 sub(/Pre[Rr]eq:/, "Requires:", $1);
915         }
916         format_preamble()
917 #       kill_preamble_macros(); # breaks tabbing
918
919         b_idx++;
920         l = substr($0, index($0, $2));
921         b_ktmp = b_makekey($1, l);
922         b_key[b_idx] = b_ktmp;
923         b_val[b_ktmp] = $0;
924
925         next;
926 }
927
928 preamble == 1 {
929         if (b_idx > 0) {
930                 isort(b_key, b_idx);
931                 for (i = 1; i <= b_idx; i++) {
932                         v = b_val[b_key[i]];
933                         sub(/[ \t]+$/, "", v);
934                         print "" v;
935                 }
936                 b_idx = 0
937         }
938 }
939
940 # main() ;-)
941 {
942         preamble = 1
943
944         sub(/[ \t]+$/, "")
945         print
946
947         if (name_seen == 0 && name) {
948                 print "Name:\t\t" name
949                 name_seen = 1
950         }
951
952         if (version_seen == 0 && version) {
953                 print "Version:\t" version
954                 version_seen = 1
955         }
956
957         if (release_seen == 0 && release) {
958                 print "Release:\t" release
959                 release_seen = 1
960         }
961
962         if (did_build_root == 0) {
963 #               print "BuildRoot:\t%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
964                 did_build_root = 1
965         }
966         if (did_groups == 0) {
967 #               print "Group:\t\tunknown"
968                 did_groups = 1
969         }
970 }
971
972
973 END {
974         if (do_not_touch_anything)
975                 exit 0
976
977         close(changelog_file)
978         while ((getline < changelog_file) > 0)
979                 print
980         system("rm -f " changelog_file)
981
982         if (did_clean == 0) {
983                 print ""
984                 print "%clean"
985                 print "rm -rf $RPM_BUILD_ROOT"
986         }
987
988         if (date == 0) {
989                 print ""
990                 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
991         }
992
993         if (has_changelog == 0)
994                 print "%changelog"
995
996         if (boc > 2)
997                 print "* %{date} PLD Team <feedback@pld-linux.org>"
998         if (boc > 1) {
999                 printf "All persons listed below can be reached at "
1000                 print "<cvs_login>@pld-linux.org\n"
1001         }
1002         if (boc > 0)
1003                 print "$" "Log:$"
1004 }
1005
1006 function fixedsub(s1,s2,t, ind) {
1007 # substitutes fixed strings (not regexps)
1008         if (ind = index(t,s1))
1009                 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
1010         return t
1011 }
1012
1013 # There should be one or two tabs after the colon.
1014 function format_preamble()
1015 {
1016         if (/^#/ || /^%bcond_with/) {
1017                 return;
1018         }
1019         sub(/:[ \t]*/, ":")
1020         if (match($0, /[A-Za-z0-9(),#_ \t]+[ \t]*:[ \t]*/) == 1) {
1021                 if (RLENGTH < 8)
1022                         sub(/:/, ":\t\t")
1023                 else
1024                         sub(/:/, ":\t")
1025         }
1026 }
1027
1028 # Replace directly specified directories with macros
1029 function use_macros()
1030 {
1031         # -m, --skip-macros, --no-macros -- skip macros subst
1032         if (ENVIRON["SKIP_MACROS"]) {
1033                 return
1034         }
1035
1036         # leave inline sed lines alone
1037         if (/(%{__sed}|sed) -i -e/) {
1038                 return;
1039         }
1040
1041         gsub(perl_sitearch, "%{perl_sitearch}")
1042         gsub(perl_archlib, "%{perl_archlib}")
1043         gsub(perl_privlib, "%{perl_privlib}")
1044         gsub(perl_vendorlib, "%{perl_vendorlib}")
1045         gsub(perl_vendorarch, "%{perl_vendorarch}")
1046         gsub(perl_sitelib, "%{perl_sitelib}")
1047         
1048         gsub(py_sitescriptdir, "%{py_sitescriptdir}")
1049         gsub(py_sitedir, "%{py_sitedir}")
1050         gsub(py_scriptdir, "%{py_scriptdir}")
1051         gsub("%{_libdir}/python2.4/site-packages", "%{py_sitedir}")
1052         gsub("%{python_sitelib}", "%{py_sitedir}")
1053         gsub("%{_datadir}/applications", "%{_desktopdir}")
1054         gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}")
1055
1056         gsub(bindir, "%{_bindir}")
1057         gsub("%{prefix}/bin", "%{_bindir}")
1058         if (prefix"/bin" == bindir)
1059                 gsub("%{_prefix}/bin", "%{_bindir}")
1060
1061         for (c = 1; c <= NF; c++) {
1062                 if ($c ~ sbindir "/fix-info-dir")
1063                         continue;
1064                 if ($c ~ sbindir "/webapp")
1065                         continue;
1066                 if ($c ~ sbindir "/chsh")
1067                         continue;
1068                 if ($c ~ sbindir "/usermod")
1069                         continue;
1070                 if ($c ~ sbindir "/chkconfig")
1071                         continue;
1072                 if ($c ~ sbindir "/installzope(product|3package)")
1073                         continue;
1074                 gsub(sbindir, "%{_sbindir}", $c)
1075         }
1076
1077         gsub("%{prefix}/sbin", "%{_sbindir}")
1078         if (prefix"/sbin" == sbindir) {
1079                 gsub("%{_prefix}/sbin", "%{_sbindir}")
1080         }
1081
1082         for (c = 1; c <= NF; c++) {
1083                 if ($c ~ sysconfdir "/{?cron.")
1084                         continue;
1085                 if ($c ~ sysconfdir "/{?crontab.d")
1086                         continue;
1087                 if ($c ~ sysconfdir "/{?env.d")
1088                         continue;
1089                 if ($c ~ sysconfdir "/{?modprobe.(d|conf)")
1090                         continue;
1091                 if ($c ~ sysconfdir "/{?udev/rules.d")
1092                         continue;
1093                 if ($c ~ sysconfdir "/{?logrotate.d")
1094                         continue;
1095                 if ($c ~ sysconfdir "/{?pam.d")
1096                         continue;
1097                 if ($c ~ sysconfdir "/{?profile.d")
1098                         continue;
1099                 if ($c ~ sysconfdir "/{?rc.d")
1100                         continue;
1101                 if ($c ~ sysconfdir "/{?security")
1102                         continue;
1103                 if ($c ~ sysconfdir "/{?skel")
1104                         continue;
1105                 if ($c ~ sysconfdir "/{?sysconfig")
1106                         continue;
1107                 if ($c ~ sysconfdir "/{?shrc.d")
1108                         continue;
1109                 if ($c ~ sysconfdir "/{?certs")
1110                         continue;
1111                 if ($c ~ sysconfdir "/{?X11")
1112                         continue;
1113                 if ($c ~ sysconfdir "/{?ld.so.conf.d")
1114                         continue;
1115                 if ($c ~ sysconfdir "/{?rpm")
1116                         continue;
1117                 if ($c ~ sysconfdir "/{?bash_completion.d")
1118                         continue;
1119                 if ($c ~ sysconfdir "/{?samba")
1120                         continue;
1121                 if ($c ~ sysconfdir "/shells")
1122                         continue;
1123                 gsub(sysconfdir, "%{_sysconfdir}", $c)
1124         }
1125
1126         gsub(docdir, "%{_docdir}")
1127         gsub(php_pear_dir, "%{php_pear_dir}")
1128
1129         for (c = 1; c <= NF; c++) {
1130                 if ($c ~ datadir "/automake")
1131                         continue;
1132                 if ($c ~ datadir "/unsermake")
1133                         continue;
1134                 if ($c ~ datadir "/file/magic.mime")
1135                         continue;
1136                 gsub(datadir, "%{_datadir}", $c)
1137         }
1138
1139         gsub("%{prefix}/share", "%{_datadir}")
1140         if (prefix"/share" == datadir)
1141                 gsub("%{_prefix}/share", "%{_datadir}")
1142
1143         # CFLAGS="-I/usr/include/ncurses is usually correct.
1144         if (!/-I\/usr\/include/) {
1145                 gsub(includedir, "%{_includedir}")
1146         }
1147
1148         gsub("%{prefix}/include", "%{_includedir}")
1149         if (prefix"/include" == includedir) {
1150                 gsub("%{_prefix}/include", "%{_includedir}")
1151         }
1152
1153         gsub(mandir, "%{_mandir}")
1154         if ($0 !~ "%{_datadir}/manual") {
1155                 gsub("%{_datadir}/man", "%{_mandir}")
1156         }
1157         gsub("%{_prefix}/share/man", "%{_mandir}")
1158         gsub("%{prefix}/share/man", "%{_mandir}")
1159         gsub("%{prefix}/man", "%{_mandir}")
1160         gsub("%{_prefix}/man", "%{_mandir}")
1161
1162         gsub(infodir, "%{_infodir}")
1163         gsub("%{prefix}/info", "%{_infodir}")
1164         gsub("%{_prefix}/info", "%{_infodir}")
1165
1166         if (prefix !~ "/X11R6") {
1167                 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
1168         }
1169
1170         gsub(examplesdir, "%{_examplesdir}")
1171
1172         if (prefix != "/") {
1173                 # leave --with-foo=/usr alone
1174                 if ($0 !~ "--with.*=.*" prefix) {
1175                         for (c = 1; c <= NF; c++) {
1176                                 if ($c ~ prefix "/sbin/fix-info-dir")
1177                                         continue;
1178                                 if ($c ~ prefix "/sbin/webapp")
1179                                         continue;
1180                                 if ($c ~ prefix "/sbin/chsh")
1181                                         continue;
1182                                 if ($c ~ prefix "/sbin/usermod")
1183                                         continue;
1184                                 if ($c ~ prefix "/sbin/installzope(product|3package)")
1185                                         continue;
1186                                 if ($c ~ prefix "/share/automake")
1187                                         continue;
1188                                 if ($c ~ prefix "/share/unsermake")
1189                                         continue;
1190                                 if ($c ~ prefix "/lib/sendmail")
1191                                         continue;
1192                                 if ($c ~ prefix "/lib/pkgconfig")
1193                                         continue;
1194
1195                                 # CFLAGS="-I/usr..." is usually correct.
1196                                 if (/-I\/usr/)
1197                                         continue;
1198                                 # same for LDFLAGS="-L/usr..."
1199                                 if (/-L\/usr/)
1200                                         continue;
1201
1202                                 gsub(prefix, "%{_prefix}", $c)
1203                         }
1204                 }
1205                 gsub("%{prefix}", "%{_prefix}")
1206         }
1207
1208         # replace back
1209         gsub("%{_includedir}/ncurses", "/usr/include/ncurses")
1210         gsub("%{_includedir}/freetype", "/usr/include/freetype")
1211
1212         gsub("%{PACKAGE_VERSION}", "%{version}")
1213         gsub("%{PACKAGE_NAME}", "%{name}")
1214
1215         gsub("^make$", "%{__make}")
1216         gsub("^make ", "%{__make} ")
1217         gsub("^gcc ", "%{__cc} ")
1218
1219         # mandrake specs
1220         gsub("^%make$", "%{__make}")
1221         gsub("^%make ", "%{__make} ")
1222         gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1223         gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1224         gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1225         gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
1226         gsub("^%{__install}", "install")
1227         gsub("^%{__rm}", "rm")
1228         gsub("%optflags", "%{rpmcflags}")
1229         gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
1230
1231         gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1232         gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\&1")
1233         $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
1234         $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
1235         $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
1236
1237         # split configure line to multiple lines
1238         if (/%configure / && !/\\$/) {
1239                 $0 = format_configure($0);
1240         }
1241
1242         gsub("%_bindir", "%{_bindir}")
1243         gsub("%_datadir", "%{_datadir}")
1244         gsub("%_iconsdir", "%{_iconsdir}")
1245         gsub("%_sbindir", "%{_sbindir}")
1246         gsub("%_mandir", "%{_mandir}")
1247         gsub("%name", "%{name}")
1248     gsub(/%ant/, "ant")
1249     gsub(/%__rm/, "rm");
1250     gsub(/%__mkdir_p/, "install -d");
1251     gsub(/%__cp/, "cp");
1252     gsub(/%__ln_s/, "ln -s");
1253     gsub(/%__sed/, "%{__sed}");
1254     gsub(/%__cat/, "cat");
1255     gsub(/%__chmod/, "chmod");
1256
1257         gsub("/usr/src/linux", "%{_kernelsrcdir}")
1258         gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
1259 }
1260
1261 function format_configure(line,         n, a, s) {
1262         n = split(line, a, / /);
1263         s = a[1] " \\\n";
1264         for (i = 2; i <= n; i++) {
1265                 s = s "\t" a[i] " \\\n"
1266         }
1267         return s
1268 }
1269
1270
1271 # insertion sort of A[1..n]
1272 # copied from mawk manual
1273 function isort(A,n,             i,j,hold) {
1274         for (i = 2; i <= n; i++) {
1275                 hold = A[j = i]
1276                 while (A[j-1] > hold) {
1277                         j-- ; A[j+1] = A[j]
1278                 }
1279                 A[j] = hold
1280         }
1281         # sentinel A[0] = "" will be created if needed
1282 }
1283
1284
1285 function use_files_macros(      i, n, t, a)
1286 {
1287         use_macros()
1288
1289         # skip comments
1290         if (/^#/) {
1291                 return;
1292         }
1293
1294         sub("^%doc %{_mandir}", "%{_mandir}")
1295
1296         gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1297         gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1298
1299         # uid/gid nobody is not valid in %files
1300         if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1301                 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1302         }
1303
1304         # s[gu]id programs with globs are evil
1305         if (/%attr\([246]...,.*\*/ && !/FIXME/) {
1306                 $0 = $0 " # FIXME no globs for suid/sgid files"
1307         }
1308
1309         # replace back
1310         gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1311         gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1312         gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1313         gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1314         gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1315         gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1316         gsub("%{_sysconfdir}/security", "/etc/security")
1317         gsub("%{_sysconfdir}/skel", "/etc/skel")
1318         gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1319         gsub("%{_sysconfdir}/certs", "/etc/certs")
1320         gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1321
1322         # /etc/init.d -> /etc/rc.d/init.d
1323         if (!/^\/etc\/init\.d$/) {
1324                  gsub("/etc/init.d", "/etc/rc.d/init.d")
1325         }
1326
1327         if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1328                 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1329                         $0 = "%attr(754,root,root) " $0
1330                 }
1331                 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1332                         gsub("^%attr\\(... *,", "%attr(754,");
1333                 }
1334         }
1335
1336         if (/lib.+\.so/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1337                 $0 = "%attr(755,root,root) " $0
1338         }
1339
1340         if (/%{perl_vendorarch}.*\.so$/ && !/^%attr.*/) {
1341                 $0 = "%attr(755,root,root) " $0
1342         }
1343
1344         # /etc/sysconfig files
1345         # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1346         # attr not required, allow default 644 attr
1347         if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1348                 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace\)/) {
1349                         gsub("%config", "%config(noreplace)")
1350                 }
1351
1352                 if (/\/etc\/sysconfig\// && !/%config\(noreplace\)/) {
1353                         $NF = "%config(noreplace) " $NF
1354                 }
1355
1356                 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1357                         gsub("^%attr\\(... *,", "%attr(640,");
1358                 }
1359
1360                 if (/\/etc\/sysconfig\// && !/%verify/) {
1361                         gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1362                 }
1363         }
1364
1365         # kill leading zeros
1366         if (/%attr\(0[1-9]/) {
1367                 gsub("%attr\\(0", "%attr(")
1368         }
1369
1370         # sort %verify attrs
1371         if (match($0, /%verify\(not([^)]+)\)/)) {
1372                 t = substr($0, RSTART, RLENGTH)
1373                 # kill commas: %verify(not,md5,size,mtime)
1374                 gsub(/,/, " ", t);
1375
1376                 gsub(/^%verify\(not |\)$/, "", t)
1377                 n = split(t, a, / /)
1378                 isort(a, n)
1379
1380                 s = "%verify(not"
1381                 for (i = 1 ; i <= n; i++) {
1382                         s = s " " a[i]
1383                 }
1384                 s = s ")"
1385
1386                 gsub(/%verify\(not[^)]+\)/, s)
1387         }
1388
1389         if (/%{_mandir}/) {
1390                 gsub("\.gz$", "*")
1391         }
1392
1393         # locale dir and no %lang -> bad
1394         if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1395                 $(NF + 1) = "# FIXME consider using %find_lang"
1396         }
1397
1398         # atrpms
1399         $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1400         $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1401         $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1402
1403         gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1404         gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1405         gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1406
1407         gsub("%{_datadir}/applications", "%{_desktopdir}");
1408         gsub("%{_datadir}/icons", "%{_iconsdir}");
1409         gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1410 }
1411
1412 function use_script_macros()
1413 {
1414         if (gsub("/sbin/service", "%service")) {
1415                 sub(" >/dev/null 2>&1 \|\|:", "");
1416                 sub(" 2> /dev/null \|\| :", "");
1417         }
1418 }
1419
1420 function fill(ch, n, i) {
1421         for (i = 0; i < n; i++)
1422                 printf("%c", ch)
1423 }
1424
1425 function format_flush(line, indent, newline, word, first_word) {
1426         first_word = 1
1427         if (format_indent == -1)
1428                 newline = ""
1429         else
1430                 newline = fill(" ", format_indent) "- "
1431
1432         while (match(line, /[^\t ]+/)) {
1433                 word = substr(line, RSTART, RLENGTH)
1434                 if (length(newline) + length(word) + 1 > tw) {
1435                         print newline
1436
1437                         if (format_indent == -1)
1438                                 newline = ""
1439                         else
1440                                 newline = fill(" ", format_indent + 2)
1441                         first_word = 1
1442                 }
1443
1444                 if (first_word) {
1445                         newline = newline word
1446                         first_word = 0
1447                 } else
1448                         newline = newline " " word
1449
1450                 line = substr(line, RSTART + RLENGTH)
1451         }
1452         if (newline ~ /[^\t ]/) {
1453                 print newline
1454         }
1455 }
1456
1457 function cflags(var)
1458 {
1459         if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1460                 removed[var] = 1
1461                 return 0
1462         }
1463
1464         if (!/!\?debug/)
1465                 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
1466         return 1
1467 }
1468
1469 function demacroize(str)
1470 {
1471         if (mod_name) {
1472                 sub("%{mod_name}", mod_name, str);
1473         }
1474         if (name) {
1475                 sub("%{name}", name, str);
1476         }
1477         if (version) {
1478                 sub("%{version}", version, str);
1479         }
1480         if (_beta) {
1481                 sub("%{_beta}", _beta, str);
1482         }
1483         if (_rc) {
1484                 sub("%{_rc}", _rc, str);
1485         }
1486         if (_pre) {
1487                 sub("%{_pre}", _pre, str);
1488         }
1489         if (_snap) {
1490                 sub("%{_snap}", _snap, str);
1491         }
1492         return str;
1493 }
1494
1495 function kill_preamble_macros()
1496 {
1497         if ($1 ~ /^URL:/ || $1 ~ /^Obsoletes:/) {
1498                 # NB! assigning $2 a value breaks tabbing
1499                 $2 = demacroize($2);
1500                 # unify sourceforge url
1501                 sub("\.sf\.net/$", ".sourceforge.net/", $2);
1502         }
1503 }
1504
1505 function get_epoch(pkg, ver,    epoch)
1506 {
1507         return
1508 # should parse the BR lines more adequately:
1509 #       freetype = 2.0.0 -> correct
1510 #       freetype = 2.1.9 -> with epoch 1, as epoch 1 was added in 2.1.7
1511
1512         shell = "grep -o '^" pkg ":[^:]\+' ../PLD-doc/BuildRequires.txt | awk '{print $NF}'";
1513         shell | getline epoch;
1514         return epoch;
1515 }
1516
1517 function format_requires(tag, value,    n, p, i, deps, ndeps) {
1518         # skip any formatting for commented out items or some weird macros
1519         if (/^#/ || /%\(/) {
1520                 return tag "\t" value
1521         }
1522         n = split(value, p, / *,? */);
1523         for (i = 1; i <= n; i++) {
1524                 if (p[i+1] ~ /[<=>]/) {
1525                         # add epoch if the version doesn't have it but BuildRequires.txt has
1526                         if (p[i] ~ /^[a-z]/ && p[i+2] !~ /^[0-9]+:/) {
1527                                 epoch = get_epoch(p[i], p[i+2])
1528                                 if (epoch) {
1529                                         p[i+2] = epoch ":" p[i+2];
1530                                 }
1531                         }
1532                         deps[ndeps++] = p[i] " " p[i+1] " " p[i+2];
1533                         i += 2;
1534                 } else {
1535                         deps[ndeps++] = p[i];
1536                 }
1537         }
1538         s = ""
1539         for (i in deps) {
1540                 s = s sprintf("%s\t%s\n", tag, deps[i]);
1541         }
1542         return substr(s, 1, length(s)-1);
1543 }
1544
1545 function use_tabs()
1546 {
1547         # reverse vim: ts=4 sw=4 et
1548         gsub(/    /, "\t");
1549 }
This page took 0.142073 seconds and 3 git commands to generate.