OSDN Git Service

47c460a7c7aeabfbcc06ccc563bb8ecca47b1686
[pf3gnuchains/gcc-fork.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 {[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
237       }
238     }
239   }
240   cd $here
241
242   # Recurse first, so that we don't create new packages too eagerly.
243   foreach dir $subdirs {
244     scan_directory $basedir $dir
245   }
246
247   foreach file $files {
248     classify_source_file $basedir $file
249   }
250 }
251
252 # Scan known packages beneath the base directory for .java source
253 # files.
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
258     }
259   }
260 }
261
262 # Emit a rule for a 'bc' package.
263 proc emit_bc_rule {package} {
264   global package_map exclusion_map bc_objects
265
266   if {$package == "."} {
267     set pkgname ordinary
268   } else {
269     set pkgname $package
270   }
271   set varname [join [split $pkgname /] _]_source_files
272   set loname [join [split $pkgname /] -].lo
273   set tname [join [split $pkgname /] -].list
274
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.
279   set omit ""
280   if {[info exists exclusion_map($package)]} {
281     set omit "| grep -v $exclusion_map($package)"
282   }
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 "
287   }
288   puts "-findirect-dispatch -fno-indirect-classes -c -o $loname @$tname"
289   puts "\t@rm -f $tname"
290   puts ""
291
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
296   }
297 }
298
299 # Emit a rule for a 'package' package.
300 proc emit_package_rule {package} {
301   global package_map exclusion_map package_files
302
303   if {$package == "."} {
304     set pkgname ordinary
305   } else {
306     set pkgname $package
307   }
308   set varname [join [split $pkgname /] _]_source_files
309   set base $pkgname
310   set lname $base.list
311   set dname $base.deps
312
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' "
318   } else {
319     set omit ""
320   }
321
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"
326   puts ""
327   puts "-include $dname"
328   puts ""
329   puts ""
330
331   if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"
332       && $pkgname != "gnu/gcj/tools/gcj_dbtool"} {
333     lappend package_files $lname
334   }
335 }
336
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
341
342   foreach file $name_map($package) {
343     # Strip off the '.java'.
344     set root [file rootname $file]
345
346     # Look for all included .class files.  Assumes that we don't have
347     # multiple top-level classes in a .java file.
348     set lname $root.list
349     set dname $root.deps
350
351     puts "$lname: classpath/$file"
352     puts "\t@\$(mkinstalldirs) \$(dir \$@)"
353     puts "\techo \$(srcdir)/classpath/lib/${root}*.class> $lname"
354     puts ""
355     puts "-include $dname"
356     puts ""
357     puts ""
358
359     lappend package_files $lname
360   }
361 }
362
363 # Emit a package-like rule for a platform-specific Process
364 # implementation.
365 proc emit_process_package_rule {platform} {
366   set base "java/process-$platform"
367   set lname $base.list
368   set dname $base.deps
369
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"
373   puts ""
374   puts "-include $dname"
375   puts ""
376   puts ""
377 }
378
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
383
384   if {$package == "."} {
385     set pkgname ordinary
386   } else {
387     set pkgname $package
388   }
389   set uname [join [split $pkgname /] _]
390   set varname ${uname}_source_files
391   puts -nonewline "$varname ="
392
393   makearray dirs
394   foreach base [lsort $name_map($package)] {
395     # Terminate previous line.
396     puts " \\"
397     # Having files start with './' is ugly and confuses the automake
398     # "dirstamp" code; see automake PR 461.
399     set ndir $dir_map($base)/
400     if {$ndir == "./"} {
401       set ndir ""
402     }
403     puts -nonewline "${ndir}${base}"
404     set dirs($dir_map($base)) 1
405   }
406   puts ""
407   puts ""
408
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
413     # before classpath.
414     foreach dir [lsort -decreasing [array names dirs]] {
415       if {$dir != "."} {
416         set result "\$(patsubst $dir/%,%,$result)"
417       }
418     }
419
420     if {$package == "." || $package == "java/lang"} {
421       # Ugly hack.
422       set result "\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
423     }
424
425     puts "${uname}_header_files = $result"
426     puts ""
427     if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
428       lappend header_vars "${uname}_header_files"
429     }
430   }
431 }
432
433 # Pretty-print a Makefile variable.
434 proc pp_var {name valueList {pre ""} {post ""}} {
435   puts ""
436   puts -nonewline "$name ="
437   foreach val $valueList {
438     puts " \\"
439     puts -nonewline "  ${pre}${val}${post}"
440   }
441   puts ""
442 }
443
444 global argv
445 if {[llength $argv] > 0 && [lindex $argv 0] == "-verbose"} {
446   set is_verbose 1
447 }
448
449 # Read the proper .omit files.
450 read_omit_file standard.omit.in
451 read_omit_file classpath/lib/standard.omit.in
452
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
459 # Resource files.
460 scan_packages classpath/resource
461 # Now scan our own files; this will correctly override decisions made
462 # when scanning classpath.
463 scan_packages .
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
467
468 puts "## This file was automatically generated by scripts/makemake.tcl"
469 puts "## Do not edit!"
470 puts ""
471
472 foreach package [lsort [array names package_map]] {
473   if {$package_map($package) == "ignore"} {
474     continue
475   }
476   if {! [info exists name_map($package)]} {
477     continue
478   }
479
480   emit_source_var $package
481
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
490   } else {
491     error "unrecognized type: $package_map($package)"
492   }
493 }
494
495 emit_process_package_rule Ecos
496 emit_process_package_rule Win32
497 emit_process_package_rule Posix
498
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