]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - adapter.awk
version 0.4
[packages/rpm-build-tools.git] / adapter.awk
1 #!/bin/awk -f
2 #
3 # This is adapter v0.4. Adapter adapts .spec files for PLD.
4 # Copyright (C) 1999 Micha³ Kuratczyk <kura@pld.org.pl>
5
6 BEGIN {
7         preamble = 1;
8         bof = 1;        # Beggining of file
9         boc = 2;        # Beggining of %changelog
10 }
11
12 # There should be a comment with CVS keywords on the first line of file.
13 bof == 1 {
14         if (!/# \$Revision:/)
15                  print "# $" "Revision:$, " "$" "Date:$";
16         bof = 0;
17 }
18
19 # descriptions:
20 /%description/, (/^%[a-z]+/ && !/%description/) {
21         preamble = 0;
22         
23         # Define _prefix and _mandir if it is X11 application
24         if (/^%description$/ && x11 == 1) {
25                 print "%define\t\t_prefix\t\t/usr/X11R6";
26                 print "%define\t\t_mandir\t\t%{_prefix}/man\n";
27                 x11 == 2;
28         }
29 }
30
31 # %prep section:
32 /%prep/, (/^%[a-z]+$/ && !/%prep/) {
33         preamble = 0;
34         
35         # add '-q' to %setup
36         if (/%setup/ && !/-q/)
37                 sub(/%setup/, "%setup -q");
38 }
39
40 # %build section:
41 /%build/, (/^%[a-z]+$/ && !/%build/) {
42         preamble = 0;
43
44         # Any ideas?
45 }
46
47 # %install section:
48 /%install/, (/^[a-z]+$/ && !/%install/) {
49         preamble = 0;
50         
51         # 'install -d' instead 'mkdir -p'
52         if (/mkdir -p/)
53                 sub(/mkdir -p/, "install -d");
54                 
55         # no '-u root' or '-g root' for 'install'
56         if (/^install/ && /-[ug][ \t]*root/)
57                 gsub(/-[ug][ \t]*root/, "\b");
58         
59         if (/^install/ && /-m[ \t]*644/)
60                 gsub(/-m[ \t]*644/, "\b");
61         
62         # no lines contain 'chown' or 'chgrp', which changes
63         # owner/group to 'root'
64         if ($1 ~ /chown|chgrp/ && $2 ~ /root|root.root/)
65                 noprint = 1;
66         
67         # no lines contain 'chmod' if it sets the modes to '644'
68         if ($1 ~ /chmod/ && $2 ~ /644/)
69                 noprint = 1;
70         
71         # 'gzip -9nf' for compressing
72         if ($1 ~ /gzip|bzip2/) {
73                 if ($2 ~ /^-/)
74                         sub($2, "\b");
75                 sub($1, "gzip -9nf");
76         }
77 }
78
79 # %files section:
80 /%files/, (/^%[a-z]+$/ && !/%files/) {
81         preamble = 0;
82         
83         if (/%defattr/)
84                 $0 = "%defattr(644,root,root,755)";
85
86 }
87
88 # %changelog section:
89 /%changelog/, (/^%[a-z]+$/ && !/%changelog/) {
90         preamble = 0;
91         
92         # There should be some CVS keywords on the first line of %changelog.
93         if (boc == 1) {
94                 if (!/PLD Team/) {
95                         print "* %{date} PLD Team <pld-list@pld.org.pl>";
96                         printf "All below listed persons can be reached on ";
97                         print "<cvs_login>@pld.org.pl\n\n";
98                         print "$" "Log:$";
99                 }
100                 boc = 0;
101         }
102         
103         # Define date macro.
104         if (boc == 2 && date == 0) {
105                 printf "%%define date\t%%(echo `LC_ALL=\"C\"";
106                 print " date +\"%a %b %d %Y\"`)"
107                 boc--;
108         }
109 }
110
111 # preambles:
112 preamble == 1 {
113         # There should not be a space after the name of field
114         # and before the colon.
115         sub(/[ \t]*:/, ":");
116         
117         if (tolower($1) ~ /buildroot:/)
118                 $2 = "/tmp/%{name}-%{version}-root";
119
120         # Is it X11 application?
121         if (tolower($1) ~ /group/ && $2 ~ /^X11/ && x11 == 0)
122                 x11 = 1;
123                 
124         # Do not add %define of _prefix if it already is.
125         if ($1 ~ /%define/ && $2 ~ /_prefix/)
126                 x11 = 2;
127                         
128         # Use "License" instead of "Copyright" if it is (L)GPL or BSD
129         if (tolower($1) ~ /copyright:/ && $2 ~ /GPL|BSD/)
130                 $1 = "License:";
131         
132         if (tolower($1) ~ /name:/)
133                 name = $2;
134
135         if (tolower($1) ~ /version:/)
136                 version = $2;
137
138         # Use %{name} and %{version} in the filenames in "Source:"
139         if (tolower($1) ~ /source/ && $2 ~ /^ftp:|^http:/) {
140                 n = split($2, url, /\//);
141                 filename = url[n];
142                 sub(name, "%{name}", url[n]);
143                 sub(version, "%{version}", url[n]);
144                 sub(filename, url[n], $2);
145         }
146                 
147         # There should be one or two tabs after the colon.
148         sub(/:[ \t]*/, ":");
149         if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
150                 if (RLENGTH < 8)
151                         sub(/:/, ":\t\t");
152                 else
153                         sub(/:/, ":\t");
154         }
155 }
156
157
158 # If redundant_line is zero, print this line, otherwise do not print,
159 # but set the redundant_line to 0.
160 {
161         preamble = 1;
162         
163         # Macro 'date' already defined.
164         if (/%define date/)
165                 date = 1;
166         
167         if (noprint == 0)
168                 print;
169         else
170                 noprint = 0;
171 }
172
This page took 0.044464 seconds and 4 git commands to generate.