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