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