]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - adapter.awk
99122631899202e6bac78108bb934497819b66e9
[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                 byl_plik_z_groupmi = 0
650                 byl_opis_grupy = 0
651                 while ((getline linia_grup < groups_file) > 0) {
652                         byl_plik_z_groupmi = 1
653                         if (linia_grup == group) {
654                                 byl_opis_grupy = 1
655                                 break
656                         }
657                 }
658
659                 if (!byl_plik_z_groupmi)
660                         print "######\t\t" groups_file ": no such file"
661                 else if (!byl_opis_grupy)
662                         print "######\t\t" "Unknown group!"
663
664                 close(groups_file)
665                 did_groups = 1
666         }
667
668         if (field ~ /prereq:/) {
669                 sub(/Pre[Rr]eq:/, "Requires:", $1);
670         }
671
672         # split (build)requires, obsoletes on commas
673         if (field ~ /(obsoletes|requires|provides|conflicts|suggests):/ && NF > 2) {
674                 value = substr($0, index($0, $2));
675                 $0 = format_requires($1, value);
676         }
677
678         # BR: tar (and others) is to common (rpm-build requires it)
679         if (field ~ /^buildrequires:/) {
680                 l = substr($0, index($0, $2));
681                 if (l == "awk" ||
682                         l == "binutils" ||
683                         l == "bzip2" ||
684                         l == "cpio" ||
685                         l == "diffutils" ||
686                         l == "elfutils" ||
687                         l == "fileutils" ||
688                         l == "findutils" ||
689                         l == "glibc-devel" ||
690                         l == "grep" ||
691                         l == "gzip" ||
692                         l == "make" ||
693                         l == "patch" ||
694                         l == "sed" ||
695                         l == "sh-utils" ||
696                         l == "tar" ||
697                         l == "textutils") {
698                         next
699                 }
700
701                 replace_requires();
702         }
703
704         if (field ~ /^requires:/ || field ~ /^requires\(/) {
705                 replace_requires();
706         }
707
708
709         # obsolete/unwanted tags
710         if (field ~ /vendor:|packager:|distribution:|docdir:|prefix:|icon:|author:|author-email:|metadata-version:/) {
711                 next
712         }
713
714         if (field ~ /buildroot:/) {
715                 $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
716                 did_build_root = 1
717         }
718
719         # Use "License" instead of "Copyright" if it is (L)GPL or BSD
720         if (field ~ /copyright:/ && $2 ~ /GPL|BSD/) {
721                 $1 = "License:"
722         }
723
724         # ease updating from debian .dsc
725         if (field ~ /homepage:/) {
726                 $1 = "URL:"
727         }
728
729         # suse
730         if (field ~ /recommends:/) {
731                 $1 = "Suggests:"
732         }
733
734         if ($3 == "==" && $1 !~ /%/) {
735                 $3 = "="
736         }
737
738         if (field ~ /license:/) {
739                 l = substr($0, index($0, $2));
740                 if (l == "Python Software Foundation License") {
741                         l = "PSF"
742                 }
743                 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") {
744                         l = "Apache v2.0"
745                 }
746                 if (l == "Apache Group License" || l == "Apache Software License" || l == "Apache License") {
747                         l = "Apache"
748                 }
749                 if (l == "Apache-style License" || l == "Apache-style Software License") {
750                         l = "Apache-like"
751                 }
752                 if (l == "Apache Software License 1.1" || l == "Apache 1.1") {
753                         l = "Apache v1.1"
754                 }
755                 if (l == "GPLv2") {
756                         l = "GPL v2"
757                 }
758                 if (l == "GPLv2+") {
759                         l = "GPL v2+"
760                 }
761                 if (l == "GPL v2 or later") {
762                         l = "GPL v2+"
763                 }
764                 if (l == "LGPL v2.0 only") {
765                         l = "LGPL v2"
766                 }
767                 if (l == "LGPLv2+") {
768                         l = "LGPL v2+"
769                 }
770                 if (l == "GPLv3") {
771                         l = "GPL v3"
772                 }
773                 if (l == "GPLv3+") {
774                         l = "GPL v3+"
775                 }
776                 if (l == "MPLv1.1") {
777                         l = "MPL v1.1"
778                 }
779                 $0 = "License:\t" l;
780         }
781
782
783         if (field ~ /name:/) {
784                 if ($2 == "%{name}" && name) {
785                         $2 = name
786                 }
787                 name = $2
788                 name_seen = 1;
789         }
790
791         if (field ~ /version:/) {
792                 if ($2 == "%{version}" && version) {
793                         $2 = version
794                 }
795                 version = $2
796                 version_seen = 1;
797         }
798
799         if (field ~ /release:/) {
800                 if ($2 == "%{release}" && release) {
801                         $2 = release
802                 }
803                 sub(/%atrelease /, "0.", $0)
804                 release = $2
805                 release_seen = 1;
806         }
807
808
809         if (field ~ /serial:/)
810                 $1 = "Epoch:"
811
812         if (field ~ /home-page:/)
813                 $1 = "URL:"
814
815         # proper caps
816         if (field ~ /^url:$/)
817                 $1 = "URL:"
818
819         if (field ~ /^patch/)
820                 $1 = "Patch" substr(field, 6);
821
822         if (field ~ /^description:$/)
823                 $1 = "\n%description\n"
824
825         # Use %{name} and %{version} in the filenames in "Source:"
826         if (field ~ /^source/ || field ~ /patch/) {
827                 n = split($2, url, /\//)
828                 if (url[n] ~ /\.gz$/) {
829                         url[n+1] = ".gz" url[n+1]
830                         sub(/\.gz$/,"",url[n])
831                 }
832                 if (url[n] ~ /\.zip$/) {
833                         url[n+1] = ".zip" url[n+1]
834                         sub(/\.zip$/,"",url[n])
835                 }
836                 if (url[n] ~ /\.tar$/) {
837                         url[n+1] = ".tar" url[n+1]
838                         sub(/\.tar$/,"",url[n])
839                 }
840                 if (url[n] ~ /\.patch$/) {
841                         url[n+1] = ".patch" url[n+1]
842                         sub(/\.patch$/,"",url[n])
843                 }
844                 if (url[n] ~ /\.bz2$/) {
845                         url[n+1] = ".bz2" url[n+1]
846                         sub(/\.bz2$/,"",url[n])
847                 }
848                 if (url[n] ~ /\.logrotate$/) {
849                         url[n+1] = ".logrotate" url[n+1]
850                         sub(/\.logrotate$/,"",url[n])
851                 }
852                 if (url[n] ~ /\.pamd$/) {
853                         url[n+1] = ".pamd" url[n+1]
854                         sub(/\.pamd$/,"",url[n])
855                 }
856
857                 # allow %{name} only in last url component
858                 s = ""
859                 for (i = 1; i <= n; i++) {
860                         url[i] = fixedsub("%{name}", name, url[i])
861                         if (s) {
862                                 s = s "/" url[i]
863                         } else {
864                                 s = url[i]
865                         }
866                 }
867                 $2 = s url[n+1]
868
869                 filename = url[n]
870                 if (name) {
871                         url[n] = fixedsub(name, "%{name}", url[n])
872                 }
873                 if (field ~ /source/) {
874                         if (version) {
875                                 url[n] = fixedsub(version, "%{version}", url[n])
876                         }
877                         if (_beta) {
878                                 url[n] = fixedsub(_beta, "%{_beta}", url[n])
879                         }
880                         if (_rc) {
881                                 url[n] = fixedsub(_rc, "%{_rc}", url[n])
882                         }
883                         if (_pre) {
884                                 url[n] = fixedsub(_pre, "%{_pre}", url[n])
885                         }
886                         if (_snap) {
887                                 url[n] = fixedsub(_snap, "%{_snap}", url[n])
888                         }
889                         if (subver) {
890                                 url[n] = fixedsub(subver, "%{subver}", url[n])
891                         }
892                 }
893                 # assigning to $2 kills preamble formatting
894                 $2 = fixedsub(filename, url[n], $2)
895
896                 $2 = unify_url($2)
897         }
898
899
900         if (field ~ /^source:/)
901                 $1 = "Source0:"
902
903         if (field ~ /^patch:/)
904                 $1 = "Patch0:"
905
906         kill_preamble_macros();
907         format_preamble()
908
909         if (field ~ /requires/) {
910                 # atrpms
911                 $0 = fixedsub("%{eversion}", "%{epoch}:%{version}-%{release}", $0);
912         }
913 }
914
915 /^%bcond_/ {
916         # do nothing
917         print
918         next
919 }
920
921 # sort BR/R!
922 #
923 # NOTES:
924 # - mixing BR/R and anything else confuses this (all will be sorted together)
925 #       so don't do that.
926 # - comments leading the BR/R can not be associated,
927 #       so don't adapterize when the BR/R are mixed with comments
928 ENVIRON["SKIP_SORTBR"] != 1 && preamble == 1 && $0 ~ PREAMBLE_TAGS ":", $0 ~ PREAMBLE_TAGS ":"{
929         if ($1 ~ /Pre[Rr]eq:/) {
930                 sub(/Pre[Rr]eq:/, "Requires:", $1);
931         }
932         if ($1 == "BR:" ) {
933                 $1 = "BuildRequires:"
934         }
935         if ($1 == "R:" ) {
936                 $1 = "Requires:"
937         }
938         format_preamble()
939 #       kill_preamble_macros(); # breaks tabbing
940
941         b_idx++;
942         l = substr($0, index($0, $2));
943         b_ktmp = b_makekey($1, l);
944         b_key[b_idx] = b_ktmp;
945         b_val[b_ktmp] = $0;
946
947         next;
948 }
949
950 preamble == 1 {
951         if (b_idx > 0) {
952                 isort(b_key, b_idx);
953                 for (i = 1; i <= b_idx; i++) {
954                         v = b_val[b_key[i]];
955                         sub(/[ \t]+$/, "", v);
956                         print "" v;
957                 }
958                 b_idx = 0
959         }
960 }
961
962 # main() ;-)
963 {
964         preamble = 1
965
966         sub(/[ \t]+$/, "")
967         print
968
969         if (name_seen == 0 && name) {
970                 print "Name:\t\t" name
971                 name_seen = 1
972         }
973
974         if (version_seen == 0 && version) {
975                 print "Version:\t" version
976                 version_seen = 1
977         }
978
979         if (release_seen == 0 && release) {
980                 print "Release:\t" release
981                 release_seen = 1
982         }
983
984         if (did_build_root == 0) {
985 #               print "BuildRoot:\t%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
986                 did_build_root = 1
987         }
988         if (did_groups == 0) {
989 #               print "Group:\t\tunknown"
990                 did_groups = 1
991         }
992 }
993
994
995 END {
996         if (do_not_touch_anything) {
997                 exit(rc)
998         }
999
1000         # TODO: need to output these in proper place
1001         if (BR_count > 0) {
1002                 for (i = 0; i <= BR_count; i++) {
1003                         print BR[i];
1004                 }
1005         }
1006
1007         if (did_clean == 0) {
1008                 print ""
1009                 print "%clean"
1010                 print "rm -rf $RPM_BUILD_ROOT"
1011         }
1012 }
1013
1014 # substitutes fixed strings (not regexps)
1015 function fixedsub(s1,s2,t, ind) {
1016         if (ind = index(t,s1))
1017                 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
1018         return t
1019 }
1020
1021 # replace s with s2 if it equals to s1
1022 function replace(s, s1, s2) {
1023         if (s == s1) {
1024                 return s2;
1025         } else {
1026                 return s;
1027         }
1028 }
1029
1030 # There should be one or two tabs after the colon.
1031 function format_preamble()
1032 {
1033         if (/^#/ || /^%bcond_with/) {
1034                 return;
1035         }
1036         sub(/:[ \t]*/, ":")
1037         if (match($0, /[A-Za-z0-9(),#_ \t.-]+[ \t]*:[ \t]*/) == 1) {
1038                 if (RLENGTH < 8) {
1039                         sub(/:/, ":\t\t")
1040                 } else {
1041                         sub(/:/, ":\t")
1042                 }
1043         }
1044 }
1045
1046 # Replace directly specified directories with macros
1047 function use_macros()
1048 {
1049         # -m, --skip-macros, --no-macros -- skip macros subst
1050         if (ENVIRON["SKIP_MACROS"]) {
1051                 return
1052         }
1053
1054         # leave inline sed lines alone
1055         if (/(%{__sed}|sed) -i -e/) {
1056                 return;
1057         }
1058
1059         sub("%{_defaultdocdir}", "%{_docdir}");
1060         sub("%{_bindir}/perl", "%{__perl}");
1061         sub("%{_bindir}/python", "%{__python}");
1062
1063         gsub(infodir, "%{_infodir}")
1064
1065         gsub(perl_sitearch, "%{perl_sitearch}")
1066         gsub(perl_archlib, "%{perl_archlib}")
1067         gsub(perl_privlib, "%{perl_privlib}")
1068         gsub(perl_vendorlib, "%{perl_vendorlib}")
1069         gsub(perl_vendorarch, "%{perl_vendorarch}")
1070         gsub(perl_sitelib, "%{perl_sitelib}")
1071         
1072         gsub(py_sitescriptdir, "%{py_sitescriptdir}")
1073         gsub(py_sitedir, "%{py_sitedir}")
1074         gsub(py_scriptdir, "%{py_scriptdir}")
1075
1076         gsub(py3_sitescriptdir, "%{py3_sitescriptdir}")
1077         gsub(py3_sitedir, "%{py3_sitedir}")
1078         gsub(py3_scriptdir, "%{py3_scriptdir}")
1079
1080         gsub(ruby_archdir, "%{ruby_archdir}")
1081         gsub(ruby_ridir, "%{ruby_ridir}")
1082         gsub(ruby_rubylibdir, "%{ruby_rubylibdir}")
1083         gsub(ruby_sitearchdir, "%{ruby_sitearchdir}")
1084         gsub(ruby_sitelibdir, "%{ruby_sitelibdir}")
1085         gsub(ruby_rdocdir, "%{ruby_rdocdir}")
1086
1087         gsub(systemdunitdir, "%{systemdunitdir}")
1088         gsub(systemdtmpfilesdir, "%{systemdtmpfilesdir}")
1089
1090         gsub("%{_datadir}/applications", "%{_desktopdir}")
1091         gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}")
1092         gsub("%{_datadir}/java", "%{_javadir}")
1093
1094         gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}")
1095         gsub(pkgconfigdir, "%{_pkgconfigdir}")
1096
1097         gsub("%{_datadir}/pkgconfig", "%{_npkgconfigdir}")
1098         gsub(npkgconfigdir, "%{_npkgconfigdir}")
1099
1100         gsub("%{_datadir}/locale", "%{_localedir}")
1101         gsub(localedir, "%{_localedir}")
1102
1103         gsub(libdir, "%{_libdir}")
1104         gsub(javadir, "%{_javadir}")
1105
1106         gsub(bindir, "%{_bindir}")
1107         gsub("%{prefix}/bin", "%{_bindir}")
1108         if (prefix"/bin" == bindir)
1109                 gsub("%{_prefix}/bin", "%{_bindir}")
1110
1111         for (c = 1; c <= NF; c++) {
1112                 if ($c ~ sbindir "/fix-info-dir")
1113                         continue;
1114                 if ($c ~ sbindir "/webapp")
1115                         continue;
1116                 if ($c ~ sbindir "/ldconfig")
1117                         continue;
1118                 if ($c ~ sbindir "/chsh")
1119                         continue;
1120                 if ($c ~ sbindir "/usermod")
1121                         continue;
1122                 if ($c ~ sbindir "/chkconfig")
1123                         continue;
1124                 if ($c ~ sbindir "/installzope(product|3package)")
1125                         continue;
1126                 gsub(sbindir, "%{_sbindir}", $c)
1127         }
1128
1129         gsub("%{prefix}/sbin", "%{_sbindir}")
1130         if (prefix"/sbin" == sbindir) {
1131                 gsub("%{_prefix}/sbin", "%{_sbindir}")
1132         }
1133
1134         for (c = 1; c <= NF; c++) {
1135                 if ($c ~ sysconfdir "/{?cron.")
1136                         continue;
1137                 if ($c ~ sysconfdir "/{?crontab.d")
1138                         continue;
1139                 if ($c ~ sysconfdir "/{?env.d")
1140                         continue;
1141                 if ($c ~ sysconfdir "/{?modprobe.(d|conf)")
1142                         continue;
1143                 if ($c ~ sysconfdir "/{?udev")
1144                         continue;
1145                 if ($c ~ sysconfdir "/{?hotplug")
1146                         continue;
1147                 if ($c ~ sysconfdir "/{?logrotate.d")
1148                         continue;
1149                 if ($c ~ sysconfdir "/{?pam.d")
1150                         continue;
1151                 if ($c ~ sysconfdir "/{?profile.d")
1152                         continue;
1153                 if ($c ~ sysconfdir "/{?rc.d")
1154                         continue;
1155                 if ($c ~ sysconfdir "/{?security")
1156                         continue;
1157                 if ($c ~ sysconfdir "/{?skel")
1158                         continue;
1159                 if ($c ~ sysconfdir "/{?sysconfig")
1160                         continue;
1161                 if ($c ~ sysconfdir "/{?shrc.d")
1162                         continue;
1163                 if ($c ~ sysconfdir "/{?certs")
1164                         continue;
1165                 if ($c ~ sysconfdir "/{?X11")
1166                         continue;
1167                 if ($c ~ sysconfdir "/{?ld.so.conf.d")
1168                         continue;
1169                 if ($c ~ sysconfdir "/{?rpm")
1170                         continue;
1171                 if ($c ~ sysconfdir "/{?bash_completion.d")
1172                         continue;
1173                 if ($c ~ sysconfdir "/{?samba")
1174                         continue;
1175                 if ($c ~ sysconfdir "/{?xdg")
1176                         continue;
1177                 if ($c ~ sysconfdir "/shells")
1178                         continue;
1179                 if ($c ~ sysconfdir "/inittab")
1180                         continue;
1181                 if ($c ~ sysconfdir "/init")
1182                         continue;
1183                 if ($c ~ sysconfdir "/ppp")
1184                         continue;
1185                 if ($c ~ sysconfdir "/dbus-1")
1186                         continue;
1187                 if ($c ~ sysconfdir "/tmpwatch")
1188                         continue;
1189                 if ($c ~ sysconfdir "/acpi")
1190                         continue;
1191                 if ($c ~ sysconfdir "/apm")
1192                         continue;
1193                 gsub(sysconfdir, "%{_sysconfdir}", $c)
1194         }
1195
1196         gsub(docdir, "%{_docdir}")
1197
1198         gsub(kdedocdir, "%{_kdedocdir}")
1199
1200         gsub(gtkdocdir, "%{_gtkdocdir}")
1201         gsub("%{_docdir}/gtk-doc/html", "%{_gtkdocdir}")
1202
1203         gsub(php_pear_dir, "%{php_pear_dir}")
1204         gsub(php_data_dir, "%{php_data_dir}")
1205
1206         for (c = 1; c <= NF; c++) {
1207                 if ($c ~ datadir "/automake")
1208                         continue;
1209                 if ($c ~ datadir "/unsermake")
1210                         continue;
1211                 if ($c ~ datadir "/file/magic.mime")
1212                         continue;
1213                 gsub(datadir, "%{_datadir}", $c)
1214         }
1215
1216         gsub("%{prefix}/share", "%{_datadir}")
1217         if (prefix"/share" == datadir)
1218                 gsub("%{_prefix}/share", "%{_datadir}")
1219
1220         # CFLAGS="-I/usr/include/ncurses is usually correct.
1221         if (!/-I\/usr\/include/) {
1222                 gsub(includedir, "%{_includedir}")
1223         }
1224
1225         gsub("%{prefix}/include", "%{_includedir}")
1226         if (prefix"/include" == includedir) {
1227                 gsub("%{_prefix}/include", "%{_includedir}")
1228         }
1229
1230         gsub(mandir, "%{_mandir}")
1231         if ($0 !~ "%{_datadir}/manual") {
1232                 gsub("%{_datadir}/man", "%{_mandir}")
1233         }
1234         gsub("%{_prefix}/share/man", "%{_mandir}")
1235         gsub("%{prefix}/share/man", "%{_mandir}")
1236         gsub("%{prefix}/man", "%{_mandir}")
1237         gsub("%{_prefix}/man", "%{_mandir}")
1238
1239         gsub(infodir, "%{_infodir}")
1240         gsub("%{prefix}/info", "%{_infodir}")
1241         gsub("%{_prefix}/info", "%{_infodir}")
1242
1243         if (prefix !~ "/X11R6") {
1244                 gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
1245         }
1246
1247         gsub(examplesdir, "%{_examplesdir}")
1248
1249         if (prefix != "/") {
1250                 # leave --with-foo=/usr alone
1251                 if ($0 !~ "--with.*=.*" prefix) {
1252                         for (c = 1; c <= NF; c++) {
1253                                 if ($c ~ prefix "/sbin/fix-info-dir")
1254                                         continue;
1255                                 if ($c ~ prefix "/sbin/webapp")
1256                                         continue;
1257                                 if ($c ~ prefix "/sbin/chsh")
1258                                         continue;
1259                                 if ($c ~ prefix "/sbin/usermod")
1260                                         continue;
1261                                 if ($c ~ prefix "/sbin/installzope(product|3package)")
1262                                         continue;
1263                                 if ($c ~ prefix "/share/automake")
1264                                         continue;
1265                                 if ($c ~ prefix "/share/unsermake")
1266                                         continue;
1267                                 if ($c ~ prefix "/lib/sendmail")
1268                                         continue;
1269                                 if ($c ~ prefix "/lib/pkgconfig")
1270                                         continue;
1271
1272                                 # CFLAGS="-I/usr..." is usually correct.
1273                                 if (/-I\/usr/)
1274                                         continue;
1275                                 # same for LDFLAGS="-L/usr..."
1276                                 if (/-L\/usr/)
1277                                         continue;
1278
1279                                 gsub(prefix, "%{_prefix}", $c)
1280                         }
1281                 }
1282                 gsub("%{prefix}", "%{_prefix}")
1283         }
1284
1285         # replace back
1286         gsub("%{_includedir}/ncurses", "/usr/include/ncurses")
1287         gsub("%{_includedir}/freetype", "/usr/include/freetype")
1288
1289         gsub("%{PACKAGE_VERSION}", "%{version}")
1290         gsub("%{PACKAGE_NAME}", "%{name}")
1291
1292         gsub("^make$", "%{__make}")
1293         gsub("^make ", "%{__make} ")
1294         gsub("^gcc ", "%{__cc} ")
1295         gsub("^rm --interactive=never ", "%{__rm} ")
1296
1297         # fedora
1298         gsub("%{ruby_sitearch}", "%{ruby_sitearchdir}")
1299         gsub("%{python_sitearch}", "%{py_sitedir}")
1300         gsub("%{python_sitelib}", "%{py_sitescriptdir}")
1301
1302         # alt linux
1303         gsub("%_man1dir", "%{_mandir}/man1")
1304
1305         # mandrake specs
1306         gsub("^%make$", "%{__make}")
1307         gsub("^%make ", "%{__make} ")
1308         gsub("^%makeinstall_std", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1309         gsub("^%{makeinstall}", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1310         gsub("^%makeinstall", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1311         gsub("^%{__rm} -rf %{buildroot}", "rm -rf $RPM_BUILD_ROOT")
1312         gsub("^%{__install}", "install")
1313         gsub("%optflags", "%{rpmcflags}")
1314         gsub("%{compat_perl_vendorarch}", "%{perl_vendorarch}")
1315
1316         gsub("^%{__make} install DESTDIR=\$RPM_BUILD_ROOT", "%{__make} install \\\n\tDESTDIR=$RPM_BUILD_ROOT")
1317         gsub("^fix-info-dir$", "[ ! -x /usr/sbin/fix-info-dir ] || /usr/sbin/fix-info-dir -c %{_infodir} >/dev/null 2>\\&1")
1318         $0 = fixedsub("%buildroot", "$RPM_BUILD_ROOT", $0)
1319         $0 = fixedsub("%{buildroot}", "$RPM_BUILD_ROOT", $0)
1320         $0 = fixedsub("CXXFLAGS=%{rpmcflags} %configure", "CXXFLAGS=%{rpmcflags}\n%configure", $0);
1321         $0 = fixedsub("%__install", "install", $0);
1322
1323         # split configure line to multiple lines
1324         if (/%configure +$/) {
1325                 sub( / +$/, "" );
1326         } else if (/%configure / && !/\\$/) {
1327                 $0 = format_configure($0);
1328         }
1329
1330         gsub("%_bindir", "%{_bindir}")
1331         gsub("%_datadir", "%{_datadir}")
1332         gsub("%_iconsdir", "%{_iconsdir}")
1333         gsub("%_sbindir", "%{_sbindir}")
1334         gsub("%_mandir", "%{_mandir}")
1335         gsub("%name", "%{name}")
1336         gsub(/%__rm/, "rm");
1337         gsub(/%__mkdir_p/, "install -d");
1338         gsub(/%__cp/, "cp");
1339         gsub(/%__ln_s/, "ln -s");
1340         gsub(/%__sed/, "%{__sed}");
1341         gsub(/%__cat/, "cat");
1342         gsub(/%__chmod/, "chmod");
1343
1344         gsub("/usr/src/linux", "%{_kernelsrcdir}")
1345         gsub("%{_prefix}/src/linux", "%{_kernelsrcdir}")
1346
1347         if (/^ant / || /^%{ant}/) {
1348                 sub(/^ant/, "%ant")
1349                 sub(/^%{ant}/, "%ant")
1350                 add_br("BuildRequires:  jpackage-utils");
1351                 add_br("BuildRequires:  rpmbuild(macros) >= 1.300");
1352         }
1353
1354         $0 = fixedsub("%(%{__cc} -dumpversion)", "%{cc_version}", $0);
1355         $0 = fixedsub("%(%{__cxx} -dumpversion)", "%{cxx_version}", $0);
1356
1357         # kill the _class and _subclass pear macros
1358         if (pear_class) {
1359                 gsub("%{_class}", pear_class);
1360         }
1361         if (pear_subclass) {
1362                 gsub("%{_subclass}", pear_subclass);
1363         }
1364 }
1365
1366 function format_configure(line,         n, a, s) {
1367         n = split(line, a, / /);
1368         s = a[1] " \\\n";
1369         for (i = 2; i <= n; i++) {
1370                 s = s "\t" a[i] " \\\n"
1371         }
1372         return s
1373 }
1374
1375
1376 # insertion sort of A[1..n]
1377 # copied from mawk manual
1378 function isort(A,n,             i,j,hold) {
1379         for (i = 2; i <= n; i++) {
1380                 hold = A[j = i]
1381                 while (A[j-1] > hold) {
1382                         j-- ; A[j+1] = A[j]
1383                 }
1384                 A[j] = hold
1385         }
1386         # sentinel A[0] = "" will be created if needed
1387 }
1388
1389
1390 function use_files_macros(      i, n, t, a, l)
1391 {
1392         use_macros()
1393
1394         # skip comments
1395         if (/^#/) {
1396                 return 1;
1397         }
1398
1399         sub("^%doc %{_mandir}", "%{_mandir}")
1400
1401         gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
1402         gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
1403
1404         # uid/gid nobody is not valid in %files
1405         if (/%attr([^)]*nobody[^)]*)/ && !/FIXME/) {
1406                 $0 = $0 " # FIXME nobody user/group can't own files! -adapter.awk"
1407         }
1408
1409         # s[gu]id programs with globs are evil
1410         if (/%attr\([246]...,.*\*/ && !/FIXME/) {
1411                 $0 = $0 " # FIXME no globs for suid/sgid files"
1412         }
1413
1414         # replace back
1415         gsub("%{_sysconfdir}/cron\.d", "/etc/cron.d")
1416         gsub("%{_sysconfdir}/crontab\.d", "/etc/crontab.d")
1417         gsub("%{_sysconfdir}/logrotate\.d", "/etc/logrotate.d")
1418         gsub("%{_sysconfdir}/pam\.d", "/etc/pam.d")
1419         gsub("%{_sysconfdir}/profile\.d", "/etc/profile.d")
1420         gsub("%{_sysconfdir}/rc\.d", "/etc/rc.d")
1421         gsub("%{_sysconfdir}/security", "/etc/security")
1422         gsub("%{_sysconfdir}/skel", "/etc/skel")
1423         gsub("%{_sysconfdir}/sysconfig", "/etc/sysconfig")
1424         gsub("%{_sysconfdir}/certs", "/etc/certs")
1425         gsub("%{_sysconfdir}/init.d", "/etc/init.d")
1426         gsub("%{_sysconfdir}/dbus-1", "/etc/dbus-1")
1427         gsub("%{_sysconfdir}/pki", "/etc/pki")
1428         gsub("%{_sysconfdir}/tmpwatch", "/etc/tmpwatch")
1429
1430         # /etc/init.d -> /etc/rc.d/init.d
1431         if (!/^\/etc\/init\.d$/) {
1432                  gsub("/etc/init.d", "/etc/rc.d/init.d")
1433         }
1434
1435         if (/\/etc\/rc\.d\/init\.d\// && !/functions/) {
1436                 if (!/%attr.*\/etc\/rc\.d\/init\.d/) {
1437                         $0 = "%attr(754,root,root) " $0
1438                 }
1439                 if (/^%attr.*\/etc\/rc\.d\/init\.d/ && !/^%attr\(754 *,/) {
1440                         gsub("^%attr\\(... *,", "%attr(754,");
1441                 }
1442         }
1443
1444         if (/lib.+\.so\b/ && !/\.so$/ && !/^%attr.*/ && !/%exclude/) {
1445                 $0 = "%attr(755,root,root) " $0
1446         }
1447
1448         if (/%{perl_vendorarch}.*\.so$/ && !/^%attr.*/) {
1449                 $0 = "%attr(755,root,root) " $0
1450         }
1451
1452         # remove attrs from man pages
1453         if (/%{_mandir}/ && /^%attr/) {
1454                 sub("^%attr\\(.*\\) *", "");
1455         }
1456
1457         # /etc/sysconfig files
1458         # %attr(640,root,root) %config(noreplace) %verify(not size mtime md5) /etc/sysconfig/*
1459         # attr not required, allow default 644 attr
1460         if (!/network-scripts/ && !/%dir/ && !/\.d$/ && !/functions/ && !/\/etc\/sysconfig\/wmstyle/) {
1461                 if (/\/etc\/sysconfig\// && /%config/ && !/%config\(noreplace/) {
1462                         gsub("%config", "%config(noreplace)")
1463                 }
1464
1465                 if (/\/etc\/sysconfig\// && !/%config\(noreplace/) {
1466                         $NF = "%config(noreplace) " $NF
1467                 }
1468
1469                 if (/\/etc\/sysconfig\// && /%attr\(755/) {
1470                         gsub("^%attr\\(... *,", "%attr(640,");
1471                 }
1472
1473                 if (/\/etc\/sysconfig\// && !/%verify/) {
1474                         gsub("/etc/sysconfig", "%verify(not size mtime md5) /etc/sysconfig");
1475                 }
1476         }
1477
1478         # kill leading zeros
1479         if (/%attr\(0[1-9]/) {
1480                 gsub("%attr\\(0", "%attr(")
1481         }
1482
1483         # kill leading whitespace
1484         gsub(/^ +/, "");
1485
1486         # kill default attrs
1487         gsub(/%dir %attr\(755,root,root\)/, "%dir");
1488         gsub(/%attr\(755,root,root\) %dir/, "%dir");
1489         if (!/%dir/) {
1490                 gsub(/%attr\(644,root,root\) /, "");
1491         }
1492
1493         # sort %verify attrs
1494         if (match($0, /%verify\(not([^)]+)\)/)) {
1495                 t = substr($0, RSTART, RLENGTH)
1496                 # kill commas: %verify(not,md5,size,mtime)
1497                 gsub(/,/, " ", t);
1498
1499                 gsub(/^%verify\(not |\)$/, "", t)
1500                 n = split(t, a, / /)
1501                 isort(a, n)
1502
1503                 s = "%verify(not"
1504                 for (i = 1 ; i <= n; i++) {
1505                         s = s " " a[i]
1506                 }
1507                 s = s ")"
1508
1509                 gsub(/%verify\(not[^)]+\)/, s)
1510         }
1511
1512         if (/%{_mandir}/) {
1513                 gsub("\.gz$", "*")
1514                 gsub("%ext_man$", "*")
1515         }
1516
1517         # locale dir and no %lang -> bad
1518         if (/%{_datadir}\/locale\/.*\// && !/%(dir|lang)/) {
1519                 $(NF + 1) = "# FIXME consider using %find_lang"
1520         }
1521
1522         # python egg-infos
1523         if (match($0, "^%{py_site(script)?dir}/.+-py"py_ver".egg-info$")) {
1524                 # tests:
1525                 #%{py_sitedir}/*-py2.4.egg-info
1526                 #%{py_sitescriptdir}/GnuPGInterface-%{version}-py2.4.egg-info
1527                 #%{py_sitescriptdir}/python_mpd-%{version}-py2.4.egg-info
1528                 #%{py_sitescriptdir}/mechanize-0.1.6b-py2.4.egg-info
1529
1530                 l = index($0, "/");
1531                 t = substr($0, 0, l);
1532                 s = substr($0, l + 1, RLENGTH - l - length("-py"py_ver".egg-info"));
1533                 if (match(s, "[^-]+$")) {
1534                         if (RSTART > 1) {
1535                                 s = substr(s, 0, RSTART - 1);
1536                         }
1537                         print "%if \"%{py_ver}\" > \"2.4\""
1538                         gsub(t "/.+.egg-info", t "/" s "-*.egg-info");
1539                         print
1540                         print "%endif"
1541                         return 0;
1542                 }
1543         }
1544
1545         # atrpms
1546         $0 = fixedsub("%{perl_man1dir}", "%{_mandir}/man1", $0);
1547         $0 = fixedsub("%{perl_man3dir}", "%{_mandir}/man3", $0);
1548         $0 = fixedsub("%{perl_bin}", "%{_bindir}", $0);
1549
1550         gsub(libdir "/pkgconfig", "%{_pkgconfigdir}");
1551         gsub("%{_libdir}/pkgconfig", "%{_pkgconfigdir}");
1552         gsub("%{_prefix}/lib/pkgconfig", "%{_pkgconfigdir}");
1553
1554         gsub("%{_datadir}/applications", "%{_desktopdir}");
1555         gsub("%{_datadir}/icons", "%{_iconsdir}");
1556         gsub("%{_datadir}/pixmaps", "%{_pixmapsdir}");
1557         gsub("%{_datadir}/pear", "%{php_pear_dir}");
1558         gsub("%{_datadir}/php", "%{php_data_dir}");
1559
1560         return 1
1561 }
1562
1563 function use_script_macros()
1564 {
1565         if (gsub("/sbin/service", "%service")) {
1566                 sub(" >/dev/null 2>&1 \|\|:", "");
1567                 sub(" 2> /dev/null \|\| :", "");
1568         }
1569 }
1570
1571 function fill(ch, n, i) {
1572         for (i = 0; i < n; i++)
1573                 printf("%c", ch)
1574 }
1575
1576 function format_flush(line, indent, newline, word, first_word) {
1577         first_word = 1
1578         if (format_indent == -1)
1579                 newline = ""
1580         else
1581                 newline = fill(" ", format_indent) "- "
1582
1583         while (match(line, /[^\t ]+/)) {
1584                 word = substr(line, RSTART, RLENGTH)
1585                 if (length(newline) + length(word) + 1 > tw) {
1586                         print newline
1587
1588                         if (format_indent == -1)
1589                                 newline = ""
1590                         else
1591                                 newline = fill(" ", format_indent + 2)
1592                         first_word = 1
1593                 }
1594
1595                 if (first_word) {
1596                         newline = newline word
1597                         first_word = 0
1598                 } else
1599                         newline = newline " " word
1600
1601                 line = substr(line, RSTART + RLENGTH)
1602         }
1603         if (newline ~ /[^\t ]/) {
1604                 print newline
1605         }
1606 }
1607
1608 function cflags(var)
1609 {
1610         if ($0 == var "=\"$RPM_OPT_FLAGS\"") {
1611                 removed[var] = 1
1612                 return 0
1613         }
1614
1615         if (!/!\?debug/)
1616                 sub("\$RPM_OPT_FLAGS", "%{rpmcflags}")
1617         return 1
1618 }
1619
1620 # return whole matched pattern
1621 function matchstr(str, pat)
1622 {
1623         match(str, "[^/]+$");
1624         return substr(str, RSTART, RLENGTH);
1625 }
1626
1627 function unify_url(url)
1628 {
1629
1630         # sourceforge urls
1631         # Docs about sourceforge mirror system: http://sourceforge.net/apps/trac/sourceforge/wiki/Mirrors
1632
1633         # 1. unify domains
1634         sub("^http://prdownloads\.sourceforge\.net/", "http://downloads.sourceforge.net/", url)
1635         sub("^http://download\.sf\.net/", "http://downloads.sourceforge.net/", url)
1636         sub("^http://download\.sourceforge\.net/", "http://downloads.sourceforge.net/", url)
1637         sub("^http://dl\.sourceforge\.net/", "http://downloads.sourceforge.net/", url)
1638         sub("^http://.*\.dl\.sourceforge\.net/", "http://downloads.sourceforge.net/", url)
1639         sub("^http://dl\.sf\.net/", "http://downloads.sourceforge.net/", url)
1640         sub("^http://downloads\.sourceforge\.net/sourceforge/", "http://downloads.sourceforge.net/", url)
1641
1642         # 3. unify urls
1643         if (url ~ /sourceforge.net/) {
1644                 sub("[?&]big_mirror=.*$", "", url);
1645                 sub("[?&]modtime=.*$", "", url);
1646                 sub("[?]use_mirror=.*$", "", url);
1647                 sub("[?]download$", "", url);
1648                 sub("/download$", "", url);
1649         }
1650
1651         # SF: new style urls, strip "files/" between and prepend dl.
1652         if (match(url, "^http://sourceforge.net/projects/[^/]+/files/")) {
1653                 url = substr(url, 1, RLENGTH - length("files/")) substr(url, RSTART + RLENGTH);
1654                 sub("^http://sourceforge.net/projects/", "http://downloads.sourceforge.net/project/", url);
1655         }
1656
1657         # SF unify: http://downloads.sourceforge.net/PROJECT/TARBALL
1658         # http://downloads.sourceforge.net/project/PROJECT/FILE/VERSION/%{name}-%{version}.zip
1659         if (match(url, "^http://downloads.sourceforge.net/project/[^/]+")) {
1660                 url = sprintf("http://downloads.sourceforge.net/%s/%s", substr(url, 42, RLENGTH - 41), matchstr(url, "[^/]+$"));
1661         }
1662
1663         sub("^ftp://ftp\.gnome\.org/", "http://ftp.gnome.org/", url)
1664         sub("^http://ftp\.gnome\.org/pub/gnome/", "http://ftp.gnome.org/pub/GNOME/", url)
1665
1666         # apache urls
1667         sub("^http://apache.zone-h.org/", "http://www.apache.org/dist/", url)
1668
1669         # gnu.org
1670         sub("^ftp://ftp\.gnu\.org/", "http://ftp.gnu.org/", url)
1671         sub("^http://ftp\.gnu\.org/pub/gnu/", "http://ftp.gnu.org/gnu/", url)
1672
1673         # debian.org
1674         sub("^ftp://ftp\.[^.]+\.debian\.org/", "ftp://ftp.debian.org/", url)
1675         sub("^http://ftp\.[^.]+\.debian\.org/", "ftp://ftp.debian.org/", url)
1676         sub("^ftp://ftp\.debian\.org/pub/debian/", "ftp://ftp.debian.org/debian/", url)
1677
1678         return url
1679 }
1680
1681 function demacroize(str)
1682 {
1683         if (mod_name) {
1684                 sub("%{mod_name}", mod_name, str);
1685         }
1686         if (pearname) {
1687                 sub("%{_pearname}", pearname, str);
1688         }
1689         if (pearname) {
1690                 sub("%{pearname}", pearname, str);
1691         }
1692         if (name) {
1693                 sub("%{name}", name, str);
1694         }
1695         if (version) {
1696                 sub("%{version}", version, str);
1697         }
1698         if (_beta) {
1699                 sub("%{_beta}", _beta, str);
1700         }
1701         if (_rc) {
1702                 sub("%{_rc}", _rc, str);
1703         }
1704         if (_pre) {
1705                 sub("%{_pre}", _pre, str);
1706         }
1707         if (_snap) {
1708                 sub("%{_snap}", _snap, str);
1709         }
1710         if (subver) {
1711                 sub("%{subver}", subver, str);
1712         }
1713         return str;
1714 }
1715
1716 function kill_preamble_macros()
1717 {
1718         if ($1 ~ /^Obsoletes:/) {
1719                 # NB! assigning $2 a value breaks tabbing
1720                 $2 = demacroize($2);
1721         }
1722         if ($1 ~ /^URL:/) {
1723                 # NB! assigning $2 a value breaks tabbing
1724                 $2 = demacroize($2);
1725                 $2 = unify_url($2)
1726         }
1727
1728         # fedora extras
1729         if (/%{\?FE_USERADD_REQ}/) {
1730                 $0 = "";
1731                 print "BuildRequires:   rpmbuild(macros) >= 1.202"
1732                 print "Provides:        user(xxx)"
1733                 print "Requires(postun):        /usr/sbin/userdel"
1734                 print "Requires(pre):  /bin/id"
1735                 print "Requires(pre):  /usr/sbin/useradd"
1736         }
1737 }
1738
1739 function get_epoch(pkg, ver,    epoch)
1740 {
1741         return
1742 # should parse the BR lines more adequately:
1743 #       freetype = 2.0.0 -> correct
1744 #       freetype = 2.1.9 -> with epoch 1, as epoch 1 was added in 2.1.7
1745
1746         shell = "grep -o '^" pkg ":[^:]\+' ../PLD-doc/BuildRequires.txt | awk '{print $NF}'";
1747         shell | getline epoch;
1748         return epoch;
1749 }
1750
1751 function format_requires(tag, value,    n, p, i, deps, ndeps) {
1752         # skip any formatting for commented out items or some weird macros
1753         if (/^#/ || /%\(/) {
1754                 return tag "\t" value
1755         }
1756         n = split(value, p, / *,? */);
1757         for (i = 1; i <= n; i++) {
1758                 if (p[i+1] ~ /[<=>]/) {
1759                         # add epoch if the version doesn't have it but BuildRequires.txt has
1760                         if (p[i] ~ /^[a-z]/ && p[i+2] !~ /^[0-9]+:/) {
1761                                 epoch = get_epoch(p[i], p[i+2])
1762                                 if (epoch) {
1763                                         p[i+2] = epoch ":" p[i+2];
1764                                 }
1765                         }
1766                         deps[ndeps++] = p[i] " " p[i+1] " " p[i+2];
1767                         i += 2;
1768                 } else {
1769                         deps[ndeps++] = p[i];
1770                 }
1771         }
1772         s = ""
1773         for (i in deps) {
1774                 s = s sprintf("%s\t%s\n", tag, deps[i]);
1775         }
1776         return substr(s, 1, length(s)-1);
1777 }
1778
1779 function use_tabs()
1780 {
1781         # reverse vim: ts=4 sw=4 et
1782         gsub(/    /, "\t");
1783 }
1784
1785 function add_br(br)
1786 {
1787         BR[BR_count++] = br
1788 }
1789
1790 # Load rpm macros
1791 # you should update the list also in adapter when making changes here
1792 function import_rpm_macros(  v) {
1793         # File with rpm groups
1794         topdir = ENVIRON["_topdir"]
1795
1796         if (!topdir) {
1797                 print "adapter.awk should not not be invoked directly, but via adapter script" > "/dev/stderr"
1798                 do_not_touch_anything = 1
1799                 exit(rc = 1);
1800         }
1801
1802         # update this version dep each time some new macro export is added
1803         v = 1.49
1804         if (!ENVIRON["ADAPTER_REVISION"] || ENVIRON["ADAPTER_REVISION"] < v) {
1805                 printf("adapter shell script is outdated: Need %s, got %s. Please update it.\n", v, ENVIRON["ADAPTER_REVISION"]) > "/dev/stderr"
1806                 do_not_touch_anything = 1
1807                 exit(rc = 1);
1808         }
1809
1810         prefix = ENVIRON["_prefix"]
1811         bindir = ENVIRON["_bindir"]
1812         sbindir = ENVIRON["_sbindir"]
1813         libdir = ENVIRON["_libdir"]
1814         sysconfdir = ENVIRON["_sysconfdir"]
1815         datadir = ENVIRON["_datadir"]
1816         includedir = ENVIRON["_includedir"]
1817         mandir = ENVIRON["_mandir"]
1818         infodir = ENVIRON["_infodir"]
1819         examplesdir = ENVIRON["_examplesdir"]
1820         docdir = ENVIRON["_defaultdocdir"]
1821         kdedocdir = ENVIRON["_kdedocdir"]
1822         gtkdocdir = ENVIRON["_gtkdocdir"]
1823         desktopdir = ENVIRON["_desktopdir"]
1824         pixmapsdir = ENVIRON["_pixmapsdir"]
1825         javadir = ENVIRON["_javadir"]
1826         pkgconfigdir = ENVIRON["_pkgconfigdir"]
1827         npkgconfigdir = ENVIRON["_npkgconfigdir"]
1828         localedir = ENVIRON["_localedir"]
1829
1830         perl_sitearch = ENVIRON["perl_sitearch"]
1831         perl_archlib = ENVIRON["perl_archlib"]
1832         perl_privlib = ENVIRON["perl_privlib"]
1833         perl_vendorlib = ENVIRON["perl_vendorlib"]
1834         perl_vendorarch = ENVIRON["perl_vendorarch"]
1835         perl_sitelib = ENVIRON["perl_sitelib"]
1836
1837         py_sitescriptdir = ENVIRON["py_sitescriptdir"]
1838         py_sitedir = ENVIRON["py_sitedir"]
1839         py_scriptdir = ENVIRON["py_scriptdir"]
1840         py_ver = ENVIRON["py_ver"]
1841
1842         py3_sitescriptdir = ENVIRON["py3_sitescriptdir"]
1843         py3_sitedir = ENVIRON["py3_sitedir"]
1844         py3_scriptdir = ENVIRON["py3_scriptdir"]
1845         py3_ver = ENVIRON["py3_ver"]
1846
1847         ruby_archdir = ENVIRON["ruby_archdir"]
1848         ruby_ridir = ENVIRON["ruby_ridir"]
1849         ruby_rubylibdir = ENVIRON["ruby_rubylibdir"]
1850         ruby_sitearchdir = ENVIRON["ruby_sitearchdir"]
1851         ruby_sitelibdir = ENVIRON["ruby_sitelibdir"]
1852         ruby_rdocdir = ENVIRON["ruby_rdocdir"]
1853
1854         php_pear_dir = ENVIRON["php_pear_dir"]
1855         php_data_dir = ENVIRON["php_data_dir"]
1856         tmpdir = ENVIRON["tmpdir"]
1857
1858         systemdunitdir = ENVIRON["systemdunitdir"]
1859         systemdtmpfilesdir = ENVIRON["systemdtmpfilesdir"]
1860 }
1861
1862 # php virtual deps as discussed in devel-en
1863 function replace_php_virtual_deps() {
1864         pkg = $2
1865 #       if (pkg == "php-program") {
1866 #               $0 = $1 "\t/usr/bin/php"
1867 #               return
1868 #       }
1869
1870 #       if (pkg ~ /^php-[a-z]/ && pkg !~ /^php-(pear|common|cli|devel|fcgi|cgi|dirs|program|pecl-)/) {
1871 #               sub(/^php-/, "php(", pkg);
1872 #               sub(/$/, ") # verify this correctness -- it may be wanted to use specific not virtual dep", pkg);
1873 #               $2 = pkg
1874 #       }
1875
1876         if (pkg ~/^php$/) {
1877                 $2 = "webserver(php)";
1878                 if ($4 ~ /^[0-9]:/) {
1879                         $4 = substr($4, 3);
1880                 }
1881         }
1882
1883         if (pkg ~/^php4$/) {
1884                 $2 = "webserver(php)";
1885                 if ($4 ~ /^[0-9]:/) {
1886                         $4 = substr($4, 3);
1887                 }
1888         }
1889 }
1890
1891 function replace_groupnames(group) {
1892         group = replace(group, "Amusements/Games", "Applications/Games");
1893         group = replace(group, "Amusements/Games/Strategy/Real Time", "X11/Applications/Games/Strategy");
1894         group = replace(group, "Application/Multimedia", "Applications/Multimedia");
1895         group = replace(group, "Application/System", "Applications/System");
1896         group = replace(group, "Applications/Compilers", "Development/Languages");
1897         group = replace(group, "Applications/Daemons", "Daemons");
1898         group = replace(group, "Applications/Internet", "Applications/Networking");
1899         group = replace(group, "Applications/Internet/Peer to Peer", "Applications/Networking");
1900         group = replace(group, "Applications/Productivity", "X11/Applications");
1901         group = replace(group, "Applications/Security", "Applications/System");
1902         group = replace(group, "Applications/Web", "Applications/WWW");
1903         group = replace(group, "Database", "Applications/Databases");
1904         group = replace(group, "Development/C", "Development/Libraries");
1905         group = replace(group, "Development/Code Generators", "Development");
1906         group = replace(group, "Development/Docs", "Documentation");
1907         group = replace(group, "Development/Documentation", "Documentation");
1908         group = replace(group, "Development/Java", "Development/Languages/Java");
1909         group = replace(group, "Development/Languages/C and C++", "Libraries");
1910         group = replace(group, "Development/Languages/Other", "Development/Languages");;
1911         group = replace(group, "Development/Languages/Ruby", "Development/Languages");
1912         group = replace(group, "Development/Libraries/C and C++", "Development/Libraries");
1913         group = replace(group, "Development/Libraries/Java", "Development/Languages/Java");
1914         group = replace(group, "Development/Libraries/Python", "Development/Languages/Python");
1915         group = replace(group, "Development/Libraries/TCL", "Development/Languages/Tcl");;
1916         group = replace(group, "Development/Other", "Development");
1917         group = replace(group, "Development/Python", "Development/Languages/Python");
1918         group = replace(group, "Development/Testing", "Development");
1919         group = replace(group, "Editors", "Applications/Text");
1920         group = replace(group, "Emulators", "Applications/Emulators");
1921         group = replace(group, "File tools", "Applications/File");
1922         group = replace(group, "Games", "Applications/Games");
1923         group = replace(group, "Library/Development", "Development/Libraries");
1924         group = replace(group, "Networking/Deamons", "Networking/Daemons");
1925         group = replace(group, "Networking/Mail", "Applications/Mail");
1926         group = replace(group, "Networking/Other", "Networking");
1927         group = replace(group, "Productivity/Databases/Servers", "Applications/Databases");
1928         group = replace(group, "Productivity/Multimedia/Other", "X11/Applications/Multimedia");
1929         group = replace(group, "Productivity/Networking/Web/Servers", "Networking/Daemons/HTTP");;
1930         group = replace(group, "Shells", "Applications/Shells");
1931         group = replace(group, "System Environment/Base", "Base");
1932         group = replace(group, "System Environment/Daemons", "Daemons");
1933         group = replace(group, "System Environment/Kernel", "Base/Kernel");
1934         group = replace(group, "System Environment/Libraries", "Libraries");
1935         group = replace(group, "System Tools", "Applications/System");
1936         group = replace(group, "System", "Base");
1937         group = replace(group, "System/Base", "Base");
1938         group = replace(group, "System/Kernel and hardware", "Base/Kernel");
1939         group = replace(group, "System/Libraries", "Libraries");
1940         group = replace(group, "System/Servers", "Daemons");
1941         group = replace(group, "Text Processing/Markup/HTML", "Applications/Text");
1942         group = replace(group, "Text Processing/Markup/XML", "Applications/Text");
1943         group = replace(group, "Text tools", "Applications/Text");
1944         group = replace(group, "User Interface/Desktops", "X11/Applications");
1945         group = replace(group, "User Interface/X", "X11/Applications");
1946         group = replace(group, "Utilities/System", "Applications/System");
1947         group = replace(group, "Web/Database", "Applications/WWW");
1948         group = replace(group, "X11/GNOME", "X11/Applications");
1949         group = replace(group, "X11/GNOME/Applications", "X11/Applications");
1950         group = replace(group, "X11/GNOME/Development/Libraries", "X11/Development/Libraries");
1951         group = replace(group, "X11/Games", "X11/Applications/Games");
1952         group = replace(group, "X11/Games/Strategy", "X11/Applications/Games/Strategy");
1953         group = replace(group, "X11/Library", "X11/Libraries");
1954         group = replace(group, "X11/Utilities", "X11/Applications");
1955         group = replace(group, "X11/XFree86", "X11");
1956         group = replace(group, "X11/Xserver", "X11/Servers");
1957
1958         return group;
1959 }
1960
1961 function replace_requires() {
1962
1963         sub(/^python-setuptools-devel$/, "python-distribute", $2);
1964         sub(/^gcc-g77/, "gcc-fortran", $2);
1965
1966         # use virtual, not package name
1967         sub(/^rpm-build-macros$/, "rpmbuild(macros)", $2);
1968
1969         # bad package.xml, see http://pear.php.net/bugs/bug.php?id=17779
1970         sub(/^php-php-gtk/, "php-gtk2", $2);
1971
1972         # jpackages / fedora java packages
1973         sub(/^antlr3$/, "java-antlr3", $2);
1974         sub(/^aqute-bnd$/, "java-bnd", $2);
1975         sub(/^avalon-framework$/, "java-avalon-framework", $2);
1976         sub(/^avalon-logkit$/, "java-avalon-logkit", $2);
1977         sub(/^axis$/, "java-axis", $2);
1978         sub(/^bouncycastle$/, "java-bcprov", $2);
1979         sub(/^bouncycastle-mail$/, "java-bcmail", $2);
1980         sub(/^bouncycastle-pg$/, "java-bcpg", $2);
1981         sub(/^bouncycastle-tsp$/, "java-bctsp", $2);
1982         sub(/^bsf$/, "java-bsf", $2);
1983         sub(/^dom4j$/, "java-dom4j", $2);
1984         sub(/^flute$/, "java-flute", $2);
1985         sub(/^gnu-regexp$/, "java-gnu-regexp", $2);
1986         sub(/^gnu.regexp$/, "java-gnu-regexp", $2);
1987         sub(/^hamcrest$/, "java-hamcrest", $2);
1988         sub(/^itext$/, "java-itext", $2);
1989         sub(/^jaas$/, "java(jaas)", $2);
1990         sub(/^jaf$/, "java(jaf)", $2);
1991         sub(/^jakarta-ant$/, "ant", $2);
1992         sub(/^jakarta-commons-codec$/, "java-commons-codec", $2);
1993         sub(/^jakarta-commons-httpclient$/, "java-commons-httpclient", $2);
1994         sub(/^jakarta-commons-logging$/, "java-commons-logging", $2);
1995         sub(/^jakarta-log4j$/, "java-log4j", $2);
1996         sub(/^jakarta-oro$/, "java-oro", $2);
1997         sub(/^jakarta-servletapi$/, "java(servlet)", $2);
1998         sub(/^java-devel$/, "jdk", $2);
1999         sub(/^java\(JSP\)$/, "java(jsp)", $2);
2000         sub(/^java\(JavaServerFaces\)$/, "java(javaserverfaces)", $2);
2001         sub(/^java\(Portlet\)$/, "java(portlet)", $2);
2002         sub(/^java\(Servlet\)$/, "java(servlet)", $2);
2003         sub(/^javamail$/, "java(javamail)", $2);
2004         sub(/^jaxp$/, "java(jaxp)", $2);
2005         sub(/^jaxp_parser_impl$/, "java(jaxp_parser_impl)", $2);
2006         sub(/^jaxp_transform_impl$/, "java(jaxp_transform_impl)", $2);
2007         sub(/^jce$/, "java(jce)", $2);
2008         sub(/^jcommon$/, "java-jcommon", $2);
2009         sub(/^jdbc-stdext$/, "java(jdbc-stdext)", $2);
2010         sub(/^jdepend$/, "java-jdepend", $2);
2011         sub(/^jfreechart$/, "java-jfreechart", $2);
2012         sub(/^jmx$/, "java(jmx)", $2);
2013         sub(/^jndi$/, "java(jndi)", $2);
2014         sub(/^jsch$/, "java-jsch", $2);
2015         sub(/^jsse$/, "java(jsse)", $2);
2016         sub(/^jta$/, "java(jta)", $2);
2017         sub(/^junit$/, "java-junit", $2);
2018         sub(/^junit4$/, "java-junit", $2);
2019         sub(/^ldapjdk$/, "ldapsdk", $2);
2020         sub(/^libbase$/, "java-libbase", $2);
2021         sub(/^libfonts$/, "java-libfonts", $2);
2022         sub(/^libformula$/, "java-libformula", $2);
2023         sub(/^liblayout$/, "java-liblayout", $2);
2024         sub(/^libloader$/, "java-libloader", $2);
2025         sub(/^librepository$/, "java-librepository", $2);
2026         sub(/^libserializer$/, "java-libserializer", $2);
2027         sub(/^log4j$/, "java-log4j", $2);
2028         sub(/^logging-log4j$/, "java-log4j", $2);
2029         sub(/^oro$/, "java-oro", $2);
2030         sub(/^pdf-renderer$/, "java-pdf-renderer", $2);
2031         sub(/^pentaho-libxml$/, "java-libxml", $2);
2032         sub(/^rhino$/, "java-rhino", $2);
2033         sub(/^sac$/, "java-sac", $2);
2034         sub(/^saxon-scripts$/, "saxon", $2);
2035         sub(/^servlet$/, "java(servlet)", $2);
2036         sub(/^uddi4j$/, "java-uddi4j", $2);
2037         sub(/^ws-jaxme$/, "java-jaxme", $2);
2038         sub(/^wsdl4j$/, "java-wsdl4j", $2);
2039         sub(/^xalan-j$/, "java-xalan", $2);
2040         sub(/^xalan-j2$/, "java-xalan", $2);
2041         sub(/^xerces-j$/, "java-xerces", $2);
2042         sub(/^xerces-j2$/, "java-xerces", $2);
2043         sub(/^xml-commons-apis$/, "java-xml-commons", $2);
2044         sub(/^xml-commons-resolver$/, "java-xml-commons-resolver", $2);
2045         sub(/^xmldb-api$/, "java-xmldb", $2);
2046         sub(/^xmldb-api-sdk$/, "java-xmldb-sdk", $2);
2047
2048         # fedora / redhat
2049         sub(/^Django$/, "python-django", $2);
2050         sub(/^GitPython$/, "python-git", $2);
2051         sub(/^PyQt4-devel$/, "python-PyQt4-devel", $2);
2052         sub(/^PyQwt-devel$/, "python-PyQwt-devel", $2);
2053         sub(/^ccid$/, "pcsc-driver-ccid", $2);
2054         sub(/^chkconfig$/, "/sbin/chkconfig", $2);
2055         sub(/^db4-devel$/, "db-devel", $2);
2056         sub(/^dbus-python$/, "python-dbus", $2);
2057         sub(/^desktop-notification-daemon$/, "dbus(org.freedesktop.Notifications)", $2);
2058         sub(/^file-devel$/, "libmagic-devel", $2);
2059         sub(/^freetype2-devel$/, "freetype-devel", $2);
2060         sub(/^fuse-devel$/, "libfuse-devel", $2);
2061         sub(/^gamin-python$/, "python-gamin", $2);
2062         sub(/^gcc-c\+\+$/, "libstdc++-devel", $2);
2063         sub(/^gnome-desktop3-devel$/, "gnome-desktop-devel", $2);
2064         sub(/^gnome-python2-extras$/, "python-gnome-extras", $2);
2065         sub(/^gnome-python2-gconf$/, "python-gnome-gconf", $2);
2066         sub(/^gnome-python2-gnomekeyring$/, "python-gnome-desktop-keyring", $2);
2067         sub(/^gnome-python2-gtkspell$/, "python-gnome-extras-gtkspell", $2);
2068         sub(/^gtk-sharp2-devel$/, "dotnet-gtk-sharp2-devel", $2);
2069         sub(/^gtk2$/, "gtk+2", $2);
2070         sub(/^gtk2-devel$/, "gtk+2-devel", $2);
2071         sub(/^gtk3-devel$/, "gtk+3-devel", $2);
2072         sub(/^initscripts$/, "rc-scripts", $2);
2073         sub(/^iproute$/, "iproute2", $2);
2074         sub(/^iscsi-initiator-utils$/, "open-iscsi", $2);
2075         sub(/^keyutils-libs-devel$/, "keyutils-devel", $2);
2076         sub(/^libSM-devel$/, "xorg-lib-libSM-devel", $2);
2077         sub(/^libX11-devel$/, "xorg-lib-libX11-devel", $2);
2078         sub(/^libXScrnSaver-devel$/, "xorg-lib-libXScrnSaver-devel", $2);
2079         sub(/^libXau-devel$/, "xorg-lib-libXau-devel", $2);
2080         sub(/^libXcomposite-devel$/, "xorg-lib-libXcomposite-devel", $2);
2081         sub(/^libXcursor-devel$/, "xorg-lib-libXcursor-devel", $2);
2082         sub(/^libXdamage-devel$/, "xorg-lib-libXdamage-devel", $2);
2083         sub(/^libXext-devel$/, "xorg-lib-libXext-devel", $2);
2084         sub(/^libXft-devel$/, "xorg-lib-libXft-devel", $2);
2085         sub(/^libXinerama-devel$/, "xorg-lib-libXinerama-devel", $2);
2086         sub(/^libXrandr-devel$/, "xorg-lib-libXrandr-devel", $2);
2087         sub(/^libXrender-devel$/, "xorg-lib-libXrender-devel", $2);
2088         sub(/^libXxf86vm-devel$/, "xorg-lib-libXxf86vm-devel", $2);
2089         sub(/^libacl-devel$/, "acl-devel", $2);
2090         sub(/^libcurl-devel$/, "curl-devel", $2);
2091         sub(/^libgudev1-devel$/, "udev-glib-devel", $2);
2092         sub(/^libmx-devel$/, "mx-devel", $2);
2093         sub(/^libselinux-python$/, "python-selinux", $2);
2094         sub(/^libsrtp-devel$/, "srtp-devel", $2);
2095         sub(/^libtdb$/, "tdb", $2);
2096         sub(/^libtdb-devel$/, "tdb-devel", $2);
2097         sub(/^libtevent$/, "tevent", $2);
2098         sub(/^libtevent-devel$/, "tevent-devel", $2);
2099         sub(/^libusb1-devel$/, "libusb-devel", $2);
2100         sub(/^mod_wsgi$/, "apache-mod_wsgi", $2);
2101         sub(/^newt-python$/, "python-snack", $2);
2102         sub(/^notify-python$/, "python-pynotify", $2);
2103         sub(/^pcsc-lite-ccid$/, "pcsc-driver-ccid", $2);
2104         sub(/^pulseaudio-libs-devel$/, "pulseaudio-devel", $2);
2105         sub(/^pyOpenSSL$/, "python-pyOpenSSL", $2);
2106         sub(/^pycairo$/, "python-pycairo", $2);
2107         sub(/^pyflakes$/, "python-pyflakes", $2);
2108         sub(/^pygobject2$/, "python-pygobject", $2);
2109         sub(/^pygobject3-devel$/, "python-pygobject3-common-devel", $2);
2110         sub(/^pygtk2$/, "python-pygtk", $2);
2111         sub(/^pygtk2-devel$/, "python-pygtk-devel", $2);
2112         sub(/^pygtk2-libglade$/, "python-pygtk-glade", $2);
2113         sub(/^pysvn$/, "python-pysvn", $2);
2114         sub(/^pytalloc$/, "python-talloc", $2);
2115         sub(/^pytalloc-devel$/, "python-talloc-devel", $2);
2116         sub(/^python-cups$/, "python-pycups", $2);
2117         sub(/^python-enchant$/, "python-pyenchant", $2);
2118         sub(/^python-imaging$/, "python-PIL", $2);
2119         sub(/^python-imaging-tk$/, "python-PIL-tk", $2);
2120         sub(/^python-newt$/, "python-snack", $2);
2121         sub(/^python-pygtk$/, "python-pygtk-gtk", $2);
2122         sub(/^python-recaptcha-client$/, "python-recaptcha", $2);
2123         sub(/^python-twisted-core$/, "python-TwistedCore", $2);
2124         sub(/^python-twisted-core$/, "python-TwistedCore", $2);
2125         sub(/^python-twisted-names$/, "python-TwistedNames", $2);
2126         sub(/^python2-devel$/, "python-devel", $2);
2127         sub(/^pytz$/, "python-pytz", $2);
2128         sub(/^qt4-devel$/, "qt4-build", $2);
2129         sub(/^qt4-webkit-devel$/, "QtWebKit-devel", $2);
2130         sub(/^qtlockedfile-devel$/, "QtLockedFile-devel", $2);
2131         sub(/^qtsingleapplication-devel$/, "QtSingleApplication-devel", $2);
2132         sub(/^rpm-python$/, "python-rpm", $2);
2133         sub(/^sip-devel$/, "python-sip-devel", $2);
2134         sub(/^tftp-server$/, "tftpdaemon", $2);
2135         sub(/^tkinter$/, "python-tkinter", $2);
2136         sub(/^urw-fonts$/, "fonts-Type1-urw", $2);
2137         sub(/^webkitgtk3-devel$/, "gtk-webkit3-devel", $2);
2138         sub(/^xapian-bindings-python$/, "python-xapian", $2);
2139         sub(/^xorg-x11-server-sdk$/, "xorg-xserver-server-devel", $2);
2140
2141         # mandriva
2142         sub(/^python-gobject-devel$/, "python-pygobject-devel", $2);
2143         sub(/^python-pyrex$/, "python-Pyrex", $2);
2144         sub(/^webkitgtk-devel$/, "gtk-webkit-devel", $2);
2145         sub(/^python-curl$/, "python-pycurl", $2);
2146         sub(/^python-webkitgtk$/, "python-pywebkitgtk", $2);
2147         sub(/^pygtk2.0$/, "python-pygtk-gtk", $2);
2148         sub(/^gnome-python-gconf$/, "python-gnome-gconf", $2);
2149
2150         # debian / ubuntu
2151         sub(/^blkid-dev$/, "libblkid-devel", $2);
2152         sub(/^ext2fs-dev$/, "e2fsprogs-devel", $2);
2153         sub(/^libao-dev$/, "libao-devel", $2);
2154         sub(/^libboost-filesystem[0-9.]+-dev$/, "boost-devel", $2);
2155         sub(/^libboost-program-options[0-9.]+-dev$/, "boost-devel", $2);
2156         sub(/^libboost-regex[0-9.]+-dev$/, "boost-devel", $2);
2157         sub(/^libboost-thread[0-9.]+-dev$/, "boost-devel", $2);
2158         sub(/^libcurl4-openssl-dev$/, "curl-devel", $2);
2159         sub(/^libdnet-dev$/, "libdnet-devel", $2);
2160         sub(/^libesd0-dev$/, "esound-devel", $2);
2161         sub(/^libfishsound1-dev$/, "libfishsound-devel", $2);
2162         sub(/^libgconf2-dev$/, "GConf2-devel", $2);
2163         sub(/^libgl1-mesa-dev$/, "OpenGL-devel", $2);
2164         sub(/^libgl1-mesa-dri$/, "OpenGL", $2);
2165         sub(/^libglib2.0-dev$/, "glib2-devel", $2);
2166         sub(/^libglu1-mesa-dev$/, "OpenGL-GLU-devel", $2);
2167         sub(/^libgtk2.0-dev$/, "gtk+2-devel", $2);
2168         sub(/^libhunspell-dev$/, "hunspell-devel", $2);
2169         sub(/^libmcrypt-dev$/, "libmcrypt-devel", $2);
2170         sub(/^libmhash-dev$/, "mhash-devel", $2);
2171         sub(/^liboggz1-dev$/, "libggz-devel", $2);
2172         sub(/^libpango1.0-dev$/, "pango-devel", $2);
2173         sub(/^libqt4-dev$/, "qt4-build", $2);
2174         sub(/^libshout3-dev$/, "libshout-devel", $2);
2175         sub(/^libslp-dev$/, "openslp-devel", $2);
2176         sub(/^libsndfile1-dev$/, "libsndfile-devel", $2);
2177         sub(/^libspeex-dev$/, "speex-devel", $2);
2178         sub(/^libssl-dev$/, "openssl-devel", $2);
2179         sub(/^libvorbis-dev$/, "libvorbis-devel", $2);
2180         sub(/^libxslt1-dev$/, "libxslt-devel", $2);
2181         sub(/^libxss-dev$/, "xorg-lib-libXScrnSaver-devel", $2);
2182         sub(/^mesa-common-dev$/, "OpenGL-devel", $2);
2183         sub(/^libudev$/, "udev-libs", $2);
2184         sub(/^tcp_wrappers-devel$/, "libwrap-devel", $2);
2185         sub(/^vala-tools$/, "vala", $2);
2186         sub(/^vala-devel$/, "vala", $2);
2187
2188         # altlinux
2189         sub(/^libatk-devel$/, "atk-devel", $2);
2190         sub(/^libgit-devel$/, "git-core-devel", $2);
2191         sub(/^libgtk\+2-devel$/, "gtk+2-devel", $2);
2192         sub(/^libncurses-devel$/, "ncurses-devel", $2);
2193         sub(/^libncursesxx-devel$/, "ncurses-c++-devel", $2);
2194         sub(/^libpango-devel$/, "pango-devel", $2);
2195         sub(/^libpcre-devel$/, "pcre-devel", $2);
2196         sub(/^libpopt-devel$/, "popt-devel", $2);
2197         sub(/^libssl-devel$/, "openssl-devel", $2);
2198
2199         # suse
2200         sub(/^alsa-devel$/, "alsa-lib-devel", $2);
2201         sub(/^gtk-sharp2$/, "dotnet-gtk-sharp2", $2);
2202         sub(/^gtkmm2-devel$/, "gtkmm-devel", $2);
2203         sub(/^libexpat-devel$/, "expat-devel", $2);
2204         sub(/^libffmpeg-devel$/, "ffmpeg-devel", $2);
2205         sub(/^libopenssl-devel$/, "openssl-devel", $2);
2206         sub(/^libpulse-devel$/, "pulseaudio-devel", $2);
2207         sub(/^monodoc-core$/, "mono-monodoc", $2);
2208         sub(/^python-gtk$/, "python-pygtk-gtk", $2);
2209
2210         replace_php_virtual_deps()
2211 }
2212
2213 # vim:ts=4:sw=4
This page took 0.21032 seconds and 3 git commands to generate.