source.am, [...]: Rebuilt.
[gcc.git] / libjava / scripts / makemake.tcl
1 #!/usr/bin/tclsh
2
3 # Helper to enforce array-ness.
4 proc makearray {name} {
5 upvar $name ary
6 set ary(_) 1
7 unset ary(_)
8 }
9
10 # Verbose printer.
11 proc verbose {text} {
12 # puts stderr $text
13 }
14
15 # This maps a name to its style:
16 # * bc objects in this package and all its sub-packages
17 # are to be compiled with the BC ABI. It is an error
18 # for sub-packages to also appear in the map.
19 # * package
20 # objects in this package (and possibly sub-packages,
21 # if they do not appear in the map) will be compiled en masse
22 # from source into a single object, using the C++ ABI.
23 # * ordinary
24 # objects in this package (and possibly sub-packages
25 # if they do not appear in the map) will be compiled one at
26 # a time into separate .o files.
27 # * ignore
28 # objects in this package are not used. Note however that
29 # most ignored files are actually handled by listing them in
30 # 'standard.omit'
31 #
32 # If a package does not appear in the map, the default is 'package'.
33 global package_map
34 set package_map(.) package
35
36 # These are ignored in Classpath.
37 set package_map(gnu/test) ignore
38 set package_map(gnu/javax/swing/plaf/gtk) ignore
39
40 set package_map(gnu/java/awt/peer/swing) bc
41
42 set package_map(gnu/xml) bc
43 set package_map(javax/imageio) bc
44 set package_map(javax/xml) bc
45 set package_map(gnu/java/beans) bc
46 set package_map(gnu/java/awt/peer/gtk) bc
47 set package_map(gnu/java/awt/peer/qt) bc
48 set package_map(gnu/javax/sound/midi) bc
49 set package_map(org/xml) bc
50 set package_map(org/w3c) bc
51 set package_map(org/relaxng) bc
52 set package_map(javax/rmi) bc
53 set package_map(org/omg) bc
54 set package_map(gnu/CORBA) bc
55 set package_map(gnu/javax/rmi) bc
56
57 # This is handled specially by the Makefile.
58 # We still want it byte-compiled so it isn't in the .omit file.
59 set package_map(gnu/gcj/tools/gcj_dbtool/Main.java) ignore
60
61 # These are handled specially. If we list Class.java with other files
62 # in java.lang, we hit a compiler bug.
63 set package_map(java/lang/Class.java) ignore
64 set package_map(java/lang/Object.java) ignore
65
66 # More special cases. These end up in their own library.
67 # Note that if we BC-compile AWT we must update these as well.
68 set package_map(gnu/gcj/xlib) package
69 set package_map(gnu/awt/xlib) package
70
71 # Some BC ABI packages have classes which must not be compiled BC.
72 # This maps such packages to a grep expression for excluding such
73 # classes.
74 global exclusion_map
75 makearray exclusion_map
76 # set exclusion_map(java/awt) AWTPermission
77
78 # This maps a package name to a list of corresponding .java file base
79 # names. The package name will either appear as a key in package_map,
80 # or it will be '.' for the default.
81 global name_map
82 makearray name_map
83
84 # This maps a java file base name, like 'java/lang/Object.java', to
85 # the source directory in which it resides. We keep a layer of
86 # indirection here so that we can override sources in Classpath with
87 # our own sources.
88 global dir_map
89 makearray dir_map
90
91 # An entry in this map means that all .properties files in the
92 # corresponding directory should be ignored.
93 global properties_map
94 makearray properties_map
95
96 # logging.properties is installed and is editable.
97 set properties_map(java/util/logging) _
98 # We haven't merged locale resources yet.
99 set properties_map(gnu/java/locale) _
100
101
102 # List of all properties files.
103 set properties_files {}
104
105 # List of all '@' files that we are going to compile.
106 set package_files {}
107
108 # List of all header file variables.
109 set header_vars {}
110
111 # List of all BC object files.
112 set bc_objects {}
113
114 # List of regexps for matching ignored files.
115 set ignore_rx_list {}
116
117
118 # Return true if a given file should be ignored.
119 # The argument is the path name including the package part.
120 proc ignore_file_p {file} {
121 global ignore_rx_list
122 foreach rx $ignore_rx_list {
123 if {[regexp -- $rx $file]} {
124 verbose "ignoring $file for $rx"
125 return 1
126 }
127 }
128 return 0
129 }
130
131 # Read a '.omit' file and update the internal data structures.
132 proc read_omit_file {name} {
133 global ignore_rx_list
134 set fd [open $name r]
135 while {! [eof $fd]} {
136 set line [gets $fd]
137
138 # Classpath's entries bogusly start with "../".
139 if {[string match ../* $line]} {
140 set line [string range $line 3 end]
141 }
142
143 if {$line != ""} {
144 lappend ignore_rx_list $line
145 }
146 }
147 close $fd
148 }
149
150 # Classify a single source file.
151 proc classify_source_file {basedir file} {
152 global package_map name_map dir_map
153
154 if {[ignore_file_p $file]} {
155 return
156 }
157
158 set seen [info exists dir_map($file)]
159 set dir_map($file) $basedir
160 set pkg $file
161 while {1} {
162 if {[info exists package_map($pkg)]} {
163 # If the entry for '.' is 'package', then set up a new entry for
164 # the file's package.
165 if {$pkg == "." && $package_map($pkg) == "package"} {
166 set pkg [file dirname $file]
167 set package_map($pkg) package
168 }
169 verbose "classify succeeded: $file -> $pkg"
170 if {! $seen} {
171 lappend name_map($pkg) $file
172 }
173 return
174 }
175 set pkg [file dirname $pkg]
176 }
177 error "can't happen"
178 }
179
180 # Scan a directory and its subdirectories for .java source files or
181 # .properties files. Note that we keep basedir and subdir separate so
182 # we can properly update our global data structures.
183 proc scan_directory {basedir subdir} {
184 global dir_map properties_map properties_files
185
186 set subdirs {}
187 set files {}
188 set here [pwd]
189 cd $basedir/$subdir
190 foreach file [lsort [glob -nocomplain *]] {
191 if {[string match *.java $file]} {
192 lappend files $subdir/$file
193 } elseif {[string match *.properties $file]} {
194 if {! [info exists properties_map($subdir)]} {
195 # We assume there aren't any overrides.
196 lappend properties_files $basedir/$subdir/$file
197 }
198 } elseif {[file isdirectory $file]} {
199 lappend subdirs $subdir/$file
200 } elseif {$subdir == "META-INF/services"} {
201 # All service files are included as properties.
202 lappend properties_files $basedir/$subdir/$file
203 }
204 }
205 cd $here
206
207 # Recurse first, so that we don't create new packages too eagerly.
208 foreach dir $subdirs {
209 scan_directory $basedir $dir
210 }
211
212 foreach file $files {
213 classify_source_file $basedir $file
214 }
215 }
216
217 # Scan known packages beneath the base directory for .java source
218 # files.
219 proc scan_packages {basedir} {
220 foreach subdir {gnu java javax org META-INF} {
221 if {[file exists $basedir/$subdir]} {
222 scan_directory $basedir $subdir
223 }
224 }
225 }
226
227 # Emit a rule for a 'bc' package.
228 proc emit_bc_rule {package} {
229 global package_map exclusion_map bc_objects
230
231 if {$package == "."} {
232 set pkgname ordinary
233 } else {
234 set pkgname $package
235 }
236 set varname [join [split $pkgname /] _]_source_files
237 set loname [join [split $pkgname /] -].lo
238 set tname [join [split $pkgname /] -].list
239
240 puts "$loname: \$($varname)"
241 # Create a temporary list file and then compile it. This works
242 # around the libtool problem mentioned in PR 21058. classpath was
243 # built first, so the class files are to be found there.
244 set omit ""
245 if {[info exists exclusion_map($package)]} {
246 set omit "| grep -v $exclusion_map($package)"
247 }
248 puts "\t@find classpath/lib/$package -name '*.class'${omit} > $tname"
249 puts "\t\$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o $loname @$tname"
250 puts "\t@rm -f $tname"
251 puts ""
252
253 # We skip these because they are built into their own libraries and
254 # are handled specially in Makefile.am.
255 if {$loname != "gnu-java-awt-peer-gtk.lo"
256 && $loname != "gnu-java-awt-peer-qt.lo"} {
257 lappend bc_objects $loname
258 }
259 }
260
261 # Emit a rule for a 'package' package.
262 proc emit_package_rule {package} {
263 global package_map exclusion_map package_files
264
265 if {$package == "."} {
266 set pkgname ordinary
267 } else {
268 set pkgname $package
269 }
270 set varname [join [split $pkgname /] _]_source_files
271 set base $pkgname
272 set lname $base.list
273 set dname $base.deps
274
275 # A rule to make the phony file we are going to compile.
276 puts "$lname: \$($varname)"
277 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
278 puts "\t@for file in \$($varname); do \\"
279 puts "\t if test -f \$(srcdir)/\$\$file; then \\"
280 puts "\t echo \$(srcdir)/\$\$file; \\"
281 puts "\t else echo \$\$file; fi; \\"
282 puts "\tdone > $lname"
283 puts ""
284 puts "-include $dname"
285 puts ""
286 puts ""
287
288 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
289 lappend package_files $lname
290 }
291 }
292
293 # Emit a source file variable for a package, and corresponding header
294 # file variable, if needed.
295 proc emit_source_var {package} {
296 global package_map name_map dir_map header_vars
297
298 if {$package == "."} {
299 set pkgname ordinary
300 } else {
301 set pkgname $package
302 }
303 set uname [join [split $pkgname /] _]
304 set varname ${uname}_source_files
305 puts -nonewline "$varname ="
306
307 makearray dirs
308 foreach base [lsort $name_map($package)] {
309 # Terminate previous line.
310 puts " \\"
311 # Having files start with './' is ugly and confuses the automake
312 # "dirstamp" code; see automake PR 461.
313 set ndir $dir_map($base)/
314 if {$ndir == "./"} {
315 set ndir ""
316 }
317 puts -nonewline "${ndir}${base}"
318 set dirs($dir_map($base)) 1
319 }
320 puts ""
321 puts ""
322
323 if {$package_map($package) != "bc"} {
324 # Ugly code to build up the appropriate patsubst.
325 set result "\$(patsubst %.java,%.h,\$($varname))"
326 foreach dir [lsort [array names dirs]] {
327 if {$dir != "."} {
328 set result "\$(patsubst $dir/%,%,$result)"
329 }
330 }
331
332 if {$package == "." || $package == "java/lang"} {
333 # Ugly hack.
334 set result "\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
335 }
336
337 puts "${uname}_header_files = $result"
338 puts ""
339 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
340 lappend header_vars "${uname}_header_files"
341 }
342 }
343 }
344
345 # Pretty-print a Makefile variable.
346 proc pp_var {name valueList {pre ""} {post ""}} {
347 puts ""
348 puts -nonewline "$name ="
349 foreach val $valueList {
350 puts " \\"
351 puts -nonewline " ${pre}${val}${post}"
352 }
353 puts ""
354 }
355
356 # Read the proper .omit files.
357 read_omit_file standard.omit.in
358 read_omit_file classpath/lib/standard.omit
359
360 # Scan classpath first.
361 scan_packages classpath
362 scan_packages classpath/external/sax
363 scan_packages classpath/external/w3c_dom
364 scan_packages classpath/external/relaxngDatatype
365 # Resource files.
366 scan_packages classpath/resource
367 # Now scan our own files; this will correctly override decisions made
368 # when scanning classpath.
369 scan_packages .
370 # Files created by the build.
371 classify_source_file . java/lang/ConcreteProcess.java
372 classify_source_file classpath gnu/java/locale/LocaleData.java
373 classify_source_file classpath gnu/classpath/Configuration.java
374
375 puts "## This file was automatically generated by scripts/makemake.tcl"
376 puts "## Do not edit!"
377 puts ""
378
379 foreach package [lsort [array names package_map]] {
380 if {$package_map($package) == "ignore"} {
381 continue
382 }
383 if {! [info exists name_map($package)]} {
384 continue
385 }
386
387 emit_source_var $package
388
389 if {$package_map($package) == "bc"} {
390 emit_bc_rule $package
391 } elseif {$package_map($package) == "ordinary"} {
392 # Nothing in particular to do here.
393 } elseif {$package_map($package) == "package"} {
394 emit_package_rule $package
395 } else {
396 error "unrecognized type: $package_map($package)"
397 }
398 }
399
400 pp_var all_packages_source_files $package_files
401 pp_var ordinary_header_files $header_vars "\$(" ")"
402 pp_var bc_objects $bc_objects
403 pp_var property_files $properties_files