OSDN Git Service

Imported GNU Classpath 0.90
[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 # Verbose printer.
11 proc verbose {text} {
12 # puts stderr $text
13 }
14
15 # This maps a name to its style:
16 # * bc    objects in this package and all its sub-packages
17 #         are to be compiled with the BC ABI.  It is an error
18 #         for sub-packages to also appear in the map.
19 # * package
20 #         objects in this package (and possibly sub-packages,
21 #         if they do not appear in the map) will be compiled en masse
22 #         from source into a single object, using the C++ ABI.
23 # * ordinary
24 #         objects in this package (and possibly sub-packages
25 #         if they do not appear in the map) will be compiled one at
26 #         a time into separate .o files.
27 # * ignore
28 #         objects in this package are not used.  Note however that
29 #         most ignored files are actually handled by listing them in
30 #         'standard.omit'
31 #
32 # If a package does not appear in the map, the default is 'package'.
33 global package_map
34 set package_map(.) package
35
36 # These are ignored in Classpath.
37 set package_map(gnu/test) ignore
38 set package_map(gnu/javax/swing/plaf/gtk) ignore
39
40 # This package doesn't really work yet, and seems to trigger bug #26390
41 set package_map(gnu/java/awt/peer/swing) ignore
42
43 set package_map(gnu/xml) bc
44 set package_map(javax/imageio) bc
45 set package_map(javax/xml) bc
46 set package_map(gnu/java/beans) bc
47 set package_map(gnu/java/awt/peer/gtk) bc
48 set package_map(gnu/java/awt/peer/qt) bc
49 set package_map(gnu/javax/sound/midi) bc
50 set package_map(org/xml) bc
51 set package_map(org/w3c) bc
52 set package_map(javax/rmi) bc
53 set package_map(org/omg) bc
54 set package_map(gnu/CORBA) bc
55 set package_map(gnu/javax/rmi) bc
56
57 # This is handled specially by the Makefile.
58 # We still want it byte-compiled so it isn't in the .omit file.
59 set package_map(gnu/gcj/tools/gcj_dbtool/Main.java) ignore
60
61 # These are handled specially.  If we list Class.java with other files
62 # in java.lang, we hit a compiler bug.
63 set package_map(java/lang/Class.java) ignore
64 set package_map(java/lang/Object.java) ignore
65
66 # More special cases.  These end up in their own library.
67 # Note that if we BC-compile AWT we must update these as well.
68 set package_map(gnu/gcj/xlib) package
69 set package_map(gnu/awt/xlib) package
70
71 # Some BC ABI packages have classes which must not be compiled BC.
72 # This maps such packages to a grep expression for excluding such
73 # classes.
74 global exclusion_map
75 makearray exclusion_map
76 # set exclusion_map(java/awt) AWTPermission
77
78 # This maps a package name to a list of corresponding .java file base
79 # names.  The package name will either appear as a key in package_map,
80 # or it will be '.' for the default.
81 global name_map
82 makearray name_map
83
84 # This maps a java file base name, like 'java/lang/Object.java', to
85 # the source directory in which it resides.  We keep a layer of
86 # indirection here so that we can override sources in Classpath with
87 # our own sources.
88 global dir_map
89 makearray dir_map
90
91 # List of all '@' files that we are going to compile.
92 set package_files {}
93
94 # List of all header file variables.
95 set header_vars {}
96
97 # List of all BC object files.
98 set bc_objects {}
99
100 # List of regexps for matching ignored files.
101 set ignore_rx_list {}
102
103
104 # Return true if a given file should be ignored.
105 # The argument is the path name including the package part.
106 proc ignore_file_p {file} {
107   global ignore_rx_list
108   foreach rx $ignore_rx_list {
109     if {[regexp -- $rx $file]} {
110       verbose "ignoring $file for $rx"
111       return 1
112     }
113   }
114   return 0
115 }
116
117 # Read a '.omit' file and update the internal data structures.
118 proc read_omit_file {name} {
119   global ignore_rx_list
120   set fd [open $name r]
121   while {! [eof $fd]} {
122     set line [gets $fd]
123
124     # Classpath's entries bogusly start with "../".
125     if {[string match ../* $line]} {
126       set line [string range $line 3 end]
127     }
128
129     if {$line != ""} {
130       lappend ignore_rx_list $line
131     }
132   }
133   close $fd
134 }
135
136 # Classify a single source file.
137 proc classify_source_file {basedir file} {
138   global package_map name_map dir_map
139
140   if {[ignore_file_p $file]} {
141     return
142   }
143
144   set seen [info exists dir_map($file)]
145   set dir_map($file) $basedir
146   set pkg $file
147   while {1} {
148     if {[info exists package_map($pkg)]} {
149       # If the entry for '.' is 'package', then set up a new entry for
150       # the file's package.
151       if {$pkg == "." && $package_map($pkg) == "package"} {
152         set pkg [file dirname $file]
153         set package_map($pkg) package
154       }
155       verbose "classify succeeded: $file -> $pkg"
156       if {! $seen} {
157         lappend name_map($pkg) $file
158       }
159       return
160     }
161     set pkg [file dirname $pkg]
162   }
163   error "can't happen"
164 }
165
166 # Scan a directory and its subdirectories for .java source files.
167 # Note that we keep basedir and subdir separate so we can properly
168 # update our global data structures.
169 proc scan_directory {basedir subdir} {
170   global dir_map
171
172   set subdirs {}
173   set files {}
174   set here [pwd]
175   cd $basedir/$subdir
176   foreach file [lsort [glob -nocomplain *]] {
177     if {[string match *.java $file]} {
178       lappend files $subdir/$file
179     } elseif {[file isdirectory $file]} {
180       lappend subdirs $subdir/$file
181     }
182   }
183   cd $here
184
185   # Recurse first, so that we don't create new packages too eagerly.
186   foreach dir $subdirs {
187     scan_directory $basedir $dir
188   }
189
190   foreach file $files {
191     classify_source_file $basedir $file
192   }
193 }
194
195 # Scan known packages beneath the base directory for .java source
196 # files.
197 proc scan_packages {basedir} {
198   foreach subdir {gnu java javax org} {
199     if {[file exists $basedir/$subdir]} {
200       scan_directory $basedir $subdir
201     }
202   }
203 }
204
205 # Emit a rule for a 'bc' package.
206 proc emit_bc_rule {package} {
207   global package_map exclusion_map bc_objects
208
209   if {$package == "."} {
210     set pkgname ordinary
211   } else {
212     set pkgname $package
213   }
214   set varname [join [split $pkgname /] _]_source_files
215   set loname [join [split $pkgname /] -].lo
216   set tname [join [split $pkgname /] -].list
217
218   puts "$loname: \$($varname)"
219   # Create a temporary list file and then compile it.  This works
220   # around the libtool problem mentioned in PR 21058.  classpath was
221   # built first, so the class files are to be found there.
222   set omit ""
223   if {[info exists exclusion_map($package)]} {
224     set omit "| grep -v $exclusion_map($package)"
225   }
226   puts  "\t@find classpath/lib/$package -name '*.class'${omit} > $tname"
227   puts "\t\$(LTGCJCOMPILE) -fjni -findirect-dispatch -c -o $loname @$tname"
228   puts "\t@rm -f $tname"
229   puts ""
230
231   # We skip these because they are built into their own libraries and
232   # are handled specially in Makefile.am.
233   if {$loname != "gnu-java-awt-peer-gtk.lo"
234       && $loname != "gnu-java-awt-peer-qt.lo"} {
235     lappend bc_objects $loname
236   }
237 }
238
239 # Emit a rule for a 'package' package.
240 proc emit_package_rule {package} {
241   global package_map exclusion_map package_files
242
243   if {$package == "."} {
244     set pkgname ordinary
245   } else {
246     set pkgname $package
247   }
248   set varname [join [split $pkgname /] _]_source_files
249   set base $pkgname
250   set lname $base.list
251   set dname $base.deps
252
253   # A rule to make the phony file we are going to compile.
254   puts "$lname: \$($varname)"
255   puts "\t@\$(mkinstalldirs) \$(dir \$@)"
256   puts "\t@for file in \$($varname); do \\"
257   puts "\t  if test -f \$(srcdir)/\$\$file; then \\"
258   puts "\t    echo \$(srcdir)/\$\$file; \\"
259   puts "\t  else echo \$\$file; fi; \\"
260   puts "\tdone > $lname"
261   puts ""
262   puts "-include $dname"
263   puts ""
264   puts ""
265
266   if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
267     lappend package_files $lname
268   }
269 }
270
271 # Emit a source file variable for a package, and corresponding header
272 # file variable, if needed.
273 proc emit_source_var {package} {
274   global package_map name_map dir_map header_vars
275
276   if {$package == "."} {
277     set pkgname ordinary
278   } else {
279     set pkgname $package
280   }
281   set uname [join [split $pkgname /] _]
282   set varname ${uname}_source_files
283   puts -nonewline "$varname ="
284
285   makearray dirs
286   foreach base [lsort $name_map($package)] {
287     # Terminate previous line.
288     puts " \\"
289     # Having files start with './' is ugly and confuses the automake
290     # "dirstamp" code; see automake PR 461.
291     set ndir $dir_map($base)/
292     if {$ndir == "./"} {
293       set ndir ""
294     }
295     puts -nonewline "${ndir}${base}"
296     set dirs($dir_map($base)) 1
297   }
298   puts ""
299   puts ""
300
301   if {$package_map($package) != "bc"} {
302     # Ugly code to build up the appropriate patsubst.
303     set result "\$(patsubst %.java,%.h,\$($varname))"
304     foreach dir [lsort [array names dirs]] {
305       if {$dir != "."} {
306         set result "\$(patsubst $dir/%,%,$result)"
307       }
308     }
309
310     if {$package == "." || $package == "java/lang"} {
311       # Ugly hack.
312       set result "\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
313     }
314
315     puts "${uname}_header_files = $result"
316     puts ""
317     if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
318       lappend header_vars "${uname}_header_files"
319     }
320   }
321 }
322
323 # Pretty-print a Makefile variable.
324 proc pp_var {name valueList {pre ""} {post ""}} {
325   puts ""
326   puts -nonewline "$name ="
327   foreach val $valueList {
328     puts " \\"
329     puts -nonewline "  ${pre}${val}${post}"
330   }
331   puts ""
332 }
333
334 # Read the proper .omit files.
335 read_omit_file standard.omit.in
336 read_omit_file classpath/lib/standard.omit
337
338 # Scan classpath first.
339 scan_packages classpath
340 scan_packages classpath/external/sax
341 scan_packages classpath/external/w3c_dom
342 # Now scan our own files; this will correctly override decisions made
343 # when scanning classpath.
344 scan_packages .
345 # Files created by the build.
346 classify_source_file . java/lang/ConcreteProcess.java
347 classify_source_file classpath java/util/LocaleData.java
348 classify_source_file classpath gnu/classpath/Configuration.java
349
350 puts "## This file was automatically generated by scripts/makemake.tcl"
351 puts "## Do not edit!"
352 puts ""
353
354 foreach package [lsort [array names package_map]] {
355   if {$package_map($package) == "ignore"} {
356     continue
357   }
358   if {! [info exists name_map($package)]} {
359     continue
360   }
361
362   emit_source_var $package
363
364   if {$package_map($package) == "bc"} {
365     emit_bc_rule $package
366   } elseif {$package_map($package) == "ordinary"} {
367     # Nothing in particular to do here.
368   } elseif {$package_map($package) == "package"} {
369     emit_package_rule $package
370   } else {
371     error "unrecognized type: $package_map($package)"
372   }
373 }
374
375 pp_var all_packages_source_files $package_files
376 pp_var ordinary_header_files $header_vars "\$(" ")"
377 pp_var bc_objects $bc_objects