* collect2.c (main): In AIX specific computations for vector
[official-gcc.git] / libjava / scripts / makemake.tcl
blob6d1eea95a34f32551d4d5112bfe40cb5a03bd758
1 #!/usr/bin/tclsh
3 # Helper to enforce array-ness.
4 proc makearray {name} {
5 upvar $name ary
6 set ary(_) 1
7 unset ary(_)
10 global is_verbose
11 set is_verbose 0
13 # Verbose printer.
14 proc verbose {text} {
15 global is_verbose
16 if {$is_verbose} {
17 puts stderr $text
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.
25 # * bcheaders
26 # as bc, but generate header files and compile with CNI.
27 # * package
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.
31 # * ordinary
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.
35 # * ignore
36 # objects in this package are not used. Note however that
37 # most ignored files are actually handled by listing them in
38 # 'standard.omit'
39 # * interpreter
40 # objects in this package (and possibly sub-packages,
41 # if they do not appear in the map) are only compiled if
42 # the interpreter is enabled. They are compiled as with the
43 # 'package' specifier.
45 # If a package does not appear in the map, the default is 'package'.
46 global package_map
47 set package_map(.) package
49 # These are ignored in Classpath.
50 set package_map(gnu/test) ignore
51 set package_map(gnu/javax/swing/plaf/gtk) ignore
52 set package_map(gnu/gcj/tools/gc_analyze) ignore
54 set package_map(gnu/java/awt/peer/swing) bc
56 set package_map(gnu/xml/aelfred2) bc
57 set package_map(gnu/xml/dom) bc
58 set package_map(gnu/xml/libxmlj) bc
59 set package_map(gnu/xml/pipeline) bc
60 set package_map(gnu/xml/stream) bc
61 set package_map(gnu/xml/transform) bc
62 set package_map(gnu/xml/util) bc
63 set package_map(gnu/xml/validation) bc
64 set package_map(gnu/xml/xpath) bc
65 set package_map(javax/imageio) bc
66 set package_map(javax/xml) bc
67 set package_map(gnu/java/beans) bc
68 set package_map(gnu/java/awt/dnd/peer/gtk) bc
69 set package_map(gnu/java/util/prefs/gconf) bc
70 set package_map(gnu/java/awt/peer/gtk) bc
71 set package_map(gnu/java/awt/dnd/peer/gtk) bc
72 set package_map(gnu/java/awt/peer/qt) bc
73 set package_map(gnu/java/awt/peer/x) bc
74 set package_map(gnu/java/util/prefs/gconf) bc
75 set package_map(gnu/javax/sound/midi) bc
76 set package_map(gnu/javax/sound/sampled/gstreamer) ignore
77 set package_map(org/xml) bc
78 set package_map(org/w3c) bc
79 set package_map(org/relaxng) bc
80 set package_map(javax/rmi) bc
81 set package_map(org/omg/IOP) bc
82 set package_map(org/omg/PortableServer) bc
83 set package_map(org/omg/CosNaming) bc
84 set package_map(org/omg/CORBA_2_3) bc
85 set package_map(org/omg/Messaging) bc
86 set package_map(org/omg/stub) bc
87 set package_map(org/omg/CORBA) bc
88 set package_map(org/omg/PortableInterceptor) bc
89 set package_map(org/omg/DynamicAny) bc
90 set package_map(org/omg/SendingContext) bc
91 set package_map(org/omg/Dynamic) bc
92 set package_map(gnu/CORBA) bc
93 set package_map(gnu/javax/rmi) bc
94 set package_map(gnu/java/lang/management) bcheaders
95 set package_map(java/lang/management) bc
96 set package_map(gnu/classpath/management) bc
97 set package_map(gnu/javax/management) bc
98 set package_map(gnu/java/math) bc
100 # parser/HTML_401F.class is really big, and there have been complaints
101 # about this package requiring too much memory to build. So, we
102 # compile it as separate objects. But, we're careful to compile the
103 # sub-packages as packages.
104 set package_map(gnu/javax/swing/text/html/parser) ordinary
105 set package_map(gnu/javax/swing/text/html/parser/models) package
106 set package_map(gnu/javax/swing/text/html/parser/support) package
108 # More special cases. These end up in their own library.
109 # Note that if we BC-compile AWT we must update these as well.
110 set package_map(gnu/gcj/xlib) package
111 set package_map(gnu/awt/xlib) package
113 # These packages should only be included if the interpreter is
114 # enabled.
115 set package_map(gnu/classpath/jdwp) interpreter
116 set package_map(gnu/classpath/jdwp/event) interpreter
117 set package_map(gnu/classpath/jdwp/event/filters) interpreter
118 set package_map(gnu/classpath/jdwp/exception) interpreter
119 set package_map(gnu/classpath/jdwp/id) interpreter
120 set package_map(gnu/classpath/jdwp/processor) interpreter
121 set package_map(gnu/classpath/jdwp/transport) interpreter
122 set package_map(gnu/classpath/jdwp/util) interpreter
123 set package_map(gnu/classpath/jdwp/value) interpreter
124 set package_map(gnu/gcj/jvmti) interpreter
126 # Some BC ABI packages have classes which must not be compiled BC.
127 # This maps such packages to a grep expression for excluding such
128 # classes.
129 global exclusion_map
130 makearray exclusion_map
131 # set exclusion_map(java/awt) AWTPermission
133 # This maps a package name to a list of corresponding .java file base
134 # names. The package name will either appear as a key in package_map,
135 # or it will be '.' for the default.
136 global name_map
137 makearray name_map
139 # This maps a java file base name, like 'java/lang/Object.java', to
140 # the source directory in which it resides. We keep a layer of
141 # indirection here so that we can override sources in Classpath with
142 # our own sources.
143 global dir_map
144 makearray dir_map
146 # An entry in this map means that all .properties files in the
147 # corresponding directory should be ignored.
148 global properties_map
149 makearray properties_map
151 # logging.properties is installed and is editable.
152 set properties_map(java/util/logging) _
154 # We want to be able to load xerces if it is on the class path. So,
155 # we have to avoid compiling in the XML-related service files.
156 set properties_map(META-INF/services/javax.xml.parsers.DocumentBuilderFactory) _
157 set properties_map(META-INF/services/javax.xml.parsers.SAXParserFactory) _
158 set properties_map(META-INF/services/javax.xml.parsers.TransformerFactory) _
159 set properties_map(META-INF/services/org.relaxng.datatype.DatatypeLibraryFactory) _
160 set properties_map(META-INF/services/org.w3c.dom.DOMImplementationSourceList) _
161 set properties_map(META-INF/services/org.xml.sax.driver) _
162 set properties_map(META-INF/services/javax.sound.sampled.spi.AudioFileReader.in) ignore
163 set properties_map(META-INF/services/javax.sound.sampled.spi.MixerProvider) ignore
164 set properties_map(META-INF/services/javax.sound.sampled.spi.MixerProvider.in) ignore
166 # List of all properties files.
167 set properties_files {}
169 # List of all '@' files that we are going to compile.
170 set package_files {}
172 # List of all '@' files that we are going to compile if the
173 # interpreter is enabled.
174 set interpreter_package_files {}
176 # List of all header file variables.
177 set header_vars {}
179 # List of all header file variables for interpreter packages.
180 set interpreter_header_vars {}
182 # List of all BC object files.
183 set bc_objects {}
185 # List of regexps for matching ignored files.
186 set ignore_rx_list {}
189 # Return true if a given file should be ignored.
190 # The argument is the path name including the package part.
191 proc ignore_file_p {file} {
192 global ignore_rx_list
193 foreach rx $ignore_rx_list {
194 if {[regexp -- $rx $file]} {
195 verbose "ignoring $file for $rx"
196 return 1
199 return 0
202 # Read a '.omit' file and update the internal data structures.
203 proc read_omit_file {name} {
204 global ignore_rx_list
205 set fd [open $name r]
206 while {! [eof $fd]} {
207 set line [gets $fd]
209 # Classpath's entries bogusly start with "../".
210 if {[string match ../* $line]} {
211 set line [string range $line 3 end]
214 if {$line != ""} {
215 lappend ignore_rx_list $line
218 close $fd
221 # Classify a single source file.
222 proc classify_source_file {basedir file} {
223 global package_map name_map dir_map
225 if {[ignore_file_p $file]} {
226 return
229 set seen [info exists dir_map($file)]
230 set dir_map($file) $basedir
231 set pkg $file
232 while {1} {
233 if {[info exists package_map($pkg)]} {
234 # If the entry is 'package', then set up a new entry for the
235 # file's package.
236 if {$package_map($pkg) == "package"} {
237 set pkg [file dirname $file]
238 set package_map($pkg) package
240 verbose "classify succeeded: $file -> $pkg"
241 if {! $seen} {
242 lappend name_map($pkg) $file
244 return
246 set pkg [file dirname $pkg]
248 error "can't happen"
251 # Scan a directory and its subdirectories for .java source files or
252 # .properties files. Note that we keep basedir and subdir separate so
253 # we can properly update our global data structures.
254 proc scan_directory {basedir subdir} {
255 global dir_map properties_map properties_files
257 set subdirs {}
258 set files {}
259 set here [pwd]
260 cd $basedir/$subdir
261 foreach file [lsort [glob -nocomplain *]] {
262 if {[string match *.java $file]} {
263 lappend files $subdir/$file
264 } elseif {[string match *.properties $file]} {
265 if {! [info exists properties_map($subdir)]} {
266 # We assume there aren't any overrides.
267 lappend properties_files $basedir/$subdir/$file
269 } elseif {[string match *.css $file]} {
270 # Special case for default.css needed by javax.swing.text.html.
271 lappend properties_files $basedir/$subdir/$file
272 } elseif {[file isdirectory $file]} {
273 lappend subdirs $subdir/$file
274 } elseif {$subdir == "META-INF/services"} {
275 # Service files are generally included as properties.
276 if {! [info exists properties_map($subdir/$file)]} {
277 lappend properties_files $basedir/$subdir/$file
281 cd $here
283 # Recurse first, so that we don't create new packages too eagerly.
284 foreach dir $subdirs {
285 scan_directory $basedir $dir
288 foreach file $files {
289 classify_source_file $basedir $file
293 # Scan known packages beneath the base directory for .java source
294 # files.
295 proc scan_packages {basedir} {
296 foreach subdir {gnu java javax org sun com META-INF} {
297 if {[file exists $basedir/$subdir]} {
298 scan_directory $basedir $subdir
303 # Emit a rule for a 'bc' package.
304 proc emit_bc_rule {package} {
305 global package_map exclusion_map bc_objects
307 if {$package == "."} {
308 set pkgname ordinary
309 } else {
310 set pkgname $package
312 set varname [join [split $pkgname /] _]_source_files
313 set loname [join [split $pkgname /] -].lo
314 set tname [join [split $pkgname /] -].list
316 puts "$loname: \$($varname)"
317 # Create a temporary list file and then compile it. This works
318 # around the libtool problem mentioned in PR 21058. classpath was
319 # built first, so the class files are to be found there.
320 set omit ""
321 if {[info exists exclusion_map($package)]} {
322 set omit "| grep -v $exclusion_map($package)"
324 puts "\t@find \$(srcdir)/classpath/lib/$package -name '*.class'${omit} > $tname"
325 puts -nonewline "\t\$(LTGCJCOMPILE) -fsource-filename=\$(here)/classpath/lib/classes "
326 if {$package_map($package) == "bc"} {
327 puts -nonewline "-fjni "
329 # Unless bc is disabled with --disable-libgcj-bc, $(LIBGCJ_BC_FLAGS) is:
330 # -findirect-dispatch -fno-indirect-classes
331 puts "\$(LIBGCJ_BC_FLAGS) -c -o $loname @$tname"
332 puts "\t@rm -f $tname"
333 puts ""
335 # We skip these because they are built into their own libraries and
336 # are handled specially in Makefile.am.
337 if {$loname != "gnu-java-awt-peer-qt.lo" && $loname != "gnu-java-awt-peer-x.lo"} {
338 lappend bc_objects $loname
342 # Emit a rule for a 'package' package.
343 proc emit_package_rule_to_list {package package_files_list} {
344 global package_map exclusion_map $package_files_list
346 if {$package == "."} {
347 set pkgname ordinary
348 } else {
349 set pkgname $package
351 set varname [join [split $pkgname /] _]_source_files
352 set base $pkgname
353 set lname $base.list
354 set dname $base.deps
356 if {$pkgname == "java/lang"} {
357 # Object and Class are special cases due to an apparent compiler
358 # bug. Process is a special case because we don't build all
359 # concrete implementations of Process on all platforms.
360 set omit "| tr ' ' '\\012' | fgrep -v Object.class | fgrep -v Class.class | egrep -v '\(Ecos\|Posix\|Win32\)Process' "
361 } else {
362 set omit ""
365 # A rule to make the phony file we are going to compile.
366 puts "$lname: \$($varname)"
367 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
368 puts "\techo \$(srcdir)/classpath/lib/$package/*.class $omit> $lname"
369 puts ""
370 puts "-include $dname"
371 puts ""
372 puts ""
374 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"
375 && $pkgname != "gnu/gcj/tools/gcj_dbtool"} {
376 lappend $package_files_list $lname
380 proc emit_package_rule {package} {
381 global package_files
382 emit_package_rule_to_list $package package_files
385 proc emit_interpreter_rule {package} {
386 global interpreter_package_files
387 emit_package_rule_to_list $package interpreter_package_files
390 # Emit a rule to build a package full of 'ordinary' files, that is,
391 # one .o for each .java.
392 proc emit_ordinary_rule {package} {
393 global name_map package_files
395 foreach file $name_map($package) {
396 # Strip off the '.java'.
397 set root [file rootname $file]
399 # Look for all included .class files. Assumes that we don't have
400 # multiple top-level classes in a .java file.
401 set lname $root.list
402 set dname $root.deps
404 puts "$lname: classpath/$file"
405 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
406 puts "\techo \$(srcdir)/classpath/lib/${root}*.class> $lname"
407 puts ""
408 puts "-include $dname"
409 puts ""
410 puts ""
412 lappend package_files $lname
416 # Emit a package-like rule for a platform-specific Process
417 # implementation.
418 proc emit_process_package_rule {platform} {
419 set base "java/process-$platform"
420 set lname $base.list
421 set dname $base.deps
423 puts "$lname: java/lang/${platform}Process.java"
424 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
425 puts "\techo \$(srcdir)/classpath/lib/java/lang/${platform}Process*.class > $lname"
426 puts ""
427 puts "-include $dname"
428 puts ""
429 puts ""
432 # Emit a source file variable for a package, and corresponding header
433 # file variable, if needed.
434 proc emit_source_var {package} {
435 global package_map name_map dir_map header_vars interpreter_header_vars
437 if {$package == "."} {
438 set pkgname ordinary
439 } else {
440 set pkgname $package
442 set uname [join [split $pkgname /] _]
443 set varname ${uname}_source_files
444 puts -nonewline "$varname ="
446 makearray dirs
447 foreach base [lsort $name_map($package)] {
448 # Terminate previous line.
449 puts " \\"
450 # Having files start with './' is ugly and confuses the automake
451 # "dirstamp" code; see automake PR 461.
452 set ndir $dir_map($base)/
453 if {$ndir == "./"} {
454 set ndir ""
456 puts -nonewline "${ndir}${base}"
457 set dirs($dir_map($base)) 1
459 puts ""
460 puts ""
462 if {$package_map($package) != "bc"} {
463 # Ugly code to build up the appropriate patsubst.
464 set result "\$(patsubst %.java,%.h,\$($varname))"
465 # We use -decreasing so that classpath/external will be stripped
466 # before classpath.
467 foreach dir [lsort -decreasing [array names dirs]] {
468 if {$dir != "."} {
469 set result "\$(patsubst $dir/%,%,$result)"
473 if {$package == "." || $package == "java/lang"} {
474 # Ugly hack.
475 set result "\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
478 puts "${uname}_header_files = $result"
479 puts ""
480 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
481 if {$package_map($package) == "interpreter"} {
482 lappend interpreter_header_vars "${uname}_header_files"
483 } else {
484 lappend header_vars "${uname}_header_files"
490 # Pretty-print a Makefile variable.
491 proc pp_var {name valueList {pre ""} {post ""}} {
492 puts ""
493 puts -nonewline "$name ="
494 foreach val $valueList {
495 puts " \\"
496 puts -nonewline " ${pre}${val}${post}"
498 puts ""
501 global argv
502 if {[llength $argv] > 0 && [lindex $argv 0] == "-verbose"} {
503 set is_verbose 1
506 # Read the proper .omit files.
507 read_omit_file standard.omit.in
508 read_omit_file classpath/lib/standard.omit.in
510 # Scan classpath first.
511 scan_packages classpath
512 scan_packages classpath/external/sax
513 scan_packages classpath/external/w3c_dom
514 scan_packages classpath/external/relaxngDatatype
515 scan_packages classpath/external/jsr166
516 # Resource files.
517 scan_packages classpath/resource
518 # Now scan our own files; this will correctly override decisions made
519 # when scanning classpath.
520 scan_packages .
521 # Files created by the build.
522 classify_source_file classpath gnu/java/locale/LocaleData.java
523 classify_source_file classpath gnu/java/security/Configuration.java
524 classify_source_file classpath gnu/classpath/Configuration.java
526 puts "## This file was automatically generated by scripts/makemake.tcl"
527 puts "## Do not edit!"
528 puts ""
530 foreach package [lsort [array names package_map]] {
531 if {$package_map($package) == "ignore"} {
532 continue
534 if {! [info exists name_map($package)]} {
535 continue
538 emit_source_var $package
540 if {$package_map($package) == "bc"} {
541 emit_bc_rule $package
542 } elseif {$package_map($package) == "bcheaders"} {
543 emit_bc_rule $package
544 } elseif {$package_map($package) == "ordinary"} {
545 emit_ordinary_rule $package
546 } elseif {$package_map($package) == "package"} {
547 emit_package_rule $package
548 } elseif {$package_map($package) == "interpreter"} {
549 emit_interpreter_rule $package
550 } else {
551 error "unrecognized type: $package_map($package)"
555 emit_process_package_rule Ecos
556 emit_process_package_rule Win32
557 emit_process_package_rule Posix
559 puts "if INTERPRETER"
560 pp_var interpreter_packages_source_files $interpreter_package_files
561 pp_var interpreter_header_files $interpreter_header_vars "\$(" ")"
562 puts ""
563 puts "else"
564 puts ""
565 puts "interpreter_packages_source_files="
566 puts ""
567 puts "interpreter_header_files="
568 puts ""
569 puts "endif"
571 lappend package_files {$(interpreter_packages_source_files)}
572 lappend header_vars interpreter_header_files
574 pp_var all_packages_source_files $package_files
575 pp_var ordinary_header_files $header_vars "\$(" ")"
576 pp_var bc_objects $bc_objects
577 pp_var property_files $properties_files