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