3 # Helper to enforce array-ness.
4 proc makearray {name} {
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.
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.
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.
28 # objects in this package are not used. Note however that
29 # most ignored files are actually handled by listing them in
32 # If a package does not appear in the map, the default is 'package'.
34 set package_map(.) package
36 # These are ignored in Classpath.
37 set package_map(gnu/test) ignore
38 set package_map(gnu/javax/swing/plaf/gtk) ignore
40 # This package doesn't really work yet, and seems to trigger bug #26390
41 set package_map(gnu/java/awt/peer/swing) ignore
43 set package_map(gnu/xml) bc
44 set package_map(javax/imageio) bc
45 set package_map(javax/xml) bc
46 set package_map(gnu/java/beans) bc
47 set package_map(gnu/java/awt/peer/gtk) bc
48 set package_map(gnu/java/awt/peer/qt) bc
49 set package_map(gnu/javax/sound/midi) bc
50 set package_map(org/xml) bc
51 set package_map(org/w3c) 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
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
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
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
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
75 makearray exclusion_map
76 # set exclusion_map(java/awt) AWTPermission
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.
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
91 # List of all '@' files that we are going to compile.
94 # List of all header file variables.
97 # List of all BC object files.
100 # List of regexps for matching ignored files.
101 set ignore_rx_list {}
104 # Return true if a given file should be ignored.
105 # The argument is the path name including the package part.
106 proc ignore_file_p {file} {
107 global ignore_rx_list
108 foreach rx $ignore_rx_list {
109 if {[regexp -- $rx $file]} {
110 verbose "ignoring $file for $rx"
117 # Read a '.omit' file and update the internal data structures.
118 proc read_omit_file {name} {
119 global ignore_rx_list
120 set fd [open $name r]
121 while {! [eof $fd]} {
124 # Classpath's entries bogusly start with "../".
125 if {[string match ../* $line]} {
126 set line [string range $line 3 end]
130 lappend ignore_rx_list $line
136 # Classify a single source file.
137 proc classify_source_file {basedir file} {
138 global package_map name_map dir_map
140 if {[ignore_file_p $file]} {
144 set seen [info exists dir_map($file)]
145 set dir_map($file) $basedir
148 if {[info exists package_map($pkg)]} {
149 # If the entry for '.' is 'package', then set up a new entry for
150 # the file's package.
151 if {$pkg == "." && $package_map($pkg) == "package"} {
152 set pkg [file dirname $file]
153 set package_map($pkg) package
155 verbose "classify succeeded: $file -> $pkg"
157 lappend name_map($pkg) $file
161 set pkg [file dirname $pkg]
166 # Scan a directory and its subdirectories for .java source files.
167 # Note that we keep basedir and subdir separate so we can properly
168 # update our global data structures.
169 proc scan_directory {basedir subdir} {
176 foreach file [lsort [glob -nocomplain *]] {
177 if {[string match *.java $file]} {
178 lappend files $subdir/$file
179 } elseif {[file isdirectory $file]} {
180 lappend subdirs $subdir/$file
185 # Recurse first, so that we don't create new packages too eagerly.
186 foreach dir $subdirs {
187 scan_directory $basedir $dir
190 foreach file $files {
191 classify_source_file $basedir $file
195 # Scan known packages beneath the base directory for .java source
197 proc scan_packages {basedir} {
198 foreach subdir {gnu java javax org} {
199 if {[file exists $basedir/$subdir]} {
200 scan_directory $basedir $subdir
205 # Emit a rule for a 'bc' package.
206 proc emit_bc_rule {package} {
207 global package_map exclusion_map bc_objects
209 if {$package == "."} {
214 set varname [join [split $pkgname /] _]_source_files
215 set loname [join [split $pkgname /] -].lo
216 set tname [join [split $pkgname /] -].list
218 puts "$loname: \$($varname)"
219 # Create a temporary list file and then compile it. This works
220 # around the libtool problem mentioned in PR 21058. classpath was
221 # built first, so the class files are to be found there.
223 if {[info exists exclusion_map($package)]} {
224 set omit "| grep -v $exclusion_map($package)"
226 puts "\t@find classpath/lib/$package -name '*.class'${omit} > $tname"
227 puts "\t\$(LTGCJCOMPILE) -fjni -findirect-dispatch -c -o $loname @$tname"
228 puts "\t@rm -f $tname"
231 # We skip these because they are built into their own libraries and
232 # are handled specially in Makefile.am.
233 if {$loname != "gnu-java-awt-peer-gtk.lo"
234 && $loname != "gnu-java-awt-peer-qt.lo"} {
235 lappend bc_objects $loname
239 # Emit a rule for a 'package' package.
240 proc emit_package_rule {package} {
241 global package_map exclusion_map package_files
243 if {$package == "."} {
248 set varname [join [split $pkgname /] _]_source_files
253 # A rule to make the phony file we are going to compile.
254 puts "$lname: \$($varname)"
255 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
256 puts "\t@for file in \$($varname); do \\"
257 puts "\t if test -f \$(srcdir)/\$\$file; then \\"
258 puts "\t echo \$(srcdir)/\$\$file; \\"
259 puts "\t else echo \$\$file; fi; \\"
260 puts "\tdone > $lname"
262 puts "-include $dname"
266 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
267 lappend package_files $lname
271 # Emit a source file variable for a package, and corresponding header
272 # file variable, if needed.
273 proc emit_source_var {package} {
274 global package_map name_map dir_map header_vars
276 if {$package == "."} {
281 set uname [join [split $pkgname /] _]
282 set varname ${uname}_source_files
283 puts -nonewline "$varname ="
286 foreach base [lsort $name_map($package)] {
287 # Terminate previous line.
289 # Having files start with './' is ugly and confuses the automake
290 # "dirstamp" code; see automake PR 461.
291 set ndir $dir_map($base)/
295 puts -nonewline "${ndir}${base}"
296 set dirs($dir_map($base)) 1
301 if {$package_map($package) != "bc"} {
302 # Ugly code to build up the appropriate patsubst.
303 set result "\$(patsubst %.java,%.h,\$($varname))"
304 foreach dir [lsort [array names dirs]] {
306 set result "\$(patsubst $dir/%,%,$result)"
310 if {$package == "." || $package == "java/lang"} {
312 set result "\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
315 puts "${uname}_header_files = $result"
317 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
318 lappend header_vars "${uname}_header_files"
323 # Pretty-print a Makefile variable.
324 proc pp_var {name valueList {pre ""} {post ""}} {
326 puts -nonewline "$name ="
327 foreach val $valueList {
329 puts -nonewline " ${pre}${val}${post}"
334 # Read the proper .omit files.
335 read_omit_file standard.omit.in
336 read_omit_file classpath/lib/standard.omit
338 # Scan classpath first.
339 scan_packages classpath
340 scan_packages classpath/external/sax
341 scan_packages classpath/external/w3c_dom
342 # Now scan our own files; this will correctly override decisions made
343 # when scanning classpath.
345 # Files created by the build.
346 classify_source_file . java/lang/ConcreteProcess.java
347 classify_source_file classpath java/util/LocaleData.java
348 classify_source_file classpath gnu/classpath/Configuration.java
350 puts "## This file was automatically generated by scripts/makemake.tcl"
351 puts "## Do not edit!"
354 foreach package [lsort [array names package_map]] {
355 if {$package_map($package) == "ignore"} {
358 if {! [info exists name_map($package)]} {
362 emit_source_var $package
364 if {$package_map($package) == "bc"} {
365 emit_bc_rule $package
366 } elseif {$package_map($package) == "ordinary"} {
367 # Nothing in particular to do here.
368 } elseif {$package_map($package) == "package"} {
369 emit_package_rule $package
371 error "unrecognized type: $package_map($package)"
375 pp_var all_packages_source_files $package_files
376 pp_var ordinary_header_files $header_vars "\$(" ")"
377 pp_var bc_objects $bc_objects