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