3 # This is adapter v0.9. Adapter adapts .spec files for PLD.
4 # Copyright (C) 1999 Micha³ Kuratczyk <kura@pld.org.pl>
8 boc = 2; # Beggining of %changelog
9 bod = 0; # Beggining of %description
10 tw = 77; # Descriptions width
11 groups_file = ENVIRON["HOME"] "/rpm/groups" # File with rpm groups
13 # Is 'date' macro already defined?
14 if (is_there_line("%define date"))
18 # There should be a comment with CVS keywords on the first line of file.
20 if (!/# \$Revision:/) # If this line is already OK?
21 print "# $" "Revision:$, " "$" "Date:$"; # No
25 next; # It is enough for first line
29 /%description/, (/^%[a-z]+/ && !/%description/) {
35 # Define _prefix and _mandir if it is X11 application
36 if (/^%description$/ && x11 == 1) {
37 print "%define\t\t_prefix\t\t/usr/X11R6";
38 print "%define\t\t_mandir\t\t%{_prefix}/man\n";
42 # Collect whole text of description
43 if (description == 1 && !/^%[a-z]+/ && !/%description/) {
44 description_text = description_text $0 " ";
48 # Formt description to the length of tw (default == 77)
49 if (/^%[a-z]+/ && (!/%description/ || bod == 2)) {
50 n = split(description_text, dt, / /);
51 for (i = 1; i <= n; i++) {
52 if (length(line) + length(dt[i]) + 1 < tw)
53 line = line dt[i] " ";
64 description_text = "";
77 /%prep/, (/^%[a-z]+$/ && !/%prep/) {
81 if (/%setup/ && !/-q/)
82 sub(/%setup/, "%setup -q");
86 /%build/, (/^%[a-z]+$/ && !/%build/) {
93 /%install/, (/^[a-z]+$/ && !/%install/) {
96 # 'install -d' instead 'mkdir -p'
98 sub(/mkdir -p/, "install -d");
100 # no '-u root' or '-g root' for 'install'
101 if (/^install/ && /-[ug][ \t]*root/)
102 gsub(/-[ug][ \t]*root /, "");
104 if (/^install/ && /-m[ \t]*644/)
105 gsub(/-m[ \t]*644 /, "");
107 # no lines contain 'chown' or 'chgrp', which changes
108 # owner/group to 'root'
109 if ($1 ~ /chown|chgrp/ && $2 ~ /root|root.root/)
112 # no lines contain 'chmod' if it sets the modes to '644'
113 if ($1 ~ /chmod/ && $2 ~ /644/)
116 # 'gzip -9nf' for compressing
117 if ($1 ~ /gzip|bzip2/) {
119 sub(/-[A-Za-z0-9]+ /, "", $0);
120 sub($1, "gzip -9nf");
125 /%files/, (/^%[a-z]+$/ && !/%files/) {
129 $0 = "%defattr(644,root,root,755)";
132 # %changelog section:
133 /%changelog/, (/^%[a-z]+$/ && !/%changelog/) {
136 # There should be some CVS keywords on the first line of %changelog.
139 print "* %{date} PLD Team <pld-list@pld.org.pl>";
140 printf "All below listed persons can be reached on ";
141 print "<cvs_login>@pld.org.pl\n";
150 printf "%%define date\t%%(echo `LC_ALL=\"C\"";
151 print " date +\"%a %b %d %Y\"`)"
159 # There should not be a space after the name of field
160 # and before the colon.
165 if (field ~ /packager:|distribution:|prefix:/)
168 if (field ~ /buildroot:/)
169 $2 = "/tmp/%{name}-%{version}-root";
171 if (field ~ /group:/) {
178 if ($2 ~ /^X11/ && x11 == 0) # Is it X11 application?
181 next; # Line is already formatted and printed
184 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
185 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
191 if (field ~ /version:/)
194 # Use %{name} and %{version} in the filenames in "Source:"
195 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
196 n = split($2, url, /\//);
198 sub(name, "%{name}", url[n]);
199 sub(version, "%{version}", url[n]);
200 sub(filename, url[n], $2);
205 # Do not add %define of _prefix if it already is.
206 if ($1 ~ /%define/ && $2 ~ /_prefix/)
219 print "* %{date} PLD Team <pld-list@pld.org.pl>";
220 printf "All below listed persons can be reached on ";
221 print "<cvs_login>@pld.org.pl\n";
226 # This function uses grep to determine if there is line (in the current file)
227 # which matches regexp.
228 function is_there_line(line, l)
230 command = "grep \"" line "\" " ARGV[1];
240 # This function prints translated names of groups.
241 function translate_group(group)
244 result = getline line < groups_file;
247 print "######\t\t" groups_file ": no such file";
252 print "######\t\t" "Unknown group!";
262 if (line ~ /\[[a-z][a-z]\]:/) {
263 split(line, g, /\[|\]|\:/);
264 if (!is_there_line("^Group(" g[2] "):"))
265 printf("Group(%s):%s\n", g[2], g[4]);
273 # There should be one or two tabs after the colon.
274 function format_preamble()
277 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {