3 # This is adapter v1.0. 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"))
17 "rpm --eval %_prefix" | getline prefix
18 "rpm --eval %_bindir" | getline bindir
19 "rpm --eval %_sbindir" | getline sbindir
20 "rpm --eval %_libdir" | getline libdir
21 "rpm --eval %_sysconfdir" | getline sysconfdir
22 "rpm --eval %_datadir" | getline datadir
23 "rpm --eval %_includedir" | getline includedir
24 "rpm --eval %_mandir" | getline mandir
25 "rpm --eval %_infodir" | getline infodir
28 # There should be a comment with CVS keywords on the first line of file.
30 if (!/# \$Revision:/) # If this line is already OK?
31 print "# $" "Revision:$, " "$" "Date:$"; # No
34 next; # It is enough for first line
38 # If the latest line matched /%files/
40 if ($0 !~ /defattr/) # If no %defattr
41 print "%defattr(644,root,root,755)"; # Add it
43 $0 = "%defattr(644,root,root,755)"; # Correct mistakes (if any)
48 /%description/, (/^%[a-z]+/ && !/%description/) {
54 # Define _prefix and _mandir if it is X11 application
55 if (/^%description$/ && x11 == 1) {
56 print "%define\t\t_prefix\t\t/usr/X11R6";
57 print "%define\t\t_mandir\t\t%{_prefix}/man\n";
58 prefix = "/usr/X11R6";
62 # Collect whole text of description
63 if (description == 1 && !/^%[a-z]+/ && !/%description/) {
64 description_text = description_text $0 " ";
68 # Formt description to the length of tw (default == 77)
69 if (/^%[a-z]+/ && (!/%description/ || bod == 2)) {
70 n = split(description_text, dt, / /);
71 for (i = 1; i <= n; i++) {
72 if (length(line) + length(dt[i]) + 1 < tw)
73 line = line dt[i] " ";
75 sub(/[ ]+$/, "", line);
82 sub(/[ ]+$/, "", line);
86 description_text = "";
99 /%prep/, (/^%[a-z]+$/ && !/%prep/) {
103 if (/%setup/ && !/-q/)
104 sub(/%setup/, "%setup -q");
108 /%build/, (/^%[a-z]+$/ && !/%build/) {
115 /%install/, (/^[a-z]+$/ && !/%install/) {
120 # 'install -d' instead 'mkdir -p'
122 sub(/mkdir -p/, "install -d");
124 # No '-u root' or '-g root' for 'install'
125 if (/^install/ && /-[ug][ \t]*root/)
126 gsub(/-[ug][ \t]*root /, "");
128 if (/^install/ && /-m[ \t]*644/)
129 gsub(/-m[ \t]*644 /, "");
131 # No lines contain 'chown' or 'chgrp', which changes
132 # owner/group to 'root'
133 if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
136 # No lines contain 'chmod' if it sets the modes to '644'
137 if ($1 ~ /chmod/ && $2 ~ /644/)
140 # 'gzip -9nf' for compressing
141 if ($1 ~ /gzip|bzip2/) {
143 sub(/-[A-Za-z0-9]+ /, "", $0);
144 sub($1, "gzip -9nf");
149 /%files/, (/^%[a-z \-]+$/ && !/%files/) {
158 # %changelog section:
159 /%changelog/, (/^%[a-z]+$/ && !/%changelog/) {
162 # There should be some CVS keywords on the first line of %changelog.
165 print "* %{date} PLD Team <pld-list@pld.org.pl>";
166 printf "All below listed persons can be reached on ";
167 print "<cvs_login>@pld.org.pl\n";
176 printf "%%define date\t%%(echo `LC_ALL=\"C\"";
177 print " date +\"%a %b %d %Y\"`)"
185 # There should not be a space after the name of field
186 # and before the colon.
191 if (field ~ /packager:|distribution:|prefix:/)
194 if (field ~ /buildroot:/)
195 $2 = "/tmp/%{name}-%{version}-root";
197 if (field ~ /group:/) {
204 if ($2 ~ /^X11/ && x11 == 0) # Is it X11 application?
207 next; # Line is already formatted and printed
210 # Use "License" instead of "Copyright" if it is (L)GPL or BSD
211 if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
217 if (field ~ /version:/)
220 # Use %{name} and %{version} in the filenames in "Source:"
221 if (field ~ /source/ && $2 ~ /^ftp:|^http:/) {
222 n = split($2, url, /\//);
224 sub(name, "%{name}", url[n]);
225 sub(version, "%{version}", url[n]);
226 sub(filename, url[n], $2);
231 if ($1 ~ /%define/) {
232 # Do not add %define of _prefix if it already is.
233 if ($2 ~ /_prefix/) {
237 if ($2 ~ /_bindir/ && !/_sbindir/)
243 if ($2 ~ /_sysconfdir/)
247 if ($2 ~ /_includedir/)
264 print "* %{date} PLD Team <pld-list@pld.org.pl>";
265 printf "All below listed persons can be reached on ";
266 print "<cvs_login>@pld.org.pl\n";
271 # This function uses grep to determine if there is line (in the current file)
272 # which matches regexp.
273 function is_there_line(line, l)
275 command = "grep \"" line "\" " ARGV[1];
285 # This function prints translated names of groups.
286 function translate_group(group)
289 result = getline line < groups_file;
292 print "######\t\t" groups_file ": no such file";
297 print "######\t\t" "Unknown group!";
307 if (line ~ /\[[a-z][a-z]\]:/) {
308 split(line, g, /\[|\]|\:/);
309 if (!is_there_line("^Group(" g[2] "):"))
310 printf("Group(%s):%s\n", g[2], g[4]);
318 # There should be one or two tabs after the colon.
319 function format_preamble()
322 if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
330 # Replace directly specified directories with macros
331 function use_macros()
333 gsub(bindir, "%{_bindir}");
334 gsub(sbindir, "%{_sbindir}");
335 gsub(libdir, "%{_libdir}");
336 gsub(sysconfdir, "%{_sysconfdir}");
337 gsub(datadir, "%{_datadir}");
338 gsub(includedir, "%{_includedir}");
339 gsub(mandir, "%{_mandir}");
340 gsub(infodir, "%{_infodir}");
341 gsub(prefix, "%{_prefix}");