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
45 set package_map(gnu/gcj/tools/gc_analyze) ignore
47 set package_map(gnu/java/awt/peer/swing) bc
49 set package_map(gnu/xml/aelfred2) bc
50 set package_map(gnu/xml/dom) bc
51 set package_map(gnu/xml/libxmlj) bc
52 set package_map(gnu/xml/pipeline) bc
53 set package_map(gnu/xml/stream) bc
54 set package_map(gnu/xml/transform) bc
55 set package_map(gnu/xml/util) bc
56 set package_map(gnu/xml/validation) bc
57 set package_map(gnu/xml/xpath) bc
58 set package_map(javax/imageio) bc
59 set package_map(javax/xml) bc
60 set package_map(gnu/java/beans) bc
61 set package_map(gnu/java/awt/dnd/peer/gtk) bc
62 set package_map(gnu/java/util/prefs/gconf) bc
63 set package_map(gnu/java/awt/peer/gtk) bc
64 set package_map(gnu/java/awt/dnd/peer/gtk) bc
65 set package_map(gnu/java/awt/peer/qt) bc
66 set package_map(gnu/java/awt/peer/x) bc
67 set package_map(gnu/java/util/prefs/gconf) bc
68 set package_map(gnu/javax/sound/midi) bc
69 set package_map(org/xml) bc
70 set package_map(org/w3c) bc
71 set package_map(org/relaxng) bc
72 set package_map(javax/rmi) bc
73 set package_map(org/omg) bc
74 set package_map(gnu/CORBA) bc
75 set package_map(gnu/javax/rmi) bc
77 # parser/HTML_401F.class is really big, and there have been complaints
78 # about this package requiring too much memory to build. So, we
79 # compile it as separate objects. But, we're careful to compile the
80 # sub-packages as packages.
81 set package_map(gnu/javax/swing/text/html/parser) ordinary
82 set package_map(gnu/javax/swing/text/html/parser/models) package
83 set package_map(gnu/javax/swing/text/html/parser/support) package
85 # More special cases. These end up in their own library.
86 # Note that if we BC-compile AWT we must update these as well.
87 set package_map(gnu/gcj/xlib) package
88 set package_map(gnu/awt/xlib) package
90 # Some BC ABI packages have classes which must not be compiled BC.
91 # This maps such packages to a grep expression for excluding such
94 makearray exclusion_map
95 # set exclusion_map(java/awt) AWTPermission
97 # This maps a package name to a list of corresponding .java file base
98 # names. The package name will either appear as a key in package_map,
99 # or it will be '.' for the default.
103 # This maps a java file base name, like 'java/lang/Object.java', to
104 # the source directory in which it resides. We keep a layer of
105 # indirection here so that we can override sources in Classpath with
110 # An entry in this map means that all .properties files in the
111 # corresponding directory should be ignored.
112 global properties_map
113 makearray properties_map
115 # logging.properties is installed and is editable.
116 set properties_map(java/util/logging) _
117 # We haven't merged locale resources yet.
118 set properties_map(gnu/java/locale) _
121 # List of all properties files.
122 set properties_files {}
124 # List of all '@' files that we are going to compile.
127 # List of all header file variables.
130 # List of all BC object files.
133 # List of regexps for matching ignored files.
134 set ignore_rx_list {}
137 # Return true if a given file should be ignored.
138 # The argument is the path name including the package part.
139 proc ignore_file_p {file} {
140 global ignore_rx_list
141 foreach rx $ignore_rx_list {
142 if {[regexp -- $rx $file]} {
143 verbose "ignoring $file for $rx"
150 # Read a '.omit' file and update the internal data structures.
151 proc read_omit_file {name} {
152 global ignore_rx_list
153 set fd [open $name r]
154 while {! [eof $fd]} {
157 # Classpath's entries bogusly start with "../".
158 if {[string match ../* $line]} {
159 set line [string range $line 3 end]
163 lappend ignore_rx_list $line
169 # Classify a single source file.
170 proc classify_source_file {basedir file} {
171 global package_map name_map dir_map
173 if {[ignore_file_p $file]} {
177 set seen [info exists dir_map($file)]
178 set dir_map($file) $basedir
181 if {[info exists package_map($pkg)]} {
182 # If the entry is 'package', then set up a new entry for the
184 if {$package_map($pkg) == "package"} {
185 set pkg [file dirname $file]
186 set package_map($pkg) package
188 verbose "classify succeeded: $file -> $pkg"
190 lappend name_map($pkg) $file
194 set pkg [file dirname $pkg]
199 # Scan a directory and its subdirectories for .java source files or
200 # .properties files. Note that we keep basedir and subdir separate so
201 # we can properly update our global data structures.
202 proc scan_directory {basedir subdir} {
203 global dir_map properties_map properties_files
209 foreach file [lsort [glob -nocomplain *]] {
210 if {[string match *.java $file]} {
211 lappend files $subdir/$file
212 } elseif {[string match *.properties $file]} {
213 if {! [info exists properties_map($subdir)]} {
214 # We assume there aren't any overrides.
215 lappend properties_files $basedir/$subdir/$file
217 } elseif {[file isdirectory $file]} {
218 lappend subdirs $subdir/$file
219 } elseif {$subdir == "META-INF/services"} {
220 # All service files are included as properties.
221 lappend properties_files $basedir/$subdir/$file
226 # Recurse first, so that we don't create new packages too eagerly.
227 foreach dir $subdirs {
228 scan_directory $basedir $dir
231 foreach file $files {
232 classify_source_file $basedir $file
236 # Scan known packages beneath the base directory for .java source
238 proc scan_packages {basedir} {
239 foreach subdir {gnu java javax org sun META-INF} {
240 if {[file exists $basedir/$subdir]} {
241 scan_directory $basedir $subdir
246 # Emit a rule for a 'bc' package.
247 proc emit_bc_rule {package} {
248 global package_map exclusion_map bc_objects
250 if {$package == "."} {
255 set varname [join [split $pkgname /] _]_source_files
256 set loname [join [split $pkgname /] -].lo
257 set tname [join [split $pkgname /] -].list
259 puts "$loname: \$($varname)"
260 # Create a temporary list file and then compile it. This works
261 # around the libtool problem mentioned in PR 21058. classpath was
262 # built first, so the class files are to be found there.
264 if {[info exists exclusion_map($package)]} {
265 set omit "| grep -v $exclusion_map($package)"
267 puts "\t@find \$(srcdir)/classpath/lib/$package -name '*.class'${omit} > $tname"
268 puts "\t\$(LTGCJCOMPILE) -fsource-filename=\$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o $loname @$tname"
269 puts "\t@rm -f $tname"
272 # We skip these because they are built into their own libraries and
273 # are handled specially in Makefile.am.
274 if {$loname != "gnu-java-awt-peer-qt.lo" && $loname != "gnu-java-awt-peer-x.lo"} {
275 lappend bc_objects $loname
279 # Emit a rule for a 'package' package.
280 proc emit_package_rule {package} {
281 global package_map exclusion_map package_files
283 if {$package == "."} {
288 set varname [join [split $pkgname /] _]_source_files
293 if {$pkgname == "java/lang"} {
294 # Object and Class are special cases due to an apparent compiler
295 # bug. Process is a special case because we don't build all
296 # concrete implementations of Process on all platforms.
297 set omit "| tr ' ' '\\n' | fgrep -v Object.class | fgrep -v Class.class | grep -v '\[^/\]Process' "
302 # A rule to make the phony file we are going to compile.
303 puts "$lname: \$($varname)"
304 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
305 puts "\techo \$(srcdir)/classpath/lib/$package/*.class $omit> $lname"
307 puts "-include $dname"
311 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"
312 && $pkgname != "gnu/gcj/tools/gcj_dbtool"} {
313 lappend package_files $lname
317 # Emit a rule to build a package full of 'ordinary' files, that is,
318 # one .o for each .java.
319 proc emit_ordinary_rule {package} {
320 global name_map package_files
322 foreach file $name_map($package) {
323 # Strip off the '.java'.
324 set root [file rootname $file]
326 # Look for all included .class files. Assumes that we don't have
327 # multiple top-level classes in a .java file.
331 puts "$lname: classpath/$file"
332 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
333 puts "\techo \$(srcdir)/classpath/lib/${root}*.class> $lname"
335 puts "-include $dname"
339 lappend package_files $lname
343 # Emit a package-like rule for a platform-specific Process
345 proc emit_process_package_rule {platform} {
346 set base "java/process-$platform"
350 puts "$lname: java/lang/${platform}Process.java"
351 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
352 puts "\techo \$(srcdir)/classpath/lib/java/lang/${platform}Process*.class > $lname"
354 puts "-include $dname"
359 # Emit a source file variable for a package, and corresponding header
360 # file variable, if needed.
361 proc emit_source_var {package} {
362 global package_map name_map dir_map header_vars
364 if {$package == "."} {
369 set uname [join [split $pkgname /] _]
370 set varname ${uname}_source_files
371 puts -nonewline "$varname ="
374 foreach base [lsort $name_map($package)] {
375 # Terminate previous line.
377 # Having files start with './' is ugly and confuses the automake
378 # "dirstamp" code; see automake PR 461.
379 set ndir $dir_map($base)/
383 puts -nonewline "${ndir}${base}"
384 set dirs($dir_map($base)) 1
389 if {$package_map($package) != "bc"} {
390 # Ugly code to build up the appropriate patsubst.
391 set result "\$(patsubst %.java,%.h,\$($varname))"
392 # We use -decreasing so that classpath/external will be stripped
394 foreach dir [lsort -decreasing [array names dirs]] {
396 set result "\$(patsubst $dir/%,%,$result)"
400 if {$package == "." || $package == "java/lang"} {
402 set result "\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
405 puts "${uname}_header_files = $result"
407 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
408 lappend header_vars "${uname}_header_files"
413 # Pretty-print a Makefile variable.
414 proc pp_var {name valueList {pre ""} {post ""}} {
416 puts -nonewline "$name ="
417 foreach val $valueList {
419 puts -nonewline " ${pre}${val}${post}"
425 if {[llength $argv] > 0 && [lindex $argv 0] == "-verbose"} {
429 # Read the proper .omit files.
430 read_omit_file standard.omit.in
431 read_omit_file classpath/lib/standard.omit.in
433 # Scan classpath first.
434 scan_packages classpath
435 scan_packages classpath/external/sax
436 scan_packages classpath/external/w3c_dom
437 scan_packages classpath/external/relaxngDatatype
438 scan_packages classpath/external/jsr166
440 scan_packages classpath/resource
441 # Now scan our own files; this will correctly override decisions made
442 # when scanning classpath.
444 # Files created by the build.
445 classify_source_file classpath gnu/java/locale/LocaleData.java
446 classify_source_file classpath gnu/java/security/Configuration.java
448 puts "## This file was automatically generated by scripts/makemake.tcl"
449 puts "## Do not edit!"
452 foreach package [lsort [array names package_map]] {
453 if {$package_map($package) == "ignore"} {
456 if {! [info exists name_map($package)]} {
460 emit_source_var $package
462 if {$package_map($package) == "bc"} {
463 emit_bc_rule $package
464 } elseif {$package_map($package) == "ordinary"} {
465 emit_ordinary_rule $package
466 } elseif {$package_map($package) == "package"} {
467 emit_package_rule $package
469 error "unrecognized type: $package_map($package)"
473 emit_process_package_rule Ecos
474 emit_process_package_rule Win32
475 emit_process_package_rule Posix
477 pp_var all_packages_source_files $package_files
478 pp_var ordinary_header_files $header_vars "\$(" ")"
479 pp_var bc_objects $bc_objects
480 pp_var property_files $properties_files