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