OSDN Git Service

5a60097d698de0a48ad36bccccc77ccfc5e7e969
[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 # * package
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.
29 # * ordinary
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.
33 # * ignore
34 #         objects in this package are not used.  Note however that
35 #         most ignored files are actually handled by listing them in
36 #         'standard.omit'
37 #
38 # If a package does not appear in the map, the default is 'package'.
39 global package_map
40 set package_map(.) package
41
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
46
47 set package_map(gnu/java/awt/peer/swing) bc
48
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
76
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
84
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
89
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
92 # classes.
93 global exclusion_map
94 makearray exclusion_map
95 # set exclusion_map(java/awt) AWTPermission
96
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.
100 global name_map
101 makearray name_map
102
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
106 # our own sources.
107 global dir_map
108 makearray dir_map
109
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
114
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) _
119
120
121 # List of all properties files.
122 set properties_files {}
123
124 # List of all '@' files that we are going to compile.
125 set package_files {}
126
127 # List of all header file variables.
128 set header_vars {}
129
130 # List of all BC object files.
131 set bc_objects {}
132
133 # List of regexps for matching ignored files.
134 set ignore_rx_list {}
135
136
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"
144       return 1
145     }
146   }
147   return 0
148 }
149
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]} {
155     set line [gets $fd]
156
157     # Classpath's entries bogusly start with "../".
158     if {[string match ../* $line]} {
159       set line [string range $line 3 end]
160     }
161
162     if {$line != ""} {
163       lappend ignore_rx_list $line
164     }
165   }
166   close $fd
167 }
168
169 # Classify a single source file.
170 proc classify_source_file {basedir file} {
171   global package_map name_map dir_map
172
173   if {[ignore_file_p $file]} {
174     return
175   }
176
177   set seen [info exists dir_map($file)]
178   set dir_map($file) $basedir
179   set pkg $file
180   while {1} {
181     if {[info exists package_map($pkg)]} {
182       # If the entry is 'package', then set up a new entry for the
183       # file's package.
184       if {$package_map($pkg) == "package"} {
185         set pkg [file dirname $file]
186         set package_map($pkg) package
187       }
188       verbose "classify succeeded: $file -> $pkg"
189       if {! $seen} {
190         lappend name_map($pkg) $file
191       }
192       return
193     }
194     set pkg [file dirname $pkg]
195   }
196   error "can't happen"
197 }
198
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
204
205   set subdirs {}
206   set files {}
207   set here [pwd]
208   cd $basedir/$subdir
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
216       }
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
222     }
223   }
224   cd $here
225
226   # Recurse first, so that we don't create new packages too eagerly.
227   foreach dir $subdirs {
228     scan_directory $basedir $dir
229   }
230
231   foreach file $files {
232     classify_source_file $basedir $file
233   }
234 }
235
236 # Scan known packages beneath the base directory for .java source
237 # files.
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
242     }
243   }
244 }
245
246 # Emit a rule for a 'bc' package.
247 proc emit_bc_rule {package} {
248   global package_map exclusion_map bc_objects
249
250   if {$package == "."} {
251     set pkgname ordinary
252   } else {
253     set pkgname $package
254   }
255   set varname [join [split $pkgname /] _]_source_files
256   set loname [join [split $pkgname /] -].lo
257   set tname [join [split $pkgname /] -].list
258
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.
263   set omit ""
264   if {[info exists exclusion_map($package)]} {
265     set omit "| grep -v $exclusion_map($package)"
266   }
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"
270   puts ""
271
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
276   }
277 }
278
279 # Emit a rule for a 'package' package.
280 proc emit_package_rule {package} {
281   global package_map exclusion_map package_files
282
283   if {$package == "."} {
284     set pkgname ordinary
285   } else {
286     set pkgname $package
287   }
288   set varname [join [split $pkgname /] _]_source_files
289   set base $pkgname
290   set lname $base.list
291   set dname $base.deps
292
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' "
298   } else {
299     set omit ""
300   }
301
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"
306   puts ""
307   puts "-include $dname"
308   puts ""
309   puts ""
310
311   if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"
312       && $pkgname != "gnu/gcj/tools/gcj_dbtool"} {
313     lappend package_files $lname
314   }
315 }
316
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
321
322   foreach file $name_map($package) {
323     # Strip off the '.java'.
324     set root [file rootname $file]
325
326     # Look for all included .class files.  Assumes that we don't have
327     # multiple top-level classes in a .java file.
328     set lname $root.list
329     set dname $root.deps
330
331     puts "$lname: classpath/$file"
332     puts "\t@\$(mkinstalldirs) \$(dir \$@)"
333     puts "\techo \$(srcdir)/classpath/lib/${root}*.class> $lname"
334     puts ""
335     puts "-include $dname"
336     puts ""
337     puts ""
338
339     lappend package_files $lname
340   }
341 }
342
343 # Emit a package-like rule for a platform-specific Process
344 # implementation.
345 proc emit_process_package_rule {platform} {
346   set base "java/process-$platform"
347   set lname $base.list
348   set dname $base.deps
349
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"
353   puts ""
354   puts "-include $dname"
355   puts ""
356   puts ""
357 }
358
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
363
364   if {$package == "."} {
365     set pkgname ordinary
366   } else {
367     set pkgname $package
368   }
369   set uname [join [split $pkgname /] _]
370   set varname ${uname}_source_files
371   puts -nonewline "$varname ="
372
373   makearray dirs
374   foreach base [lsort $name_map($package)] {
375     # Terminate previous line.
376     puts " \\"
377     # Having files start with './' is ugly and confuses the automake
378     # "dirstamp" code; see automake PR 461.
379     set ndir $dir_map($base)/
380     if {$ndir == "./"} {
381       set ndir ""
382     }
383     puts -nonewline "${ndir}${base}"
384     set dirs($dir_map($base)) 1
385   }
386   puts ""
387   puts ""
388
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
393     # before classpath.
394     foreach dir [lsort -decreasing [array names dirs]] {
395       if {$dir != "."} {
396         set result "\$(patsubst $dir/%,%,$result)"
397       }
398     }
399
400     if {$package == "." || $package == "java/lang"} {
401       # Ugly hack.
402       set result "\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
403     }
404
405     puts "${uname}_header_files = $result"
406     puts ""
407     if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
408       lappend header_vars "${uname}_header_files"
409     }
410   }
411 }
412
413 # Pretty-print a Makefile variable.
414 proc pp_var {name valueList {pre ""} {post ""}} {
415   puts ""
416   puts -nonewline "$name ="
417   foreach val $valueList {
418     puts " \\"
419     puts -nonewline "  ${pre}${val}${post}"
420   }
421   puts ""
422 }
423
424 global argv
425 if {[llength $argv] > 0 && [lindex $argv 0] == "-verbose"} {
426   set is_verbose 1
427 }
428
429 # Read the proper .omit files.
430 read_omit_file standard.omit.in
431 read_omit_file classpath/lib/standard.omit.in
432
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
439 # Resource files.
440 scan_packages classpath/resource
441 # Now scan our own files; this will correctly override decisions made
442 # when scanning classpath.
443 scan_packages .
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
447
448 puts "## This file was automatically generated by scripts/makemake.tcl"
449 puts "## Do not edit!"
450 puts ""
451
452 foreach package [lsort [array names package_map]] {
453   if {$package_map($package) == "ignore"} {
454     continue
455   }
456   if {! [info exists name_map($package)]} {
457     continue
458   }
459
460   emit_source_var $package
461
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
468   } else {
469     error "unrecognized type: $package_map($package)"
470   }
471 }
472
473 emit_process_package_rule Ecos
474 emit_process_package_rule Win32
475 emit_process_package_rule Posix
476
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