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