]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - adapter.awk
- use mktemp instead of hardcoded tmp path
[packages/rpm-build-tools.git] / adapter.awk
1 #!/usr/bin/gawk -f
2 #
3 # Adapter adapts .spec files for PLD Linux.
4 #
5 # Copyright (C) 1999-2011 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 #       Jakub Bogusz <qboosh@pld-linux.org>
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 # - really long sourceX make preamble sorting totally fcked up (try snake.spec r1.1)
21 # - parse ../PLD-doc/BuildRequires.txt and setup proper BR epoches?
22 # - add "-nc" option to skip CVS interaction
23 # - sort Summary(XX)
24 # - sort Requires, BuildRequires
25 # - check if %description (lang=C) contains 8bit
26 # - desc wrapping is totally fucked up on global.spec,1.25, dosemu.spec,1.115-
27 # - it should change: /%source([0-9]+)/i to %{SOURCE\1}
28 # - extra quote on LDFLAGS line: https://bugs.launchpad.net/pld-linux/+bug/385836
29 # - %{with_foo:%attr()...} gets converted to %attr() %{with_foo:...} [vlc.spec]
30 # - 'R: foo ' (with traliling space) gets coverted to "R: foo\nR: " [vlc.spec @ 1.199 ]
31
32 BEGIN {
33         RPM_SECTIONS = "package|build|changelog|clean|description|install|post|posttrans|postun|pre|prep|pretrans|preun|triggerin|triggerpostun|triggerun|verifyscript|check"
34         SECTIONS = "^%(" RPM_SECTIONS ")"
35
36         RCSID = "$Id$"
37         rev = RCSID # TODO: parse from RCSID
38         VERSION = "0.35/" rev
39
40         PREAMBLE_TAGS = "(R|BR|Summary|Name|Version|Release|Epoch|License|Group|URL|BuildArch|BuildRoot|Obsoletes|Conflicts|Provides|ExclusiveArch|ExcludeArch|Pre[Rr]eq|(Build)?Requires|Suggests|Auto(Req|Prov))"
41
42         usedigest = 0   # Enable to switch to rpm 4.4.6+ md5 digests
43
44         preamble = 1    # Is it part of preamble? Default - yes
45         boc = 4                 # Beginning of %changelog
46         bod = 0                 # Beginning of %description
47         tw = 70                 # Descriptions width
48
49         b_idx = 0               # index of BR/R arrays
50         BR_count = 0    # number of additional BuildRequires
51
52         # If variable removed, then 1 (for removing it from export)
53         removed["LDFLAGS"] = 0
54         removed["CFLAGS"] = 0
55         removed["CXXFLAGS"] = 0
56
57         # If 1, we are inside of comment block (started with /^#%/)
58         comment_block = 0
59
60         import_rpm_macros()
61
62         packages_dir = topdir
63         groups_file = packages_dir "/rpm.groups"
64
65         system("cd "packages_dir"; [ -f rpm.groups ] || cvs up rpm.groups > /dev/null")
66         system("[ -d ../PLD-doc ] && cd ../PLD-doc && ([ -f BuildRequires.txt ] || cvs up BuildRequires.txt >/dev/null)");
67
68         # Temporary file for changelog section
69         changelog_file = mktemp("adapter.changelogXXXXXX")
70 }
71
72 # There should be a comment with CVS keywords on the first line of file.
73 FNR == 1 {
74         if (!/^# \$[R]evision: .* \$, \$[D]ate: .* \$$/) {      # If this line is already OK?
75                 print "# $" "Revision:$, " "$" "Date:$" # No
76                 if ( /^#.*([rR]evision|[dD]ate)/ ) # There was something similar, but incorrect
77                          next
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 (ENVIRON["SKIP_DEFATTR"] != 1) {
87                 if ($0 !~ /defattr/) {  # If no %defattr
88                         print "%defattr(644,root,root,755)"     # Add it
89                 } else {
90                         $0 = "%defattr(644,root,root,755)"      # Correct mistakes (if any)
91                 }
92         }
93         defattr = 0
94 }
95
96 # call mktemp(1) and return the value
97 function mktemp(template, tmp) {
98    "mktemp " template | getline tmp
99    return tmp
100 }
101
102 function b_makekey(a, b,        s) {
103         s = a "" b;
104         # kill bcond
105         gsub(/[#%]+{[!?]+[_a-zA-Z0-9]+:/, "", s);
106
107         # kill commented out items
108         gsub(/^#[ \t]*/, "", s);
109
110         # force order
111         gsub(/^Summary\(/, "11Summary(", s);
112         gsub(/^Summary/, "10Summary", s);
113
114         gsub(/^Name/, "2Name", s);
115         gsub(/^Version/, "3Version", s);
116         gsub(/^Release/, "4Release", s);
117         gsub(/^Epoch/, "5Epoch", s);
118         gsub(/^License/, "5License", s);
119         gsub(/^Group/, "6Group", s);
120         gsub(/^URL/, "7URL", s);
121
122         gsub(/^BuildRequires/, "B1BuildRequires", s);
123         gsub(/^BuildConflicts/, "B2BuildConflicts", s);
124
125         gsub(/^Suggests/, "X1Suggests", s);
126         gsub(/^Provides/, "X2Provides", s);
127         gsub(/^Obsoletes/, "X3Obsoletes", s);
128         gsub(/^Conflicts/, "X4Conflicts", s);
129         gsub(/^BuildArch/, "X5BuildArch", s);
130         gsub(/^ExclusiveArch/, "X6ExclusiveArch", s);
131         gsub(/^ExcludeArch/, "X7ExcludeArch", s);
132         gsub(/^BuildRoot/, "X9BuildRoot", s);
133
134         gsub(/^AutoProv/, "Xx1AutoProv", s);
135         gsub(/^AutoReq/, "Xx2AutoReq", s);
136
137 #       printf("%s -> %s\n", a""b, s);
138         return s;
139 }
140
141 # Comments
142 /^#/ && (description == 0) {
143         if (/This file does not like to be adapterized!/) {
144                 print                   # print this message
145                 while (getline)         # print the rest of spec as it is
146                         print
147                 do_not_touch_anything = 1 # do not touch anything in END()
148                 exit(rc = 0)
149         }
150
151         # Generally, comments are printed without touching
152         sub(/[ \t]+$/, "")
153
154         if (/#[ \t]*Source.*md5/) {
155                 if (usedigest == 1) {
156                         sub(/^#[ \t]*Source/, "BuildRequires:\tdigest(%SOURCE", $0)
157                         sub(/-md5[ \t]*:[ \t]*/, ") = ", $0)
158                 }
159                 print $0
160                 next
161         }
162 }
163
164 /^%define/ {
165         # Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
166         if ($2 == "_applnkdir") {
167                 next
168         }
169         if ($2 == "date") {
170                 date = 1
171                 if (did_files == 0) {
172                         print "%files"
173                         print ""
174                         did_files = 1
175                 }
176         }
177
178         # Do not add %define of _prefix if it already is.
179         if ($2 ~ /^_prefix/) {
180                 sub("^"prefix, $3, bindir)
181                 sub("^"prefix, $3, sbindir)
182                 sub("^"prefix, $3, libdir)
183                 sub("^"prefix, $3, datadir)
184                 sub("^"prefix, $3, includedir)
185                 prefix = $3
186         }
187
188         if ($2 ~ /_bindir/ && !/_sbindir/)
189                 bindir = $3
190         if ($2 ~ /_sbindir/)
191                 sbindir = $3
192         if ($2 ~ /_libdir/) {
193                 if ($3 ~ /^%\(/) {
194                         # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
195                         libdir = "%%%%%%%%%%%%%%"
196                 } else {
197                         libdir = $3
198                 }
199         }
200         if ($2 ~ /_sysconfdir/) {
201                 if ($3 ~ /^%\(/) {
202                         # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
203                         sysconfdir = "%%%%%%%%%%%%%%"
204                 } else {
205                         sysconfdir = $3
206                 }
207         }
208         if ($2 ~ /_datadir/) {
209                 if ($3 ~ /^%\(/) {
210                         # TODO: should escape for latter checks like: ($c ~ sysconfdir "/{?cron.")
211                         datadir = "%%%%%%%%%%%%%%"
212                 } else {
213                         datadir = $3
214                 }
215         }
216         if ($2 ~ /_includedir/)
217                 includedir = $3
218         if ($2 ~ /_mandir/)
219                 mandir = $3
220         if ($2 ~ /_infodir/)
221                 infodir = $3
222         if ($2 ~ /_docdir/)
223                 docdir = $3
224
225         # version related macros
226         if ($2 ~ /^_beta$/)
227                 _beta = $3
228         if ($2 ~ /^_rc$/)
229                 _rc = $3
230         if ($2 ~ /^_pre$/)
231                 _pre = $3
232         if ($2 ~ /^_snap$/)
233                 _snap = $3
234         if ($2 ~ /^subver$/)
235                 subver = $3
236
237         # these are used usually when adapterizing external spec
238         if ($2 ~ /^name$/)
239                 name = $3
240         if ($2 ~ /^version$/)
241                 version = $3
242         if ($2 ~ /^release$/)
243                 release = $3
244
245         if ($2 ~ /^mod_name$/)
246                 mod_name = $3
247         if ($2 ~ /^_?pearname$/)
248                 pearname = $3
249         if ($2 ~ /^_class$/)
250                 pear_class = $3
251         if ($2 ~ /^_subclass$/)
252                 pear_subclass = $3
253
254         # kill the _class and _subclass pear macros
255         if ($2 == "_pearname" || $2 == "pearname") {
256                 if (pear_class) {
257                         gsub("%{_class}", pear_class, $3);
258                 }
259                 if (pear_subclass) {
260                         gsub("%{_subclass}", pear_subclass, $3);
261                 }
262         }
263
264         sub(/[ \t]+$/, "");
265         # do nothing further, otherwise adapter thinks we're at preamble
266         print
267         next
268 }
269
270 # Obsolete
271 /^%include.*\/usr\/lib\/rpm\/macros\.python$/ {
272         next
273 }
274
275 ################
276 # %description #
277 ################
278 /^%description/, (!/^%description/ && $0 ~ SECTIONS) {
279         preamble = 0
280
281         if (/^%description/) {
282                 bod++
283                 format_line = ""
284                 format_indent = -1
285         }
286
287         # Format description
288         if (ENVIRON["SKIP_DESC"] != 1 && description == 1 && !/^%[a-z]+/ && !/^%description/) {
289                 if (/^[ \t]*$/) {
290                         format_flush(format_line, format_indent)
291                         print ""
292                         format_line = ""
293                         format_indent = -1
294                 } else if (/^[ \t]*[-\*][ \t]*/) {
295                         format_flush(format_line, format_indent)
296                         match($0, /^[ \t]*/)
297                         format_indent = RLENGTH
298                         match($0, /^[ \t]*[-\*][ \t]/)
299                         format_line = substr($0, RLENGTH)
300                 } else
301                         format_line = format_line " " $0
302                 next
303         }
304
305         if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
306                 if (NF > 3 && $2 == "-l") {
307                         ll = $1
308                         for (i = 4; i <= NF; i++)
309                                 ll = ll " " $i
310                         $0 = ll " -l " $3
311                 }
312                 format_flush(format_line, format_indent)
313                 if (bod == 2) {
314                         bod = 1
315                         description = 1
316                 } else {
317                         bod = 0
318                         description = 0
319                 }
320         } else
321                 description = 1
322 }
323
324 #########
325 # %prep #
326 #########
327 /^%prep/, (!/^%prep/ && $0 ~ SECTIONS) {
328         preamble = 0
329         did_prep = 1
330
331         use_macros()
332
333         # Add '-q' to %setup
334         if (/^%setup/ && !/-q/) {
335                 sub(/^%setup/, "%setup -q")
336         }
337
338         if (/^%setup/ && name != "setup") {
339                 $0 = fixedsub(name, "%{name}", $0);
340                 $0 = fixedsub(version, "%{version}", $0);
341                 if (_beta) {
342                         $0 = fixedsub(_beta, "%{_beta}", $0);
343                 }
344                 if (_rc) {
345                         $0 = fixedsub(_rc, "%{_rc}", $0);
346                 }
347                 if (_pre) {
348                         $0 = fixedsub(_pre, "%{_pre}", $0);
349                 }
350                 if (_snap) {
351                         $0 = fixedsub(_snap, "%{_snap}", $0);
352                 }
353                 if (subver) {
354                         $0 = fixedsub(subver, "%{subver}", $0);
355                 }
356         }
357
358         if (/^%setup/ && /-n %{name}-%{version}( |$)/) {
359                 $0 = fixedsub(" -n %{name}-%{version}", "", $0)
360         }
361         sub("^%patch ", "%patch0 ");
362
363         # invalid in %prep
364         sub("^rm -rf \$RPM_BUILD_ROOT.*", "");
365 }
366
367 ##########
368 # %build #
369 ##########
370 /^%build/, (!/^%build/ && $0 ~ SECTIONS) {
371         preamble = 0
372
373         if (did_prep == 0) {
374                 print "%prep"
375                 print ""
376                 did_prep = 1
377         }
378
379         use_macros()
380         use_tabs()
381
382         if (/^automake$/)
383                 sub(/$/, " -a -c")
384
385         if (/LDFLAGS/) {
386                 if (/LDFLAGS="-s"/) {
387                         removed["LDFLAGS"] = 1
388                         next
389                 } else {
390                         split($0, tmp, "LDFLAGS=")
391                         count = split(tmp[2], flags, "\"")
392                         if (flags[1] != "" && flags[1] !~ "!?debug") {
393                                 sub(/-s[" ]?/, "%{rpmldflags} ", flags[1])
394                                 $0 = tmp[1] line[1] "LDFLAGS=" flags[1] "\""
395                                 for (i = 2; i < count; i++)
396                                         $0 = $0 flags[i] "\""
397                         }
398                 }
399         }
400
401         if (/CFLAGS=/)
402                 if (cflags("CFLAGS") == 0)
403                         next
404
405         if (/CXXFLAGS=/)
406                 if (cflags("CXXFLAGS") == 0)
407                         next
408
409         if (/^export /) {
410                 if (removed["LDFLAGS"])
411                         sub(" LDFLAGS", "")
412                 if (removed["CFLAGS"])
413                         sub(" CFLAGS", "")
414                 if (removed["CXXFLAGS"])
415                         sub(" CXXFLAGS", "")
416                 # Is there still something?
417                 if (/^export[ ]*$/)
418                         next
419         }
420
421         # quote CC
422         if (/CC=%{__cc} /) {
423                 sub("CC=%{__cc}", "CC=\"%{__cc}\"")
424         }
425         
426         # use PLD Linux macros
427         $0 = fixedsub("glib-gettextize --copy --force","%{__glib_gettextize}", $0);
428         $0 = fixedsub("intltoolize --copy --force", "%{__intltoolize}", $0);
429         $0 = fixedsub("automake --add-missing --copy", "%{__automake}", $0);
430         $0 = fixedsub("automake -a --foreign --copy", "%{__automake}", $0);
431         $0 = fixedsub("automake -a -c --foreign", "%{__automake}", $0);
432         $0 = fixedsub("automake -a -c", "%{__automake}", $0);
433         $0 = fixedsub("libtoolize --force --automake --copy", "%{__libtoolize}", $0);
434         $0 = fixedsub("libtoolize -c -f --automake", "%{__libtoolize}", $0);
435
436         sub(/^aclocal$/, "%{__aclocal}");
437         sub(/^autoheader$/, "%{__autoheader}");
438         sub(/^autoconf$/, "%{__autoconf}");
439         sub(/^automake$/, "%{__automake}");
440         sub(/^libtoolize$/, "%{__libtoolize}");
441
442         # atrpms
443         $0 = fixedsub("%perl_configure", "%{__perl} Makefile.PL \\\n\tINSTALLDIRS=vendor", $0);
444         $0 = fixedsub("%perl_makecheck", "%{?with_tests:%{__make} test}", $0);
445
446         # alt linux
447         $0 = fixedsub("%make_build", "%{__make}", $0);
448 }
449
450 ##########
451 # %clean #
452 ##########
453 /^%clean/, (!/^%clean/ && $0 ~ SECTIONS) {
454         did_clean = 1
455
456         use_macros()
457 }
458
459 ############
460 # %install #
461 ############
462 /^%install/, (!/^%install/ && $0 ~ SECTIONS) {
463
464         preamble = 0
465
466         # foreign rpms
467         sub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
468         sub("%buildroot", "$RPM_BUILD_ROOT");
469         sub("%{buildroot}", "$RPM_BUILD_ROOT");
470
471         if (/^[ \t]*rm([ \t]+-[rf]+)*[ \t]+(\${?RPM_BUILD_ROOT}?|%{?buildroot}?)/ && did_rmroot==0) {
472                 did_rmroot=1
473                 print "rm -rf $RPM_BUILD_ROOT"
474                 next
475         }
476
477         if (!/^(#?[ \t]*)$/ && !/^%install/ && did_rmroot==0) {
478                 print "rm -rf $RPM_BUILD_ROOT"
479                 did_rmroot=1
480         }
481
482         if (tmpdir) {
483                 buildroot = tmpdir "/" name "-" version "-root-" ENVIRON["USER"]
484                 gsub(buildroot, "$RPM_BUILD_ROOT")
485         }
486
487         if (!/%{_lib}/) {
488                 sub("\$RPM_BUILD_ROOT/%", "$RPM_BUILD_ROOT%")
489         }
490
491         use_macros()
492
493         # 'install -d' instead 'mkdir -p'
494         if (/mkdir -p/)
495                 sub(/mkdir -p/, "install -d")
496
497         # cp -a already implies cp -r
498         sub(/^cp -ar/, "cp -a")
499
500         # No '-u root' or '-g root' for 'install'
501         if (/^install/ && /-[ug][ \t]*root/)
502                 gsub(/-[ug][ \t]*root /, "")
503
504         if (/^install/ && /-m[ \t]*[0-9]+/)
505                 gsub(/-m[ \t]*[0-9]+ /, "")
506
507         # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
508         if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
509                 next
510
511         # No lines contain 'chmod' if it sets the modes to '644'
512         if ($1 ~ /chmod/ && $2 ~ /644/)
513                 next
514
515         # atrpms
516         $0 = fixedsub("%perl_makeinstall", "%{__make} pure_install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
517
518         # alt linux
519         $0 = fixedsub("%make_install DESTDIR=$RPM_BUILD_ROOT install", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT", $0);
520 }
521
522 ##########
523 # %files #
524 ##########
525 /^%files/, (!/^%files/ && $0 ~ SECTIONS) {
526         preamble = 0
527         did_files = 1
528
529         if ($0 ~ /^%files/)
530                 defattr = 1
531
532         if (!use_files_macros()) {
533                 next
534         }
535 }
536
537 ##############
538 # %changelog #
539 ##############
540 /^%changelog/, (!/^%changelog/ && $0 ~ SECTIONS) {
541         preamble = 0
542         has_changelog = 1
543         skip = 0
544         # There should be some CVS keywords on the first line of %changelog.
545         if (boc == 3) {
546                 if ($0 !~ _cvsmailfeedback) {
547                         print "* %{date} " _cvsmailfeedback > changelog_file
548                 } else {
549                         skip = 1
550                 }
551                 boc = 2
552         }
553         if (boc == 2 && !skip) {
554                 if (!/All persons listed below/) {
555                         printf "All persons listed below can be reached at " > changelog_file
556                         print "<cvs_login>" _cvsmaildomain "\n" > changelog_file
557                 } else {
558                         skip = 1
559                 }
560                 boc = 1
561         }
562         if (boc == 1 && !skip) {
563                 if (!/^$/) {
564                         if (!/\$.*Log:.*\$/) {
565                                 print "$" "Log:$" > changelog_file
566                         }
567                         boc = 0
568                 }
569         }
570         # Define date macro.
571         if (boc == 4) {
572                 if (date == 0) {
573                         printf "%%define date\t%%(echo `LC_ALL=\"C\"" > changelog_file
574                         print " date +\"%a %b %d %Y\"`)" > changelog_file
575                         date = 1
576                 }
577                 boc = 3
578         }
579
580         sub(/[ \t]+$/, "");
581         if (!/^%[a-z]+$/ || /changelog/) {
582                 # stop changelog if "real" changelog starts
583                 if (boc == 0 && /^\* /) {
584                         boc = -1
585                 }
586                 if (boc == -1) {
587                         next;
588                 }
589                 print > changelog_file
590         } else {
591                 print
592         }
593         next
594 }
595
596 ###########
597 # SCRIPTS #
598 ###########
599 /^%pre/, (!/^%pre/ && $0 ~ SECTIONS) {
600         preamble = 0
601
602         if (gsub("/usr/sbin/useradd", "%useradd")) {
603                 sub(" 2> /dev/null \|\| :", "");
604                 sub(" >/dev/null 2>&1 \|\|:", "");
605         }
606
607         # %useradd and %groupadd may not be wrapped
608         if (/%(useradd|groupadd).*\\$/) {
609                 a = $0; getline;
610                 sub(/^[\s\t]*/, "");
611                 $0 = substr(a, 1, length(a) - 1) $0;
612         }
613         use_script_macros()
614 }
615
616 /^%post/, (!/^%post/ && $0 ~ SECTIONS) {
617         preamble = 0
618         use_macros()
619 }
620 /^%preun/, (!/^%preun/ && $0 ~ SECTIONS) {
621         preamble = 0
622         use_macros()
623 }
624 /^%postun/, (!/^%postun/ && $0 ~ SECTIONS) {
625         preamble = 0
626         use_script_macros()
627 }
628 /^%triggerin/, (!/^%triggerin/ && $0 ~ SECTIONS) {
629         preamble = 0
630         use_script_macros()
631 }
632 /^%triggerun/, (!/^%triggerun/ && $0 ~ SECTIONS) {
633         preamble = 0
634         use_script_macros()
635 }
636 /^%triggerpostun/, (!/^%triggerpostun/ && $0 ~ SECTIONS) {
637         preamble = 0
638         use_script_macros()
639 }
640 /^%pretrans/, (!/^%pretrans/ && $0 ~ SECTIONS) {
641         preamble = 0
642         use_script_macros()
643 }
644 /^%posttrans/, (!/^%posttrans/ && $0 ~ SECTIONS) {
645         preamble = 0
646         use_script_macros()
647 }
648 /^%verifyscript/, (!/^%verifyscript/ && $0 ~ SECTIONS) {
649         preamble = 0
650         use_script_macros()
651 }
652 /^%check/, (!/^%check/ && $0 ~ SECTIONS) {
653         preamble = 0
654         use_script_macros()
655 }
656
657 #############
658 # PREAMBLES #
659 #############
660 preamble == 1 {
661         # There should not be a space after the name of field
662         # and before the colon.
663         sub(/[ \t]*:/, ":")
664
665         if (/^%perl_module_wo_prefix/) {
666                 name = $2
667                 version = $3
668                 release = "0." fixedsub(".%{disttag}.at", "", $4)
669         }
670
671         field = tolower($1)
672         if (field ~ /summary:/ && !/etc\.$/ && !/Inc\.$/) {
673                 sub(/\.$/, "", $0);
674         }
675         if (field ~ /group(\([^)]+\)):/)
676                 next
677         if (field ~ /group:/) {
678                 format_preamble()
679                 group = $0;
680                 sub(/^[^ \t]*[ \t]*/, "", group);
681                 group = replace_groupnames(group);
682                 $0 = "Group:\t\t" group
683
684                 if (group ~ /^X11/ && x11 == 0) # Is it X11 application?
685                         x11 = 1
686
687                 byl_plik_z_groupmi = 0
688                 byl_opis_grupy = 0
689                 while ((getline linia_grup < groups_file) > 0) {
690                         byl_plik_z_groupmi = 1
691                         if (linia_grup == group) {
692                                 byl_opis_grupy = 1
693                                 break
694                         }
695                 }
696
697                 if (!byl_plik_z_groupmi)
698                         print "######\t\t" groups_file ": no such file"
699                 else if (!byl_opis_grupy)
700                         print "######\t\t" "Unknown group!"
701
702                 close(groups_file)
703                 did_groups = 1
704         }
705
706         if (field ~ /prereq:/) {
707                 sub(/Pre[Rr]eq:/, "Requires:", $1);
708         }
709
710         # split (build)requires, obsoletes on commas
711         if (field ~ /(obsoletes|requires|provides|conflicts|suggests):/ && NF > 2) {
712                 value = substr($0, index($0, $2));
713                 $0 = format_requires($1, value);
714         }
715
716         # BR: tar (and others) is to common (rpm-build requires it)
717         if (field ~ /^buildrequires:/) {
718                 l = substr($0, index($0, $2));
719                 if (l == "awk" ||
720                         l == "binutils" ||
721                         l == "bzip2" ||
722                         l == "cpio" ||
723                         l == "diffutils" ||
724                         l == "elfutils" ||
725                         l == "fileutils" ||
726                         l == "findutils" ||
727                         l == "glibc-devel" ||
728                         l == "grep" ||
729                         l == "gzip" ||
730                         l == "make" ||
731                         l == "patch" ||
732                         l == "sed" ||
733                         l == "sh-utils" ||
734                         l == "tar" ||
735                         l == "textutils") {
736                         next
737                 }
738
739                 replace_requires();
740         }
741
742         if (field ~ /^requires:/ || field ~ /^requires\(/) {
743                 replace_requires();
744         }
745
746
747         # obsolete/unwanted tags
748         if (field ~ /vendor:|packager:|distribution:|docdir:|prefix:|icon:|author:|author-email:|metadata-version:/) {
749                 next
750         }
751
752         if (field ~ /buildroot:/) {
753                 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
754                 did_build_root = 1
755         }
756
757         # Use "License" instead of "Copyright" if it is (L)GPL or BSD
758         if (field ~ /copyright:/ && $2 ~ /GPL|BSD/) {
759                 $1 = "License:"
760         }
761
762         # ease updating from debian .dsc
763         if (field ~ /homepage:/) {
764                 $1 = "URL:"
765         }
766
767         # suse
768         if (field ~ /recommends:/) {
769                 $1 = "Suggests:"
770         }
771
772         if ($3 == "==" && $1 !~ /%/) {
773                 $3 = "="
774         }
775
776         if (field ~ /license:/) {
777                 l = substr($0, index($0, $2));
778                 if (l == "Python Software Foundation License") {
779                         l = "PSF"
780                 }
781                 if (l == "Apache License 2.0" || l == "Apache 2.0" || l == "Apache License Version 2.0" || l == "Apache License, Version 2.0" || l == "Apache Software License v2") {
782                         l = "Apache v2.0"
783                 }
784                 if (l == "Apache Group License" || l == "Apache Software License" || l == "Apache License") {
785                         l = "Apache"
786                 }
787                 if (l == "Apache-style License" || l == "Apache-style Software License") {
788                         l = "Apache-like"
789                 }
790                 if (l == "Apache Software License 1.1" || l == "Apache 1.1") {
791                         l = "Apache v1.1"
792                 }
793                 if (l == "GPLv2") {
794                         l = "GPL v2"
795                 }
796                 if (l == "GPLv2+") {
797                         l = "GPL v2+"
798                 }
799                 if (l == "GPL v2 or later") {
800                         l = "GPL v2+"
801                 }
802                 if (l == "LGPL v2.0 only") {
803                         l = "LGPL v2"
804                 }
805                 if (l == "LGPLv2+") {
806                         l = "LGPL v2+"
807                 }
808                 if (l == "GPLv3") {
809                         l = "GPL v3"
810                 }
811                 if (l == "GPLv3+") {
812                         l = "GPL v3+"
813                 }
814                 if (l == "MPLv1.1") {
815                         l = "MPL v1.1"
816                 }
817                 $0 = "License:\t" l;
818         }
819
820
821         if (field ~ /name:/) {
822                 if ($2 == "%{name}" && name) {
823                         $2 = name
824                 }
825                 name = $2
826                 name_seen = 1;
827         }
828
829         if (field ~ /version:/) {
830                 if ($2 == "%{version}" && version) {
831                         $2 = version
832                 }
833                 version = $2
834                 version_seen = 1;
835         }
836
837         if (field ~ /release:/) {
838                 if ($2 == "%{release}" && release) {
839                         $2 = release
840                 }
841                 sub(/%atrelease /, "0.", $0)
842                 release = $2
843                 release_seen = 1;
844         }
845
846
847         if (field ~ /serial:/)
848                 $1 = "Epoch:"
849
850         if (field ~ /home-page:/)
851                 $1 = "URL:"
852
853         # proper caps
854         if (field ~ /^url:$/)
855                 $1 = "URL:"
856
857         if (field ~ /^patch/)
858                 $1 = "Patch" substr(field, 6);
859
860         if (field ~ /^description:$/)
861                 $1 = "\n%description\n"
862
863         # Use %{name} and %{version} in the filenames in "Source:"
864         if (field ~ /^source/ || field ~ /patch/) {
865                 n = split($2, url, /\//)
866                 if (url[n] ~ /\.gz$/) {
867                         url[n+1] = ".gz" url[n+1]
868                         sub(/\.gz$/,"",url[n])
869                 }
870                 if (url[n] ~ /\.zip$/) {
871                         url[n+1] = ".zip" url[n+1]
872                         sub(/\.zip$/,"",url[n])
873                 }
874                 if (url[n] ~ /\.tar$/) {
875                         url[n+1] = ".tar" url[n+1]
876                         sub(/\.tar$/,"",url[n])
877                 }
878                 if (url[n] ~ /\.patch$/) {
879                         url[n+1] = ".patch" url[n+1]
880                         sub(/\.patch$/,"",url[n])
881                 }
882                 if (url[n] ~ /\.bz2$/) {
883                         url[n+1] = ".bz2" url[n+1]
884                         sub(/\.bz2$/,"",url[n])
885                 }
886                 if (url[n] ~ /\.logrotate$/) {
887                         url[n+1] = ".logrotate" url[n+1]
888                         sub(/\.logrotate$/,"",url[n])
889                 }
890                 if (url[n] ~ /\.pamd$/) {
891                         url[n+1] = ".pamd" url[n+1]
892                         sub(/\.pamd$/,"",url[n])
893                 }
894
895                 # allow %{name} only in last url component
896                 s = ""
897                 for (i = 1; i <= n; i++) {
898                         url[i] = fixedsub("%{name}", name, url[i])
899                         if (s) {
900                                 s = s "/" url[i]
901                         } else {
902                                 s = url[i]
903                         }
904                 }
905                 $2 = s url[n+1]
906
907                 filename = url[n]
908                 if (name) {
909                         url[n] = fixedsub(name, "%{name}", url[n])
910                 }
911                 if (field ~ /source/) {
912                         if (version) {
913                                 url[n] = fixedsub(version, "%{version}", url[n])
914                         }
915                         if (_beta) {
916                                 url[n] = fixedsub(_beta, "%{_beta}", url[n])
917                         }
918                         if (_rc) {
919                                 url[n] = fixedsub(_rc, "%{_rc}", url[n])
920                         }
921                         if (_pre) {
922                                 url[n] = fixedsub(_pre, "%{_pre}", url[n])
923                         }
924                         if (_snap) {
925                                 url[n] = fixedsub(_snap, "%{_snap}", url[n])
926                         }
927                         if (subver) {
928                                 url[n] = fixedsub(subver, "%{subver}", url[n])
929                         }
930                 }
931                 # assigning to $2 kills preamble formatting
932                 $2 = fixedsub(filename, url[n], $2)
933
934                 $2 = unify_url($2)
935         }
936
937
938         if (field ~ /^source:/)
939                 $1 = "Source0:"
940
941         if (field ~ /^patch:/)
942                 $1 = "Patch0:"
943
944         kill_preamble_macros();
945         format_preamble()
946
947         if (field ~ /requires/) {
948                 # atrpms
949                 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
950         }
951 }
952
953 /^%bcond_/ {
954         # do nothing
955         print
956         next
957 }
958
959 # sort BR/R!
960 #
961 # NOTES:
962 # - mixing BR/R and anything else confuses this (all will be sorted together)
963 #       so don't do that.
964 # - comments leading the BR/R can not be associated,
965 #       so don't adapterize when the BR/R are mixed with comments
966 ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && $0 ~ PREAMBLE_TAGS ":", $0 ~ PREAMBLE_TAGS ":"{
967         if ($1 ~ /Pre[Rr]eq:/) {
968                 sub(/Pre[Rr]eq:/, "Requires:", $1);
969         }
970         if ($1 == "BR:" ) {
971                 $1 = "BuildRequires:"
972         }
973         if ($1 == "R:" ) {
974                 $1 = "Requires:"
975         }
976         format_preamble()
977 #       kill_preamble_macros(); # breaks tabbing
978
979         b_idx++;
980         l = substr($0, index($0, $2));
981         b_ktmp = b_makekey($1, l);
982         b_key[b_idx] = b_ktmp;
983         b_val[b_ktmp] = $0;
984
985         next;
986 }
987
988 preamble == 1 {
989         if (b_idx > 0) {
990                 isort(b_key, b_idx);
991                 for (i = 1; i <= b_idx; i++) {
992                         v = b_val[b_key[i]];
993                         sub(/[ \t]+$/, "", v);
994                         print "" v;
995                 }
996                 b_idx = 0
997         }
998 }
999
1000 # main() ;-)
1001 {
1002         preamble = 1
1003
1004         sub(/[ \t]+$/, "")
1005         print
1006
1007         if (name_seen == 0 && name) {
1008                 print "Name:\t\t" name
1009                 name_seen = 1
1010         }
1011
1012         if (version_seen == 0 && version) {
1013                 print "Version:\t" version
1014                 version_seen = 1
1015         }
1016
1017         if (release_seen == 0 && release) {
1018                 print "Release:\t" release
1019                 release_seen = 1
1020         }
1021
1022         if (did_build_root == 0) {
1023 #               print "BuildRoot:\t%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
1024                 did_build_root = 1
1025         }
1026         if (did_groups == 0) {
1027 #               print "Group:\t\tunknown"
1028                 did_groups = 1
1029         }
1030 }
1031
1032
1033 END {
1034         if (do_not_touch_anything) {
1035                 exit(rc)
1036         }
1037
1038         # TODO: need to output these in proper place
1039         if (BR_count > 0) {
1040                 for (i = 0; i <= BR_count; i++) {
1041                         print BR[i];
1042                 }
1043         }
1044
1045         close(changelog_file)
1046         while ((getline < changelog_file) > 0)
1047                 print
1048         system("rm -f " changelog_file)
1049
1050         if (did_clean == 0) {
1051                 print ""
1052                 print "%clean"
1053                 print "rm -rf $RPM_BUILD_ROOT"
1054         }
1055
1056         if (date == 0) {
1057                 print ""
1058                 print "%define date\t%(echo `LC_ALL=\"C\" date +\"%a %b %d %Y\"`)"
1059         }
1060
1061         if (has_changelog == 0) {
1062                 print "%changelog"
1063         }
1064
1065         if (boc > 2) {
1066                 print "* %{date} PLD Team <feedback@pld-linux.org>"
1067         }
1068         if (boc > 1) {
1069                 printf "All persons listed below can be reached at "
1070                 print "<cvs_login>@pld-linux.org\n"
1071         }
1072         if (boc > 0) {
1073                 print "$" "Log:$"
1074         }
1075 }
1076
1077 # substitutes fixed strings (not regexps)
1078 function fixedsub(s1,s2,t, ind) {
1079         if (ind = index(t,s1))
1080                 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
1081         return t
1082 }
1083
1084 # replace s with s2 if it equals to s1
1085 function replace(s, s1, s2) {
1086         if (s == s1) {
1087                 return s2;
1088         } else {
1089                 return s;
1090         }
1091 }
1092
1093 # There should be one or two tabs after the colon.
1094 function format_preamble()
1095 {
1096         if (/^#/ || /^%bcond_with/) {
1097                 return;
1098         }
1099         sub(/:[ \t]*/, ":")
1100         if (match($0, /[A-Za-z0-9(),#_ \t.-]+[ \t]*:[ \t]*/) == 1) {
1101                 if (RLENGTH < 8) {
1102                         sub(/:/, ":\t\t")
1103                 } else {
1104                         sub(/:/, ":\t")
1105                 }
1106         }
1107 }
1108
1109 # Replace directly specified directories with macros
1110 function use_macros()
1111 {
1112         # -m, --skip-macros, --no-macros -- skip macros subst
1113         if (ENVIRON["SKIP_MACROS"]) {
1114                 return
1115         }
1116
1117         # leave inline sed lines alone
1118         if (/(%{__sed}|sed) -i -e/) {
1119                 return;
1120         }
1121
1122         sub("%{_defaultdocdir}", "%{_docdir}");
1123         sub("%{_bindir}/perl", "%{__perl}");
1124         sub("%{_bindir}/python", "%{__python}");
1125
1126         gsub(infodir, "%{_infodir}")
1127
1128         gsub(perl_sitearch, "%{perl_sitearch}")
1129         gsub(perl_archlib, "%{perl_archlib}")
1130         gsub(perl_privlib, "%{perl_privlib}")
1131         gsub(perl_vendorlib, "%{perl_vendorlib}")
1132         gsub(perl_vendorarch, "%{perl_vendorarch}")
1133         gsub(perl_sitelib, "%{perl_sitelib}")
1134         
1135         gsub(py_sitescriptdir, "%{py_sitescriptdir}")
1136         gsub(py_sitedir, "%{py_sitedir}")
1137         gsub(py_scriptdir, "%{py_scriptdir}")
1138
1139         gsub(py3_sitescriptdir, "%{py3_sitescriptdir}")
1140         gsub(py3_sitedir, "%{py3_sitedir}")
1141         gsub(py3_scriptdir, "%{py3_scriptdir}")
1142
1143         gsub(ruby_archdir, "%{ruby_archdir}")
1144         gsub(ruby_ridir, "%{ruby_ridir}")
1145         gsub(ruby_rubylibdir, "%{ruby_rubylibdir}")
1146         gsub(ruby_sitearchdir, "%{ruby_sitearchdir}")
1147         gsub(ruby_sitelibdir, "%{ruby_sitelibdir}")
1148         gsub(ruby_rdocdir, "%{ruby_rdocdir}")
1149
1150         gsub("%{_datadir}/applications", "%{_desktopdir}")
1151         gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}")
1152         gsub("%{_datadir}/java", "%{_javadir}")
1153
1154         gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}")
1155         gsub(pkgconfigdir, "%{_pkgconfigdir}")
1156
1157         gsub("%{_datadir}/pkgconfig", "%{_npkgconfigdir}")
1158         gsub(npkgconfigdir, "%{_npkgconfigdir}")
1159
1160         gsub(libdir, "%{_libdir}")
1161         gsub(javadir, "%{_javadir}")
1162
1163         gsub(bindir, "%{_bindir}")
1164         gsub("%{prefix}/bin", "%{_bindir}")
1165         if (prefix"/bin" == bindir)
1166                 gsub("%{_prefix}/bin", "%{_bindir}")
1167
1168         for (c = 1; c <= NF; c++) {
1169                 if ($c ~ sbindir "/fix-info-dir")
1170                         continue;
1171                 if ($c ~ sbindir "/webapp")
1172                         continue;
1173                 if ($c ~ sbindir "/ldconfig")
1174                         continue;
1175                 if ($c ~ sbindir "/chsh")
1176                         continue;
1177                 if ($c ~ sbindir "/usermod")
1178                         continue;
1179                 if ($c ~ sbindir "/chkconfig")
1180                         continue;
1181                 if ($c ~ sbindir "/installzope(product|3package)")
1182                         continue;
1183                 gsub(sbindir, "%{_sbindir}", $c)
1184         }
1185
1186         gsub("%{prefix}/sbin", "%{_sbindir}")
1187         if (prefix"/sbin" == sbindir) {
1188                 gsub("%{_prefix}/sbin", "%{_sbindir}")
1189         }
1190
1191         for (c = 1; c <= NF; c++) {
1192                 if ($c ~ sysconfdir "/{?cron.")
1193                         continue;
1194                 if ($c ~ sysconfdir "/{?crontab.d")
1195                         continue;
1196                 if ($c ~ sysconfdir "/{?env.d")
1197                         continue;
1198                 if ($c ~ sysconfdir "/{?modprobe.(d|conf)")
1199                         continue;
1200                 if ($c ~ sysconfdir "/{?udev")
1201                         continue;
1202                 if ($c ~ sysconfdir "/{?hotplug")
1203                         continue;
1204                 if ($c ~ sysconfdir "/{?logrotate.d")
1205                         continue;
1206                 if ($c ~ sysconfdir "/{?pam.d")
1207                         continue;
1208                 if ($c ~ sysconfdir "/{?profile.d")
1209                         continue;
1210                 if ($c ~ sysconfdir "/{?rc.d")
1211                         continue;
1212                 if ($c ~ sysconfdir "/{?security")
1213                         continue;
1214                 if ($c ~ sysconfdir "/{?skel")
1215                         continue;
1216                 if ($c ~ sysconfdir "/{?sysconfig")
1217                         continue;
1218                 if ($c ~ sysconfdir "/{?shrc.d")
1219                         continue;
1220                 if ($c ~ sysconfdir "/{?certs")
1221                         continue;
1222                 if ($c ~ sysconfdir "/{?X11")
1223                         continue;
1224                 if ($c ~ sysconfdir "/{?ld.so.conf.d")
1225                         continue;
1226                 if ($c ~ sysconfdir "/{?rpm")
1227                         continue;
1228                 if ($c ~ sysconfdir "/{?bash_completion.d")
1229                         continue;
1230                 if ($c ~ sysconfdir "/{?samba")
1231                         continue;
1232                 if ($c ~ sysconfdir "/{?xdg")
1233                         continue;
1234                 if ($c ~ sysconfdir "/shells")
1235                         continue;
1236                 if ($c ~ sysconfdir "/inittab")
1237                         continue;
1238                 if ($c ~ sysconfdir "/init")
1239                         continue;
1240                 if ($c ~ sysconfdir "/ppp")
1241                         continue;
1242                 if ($c ~ sysconfdir "/dbus-1")
1243                         continue;
1244                 if ($c ~ sysconfdir "/tmpwatch")
1245                         continue;
1246                 if ($c ~ sysconfdir "/acpi")
1247                         continue;
1248                 if ($c ~ sysconfdir "/apm")
1249                         continue;
1250                 gsub(sysconfdir, "%{_sysconfdir}", $c)
1251         }
1252
1253         gsub(docdir, "%{_docdir}")
1254
1255         gsub(kdedocdir, "%{_kdedocdir}")
1256
1257         gsub(gtkdocdir, "%{_gtkdocdir}")
1258         gsub("%{_docdir}/gtk-doc/html", "%{_gtkdocdir}")
1259
1260         gsub(php_pear_dir, "%{php_pear_dir}")
1261         gsub(php_data_dir, "%{php_data_dir}")
1262
1263         for (c = 1; c <= NF; c++) {
1264                 if ($c ~ datadir "/automake")
1265                         continue;
1266                 if ($c ~ datadir "/unsermake")
1267                         continue;
1268                 if ($c ~ datadir "/file/magic.mime")
1269                         continue;
1270                 gsub(datadir, "%{_datadir}", $c)
1271         }
1272
1273         gsub("%{prefix}/share", "%{_datadir}")
1274         if (prefix"/share" == datadir)
1275                 gsub("%{_prefix}/share", "%{_datadir}")
1276
1277         # CFLAGS="-I/usr/include/ncurses is usually correct.
1278         if (!/-I\/usr\/include/) {
1279                 gsub(includedir, "%{_includedir}")
1280         }
1281
1282         gsub("%{prefix}/include", "%{_includedir}")
1283         if (prefix"/include" == includedir) {
1284                 gsub("%{_prefix}/include", "%{_includedir}")
1285         }
1286
1287         gsub(mandir, "%{_mandir}")
1288         if ($0 !~ "%{_datadir}/manual") {
1289                 gsub("%{_datadir}/man", "%{_mandir}")
1290         }
1291         gsub("%{_prefix}/share/man", "%{_mandir}")
1292         gsub("%{prefix}/share/man", "%{_mandir}")
1293         gsub("%{prefix}/man", "%{_mandir}")
1294         gsub("%{_prefix}/man", "%{_mandir}")
1295
1296         gsub(infodir, "%{_infodir}")
1297         gsub("%{prefix}/info", "%{_infodir}")
1298         gsub("%{_prefix}/info", "%{_infodir}")
1299
1300         if (prefix !~ "/X11R6") {
1301                 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
1302         }
1303
1304         gsub(examplesdir, "%{_examplesdir}")
1305
1306         if (prefix != "/") {
1307                 # leave --with-foo=/usr alone
1308                 if ($0 !~ "--with.*=.*" prefix) {
1309                         for (c = 1; c <= NF; c++) {
1310                                 if ($c ~ prefix "/sbin/fix-info-dir")
1311                                         continue;
1312                                 if ($c ~ prefix "/sbin/webapp")
1313                                         continue;
1314                                 if ($c ~ prefix "/sbin/chsh")
1315                                         continue;
1316                                 if ($c ~ prefix "/sbin/usermod")
1317                                         continue;
1318                                 if ($c ~ prefix "/sbin/installzope(product|3package)")
1319                                         continue;
1320                                 if ($c ~ prefix "/share/automake")
1321                                         continue;
1322                                 if ($c ~ prefix "/share/unsermake")
1323                                         continue;
1324                                 if ($c ~ prefix "/lib/sendmail")
1325                                         continue;
1326                                 if ($c ~ prefix "/lib/pkgconfig")
1327                                         continue;
1328
1329                                 # CFLAGS="-I/usr..." is usually correct.
1330                                 if (/-I\/usr/)
1331                                         continue;
1332                                 # same for LDFLAGS="-L/usr..."
1333                                 if (/-L\/usr/)
1334                                         continue;
1335
1336                                 gsub(prefix, "%{_prefix}", $c)
1337                         }
1338                 }
1339                 gsub("%{prefix}", "%{_prefix}")
1340         }
1341
1342         # replace back
1343         gsub("%{_includedir}/ncurses", "/usr/include/ncurses")
1344         gsub("%{_includedir}/freetype", "/usr/include/freetype")
1345
1346         gsub("%{PACKAGE_VERSION}", "%{version}")
1347         gsub("%{PACKAGE_NAME}", "%{name}")
1348
1349         gsub("^make$", "%{__make}")
1350         gsub("^make ", "%{__make} ")
1351         gsub("^gcc ", "%{__cc} ")
1352         gsub("^rm --interactive=never ", "%{__rm} ")
1353
1354         # fedora
1355         gsub("%{ruby_sitearch}", "%{ruby_sitearchdir}")
1356         gsub("%{python_sitearch}", "%{py_sitedir}")
1357         gsub("%{python_sitelib}", "%{py_sitescriptdir}")
1358
1359         # alt linux
1360         gsub("%_man1dir", "%{_mandir}/man1")
1361
1362         # mandrake specs
1363         gsub("^%make$", "%{__make}")
1364         gsub("^%make ", "%{__make} ")
1365         gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1366         gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1367         gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1368         gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
1369         gsub("^%{__install}", "install")
1370         gsub("%optflags", "%{rpmcflags}")
1371         gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
1372
1373         gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1374         gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\\&1")
1375         $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
1376         $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
1377         $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
1378         $0 = fixedsub("%__install", "install", $0);
1379
1380         # split configure line to multiple lines
1381         if (/%configure +$/) {
1382                 sub( / +$/, "" );
1383         } else if (/%configure / && !/\\$/) {
1384                 $0 = format_configure($0);
1385         }
1386
1387         gsub("%_bindir", "%{_bindir}")
1388         gsub("%_datadir", "%{_datadir}")
1389         gsub("%_iconsdir", "%{_iconsdir}")
1390         gsub("%_sbindir", "%{_sbindir}")
1391         gsub("%_mandir", "%{_mandir}")
1392         gsub("%name", "%{name}")
1393         gsub(/%__rm/, "rm");
1394         gsub(/%__mkdir_p/, "install -d");
1395         gsub(/%__cp/, "cp");
1396         gsub(/%__ln_s/, "ln -s");
1397         gsub(/%__sed/, "%{__sed}");
1398         gsub(/%__cat/, "cat");
1399         gsub(/%__chmod/, "chmod");
1400
1401         gsub("/usr/src/linux", "%{_kernelsrcdir}")
1402         gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
1403
1404         if (/^ant / || /^%{ant}/) {
1405                 sub(/^ant/, "%ant")
1406                 sub(/^%{ant}/, "%ant")
1407                 add_br("BuildRequires:  jpackage-utils");
1408                 add_br("BuildRequires:  rpmbuild(macros) >= 1.300");
1409         }
1410
1411         $0 = fixedsub("%(%{__cc} -dumpversion)", "%{cc_version}", $0);
1412         $0 = fixedsub("%(%{__cxx} -dumpversion)", "%{cxx_version}", $0);
1413
1414         # kill the _class and _subclass pear macros
1415         if (pear_class) {
1416                 gsub("%{_class}", pear_class);
1417         }
1418         if (pear_subclass) {
1419                 gsub("%{_subclass}", pear_subclass);
1420         }
1421
1422 }
1423
1424 function format_configure(line,         n, a, s) {
1425         n = split(line, a, / /);
1426         s = a[1] " \\\n";
1427         for (i = 2; i <= n; i++) {
1428                 s = s "\t" a[i] " \\\n"
1429         }
1430         return s
1431 }
1432
1433
1434 # insertion sort of A[1..n]
1435 # copied from mawk manual
1436 function isort(A,n,             i,j,hold) {
1437         for (i = 2; i <= n; i++) {
1438                 hold = A[j = i]
1439                 while (A[j-1] > hold) {
1440                         j-- ; A[j+1] = A[j]
1441                 }
1442                 A[j] = hold
1443         }
1444         # sentinel A[0] = "" will be created if needed
1445 }
1446
1447
1448 function use_files_macros(      i, n, t, a, l)
1449 {
1450         use_macros()
1451
1452         # skip comments
1453         if (/^#/) {
1454                 return 1;
1455         }
1456
1457         sub("^%doc %{_mandir}", "%{_mandir}")
1458
1459         gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1460         gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1461
1462         # uid/gid nobody is not valid in %files
1463         if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1464                 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1465         }
1466
1467         # s[gu]id programs with globs are evil
1468         if (/%attr\([246]...,.*\*/ && !/FIXME/) {
1469                 $0 = $0 " # FIXME no globs for suid/sgid files"
1470         }
1471
1472         # replace back
1473         gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1474         gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1475         gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1476         gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1477         gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1478         gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1479         gsub("%{_sysconfdir}/security", "/etc/security")
1480         gsub("%{_sysconfdir}/skel", "/etc/skel")
1481         gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1482         gsub("%{_sysconfdir}/certs", "/etc/certs")
1483         gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1484         gsub("%{_sysconfdir}/dbus-1", "/etc/dbus-1")
1485         gsub("%{_sysconfdir}/pki", "/etc/pki")
1486         gsub("%{_sysconfdir}/tmpwatch", "/etc/tmpwatch")
1487
1488         # /etc/init.d -> /etc/rc.d/init.d
1489         if (!/^\/etc\/init\.d$/) {
1490                  gsub("/etc/init.d", "/etc/rc.d/init.d")
1491         }
1492
1493         if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1494                 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1495                         $0 = "%attr(754,root,root) " $0
1496                 }
1497                 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1498                         gsub("^%attr\\(... *,", "%attr(754,");
1499                 }
1500         }
1501
1502         if (/lib.+\.so\b/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1503                 $0 = "%attr(755,root,root) " $0
1504         }
1505
1506         if (/%{perl_vendorarch}.*\.so$/ && !/^%attr.*/) {
1507                 $0 = "%attr(755,root,root) " $0
1508         }
1509
1510         # remove attrs from man pages
1511         if (/%{_mandir}/ && /^%attr/) {
1512                 sub("^%attr\\(.*\\) *", "");
1513         }
1514
1515         # /etc/sysconfig files
1516         # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1517         # attr not required, allow default 644 attr
1518         if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1519                 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace/) {
1520                         gsub("%config", "%config(noreplace)")
1521                 }
1522
1523                 if (/\/etc\/sysconfig\// && !/%config\(noreplace/) {
1524                         $NF = "%config(noreplace) " $NF
1525                 }
1526
1527                 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1528                         gsub("^%attr\\(... *,", "%attr(640,");
1529                 }
1530
1531                 if (/\/etc\/sysconfig\// && !/%verify/) {
1532                         gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1533                 }
1534         }
1535
1536         # kill leading zeros
1537         if (/%attr\(0[1-9]/) {
1538                 gsub("%attr\\(0", "%attr(")
1539         }
1540
1541         # kill leading whitespace
1542         gsub(/^ +/, "");
1543
1544         # kill default attrs
1545         gsub(/%dir %attr\(755,root,root\)/, "%dir");
1546         gsub(/%attr\(755,root,root\) %dir/, "%dir");
1547         if (!/%dir/) {
1548                 gsub(/%attr\(644,root,root\) /, "");
1549         }
1550
1551         # sort %verify attrs
1552         if (match($0, /%verify\(not([^)]+)\)/)) {
1553                 t = substr($0, RSTART, RLENGTH)
1554                 # kill commas: %verify(not,md5,size,mtime)
1555                 gsub(/,/, " ", t);
1556
1557                 gsub(/^%verify\(not |\)$/, "", t)
1558                 n = split(t, a, / /)
1559                 isort(a, n)
1560
1561                 s = "%verify(not"
1562                 for (i = 1 ; i <= n; i++) {
1563                         s = s " " a[i]
1564                 }
1565                 s = s ")"
1566
1567                 gsub(/%verify\(not[^)]+\)/, s)
1568         }
1569
1570         if (/%{_mandir}/) {
1571                 gsub("\.gz$", "*")
1572                 gsub("%ext_man$", "*")
1573         }
1574
1575         # locale dir and no %lang -> bad
1576         if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1577                 $(NF + 1) = "# FIXME consider using %find_lang"
1578         }
1579
1580         # python egg-infos
1581         if (match($0, "^%{py_site(script)?dir}/.+-py"py_ver".egg-info$")) {
1582                 # tests:
1583                 #%{py_sitedir}/*-py2.4.egg-info
1584                 #%{py_sitescriptdir}/GnuPGInterface-%{version}-py2.4.egg-info
1585                 #%{py_sitescriptdir}/python_mpd-%{version}-py2.4.egg-info
1586                 #%{py_sitescriptdir}/mechanize-0.1.6b-py2.4.egg-info
1587
1588                 l = index($0, "/");
1589                 t = substr($0, 0, l);
1590                 s = substr($0, l + 1, RLENGTH - l - length("-py"py_ver".egg-info"));
1591                 if (match(s, "[^-]+$")) {
1592                         if (RSTART > 1) {
1593                                 s = substr(s, 0, RSTART - 1);
1594                         }
1595                         print "%if \"%{py_ver}\" > \"2.4\""
1596                         gsub(t "/.+.egg-info", t "/" s "-*.egg-info");
1597                         print
1598                         print "%endif"
1599                         return 0;
1600                 }
1601         }
1602
1603         # atrpms
1604         $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1605         $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1606         $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1607
1608         gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1609         gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1610         gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1611
1612         gsub("%{_datadir}/applications", "%{_desktopdir}");
1613         gsub("%{_datadir}/icons", "%{_iconsdir}");
1614         gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1615         gsub("%{_datadir}/pear", "%{php_pear_dir}");
1616         gsub("%{_datadir}/php", "%{php_data_dir}");
1617
1618         return 1
1619 }
1620
1621 function use_script_macros()
1622 {
1623         if (gsub("/sbin/service", "%service")) {
1624                 sub(" >/dev/null 2>&1 \|\|:", "");
1625                 sub(" 2> /dev/null \|\| :", "");
1626         }
1627 }
1628
1629 function fill(ch, n, i) {
1630         for (i = 0; i < n; i++)
1631                 printf("%c", ch)
1632 }
1633
1634 function format_flush(line, indent, newline, word, first_word) {
1635         first_word = 1
1636         if (format_indent == -1)
1637                 newline = ""
1638         else
1639                 newline = fill(" ", format_indent) "- "
1640
1641         while (match(line, /[^\t ]+/)) {
1642                 word = substr(line, RSTART, RLENGTH)
1643                 if (length(newline) + length(word) + 1 > tw) {
1644                         print newline
1645
1646                         if (format_indent == -1)
1647                                 newline = ""
1648                         else
1649                                 newline = fill(" ", format_indent + 2)
1650                         first_word = 1
1651                 }
1652
1653                 if (first_word) {
1654                         newline = newline word
1655                         first_word = 0
1656                 } else
1657                         newline = newline " " word
1658
1659                 line = substr(line, RSTART + RLENGTH)
1660         }
1661         if (newline ~ /[^\t ]/) {
1662                 print newline
1663         }
1664 }
1665
1666 function cflags(var)
1667 {
1668         if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1669                 removed[var] = 1
1670                 return 0
1671         }
1672
1673         if (!/!\?debug/)
1674                 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
1675         return 1
1676 }
1677
1678 # return whole matched pattern
1679 function matchstr(str, pat)
1680 {
1681         match(str, "[^/]+$");
1682         return substr(str, RSTART, RLENGTH);
1683 }
1684
1685 function unify_url(url)
1686 {
1687
1688         # sourceforge urls
1689         # Docs about sourceforge mirror system: http://sourceforge.net/apps/trac/sourceforge/wiki/Mirrors
1690
1691         # 1. unify domains
1692         sub("^http://prdownloads\.sourceforge\.net/", "http://downloads.sourceforge.net/", url)
1693         sub("^http://download\.sf\.net/", "http://downloads.sourceforge.net/", url)
1694         sub("^http://download\.sourceforge\.net/", "http://downloads.sourceforge.net/", url)
1695         sub("^http://dl\.sourceforge\.net/", "http://downloads.sourceforge.net/", url)
1696         sub("^http://.*\.dl\.sourceforge\.net/", "http://downloads.sourceforge.net/", url)
1697         sub("^http://dl\.sf\.net/", "http://downloads.sourceforge.net/", url)
1698         sub("^http://downloads\.sourceforge\.net/sourceforge/", "http://downloads.sourceforge.net/", url)
1699
1700         # 3. unify urls
1701         if (url ~ /sourceforge.net/) {
1702                 sub("[?&]big_mirror=.*$", "", url);
1703                 sub("[?&]modtime=.*$", "", url);
1704                 sub("[?]use_mirror=.*$", "", url);
1705                 sub("[?]download$", "", url);
1706                 sub("/download$", "", url);
1707         }
1708
1709         # SF: new style urls, strip "files/" between and prepend dl.
1710         if (match(url, "^http://sourceforge.net/projects/[^/]+/files/")) {
1711                 url = substr(url, 1, RLENGTH - length("files/")) substr(url, RSTART + RLENGTH);
1712                 sub("^http://sourceforge.net/projects/", "http://downloads.sourceforge.net/project/", url);
1713         }
1714
1715         # SF unify: http://downloads.sourceforge.net/PROJECT/TARBALL
1716         # http://downloads.sourceforge.net/project/PROJECT/FILE/VERSION/%{name}-%{version}.zip
1717         if (match(url, "^http://downloads.sourceforge.net/project/[^/]+")) {
1718                 url = sprintf("http://downloads.sourceforge.net/%s/%s", substr(url, 42, RLENGTH - 41), matchstr(url, "[^/]+$"));
1719         }
1720
1721         sub("^ftp://ftp\.gnome\.org/", "http://ftp.gnome.org/", url)
1722         sub("^http://ftp\.gnome\.org/pub/gnome/", "http://ftp.gnome.org/pub/GNOME/", url)
1723
1724         # apache urls
1725         sub("^http://apache.zone-h.org/", "http://www.apache.org/dist/", url)
1726
1727         # gnu.org
1728         sub("^ftp://ftp\.gnu\.org/", "http://ftp.gnu.org/", url)
1729         sub("^http://ftp\.gnu\.org/pub/gnu/", "http://ftp.gnu.org/gnu/", url)
1730
1731         # debian.org
1732         sub("^ftp://ftp\.[^.]+\.debian\.org/", "ftp://ftp.debian.org/", url)
1733         sub("^http://ftp\.[^.]+\.debian\.org/", "ftp://ftp.debian.org/", url)
1734         sub("^ftp://ftp\.debian\.org/pub/debian/", "ftp://ftp.debian.org/debian/", url)
1735
1736         return url
1737 }
1738
1739 function demacroize(str)
1740 {
1741         if (mod_name) {
1742                 sub("%{mod_name}", mod_name, str);
1743         }
1744         if (pearname) {
1745                 sub("%{_pearname}", pearname, str);
1746         }
1747         if (pearname) {
1748                 sub("%{pearname}", pearname, str);
1749         }
1750         if (name) {
1751                 sub("%{name}", name, str);
1752         }
1753         if (version) {
1754                 sub("%{version}", version, str);
1755         }
1756         if (_beta) {
1757                 sub("%{_beta}", _beta, str);
1758         }
1759         if (_rc) {
1760                 sub("%{_rc}", _rc, str);
1761         }
1762         if (_pre) {
1763                 sub("%{_pre}", _pre, str);
1764         }
1765         if (_snap) {
1766                 sub("%{_snap}", _snap, str);
1767         }
1768         if (subver) {
1769                 sub("%{subver}", subver, str);
1770         }
1771         return str;
1772 }
1773
1774 function kill_preamble_macros()
1775 {
1776         if ($1 ~ /^Obsoletes:/) {
1777                 # NB! assigning $2 a value breaks tabbing
1778                 $2 = demacroize($2);
1779         }
1780         if ($1 ~ /^URL:/) {
1781                 # NB! assigning $2 a value breaks tabbing
1782                 $2 = demacroize($2);
1783                 $2 = unify_url($2)
1784         }
1785 }
1786
1787 function get_epoch(pkg, ver,    epoch)
1788 {
1789         return
1790 # should parse the BR lines more adequately:
1791 #       freetype = 2.0.0 -> correct
1792 #       freetype = 2.1.9 -> with epoch 1, as epoch 1 was added in 2.1.7
1793
1794         shell = "grep -o '^" pkg ":[^:]\+' ../PLD-doc/BuildRequires.txt | awk '{print $NF}'";
1795         shell | getline epoch;
1796         return epoch;
1797 }
1798
1799 function format_requires(tag, value,    n, p, i, deps, ndeps) {
1800         # skip any formatting for commented out items or some weird macros
1801         if (/^#/ || /%\(/) {
1802                 return tag "\t" value
1803         }
1804         n = split(value, p, / *,? */);
1805         for (i = 1; i <= n; i++) {
1806                 if (p[i+1] ~ /[<=>]/) {
1807                         # add epoch if the version doesn't have it but BuildRequires.txt has
1808                         if (p[i] ~ /^[a-z]/ && p[i+2] !~ /^[0-9]+:/) {
1809                                 epoch = get_epoch(p[i], p[i+2])
1810                                 if (epoch) {
1811                                         p[i+2] = epoch ":" p[i+2];
1812                                 }
1813                         }
1814                         deps[ndeps++] = p[i] " " p[i+1] " " p[i+2];
1815                         i += 2;
1816                 } else {
1817                         deps[ndeps++] = p[i];
1818                 }
1819         }
1820         s = ""
1821         for (i in deps) {
1822                 s = s sprintf("%s\t%s\n", tag, deps[i]);
1823         }
1824         return substr(s, 1, length(s)-1);
1825 }
1826
1827 function use_tabs()
1828 {
1829         # reverse vim: ts=4 sw=4 et
1830         gsub(/    /, "\t");
1831 }
1832
1833 function add_br(br)
1834 {
1835         BR[BR_count++] = br
1836 }
1837
1838 # Load rpm macros
1839 # you should update the list also in adapter when making changes here
1840 function import_rpm_macros() {
1841         # File with rpm groups
1842         topdir = ENVIRON["_topdir"]
1843
1844         if (!topdir) {
1845                 print "adapter.awk should not not be invoked directly, but via adapter script" > "/dev/stderr"
1846                 do_not_touch_anything = 1
1847                 exit(rc = 1);
1848         }
1849
1850         # update this version dep each time some new macro export is added
1851         if (!ENVIRON["ADAPTER_REVISION"] || ENVIRON["ADAPTER_REVISION"] < 1.47) {
1852                 print "adapter shell script is outdated, please cvs up it" > "/dev/stderr"
1853                 do_not_touch_anything = 1
1854                 exit(rc = 1);
1855         }
1856
1857         # get cvsaddress for changelog section
1858         # using rpm macros as too lazy to add ~/.adapterrc parsing support.
1859         _cvsmaildomain = ENVIRON["_cvsmaildomain"]
1860         _cvsmailfeedback = ENVIRON["_cvsmailfeedback"]
1861
1862         prefix = ENVIRON["_prefix"]
1863         bindir = ENVIRON["_bindir"]
1864         sbindir = ENVIRON["_sbindir"]
1865         libdir = ENVIRON["_libdir"]
1866         sysconfdir = ENVIRON["_sysconfdir"]
1867         datadir = ENVIRON["_datadir"]
1868         includedir = ENVIRON["_includedir"]
1869         mandir = ENVIRON["_mandir"]
1870         infodir = ENVIRON["_infodir"]
1871         examplesdir = ENVIRON["_examplesdir"]
1872         docdir = ENVIRON["_defaultdocdir"]
1873         kdedocdir = ENVIRON["_kdedocdir"]
1874         gtkdocdir = ENVIRON["_gtkdocdir"]
1875         desktopdir = ENVIRON["_desktopdir"]
1876         pixmapsdir = ENVIRON["_pixmapsdir"]
1877         javadir = ENVIRON["_javadir"]
1878         pkgconfigdir = ENVIRON["_pkgconfigdir"]
1879         npkgconfigdir = ENVIRON["_npkgconfigdir"]
1880
1881         perl_sitearch = ENVIRON["perl_sitearch"]
1882         perl_archlib = ENVIRON["perl_archlib"]
1883         perl_privlib = ENVIRON["perl_privlib"]
1884         perl_vendorlib = ENVIRON["perl_vendorlib"]
1885         perl_vendorarch = ENVIRON["perl_vendorarch"]
1886         perl_sitelib = ENVIRON["perl_sitelib"]
1887
1888         py_sitescriptdir = ENVIRON["py_sitescriptdir"]
1889         py_sitedir = ENVIRON["py_sitedir"]
1890         py_scriptdir = ENVIRON["py_scriptdir"]
1891         py_ver = ENVIRON["py_ver"]
1892
1893         py3_sitescriptdir = ENVIRON["py3_sitescriptdir"]
1894         py3_sitedir = ENVIRON["py3_sitedir"]
1895         py3_scriptdir = ENVIRON["py3_scriptdir"]
1896         py3_ver = ENVIRON["py3_ver"]
1897
1898         ruby_archdir = ENVIRON["ruby_archdir"]
1899         ruby_ridir = ENVIRON["ruby_ridir"]
1900         ruby_rubylibdir = ENVIRON["ruby_rubylibdir"]
1901         ruby_sitearchdir = ENVIRON["ruby_sitearchdir"]
1902         ruby_sitelibdir = ENVIRON["ruby_sitelibdir"]
1903         ruby_rdocdir = ENVIRON["ruby_rdocdir"]
1904
1905         php_pear_dir = ENVIRON["php_pear_dir"]
1906         php_data_dir = ENVIRON["php_data_dir"]
1907         tmpdir = ENVIRON["tmpdir"]
1908 }
1909
1910 # php virtual deps as discussed in devel-en
1911 function replace_php_virtual_deps() {
1912         pkg = $2
1913 #       if (pkg == "php-program") {
1914 #               $0 = $1 "\t/usr/bin/php"
1915 #               return
1916 #       }
1917
1918 #       if (pkg ~ /^php-[a-z]/ && pkg !~ /^php-(pear|common|cli|devel|fcgi|cgi|dirs|program|pecl-)/) {
1919 #               sub(/^php-/, "php(", pkg);
1920 #               sub(/$/, ") # verify this correctness -- it may be wanted to use specific not virtual dep", pkg);
1921 #               $2 = pkg
1922 #       }
1923
1924         if (pkg ~/^php$/) {
1925                 $2 = "webserver(php)";
1926                 if ($4 ~ /^[0-9]:/) {
1927                         $4 = substr($4, 3);
1928                 }
1929         }
1930
1931         if (pkg ~/^php4$/) {
1932                 $2 = "webserver(php)";
1933                 if ($4 ~ /^[0-9]:/) {
1934                         $4 = substr($4, 3);
1935                 }
1936         }
1937 }
1938
1939 function replace_groupnames(group) {
1940         group = replace(group, "Amusements/Games", "Applications/Games");
1941         group = replace(group, "Amusements/Games/Strategy/Real Time", "X11/Applications/Games/Strategy");
1942         group = replace(group, "Application/Multimedia", "Applications/Multimedia");
1943         group = replace(group, "Application/System", "Applications/System");
1944         group = replace(group, "Applications/Compilers", "Development/Languages");
1945         group = replace(group, "Applications/Daemons", "Daemons");
1946         group = replace(group, "Applications/Internet", "Applications/Networking");
1947         group = replace(group, "Applications/Internet/Peer to Peer", "Applications/Networking");
1948         group = replace(group, "Applications/Productivity", "X11/Applications");
1949         group = replace(group, "Applications/Security", "Applications/System");
1950         group = replace(group, "Applications/Web", "Applications/WWW");
1951         group = replace(group, "Database", "Applications/Databases");
1952         group = replace(group, "Development/C", "Development/Libraries");
1953         group = replace(group, "Development/Code Generators", "Development");
1954         group = replace(group, "Development/Docs", "Documentation");
1955         group = replace(group, "Development/Documentation", "Documentation");
1956         group = replace(group, "Development/Java", "Development/Languages/Java");
1957         group = replace(group, "Development/Languages/C and C++", "Libraries");
1958         group = replace(group, "Development/Languages/Other", "Development/Languages");;
1959         group = replace(group, "Development/Languages/Ruby", "Development/Languages");
1960         group = replace(group, "Development/Libraries/C and C++", "Development/Libraries");
1961         group = replace(group, "Development/Libraries/Java", "Development/Languages/Java");
1962         group = replace(group, "Development/Libraries/Python", "Development/Languages/Python");
1963         group = replace(group, "Development/Libraries/TCL", "Development/Languages/Tcl");;
1964         group = replace(group, "Development/Other", "Development");
1965         group = replace(group, "Development/Python", "Development/Languages/Python");
1966         group = replace(group, "Development/Testing", "Development");
1967         group = replace(group, "Editors", "Applications/Text");
1968         group = replace(group, "Emulators", "Applications/Emulators");
1969         group = replace(group, "File tools", "Applications/File");
1970         group = replace(group, "Games", "Applications/Games");
1971         group = replace(group, "Library/Development", "Development/Libraries");
1972         group = replace(group, "Networking/Deamons", "Networking/Daemons");
1973         group = replace(group, "Networking/Mail", "Applications/Mail");
1974         group = replace(group, "Networking/Other", "Networking");
1975         group = replace(group, "Productivity/Databases/Servers", "Applications/Databases");
1976         group = replace(group, "Productivity/Multimedia/Other", "X11/Applications/Multimedia");
1977         group = replace(group, "Productivity/Networking/Web/Servers", "Networking/Daemons/HTTP");;
1978         group = replace(group, "Shells", "Applications/Shells");
1979         group = replace(group, "System Environment/Base", "Base");
1980         group = replace(group, "System Environment/Daemons", "Daemons");
1981         group = replace(group, "System Environment/Kernel", "Base/Kernel");
1982         group = replace(group, "System Environment/Libraries", "Libraries");
1983         group = replace(group, "System Tools", "Applications/System");
1984         group = replace(group, "System", "Base");
1985         group = replace(group, "System/Base", "Base");
1986         group = replace(group, "System/Kernel and hardware", "Base/Kernel");
1987         group = replace(group, "System/Libraries", "Libraries");
1988         group = replace(group, "System/Servers", "Daemons");
1989         group = replace(group, "Text Processing/Markup/HTML", "Applications/Text");
1990         group = replace(group, "Text Processing/Markup/XML", "Applications/Text");
1991         group = replace(group, "Text tools", "Applications/Text");
1992         group = replace(group, "User Interface/Desktops", "X11/Applications");
1993         group = replace(group, "Utilities/System", "Applications/System");
1994         group = replace(group, "Web/Database", "Applications/WWW");
1995         group = replace(group, "X11/GNOME", "X11/Applications");
1996         group = replace(group, "X11/GNOME/Applications", "X11/Applications");
1997         group = replace(group, "X11/GNOME/Development/Libraries", "X11/Development/Libraries");
1998         group = replace(group, "X11/Games", "X11/Applications/Games");
1999         group = replace(group, "X11/Games/Strategy", "X11/Applications/Games/Strategy");
2000         group = replace(group, "X11/Library", "X11/Libraries");
2001         group = replace(group, "X11/Utilities", "X11/Applications");
2002         group = replace(group, "X11/XFree86", "X11");
2003         group = replace(group, "X11/Xserver", "X11/Servers");
2004
2005         return group;
2006 }
2007
2008 function replace_requires() {
2009
2010         sub(/^python-setuptools-devel$/, "python-distribute", $2);
2011         sub(/^gcc-g77/, "gcc-fortran", $2);
2012
2013         # use virtual, not package name
2014         sub(/^rpm-build-macros$/, "rpmbuild(macros)", $2);
2015
2016         # bad package.xml, see http://pear.php.net/bugs/bug.php?id=17779
2017         sub(/^php-php-gtk/, "php-gtk2", $2);
2018
2019         # jpackages
2020         sub(/^antlr3$/, "java-antlr3", $2);
2021         sub(/^avalon-framework$/, "java-avalon-framework", $2);
2022         sub(/^avalon-logkit$/, "java-avalon-logkit", $2);
2023         sub(/^axis$/, "java-axis", $2);
2024         sub(/^bsf$/, "java-bsf", $2);
2025         sub(/^gnu-regexp$/, "java-gnu-regexp", $2);
2026         sub(/^gnu.regexp$/, "java-gnu-regexp", $2);
2027         sub(/^hamcrest$/, "java-hamcrest", $2);
2028         sub(/^jaas$/, "java(jaas)", $2);
2029         sub(/^jaf$/, "java(jaf)", $2);
2030         sub(/^jakarta-ant$/, "ant", $2);
2031         sub(/^jakarta-commons-httpclient$/, "java-commons-httpclient", $2);
2032         sub(/^jakarta-log4j$/, "java-log4j", $2);
2033         sub(/^jakarta-oro$/, "java-oro", $2);
2034         sub(/^jakarta-servletapi$/, "java(servlet)", $2);
2035         sub(/^java-devel$/, "jdk", $2);
2036         sub(/^java\(JSP\)$/, "java(jsp)", $2);
2037         sub(/^java\(JavaServerFaces\)$/, "java(javaserverfaces)", $2);
2038         sub(/^java\(Portlet\)$/, "java(portlet)", $2);
2039         sub(/^java\(Servlet\)$/, "java(servlet)", $2);
2040         sub(/^javamail$/, "java(javamail)", $2);
2041         sub(/^jaxp$/, "java(jaxp)", $2);
2042         sub(/^jaxp_parser_impl$/, "java(jaxp_parser_impl)", $2);
2043         sub(/^jaxp_transform_impl$/, "java(jaxp_transform_impl)", $2);
2044         sub(/^jce$/, "java(jce)", $2);
2045         sub(/^jcommon$/, "java-jcommon", $2);
2046         sub(/^jdbc-stdext$/, "java(jdbc-stdext)", $2);
2047         sub(/^jdepend$/, "java-jdepend", $2);
2048         sub(/^jfreechart$/, "java-jfreechart", $2);
2049         sub(/^jmx$/, "java(jmx)", $2);
2050         sub(/^jndi$/, "java(jndi)", $2);
2051         sub(/^jsch$/, "java-jsch", $2);
2052         sub(/^jsse$/, "java(jsse)", $2);
2053         sub(/^jta$/, "java(jta)", $2);
2054         sub(/^junit$/, "java-junit", $2);
2055         sub(/^ldapjdk$/, "ldapsdk", $2);
2056         sub(/^log4j$/, "java-log4j", $2);
2057         sub(/^logging-log4j$/, "java-log4j", $2);
2058         sub(/^oro$/, "java-oro", $2);
2059         sub(/^rhino$/, "java-rhino", $2);
2060         sub(/^saxon-scripts$/, "saxon", $2);
2061         sub(/^servlet$/, "java(servlet)", $2);
2062         sub(/^uddi4j$/, "java-uddi4j", $2);
2063         sub(/^wsdl4j$/, "java-wsdl4j", $2);
2064         sub(/^xalan-j$/, "java-xalan", $2);
2065         sub(/^xalan-j2$/, "java-xalan", $2);
2066         sub(/^xerces-j$/, "java(jaxp_parser_impl)", $2);
2067         sub(/^xerces-j2$/, "java(jaxp_parser_impl)", $2);
2068         sub(/^java-xerces$/, "java(jaxp_parser_impl)", $2);
2069         sub(/^xml-commons-apis$/, "java-xml-commons-apis", $2);
2070         sub(/^xml-commons-resolver$/, "java-xml-commons-resolver", $2);
2071
2072         # fedora / redhat
2073         sub(/^Django$/, "python-django", $2);
2074         sub(/^GitPython$/, "python-git", $2);
2075         sub(/^PyQt4-devel$/, "python-PyQt4-devel", $2);
2076         sub(/^PyQwt-devel$/, "python-PyQwt-devel", $2);
2077         sub(/^ccid$/, "pcsc-driver-ccid", $2);
2078         sub(/^chkconfig$/, "/sbin/chkconfig", $2);
2079         sub(/^db4-devel$/, "db-devel", $2);
2080         sub(/^dbus-python$/, "python-dbus", $2);
2081         sub(/^file-devel$/, "libmagic-devel", $2);
2082         sub(/^freetype2-devel$/, "freetype-devel", $2);
2083         sub(/^fuse-devel$/, "libfuse-devel", $2);
2084         sub(/^gamin-python$/, "python-gamin", $2);
2085         sub(/^gcc-c\+\+$/, "libstdc++-devel", $2);
2086         sub(/^gnome-python2-extras$/, "python-gnome-extras", $2);
2087         sub(/^gnome-python2-gtkspell$/, "python-gnome-extras-gtkspell", $2);
2088         sub(/^gtk-sharp2-devel$/, "dotnet-gtk-sharp2-devel", $2);
2089         sub(/^gtk2$/, "gtk+2", $2);
2090         sub(/^gtk2-devel$/, "gtk+2-devel", $2);
2091         sub(/^initscripts$/, "rc-scripts", $2);
2092         sub(/^iproute$/, "iproute2", $2);
2093         sub(/^iscsi-initiator-utils$/, "open-iscsi", $2);
2094         sub(/^libXft-devel$/, "xorg-lib-libXft-devel", $2);
2095         sub(/^libXrandr-devel$/, "xorg-lib-libXrandr-devel", $2);
2096         sub(/^libcurl-devel$/, "curl-devel", $2);
2097         sub(/^libsrtp-devel$/, "srtp-devel", $2);
2098         sub(/^mod_wsgi$/, "apache-mod_wsgi", $2);
2099         sub(/^notify-python$/, "python-pynotify", $2);
2100         sub(/^pcsc-lite-ccid$/, "pcsc-driver-ccid", $2);
2101         sub(/^pulseaudio-libs-devel$/, "pulseaudio-devel", $2);
2102         sub(/^pyOpenSSL$/, "python-pyOpenSSL", $2);
2103         sub(/^pyflakes$/, "python-pyflakes", $2);
2104         sub(/^pygobject2$/, "python-pygobject", $2);
2105         sub(/^pygtk2$/, "python-pygtk", $2);
2106         sub(/^pygtk2-devel$/, "python-pygtk-devel", $2);
2107         sub(/^pysvn$/, "python-pysvn", $2);
2108         sub(/^python-enchant$/, "python-pyenchant", $2);
2109         sub(/^python-imaging$/, "python-PIL", $2);
2110         sub(/^python-imaging-tk$/, "python-PIL-tk", $2);
2111         sub(/^python-pygtk$/, "python-pygtk-gtk", $2);
2112         sub(/^python-recaptcha-client$/, "python-recaptcha", $2);
2113         sub(/^python-twisted-core$/, "python-TwistedCore", $2);
2114         sub(/^python-twisted-core$/, "python-TwistedCore", $2);
2115         sub(/^python-twisted-names$/, "python-TwistedNames", $2);
2116         sub(/^python2-devel$/, "python-devel", $2);
2117         sub(/^pytz$/, "python-pytz", $2);
2118         sub(/^qt4-devel$/, "qt4-build", $2);
2119         sub(/^qt4-webkit-devel$/, "QtWebKit-devel", $2);
2120         sub(/^qtlockedfile-devel$/, "QtLockedFile-devel", $2);
2121         sub(/^qtsingleapplication-devel$/, "QtSingleApplication-devel", $2);
2122         sub(/^rpm-python$/, "python-rpm", $2);
2123         sub(/^sip-devel$/, "python-sip-devel", $2);
2124         sub(/^tftp-server$/, "tftpdaemon", $2);
2125         sub(/^tkinter$/, "python-tkinter", $2);
2126         sub(/^xapian-bindings-python$/, "python-xapian", $2);
2127         sub(/^xorg-x11-server-sdk$/, "xorg-xserver-server-devel", $2);
2128
2129         # mandriva
2130         sub(/^python-gobject-devel$/, "python-pygobject-devel", $2);
2131         sub(/^python-pyrex$/, "python-Pyrex", $2);
2132         sub(/^webkitgtk-devel$/, "gtk-webkit-devel", $2);
2133         sub(/^python-curl$/, "python-pycurl", $2);
2134         sub(/^python-webkitgtk$/, "python-pywebkitgtk", $2);
2135         sub(/^pygtk2.0$/, "python-pygtk-gtk", $2);
2136         sub(/^gnome-python-gconf$/, "python-gnome-gconf", $2);
2137
2138         # debian / ubuntu
2139         sub(/^blkid-dev$/, "libblkid-devel", $2);
2140         sub(/^ext2fs-dev$/, "e2fsprogs-devel", $2);
2141         sub(/^libao-dev$/, "libao-devel", $2);
2142         sub(/^libboost-filesystem[0-9.]+-dev$/, "boost-devel", $2);
2143         sub(/^libboost-program-options[0-9.]+-dev$/, "boost-devel", $2);
2144         sub(/^libboost-regex[0-9.]+-dev$/, "boost-devel", $2);
2145         sub(/^libboost-thread[0-9.]+-dev$/, "boost-devel", $2);
2146         sub(/^libcurl4-openssl-dev$/, "curl-devel", $2);
2147         sub(/^libdnet-dev$/, "libdnet-devel", $2);
2148         sub(/^libesd0-dev$/, "esound-devel", $2);
2149         sub(/^libfishsound1-dev$/, "libfishsound-devel", $2);
2150         sub(/^libgconf2-dev$/, "GConf2-devel", $2);
2151         sub(/^libgl1-mesa-dev$/, "OpenGL-devel", $2);
2152         sub(/^libgl1-mesa-dri$/, "OpenGL", $2);
2153         sub(/^libglib2.0-dev$/, "glib2-devel", $2);
2154         sub(/^libglu1-mesa-dev$/, "OpenGL-GLU-devel", $2);
2155         sub(/^libgtk2.0-dev$/, "gtk+2-devel", $2);
2156         sub(/^libhunspell-dev$/, "hunspell-devel", $2);
2157         sub(/^libmcrypt-dev$/, "libmcrypt-devel", $2);
2158         sub(/^libmhash-dev$/, "mhash-devel", $2);
2159         sub(/^liboggz1-dev$/, "libggz-devel", $2);
2160         sub(/^libpango1.0-dev$/, "pango-devel", $2);
2161         sub(/^libqt4-dev$/, "qt4-build", $2);
2162         sub(/^libshout3-dev$/, "libshout-devel", $2);
2163         sub(/^libslp-dev$/, "openslp-devel", $2);
2164         sub(/^libsndfile1-dev$/, "libsndfile-devel", $2);
2165         sub(/^libspeex-dev$/, "speex-devel", $2);
2166         sub(/^libssl-dev$/, "openssl-devel", $2);
2167         sub(/^libvorbis-dev$/, "libvorbis-devel", $2);
2168         sub(/^libxslt1-dev$/, "libxslt-devel", $2);
2169         sub(/^libxss-dev$/, "xorg-lib-libXScrnSaver-devel", $2);
2170         sub(/^mesa-common-dev$/, "OpenGL-devel", $2);
2171         sub(/^libudev$/, "udev-libs", $2);
2172         sub(/^tcp_wrappers-devel$/, "libwrap-devel", $2);
2173         sub(/^vala-tools$/, "vala", $2);
2174         sub(/^vala-devel$/, "vala", $2);
2175
2176         # altlinux
2177         sub(/^libgit-devel$/, "git-core-devel", $2);
2178         sub(/^libncurses-devel$/, "ncurses-devel", $2);
2179         sub(/^libncursesxx-devel$/, "ncurses-c++-devel", $2);
2180         sub(/^libpcre-devel$/, "pcre-devel", $2);
2181         sub(/^libssl-devel$/, "openssl-devel", $2);
2182
2183         # suse
2184         sub(/^alsa-devel$/, "alsa-lib-devel", $2);
2185         sub(/^gtk-sharp2$/, "dotnet-gtk-sharp2", $2);
2186         sub(/^gtkmm2-devel$/, "gtkmm-devel", $2);
2187         sub(/^libexpat-devel$/, "expat-devel", $2);
2188         sub(/^libffmpeg-devel$/, "ffmpeg-devel", $2);
2189         sub(/^libopenssl-devel$/, "openssl-devel", $2);
2190         sub(/^libpulse-devel$/, "pulseaudio-devel", $2);
2191         sub(/^monodoc-core$/, "mono-monodoc", $2);
2192         sub(/^python-gtk$/, "python-pygtk-gtk", $2);
2193
2194         replace_php_virtual_deps()
2195 }
2196
2197 # vim:ts=4:sw=4
This page took 0.253625 seconds and 4 git commands to generate.