Makefile.in: Regenerate.
[gcc.git] / libjava / scripts / makemake.tcl
1 #!/usr/bin/tclsh
2
3 # Helper to enforce array-ness.
4 proc makearray {name} {
5 upvar $name ary
6 set ary(_) 1
7 unset ary(_)
8 }
9
10 global is_verbose
11 set is_verbose 0
12
13 # Verbose printer.
14 proc verbose {text} {
15 global is_verbose
16 if {$is_verbose} {
17 puts stderr $text
18 }
19 }
20
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 #
40 # If a package does not appear in the map, the default is 'package'.
41 global package_map
42 set package_map(.) package
43
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
48
49 set package_map(gnu/java/awt/peer/swing) bc
50
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
82
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
90
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
95
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
98 # classes.
99 global exclusion_map
100 makearray exclusion_map
101 # set exclusion_map(java/awt) AWTPermission
102
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.
106 global name_map
107 makearray name_map
108
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
112 # our own sources.
113 global dir_map
114 makearray dir_map
115
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
120
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) _
125
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) _
134
135 # List of all properties files.
136 set properties_files {}
137
138 # List of all '@' files that we are going to compile.
139 set package_files {}
140
141 # List of all header file variables.
142 set header_vars {}
143
144 # List of all BC object files.
145 set bc_objects {}
146
147 # List of regexps for matching ignored files.
148 set ignore_rx_list {}
149
150
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"
158 return 1
159 }
160 }
161 return 0
162 }
163
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]} {
169 set line [gets $fd]
170
171 # Classpath's entries bogusly start with "../".
172 if {[string match ../* $line]} {
173 set line [string range $line 3 end]
174 }
175
176 if {$line != ""} {
177 lappend ignore_rx_list $line
178 }
179 }
180 close $fd
181 }
182
183 # Classify a single source file.
184 proc classify_source_file {basedir file} {
185 global package_map name_map dir_map
186
187 if {[ignore_file_p $file]} {
188 return
189 }
190
191 set seen [info exists dir_map($file)]
192 set dir_map($file) $basedir
193 set pkg $file
194 while {1} {
195 if {[info exists package_map($pkg)]} {
196 # If the entry is 'package', then set up a new entry for the
197 # file's package.
198 if {$package_map($pkg) == "package"} {
199 set pkg [file dirname $file]
200 set package_map($pkg) package
201 }
202 verbose "classify succeeded: $file -> $pkg"
203 if {! $seen} {
204 lappend name_map($pkg) $file
205 }
206 return
207 }
208 set pkg [file dirname $pkg]
209 }
210 error "can't happen"
211 }
212
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
218
219 set subdirs {}
220 set files {}
221 set here [pwd]
222 cd $basedir/$subdir
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
230 }
231 } elseif {[string match *.css $file]} {
232 # Special case for default.css needed by javax.swing.text.html.
233 lappend properties_files $basedir/$subdir/$file
234 } elseif {[file isdirectory $file]} {
235 lappend subdirs $subdir/$file
236 } elseif {$subdir == "META-INF/services"} {
237 # Service files are generally included as properties.
238 if {! [info exists properties_map($subdir/$file)]} {
239 lappend properties_files $basedir/$subdir/$file
240 }
241 }
242 }
243 cd $here
244
245 # Recurse first, so that we don't create new packages too eagerly.
246 foreach dir $subdirs {
247 scan_directory $basedir $dir
248 }
249
250 foreach file $files {
251 classify_source_file $basedir $file
252 }
253 }
254
255 # Scan known packages beneath the base directory for .java source
256 # files.
257 proc scan_packages {basedir} {
258 foreach subdir {gnu java javax org sun com META-INF} {
259 if {[file exists $basedir/$subdir]} {
260 scan_directory $basedir $subdir
261 }
262 }
263 }
264
265 # Emit a rule for a 'bc' package.
266 proc emit_bc_rule {package} {
267 global package_map exclusion_map bc_objects
268
269 if {$package == "."} {
270 set pkgname ordinary
271 } else {
272 set pkgname $package
273 }
274 set varname [join [split $pkgname /] _]_source_files
275 set loname [join [split $pkgname /] -].lo
276 set tname [join [split $pkgname /] -].list
277
278 puts "$loname: \$($varname)"
279 # Create a temporary list file and then compile it. This works
280 # around the libtool problem mentioned in PR 21058. classpath was
281 # built first, so the class files are to be found there.
282 set omit ""
283 if {[info exists exclusion_map($package)]} {
284 set omit "| grep -v $exclusion_map($package)"
285 }
286 puts "\t@find \$(srcdir)/classpath/lib/$package -name '*.class'${omit} > $tname"
287 puts -nonewline "\t\$(LTGCJCOMPILE) -fsource-filename=\$(here)/classpath/lib/classes "
288 if {$package_map($package) == "bc"} {
289 puts -nonewline "-fjni "
290 }
291 puts "-findirect-dispatch -fno-indirect-classes -c -o $loname @$tname"
292 puts "\t@rm -f $tname"
293 puts ""
294
295 # We skip these because they are built into their own libraries and
296 # are handled specially in Makefile.am.
297 if {$loname != "gnu-java-awt-peer-qt.lo" && $loname != "gnu-java-awt-peer-x.lo"} {
298 lappend bc_objects $loname
299 }
300 }
301
302 # Emit a rule for a 'package' package.
303 proc emit_package_rule {package} {
304 global package_map exclusion_map package_files
305
306 if {$package == "."} {
307 set pkgname ordinary
308 } else {
309 set pkgname $package
310 }
311 set varname [join [split $pkgname /] _]_source_files
312 set base $pkgname
313 set lname $base.list
314 set dname $base.deps
315
316 if {$pkgname == "java/lang"} {
317 # Object and Class are special cases due to an apparent compiler
318 # bug. Process is a special case because we don't build all
319 # concrete implementations of Process on all platforms.
320 set omit "| tr ' ' '\\n' | fgrep -v Object.class | fgrep -v Class.class | egrep -v '\(Ecos\|Posix\|Win32\)Process' "
321 } else {
322 set omit ""
323 }
324
325 # A rule to make the phony file we are going to compile.
326 puts "$lname: \$($varname)"
327 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
328 puts "\techo \$(srcdir)/classpath/lib/$package/*.class $omit> $lname"
329 puts ""
330 puts "-include $dname"
331 puts ""
332 puts ""
333
334 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"
335 && $pkgname != "gnu/gcj/tools/gcj_dbtool"} {
336 lappend package_files $lname
337 }
338 }
339
340 # Emit a rule to build a package full of 'ordinary' files, that is,
341 # one .o for each .java.
342 proc emit_ordinary_rule {package} {
343 global name_map package_files
344
345 foreach file $name_map($package) {
346 # Strip off the '.java'.
347 set root [file rootname $file]
348
349 # Look for all included .class files. Assumes that we don't have
350 # multiple top-level classes in a .java file.
351 set lname $root.list
352 set dname $root.deps
353
354 puts "$lname: classpath/$file"
355 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
356 puts "\techo \$(srcdir)/classpath/lib/${root}*.class> $lname"
357 puts ""
358 puts "-include $dname"
359 puts ""
360 puts ""
361
362 lappend package_files $lname
363 }
364 }
365
366 # Emit a package-like rule for a platform-specific Process
367 # implementation.
368 proc emit_process_package_rule {platform} {
369 set base "java/process-$platform"
370 set lname $base.list
371 set dname $base.deps
372
373 puts "$lname: java/lang/${platform}Process.java"
374 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
375 puts "\techo \$(srcdir)/classpath/lib/java/lang/${platform}Process*.class > $lname"
376 puts ""
377 puts "-include $dname"
378 puts ""
379 puts ""
380 }
381
382 # Emit a source file variable for a package, and corresponding header
383 # file variable, if needed.
384 proc emit_source_var {package} {
385 global package_map name_map dir_map header_vars
386
387 if {$package == "."} {
388 set pkgname ordinary
389 } else {
390 set pkgname $package
391 }
392 set uname [join [split $pkgname /] _]
393 set varname ${uname}_source_files
394 puts -nonewline "$varname ="
395
396 makearray dirs
397 foreach base [lsort $name_map($package)] {
398 # Terminate previous line.
399 puts " \\"
400 # Having files start with './' is ugly and confuses the automake
401 # "dirstamp" code; see automake PR 461.
402 set ndir $dir_map($base)/
403 if {$ndir == "./"} {
404 set ndir ""
405 }
406 puts -nonewline "${ndir}${base}"
407 set dirs($dir_map($base)) 1
408 }
409 puts ""
410 puts ""
411
412 if {$package_map($package) != "bc"} {
413 # Ugly code to build up the appropriate patsubst.
414 set result "\$(patsubst %.java,%.h,\$($varname))"
415 # We use -decreasing so that classpath/external will be stripped
416 # before classpath.
417 foreach dir [lsort -decreasing [array names dirs]] {
418 if {$dir != "."} {
419 set result "\$(patsubst $dir/%,%,$result)"
420 }
421 }
422
423 if {$package == "." || $package == "java/lang"} {
424 # Ugly hack.
425 set result "\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
426 }
427
428 puts "${uname}_header_files = $result"
429 puts ""
430 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
431 lappend header_vars "${uname}_header_files"
432 }
433 }
434 }
435
436 # Pretty-print a Makefile variable.
437 proc pp_var {name valueList {pre ""} {post ""}} {
438 puts ""
439 puts -nonewline "$name ="
440 foreach val $valueList {
441 puts " \\"
442 puts -nonewline " ${pre}${val}${post}"
443 }
444 puts ""
445 }
446
447 global argv
448 if {[llength $argv] > 0 && [lindex $argv 0] == "-verbose"} {
449 set is_verbose 1
450 }
451
452 # Read the proper .omit files.
453 read_omit_file standard.omit.in
454 read_omit_file classpath/lib/standard.omit.in
455
456 # Scan classpath first.
457 scan_packages classpath
458 scan_packages classpath/external/sax
459 scan_packages classpath/external/w3c_dom
460 scan_packages classpath/external/relaxngDatatype
461 scan_packages classpath/external/jsr166
462 # Resource files.
463 scan_packages classpath/resource
464 # Now scan our own files; this will correctly override decisions made
465 # when scanning classpath.
466 scan_packages .
467 # Files created by the build.
468 classify_source_file classpath gnu/java/locale/LocaleData.java
469 classify_source_file classpath gnu/java/security/Configuration.java
470
471 puts "## This file was automatically generated by scripts/makemake.tcl"
472 puts "## Do not edit!"
473 puts ""
474
475 foreach package [lsort [array names package_map]] {
476 if {$package_map($package) == "ignore"} {
477 continue
478 }
479 if {! [info exists name_map($package)]} {
480 continue
481 }
482
483 emit_source_var $package
484
485 if {$package_map($package) == "bc"} {
486 emit_bc_rule $package
487 } elseif {$package_map($package) == "bcheaders"} {
488 emit_bc_rule $package
489 } elseif {$package_map($package) == "ordinary"} {
490 emit_ordinary_rule $package
491 } elseif {$package_map($package) == "package"} {
492 emit_package_rule $package
493 } else {
494 error "unrecognized type: $package_map($package)"
495 }
496 }
497
498 emit_process_package_rule Ecos
499 emit_process_package_rule Win32
500 emit_process_package_rule Posix
501
502 pp_var all_packages_source_files $package_files
503 pp_var ordinary_header_files $header_vars "\$(" ")"
504 pp_var bc_objects $bc_objects
505 pp_var property_files $properties_files