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 # as bc, but generate header files and compile with CNI.
28 # objects in this package (and possibly sub-packages,
29 # if they do not appear in the map) will be compiled en masse
30 # from source into a single object, using the C++ ABI.
32 # objects in this package (and possibly sub-packages
33 # if they do not appear in the map) will be compiled one at
34 # a time into separate .o files.
36 # objects in this package are not used. Note however that
37 # most ignored files are actually handled by listing them in
40 # If a package does not appear in the map, the default is 'package'.
42 set package_map(.) package
44 # These are ignored in Classpath.
45 set package_map(gnu/test) ignore
46 set package_map(gnu/javax/swing/plaf/gtk) ignore
47 set package_map(gnu/gcj/tools/gc_analyze) ignore
49 set package_map(gnu/java/awt/peer/swing) bc
51 set package_map(gnu/xml/aelfred2) bc
52 set package_map(gnu/xml/dom) bc
53 set package_map(gnu/xml/libxmlj) bc
54 set package_map(gnu/xml/pipeline) bc
55 set package_map(gnu/xml/stream) bc
56 set package_map(gnu/xml/transform) bc
57 set package_map(gnu/xml/util) bc
58 set package_map(gnu/xml/validation) bc
59 set package_map(gnu/xml/xpath) bc
60 set package_map(javax/imageio) bc
61 set package_map(javax/xml) bc
62 set package_map(gnu/java/beans) bc
63 set package_map(gnu/java/awt/dnd/peer/gtk) bc
64 set package_map(gnu/java/util/prefs/gconf) bc
65 set package_map(gnu/java/awt/peer/gtk) bc
66 set package_map(gnu/java/awt/dnd/peer/gtk) bc
67 set package_map(gnu/java/awt/peer/qt) bc
68 set package_map(gnu/java/awt/peer/x) bc
69 set package_map(gnu/java/util/prefs/gconf) bc
70 set package_map(gnu/javax/sound/midi) bc
71 set package_map(org/xml) bc
72 set package_map(org/w3c) bc
73 set package_map(org/relaxng) bc
74 set package_map(javax/rmi) bc
75 set package_map(org/omg) bc
76 set package_map(gnu/CORBA) bc
77 set package_map(gnu/javax/rmi) bc
78 set package_map(gnu/java/lang/management) bcheaders
79 set package_map(java/lang/management) bc
80 set package_map(gnu/classpath/management) bc
81 set package_map(gnu/javax/management) bc
83 # parser/HTML_401F.class is really big, and there have been complaints
84 # about this package requiring too much memory to build. So, we
85 # compile it as separate objects. But, we're careful to compile the
86 # sub-packages as packages.
87 set package_map(gnu/javax/swing/text/html/parser) ordinary
88 set package_map(gnu/javax/swing/text/html/parser/models) package
89 set package_map(gnu/javax/swing/text/html/parser/support) package
91 # More special cases. These end up in their own library.
92 # Note that if we BC-compile AWT we must update these as well.
93 set package_map(gnu/gcj/xlib) package
94 set package_map(gnu/awt/xlib) package
96 # Some BC ABI packages have classes which must not be compiled BC.
97 # This maps such packages to a grep expression for excluding such
100 makearray exclusion_map
101 # set exclusion_map(java/awt) AWTPermission
103 # This maps a package name to a list of corresponding .java file base
104 # names. The package name will either appear as a key in package_map,
105 # or it will be '.' for the default.
109 # This maps a java file base name, like 'java/lang/Object.java', to
110 # the source directory in which it resides. We keep a layer of
111 # indirection here so that we can override sources in Classpath with
116 # An entry in this map means that all .properties files in the
117 # corresponding directory should be ignored.
118 global properties_map
119 makearray properties_map
121 # logging.properties is installed and is editable.
122 set properties_map(java/util/logging) _
123 # We haven't merged locale resources yet.
124 set properties_map(gnu/java/locale) _
126 # We want to be able to load xerces if it is on the class path. So,
127 # we have to avoid compiling in the XML-related service files.
128 set properties_map(META-INF/services/javax.xml.parsers.DocumentBuilderFactory) _
129 set properties_map(META-INF/services/javax.xml.parsers.SAXParserFactory) _
130 set properties_map(META-INF/services/javax.xml.parsers.TransformerFactory) _
131 set properties_map(META-INF/services/org.relaxng.datatype.DatatypeLibraryFactory) _
132 set properties_map(META-INF/services/org.w3c.dom.DOMImplementationSourceList) _
133 set properties_map(META-INF/services/org.xml.sax.driver) _
135 # List of all properties files.
136 set properties_files {}
138 # List of all '@' files that we are going to compile.
141 # List of all header file variables.
144 # List of all BC object files.
147 # List of regexps for matching ignored files.
148 set ignore_rx_list {}
151 # Return true if a given file should be ignored.
152 # The argument is the path name including the package part.
153 proc ignore_file_p {file} {
154 global ignore_rx_list
155 foreach rx $ignore_rx_list {
156 if {[regexp -- $rx $file]} {
157 verbose "ignoring $file for $rx"
164 # Read a '.omit' file and update the internal data structures.
165 proc read_omit_file {name} {
166 global ignore_rx_list
167 set fd [open $name r]
168 while {! [eof $fd]} {
171 # Classpath's entries bogusly start with "../".
172 if {[string match ../* $line]} {
173 set line [string range $line 3 end]
177 lappend ignore_rx_list $line
183 # Classify a single source file.
184 proc classify_source_file {basedir file} {
185 global package_map name_map dir_map
187 if {[ignore_file_p $file]} {
191 set seen [info exists dir_map($file)]
192 set dir_map($file) $basedir
195 if {[info exists package_map($pkg)]} {
196 # If the entry is 'package', then set up a new entry for the
198 if {$package_map($pkg) == "package"} {
199 set pkg [file dirname $file]
200 set package_map($pkg) package
202 verbose "classify succeeded: $file -> $pkg"
204 lappend name_map($pkg) $file
208 set pkg [file dirname $pkg]
213 # Scan a directory and its subdirectories for .java source files or
214 # .properties files. Note that we keep basedir and subdir separate so
215 # we can properly update our global data structures.
216 proc scan_directory {basedir subdir} {
217 global dir_map properties_map properties_files
223 foreach file [lsort [glob -nocomplain *]] {
224 if {[string match *.java $file]} {
225 lappend files $subdir/$file
226 } elseif {[string match *.properties $file]} {
227 if {! [info exists properties_map($subdir)]} {
228 # We assume there aren't any overrides.
229 lappend properties_files $basedir/$subdir/$file
231 } elseif {[file isdirectory $file]} {
232 lappend subdirs $subdir/$file
233 } elseif {$subdir == "META-INF/services"} {
234 # Service files are generally included as properties.
235 if {! [info exists properties_map($subdir/$file)]} {
236 lappend properties_files $basedir/$subdir/$file
242 # Recurse first, so that we don't create new packages too eagerly.
243 foreach dir $subdirs {
244 scan_directory $basedir $dir
247 foreach file $files {
248 classify_source_file $basedir $file
252 # Scan known packages beneath the base directory for .java source
254 proc scan_packages {basedir} {
255 foreach subdir {gnu java javax org sun META-INF} {
256 if {[file exists $basedir/$subdir]} {
257 scan_directory $basedir $subdir
262 # Emit a rule for a 'bc' package.
263 proc emit_bc_rule {package} {
264 global package_map exclusion_map bc_objects
266 if {$package == "."} {
271 set varname [join [split $pkgname /] _]_source_files
272 set loname [join [split $pkgname /] -].lo
273 set tname [join [split $pkgname /] -].list
275 puts "$loname: \$($varname)"
276 # Create a temporary list file and then compile it. This works
277 # around the libtool problem mentioned in PR 21058. classpath was
278 # built first, so the class files are to be found there.
280 if {[info exists exclusion_map($package)]} {
281 set omit "| grep -v $exclusion_map($package)"
283 puts "\t@find \$(srcdir)/classpath/lib/$package -name '*.class'${omit} > $tname"
284 puts -nonewline "\t\$(LTGCJCOMPILE) -fsource-filename=\$(here)/classpath/lib/classes "
285 if {$package_map($package) == "bc"} {
286 puts -nonewline "-fjni "
288 puts "-findirect-dispatch -fno-indirect-classes -c -o $loname @$tname"
289 puts "\t@rm -f $tname"
292 # We skip these because they are built into their own libraries and
293 # are handled specially in Makefile.am.
294 if {$loname != "gnu-java-awt-peer-qt.lo" && $loname != "gnu-java-awt-peer-x.lo"} {
295 lappend bc_objects $loname
299 # Emit a rule for a 'package' package.
300 proc emit_package_rule {package} {
301 global package_map exclusion_map package_files
303 if {$package == "."} {
308 set varname [join [split $pkgname /] _]_source_files
313 if {$pkgname == "java/lang"} {
314 # Object and Class are special cases due to an apparent compiler
315 # bug. Process is a special case because we don't build all
316 # concrete implementations of Process on all platforms.
317 set omit "| tr ' ' '\\n' | fgrep -v Object.class | fgrep -v Class.class | egrep -v '\(Ecos\|Posix\|Win32\)Process' "
322 # A rule to make the phony file we are going to compile.
323 puts "$lname: \$($varname)"
324 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
325 puts "\techo \$(srcdir)/classpath/lib/$package/*.class $omit> $lname"
327 puts "-include $dname"
331 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"
332 && $pkgname != "gnu/gcj/tools/gcj_dbtool"} {
333 lappend package_files $lname
337 # Emit a rule to build a package full of 'ordinary' files, that is,
338 # one .o for each .java.
339 proc emit_ordinary_rule {package} {
340 global name_map package_files
342 foreach file $name_map($package) {
343 # Strip off the '.java'.
344 set root [file rootname $file]
346 # Look for all included .class files. Assumes that we don't have
347 # multiple top-level classes in a .java file.
351 puts "$lname: classpath/$file"
352 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
353 puts "\techo \$(srcdir)/classpath/lib/${root}*.class> $lname"
355 puts "-include $dname"
359 lappend package_files $lname
363 # Emit a package-like rule for a platform-specific Process
365 proc emit_process_package_rule {platform} {
366 set base "java/process-$platform"
370 puts "$lname: java/lang/${platform}Process.java"
371 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
372 puts "\techo \$(srcdir)/classpath/lib/java/lang/${platform}Process*.class > $lname"
374 puts "-include $dname"
379 # Emit a source file variable for a package, and corresponding header
380 # file variable, if needed.
381 proc emit_source_var {package} {
382 global package_map name_map dir_map header_vars
384 if {$package == "."} {
389 set uname [join [split $pkgname /] _]
390 set varname ${uname}_source_files
391 puts -nonewline "$varname ="
394 foreach base [lsort $name_map($package)] {
395 # Terminate previous line.
397 # Having files start with './' is ugly and confuses the automake
398 # "dirstamp" code; see automake PR 461.
399 set ndir $dir_map($base)/
403 puts -nonewline "${ndir}${base}"
404 set dirs($dir_map($base)) 1
409 if {$package_map($package) != "bc"} {
410 # Ugly code to build up the appropriate patsubst.
411 set result "\$(patsubst %.java,%.h,\$($varname))"
412 # We use -decreasing so that classpath/external will be stripped
414 foreach dir [lsort -decreasing [array names dirs]] {
416 set result "\$(patsubst $dir/%,%,$result)"
420 if {$package == "." || $package == "java/lang"} {
422 set result "\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
425 puts "${uname}_header_files = $result"
427 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
428 lappend header_vars "${uname}_header_files"
433 # Pretty-print a Makefile variable.
434 proc pp_var {name valueList {pre ""} {post ""}} {
436 puts -nonewline "$name ="
437 foreach val $valueList {
439 puts -nonewline " ${pre}${val}${post}"
445 if {[llength $argv] > 0 && [lindex $argv 0] == "-verbose"} {
449 # Read the proper .omit files.
450 read_omit_file standard.omit.in
451 read_omit_file classpath/lib/standard.omit.in
453 # Scan classpath first.
454 scan_packages classpath
455 scan_packages classpath/external/sax
456 scan_packages classpath/external/w3c_dom
457 scan_packages classpath/external/relaxngDatatype
458 scan_packages classpath/external/jsr166
460 scan_packages classpath/resource
461 # Now scan our own files; this will correctly override decisions made
462 # when scanning classpath.
464 # Files created by the build.
465 classify_source_file classpath gnu/java/locale/LocaleData.java
466 classify_source_file classpath gnu/java/security/Configuration.java
468 puts "## This file was automatically generated by scripts/makemake.tcl"
469 puts "## Do not edit!"
472 foreach package [lsort [array names package_map]] {
473 if {$package_map($package) == "ignore"} {
476 if {! [info exists name_map($package)]} {
480 emit_source_var $package
482 if {$package_map($package) == "bc"} {
483 emit_bc_rule $package
484 } elseif {$package_map($package) == "bcheaders"} {
485 emit_bc_rule $package
486 } elseif {$package_map($package) == "ordinary"} {
487 emit_ordinary_rule $package
488 } elseif {$package_map($package) == "package"} {
489 emit_package_rule $package
491 error "unrecognized type: $package_map($package)"
495 emit_process_package_rule Ecos
496 emit_process_package_rule Win32
497 emit_process_package_rule Posix
499 pp_var all_packages_source_files $package_files
500 pp_var ordinary_header_files $header_vars "\$(" ")"
501 pp_var bc_objects $bc_objects
502 pp_var property_files $properties_files