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