3 # Helper to enforce array-ness.
4 proc makearray
{name
} {
21 # This maps a name to its style:
22 # * bc objects in this package and all its sub-packages
23 # are to be compiled with the BC ABI. It is an error
24 # for sub-packages to also appear in the map.
26 # objects in this package (and possibly sub-packages,
27 # if they do not appear in the map) will be compiled en masse
28 # from source into a single object, using the C++ ABI.
30 # objects in this package (and possibly sub-packages
31 # if they do not appear in the map) will be compiled one at
32 # a time into separate .o files.
34 # objects in this package are not used. Note however that
35 # most ignored files are actually handled by listing them in
38 # If a package does not appear in the map, the default is 'package'.
40 set package_map
(.
) package
42 # These are ignored in Classpath.
43 set package_map
(gnu
/test
) ignore
44 set package_map
(gnu
/javax
/swing
/plaf
/gtk
) ignore
46 set package_map
(gnu
/java
/awt
/peer
/swing
) bc
48 set package_map
(gnu
/xml
) bc
49 set package_map
(javax
/imageio
) bc
50 set package_map
(javax
/xml
) bc
51 set package_map
(gnu
/java
/beans
) bc
52 set package_map
(gnu
/java
/util
/prefs
/gconf
) bc
53 set package_map
(gnu
/java
/awt
/peer
/gtk
) bc
54 set package_map
(gnu
/java
/awt
/dnd
/peer
/gtk
) bc
55 set package_map
(gnu
/java
/awt
/peer
/qt
) bc
56 set package_map
(gnu
/javax
/sound
/midi
) bc
57 set package_map
(org
/xml
) bc
58 set package_map
(org
/w3c
) bc
59 set package_map
(org
/relaxng
) bc
60 set package_map
(javax
/rmi
) bc
61 set package_map
(org
/omg
) bc
62 set package_map
(gnu
/CORBA
) bc
63 set package_map
(gnu
/javax
/rmi
) bc
65 # This is handled specially by the Makefile.
66 # We still want it byte-compiled so it isn't in the .omit file.
67 set package_map
(gnu
/gcj
/tools
/gcj_dbtool
/Main.java
) ignore
69 # These are handled specially. If we list Class.java with other files
70 # in java.lang, we hit a compiler bug.
71 set package_map
(java
/lang
/Class.java
) ignore
72 set package_map
(java
/lang
/Object.java
) ignore
74 # More special cases. These end up in their own library.
75 # Note that if we BC-compile AWT we must update these as well.
76 set package_map
(gnu
/gcj
/xlib
) package
77 set package_map
(gnu
/awt
/xlib
) package
79 # Some BC ABI packages have classes which must not be compiled BC.
80 # This maps such packages to a grep expression for excluding such
83 makearray exclusion_map
84 # set exclusion_map(java/awt) AWTPermission
86 # This maps a package name to a list of corresponding .java file base
87 # names. The package name will either appear as a key in package_map,
88 # or it will be '.' for the default.
92 # This maps a java file base name, like 'java/lang/Object.java', to
93 # the source directory in which it resides. We keep a layer of
94 # indirection here so that we can override sources in Classpath with
99 # An entry in this map means that all .properties files in the
100 # corresponding directory should be ignored.
101 global properties_map
102 makearray properties_map
104 # logging.properties is installed and is editable.
105 set properties_map
(java
/util
/logging
) _
106 # We haven't merged locale resources yet.
107 set properties_map
(gnu
/java
/locale
) _
110 # List of all properties files.
111 set properties_files
{}
113 # List of all '@' files that we are going to compile.
116 # List of all header file variables.
119 # List of all BC object files.
122 # List of regexps for matching ignored files.
123 set ignore_rx_list
{}
126 # Return true if a given file should be ignored.
127 # The argument is the path name including the package part.
128 proc ignore_file_p
{file} {
129 global ignore_rx_list
130 foreach rx
$ignore_rx_list {
131 if {[regexp -- $rx $file]} {
132 verbose
"ignoring $file for $rx"
139 # Read a '.omit' file and update the internal data structures.
140 proc read_omit_file
{name
} {
141 global ignore_rx_list
142 set fd
[open $name r
]
143 while {! [eof $fd]} {
146 # Classpath's entries bogusly start with "../".
147 if {[string match ..
/* $line]} {
148 set line
[string range
$line 3 end
]
152 lappend ignore_rx_list
$line
158 # Classify a single source file.
159 proc classify_source_file
{basedir
file} {
160 global package_map name_map dir_map
162 if {[ignore_file_p
$file]} {
166 set seen
[info exists dir_map
($file)]
167 set dir_map
($file) $basedir
170 if {[info exists package_map
($pkg)]} {
171 # If the entry is 'package', then set up a new entry for the
173 if {$package_map($pkg) == "package"} {
174 set pkg
[file dirname
$file]
175 set package_map
($pkg) package
177 verbose
"classify succeeded: $file -> $pkg"
179 lappend name_map
($pkg) $file
183 set pkg
[file dirname
$pkg]
188 # Scan a directory and its subdirectories for .java source files or
189 # .properties files. Note that we keep basedir and subdir separate so
190 # we can properly update our global data structures.
191 proc scan_directory
{basedir subdir
} {
192 global dir_map properties_map properties_files
198 foreach file [lsort [glob -nocomplain *]] {
199 if {[string match
*.java
$file]} {
200 lappend files
$subdir/$file
201 } elseif
{[string match
*.properties
$file]} {
202 if {! [info exists properties_map
($subdir)]} {
203 # We assume there aren't any overrides.
204 lappend properties_files
$basedir/$subdir/$file
206 } elseif
{[file isdirectory
$file]} {
207 lappend subdirs
$subdir/$file
208 } elseif
{$subdir == "META-INF/services"} {
209 # All service files are included as properties.
210 lappend properties_files
$basedir/$subdir/$file
215 # Recurse first, so that we don't create new packages too eagerly.
216 foreach dir
$subdirs {
217 scan_directory
$basedir $dir
220 foreach file $files {
221 classify_source_file
$basedir $file
225 # Scan known packages beneath the base directory for .java source
227 proc scan_packages
{basedir
} {
228 foreach subdir
{gnu java javax org META-INF
} {
229 if {[file exists
$basedir/$subdir]} {
230 scan_directory
$basedir $subdir
235 # Emit a rule for a 'bc' package.
236 proc emit_bc_rule
{package} {
237 global package_map exclusion_map bc_objects
239 if {$package == "."} {
244 set varname
[join [split $pkgname /] _
]_source_files
245 set loname
[join [split $pkgname /] -].lo
246 set tname
[join [split $pkgname /] -].
list
248 puts "$loname: \$($varname)"
249 # Create a temporary list file and then compile it. This works
250 # around the libtool problem mentioned in PR 21058. classpath was
251 # built first, so the class files are to be found there.
253 if {[info exists exclusion_map
($package)]} {
254 set omit
"| grep -v $exclusion_map($package)"
256 puts "\t@find classpath/lib/$package -name '*.class'${omit} > $tname"
257 puts "\t\$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o $loname @$tname"
258 puts "\t@rm -f $tname"
261 lappend bc_objects
$loname
264 # Emit a rule for a 'package' package.
265 proc emit_package_rule
{package} {
266 global package_map exclusion_map package_files
268 if {$package == "."} {
273 set varname
[join [split $pkgname /] _
]_source_files
278 # A rule to make the phony file we are going to compile.
279 puts "$lname: \$($varname)"
280 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
281 puts "\t@for file in \$($varname); do \\"
282 puts "\t if test -f \$(srcdir)/\$\$file; then \\"
283 puts "\t echo \$(srcdir)/\$\$file; \\"
284 puts "\t else echo \$\$file; fi; \\"
285 puts "\tdone > $lname"
287 puts "-include $dname"
291 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
292 lappend package_files
$lname
296 # Emit a source file variable for a package, and corresponding header
297 # file variable, if needed.
298 proc emit_source_var
{package} {
299 global package_map name_map dir_map header_vars
301 if {$package == "."} {
306 set uname
[join [split $pkgname /] _
]
307 set varname
${uname
}_source_files
308 puts -nonewline "$varname ="
311 foreach base
[lsort $name_map($package)] {
312 # Terminate previous line.
314 # Having files start with './' is ugly and confuses the automake
315 # "dirstamp" code; see automake PR 461.
316 set ndir
$dir_map($base)/
320 puts -nonewline "${ndir}${base}"
321 set dirs
($dir_map($base)) 1
326 if {$package_map($package) != "bc"} {
327 # Ugly code to build up the appropriate patsubst.
328 set result
"\$(patsubst %.java,%.h,\$($varname))"
329 foreach dir
[lsort [array names dirs
]] {
331 set result
"\$(patsubst $dir/%,%,$result)"
335 if {$package == "." ||
$package == "java/lang"} {
337 set result
"\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
340 puts "${uname}_header_files = $result"
342 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
343 lappend header_vars
"${uname}_header_files"
348 # Pretty-print a Makefile variable.
349 proc pp_var
{name valueList
{pre
""} {post
""}} {
351 puts -nonewline "$name ="
352 foreach val
$valueList {
354 puts -nonewline " ${pre}${val}${post}"
360 if {[llength $argv] > 0 && [lindex $argv 0] == "-verbose"} {
364 # Read the proper .omit files.
365 read_omit_file standard.omit.in
366 read_omit_file classpath
/lib
/standard.omit
368 # Scan classpath first.
369 scan_packages classpath
370 scan_packages classpath
/external
/sax
371 scan_packages classpath
/external
/w3c_dom
372 scan_packages classpath
/external
/relaxngDatatype
374 scan_packages classpath
/resource
375 # Now scan our own files; this will correctly override decisions made
376 # when scanning classpath.
378 # Files created by the build.
379 classify_source_file . java
/lang
/ConcreteProcess.java
380 classify_source_file classpath gnu
/java
/locale
/LocaleData.java
381 classify_source_file classpath gnu
/classpath
/Configuration.java
382 classify_source_file classpath gnu
/java
/security
/Configuration.java
384 puts "## This file was automatically generated by scripts/makemake.tcl"
385 puts "## Do not edit!"
388 foreach package [lsort [array names package_map
]] {
389 if {$package_map($package) == "ignore"} {
392 if {! [info exists name_map
($package)]} {
396 emit_source_var
$package
398 if {$package_map($package) == "bc"} {
399 emit_bc_rule
$package
400 } elseif
{$package_map($package) == "ordinary"} {
401 # Nothing in particular to do here.
402 } elseif
{$package_map($package) == "package"} {
403 emit_package_rule
$package
405 error "unrecognized type: $package_map($package)"
409 pp_var all_packages_source_files
$package_files
410 pp_var ordinary_header_files
$header_vars "\$(" ")"
411 pp_var bc_objects
$bc_objects
412 pp_var property_files
$properties_files