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