Merged gcj-eclipse branch to trunk.
[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 # * 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
46 set package_map(gnu/java/awt/peer/swing) bc
47
48 set package_map(gnu/xml) bc
49 set package_map(javax/imageio) bc
50 set package_map(javax/xml) bc
51 set package_map(gnu/java/beans) bc
52 set package_map(gnu/java/awt/dnd/peer/gtk) bc
53 set package_map(gnu/java/util/prefs/gconf) bc
54 set package_map(gnu/java/awt/peer/gtk) bc
55 set package_map(gnu/java/awt/dnd/peer/gtk) bc
56 set package_map(gnu/java/awt/peer/qt) bc
57 set package_map(gnu/java/awt/peer/x) bc
58 set package_map(gnu/java/util/prefs/gconf) bc
59 set package_map(gnu/javax/sound/midi) bc
60 set package_map(org/xml) bc
61 set package_map(org/w3c) bc
62 set package_map(org/relaxng) bc
63 set package_map(javax/rmi) bc
64 set package_map(org/omg) bc
65 set package_map(gnu/CORBA) bc
66 set package_map(gnu/javax/rmi) bc
67
68 # More special cases. These end up in their own library.
69 # Note that if we BC-compile AWT we must update these as well.
70 set package_map(gnu/gcj/xlib) package
71 set package_map(gnu/awt/xlib) package
72
73 # Some BC ABI packages have classes which must not be compiled BC.
74 # This maps such packages to a grep expression for excluding such
75 # classes.
76 global exclusion_map
77 makearray exclusion_map
78 # set exclusion_map(java/awt) AWTPermission
79
80 # This maps a package name to a list of corresponding .java file base
81 # names. The package name will either appear as a key in package_map,
82 # or it will be '.' for the default.
83 global name_map
84 makearray name_map
85
86 # This maps a java file base name, like 'java/lang/Object.java', to
87 # the source directory in which it resides. We keep a layer of
88 # indirection here so that we can override sources in Classpath with
89 # our own sources.
90 global dir_map
91 makearray dir_map
92
93 # An entry in this map means that all .properties files in the
94 # corresponding directory should be ignored.
95 global properties_map
96 makearray properties_map
97
98 # logging.properties is installed and is editable.
99 set properties_map(java/util/logging) _
100 # We haven't merged locale resources yet.
101 set properties_map(gnu/java/locale) _
102
103
104 # List of all properties files.
105 set properties_files {}
106
107 # List of all '@' files that we are going to compile.
108 set package_files {}
109
110 # List of all header file variables.
111 set header_vars {}
112
113 # List of all BC object files.
114 set bc_objects {}
115
116 # List of regexps for matching ignored files.
117 set ignore_rx_list {}
118
119
120 # Return true if a given file should be ignored.
121 # The argument is the path name including the package part.
122 proc ignore_file_p {file} {
123 global ignore_rx_list
124 foreach rx $ignore_rx_list {
125 if {[regexp -- $rx $file]} {
126 verbose "ignoring $file for $rx"
127 return 1
128 }
129 }
130 return 0
131 }
132
133 # Read a '.omit' file and update the internal data structures.
134 proc read_omit_file {name} {
135 global ignore_rx_list
136 set fd [open $name r]
137 while {! [eof $fd]} {
138 set line [gets $fd]
139
140 # Classpath's entries bogusly start with "../".
141 if {[string match ../* $line]} {
142 set line [string range $line 3 end]
143 }
144
145 if {$line != ""} {
146 lappend ignore_rx_list $line
147 }
148 }
149 close $fd
150 }
151
152 # Classify a single source file.
153 proc classify_source_file {basedir file} {
154 global package_map name_map dir_map
155
156 if {[ignore_file_p $file]} {
157 return
158 }
159
160 set seen [info exists dir_map($file)]
161 set dir_map($file) $basedir
162 set pkg $file
163 while {1} {
164 if {[info exists package_map($pkg)]} {
165 # If the entry is 'package', then set up a new entry for the
166 # file's package.
167 if {$package_map($pkg) == "package"} {
168 set pkg [file dirname $file]
169 set package_map($pkg) package
170 }
171 verbose "classify succeeded: $file -> $pkg"
172 if {! $seen} {
173 lappend name_map($pkg) $file
174 }
175 return
176 }
177 set pkg [file dirname $pkg]
178 }
179 error "can't happen"
180 }
181
182 # Scan a directory and its subdirectories for .java source files or
183 # .properties files. Note that we keep basedir and subdir separate so
184 # we can properly update our global data structures.
185 proc scan_directory {basedir subdir} {
186 global dir_map properties_map properties_files
187
188 set subdirs {}
189 set files {}
190 set here [pwd]
191 cd $basedir/$subdir
192 foreach file [lsort [glob -nocomplain *]] {
193 if {[string match *.java $file]} {
194 lappend files $subdir/$file
195 } elseif {[string match *.properties $file]} {
196 if {! [info exists properties_map($subdir)]} {
197 # We assume there aren't any overrides.
198 lappend properties_files $basedir/$subdir/$file
199 }
200 } elseif {[file isdirectory $file]} {
201 lappend subdirs $subdir/$file
202 } elseif {$subdir == "META-INF/services"} {
203 # All service files are included as properties.
204 lappend properties_files $basedir/$subdir/$file
205 }
206 }
207 cd $here
208
209 # Recurse first, so that we don't create new packages too eagerly.
210 foreach dir $subdirs {
211 scan_directory $basedir $dir
212 }
213
214 foreach file $files {
215 classify_source_file $basedir $file
216 }
217 }
218
219 # Scan known packages beneath the base directory for .java source
220 # files.
221 proc scan_packages {basedir} {
222 foreach subdir {gnu java javax org sun META-INF} {
223 if {[file exists $basedir/$subdir]} {
224 scan_directory $basedir $subdir
225 }
226 }
227 }
228
229 # Emit a rule for a 'bc' package.
230 proc emit_bc_rule {package} {
231 global package_map exclusion_map bc_objects
232
233 if {$package == "."} {
234 set pkgname ordinary
235 } else {
236 set pkgname $package
237 }
238 set varname [join [split $pkgname /] _]_source_files
239 set loname [join [split $pkgname /] -].lo
240 set tname [join [split $pkgname /] -].list
241
242 puts "$loname: \$($varname)"
243 # Create a temporary list file and then compile it. This works
244 # around the libtool problem mentioned in PR 21058. classpath was
245 # built first, so the class files are to be found there.
246 set omit ""
247 if {[info exists exclusion_map($package)]} {
248 set omit "| grep -v $exclusion_map($package)"
249 }
250 puts "\t@find \$(srcdir)/classpath/lib/$package -name '*.class'${omit} > $tname"
251 puts "\t\$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o $loname @$tname"
252 puts "\t@rm -f $tname"
253 puts ""
254
255 # We skip these because they are built into their own libraries and
256 # are handled specially in Makefile.am.
257 if {$loname != "gnu-java-awt-peer-qt.lo" && $loname != "gnu-java-awt-peer-x.lo"} {
258 lappend bc_objects $loname
259 }
260 }
261
262 # Emit a rule for a 'package' package.
263 proc emit_package_rule {package} {
264 global package_map exclusion_map package_files
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 base $pkgname
273 set lname $base.list
274 set dname $base.deps
275
276 if {$pkgname == "java/lang"} {
277 # Object and Class are special cases due to an apparent compiler
278 # bug. Process is a special case because we don't build all
279 # concrete implementations of Process on all platforms.
280 set omit "| tr ' ' '\\n' | fgrep -v Object.class | fgrep -v Class.class | grep -v '\[^/\]Process' "
281 } else {
282 set omit ""
283 }
284
285 # A rule to make the phony file we are going to compile.
286 puts "$lname: \$($varname)"
287 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
288 puts "\techo \$(srcdir)/classpath/lib/$package/*.class $omit> $lname"
289 puts ""
290 puts "-include $dname"
291 puts ""
292 puts ""
293
294 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"
295 && $pkgname != "gnu/gcj/tools/gcj_dbtool"} {
296 lappend package_files $lname
297 }
298 }
299
300 # Emit a package-like rule for a platform-specific Process
301 # implementation.
302 proc emit_process_package_rule {platform} {
303 set base "java/process-$platform"
304 set lname $base.list
305 set dname $base.deps
306
307 puts "$lname: java/lang/${platform}Process.java"
308 puts "\t@\$(mkinstalldirs) \$(dir \$@)"
309 puts "\techo \$(srcdir)/classpath/lib/java/lang/${platform}Process*.class > $lname"
310 puts ""
311 puts "-include $dname"
312 puts ""
313 puts ""
314 }
315
316 # Emit a source file variable for a package, and corresponding header
317 # file variable, if needed.
318 proc emit_source_var {package} {
319 global package_map name_map dir_map header_vars
320
321 if {$package == "."} {
322 set pkgname ordinary
323 } else {
324 set pkgname $package
325 }
326 set uname [join [split $pkgname /] _]
327 set varname ${uname}_source_files
328 puts -nonewline "$varname ="
329
330 makearray dirs
331 foreach base [lsort $name_map($package)] {
332 # Terminate previous line.
333 puts " \\"
334 # Having files start with './' is ugly and confuses the automake
335 # "dirstamp" code; see automake PR 461.
336 set ndir $dir_map($base)/
337 if {$ndir == "./"} {
338 set ndir ""
339 }
340 puts -nonewline "${ndir}${base}"
341 set dirs($dir_map($base)) 1
342 }
343 puts ""
344 puts ""
345
346 if {$package_map($package) != "bc"} {
347 # Ugly code to build up the appropriate patsubst.
348 set result "\$(patsubst %.java,%.h,\$($varname))"
349 # We use -decreasing so that classpath/external will be stripped
350 # before classpath.
351 foreach dir [lsort -decreasing [array names dirs]] {
352 if {$dir != "."} {
353 set result "\$(patsubst $dir/%,%,$result)"
354 }
355 }
356
357 if {$package == "." || $package == "java/lang"} {
358 # Ugly hack.
359 set result "\$(filter-out java/lang/Object.h java/lang/Class.h,$result)"
360 }
361
362 puts "${uname}_header_files = $result"
363 puts ""
364 if {$pkgname != "gnu/gcj/xlib" && $pkgname != "gnu/awt/xlib"} {
365 lappend header_vars "${uname}_header_files"
366 }
367 }
368 }
369
370 # Pretty-print a Makefile variable.
371 proc pp_var {name valueList {pre ""} {post ""}} {
372 puts ""
373 puts -nonewline "$name ="
374 foreach val $valueList {
375 puts " \\"
376 puts -nonewline " ${pre}${val}${post}"
377 }
378 puts ""
379 }
380
381 global argv
382 if {[llength $argv] > 0 && [lindex $argv 0] == "-verbose"} {
383 set is_verbose 1
384 }
385
386 # Read the proper .omit files.
387 read_omit_file standard.omit.in
388 read_omit_file classpath/lib/standard.omit.in
389
390 # Scan classpath first.
391 scan_packages classpath
392 scan_packages classpath/external/sax
393 scan_packages classpath/external/w3c_dom
394 scan_packages classpath/external/relaxngDatatype
395 scan_packages classpath/external/jsr166
396 # Resource files.
397 scan_packages classpath/resource
398 # Now scan our own files; this will correctly override decisions made
399 # when scanning classpath.
400 scan_packages .
401 # Files created by the build.
402 classify_source_file classpath gnu/java/locale/LocaleData.java
403 classify_source_file classpath gnu/java/security/Configuration.java
404
405 puts "## This file was automatically generated by scripts/makemake.tcl"
406 puts "## Do not edit!"
407 puts ""
408
409 foreach package [lsort [array names package_map]] {
410 if {$package_map($package) == "ignore"} {
411 continue
412 }
413 if {! [info exists name_map($package)]} {
414 continue
415 }
416
417 emit_source_var $package
418
419 if {$package_map($package) == "bc"} {
420 emit_bc_rule $package
421 } elseif {$package_map($package) == "ordinary"} {
422 # Nothing in particular to do here.
423 } elseif {$package_map($package) == "package"} {
424 emit_package_rule $package
425 } else {
426 error "unrecognized type: $package_map($package)"
427 }
428 }
429
430 emit_process_package_rule Ecos
431 emit_process_package_rule Win32
432 emit_process_package_rule Posix
433
434 pp_var all_packages_source_files $package_files
435 pp_var ordinary_header_files $header_vars "\$(" ")"
436 pp_var bc_objects $bc_objects
437 pp_var property_files $properties_files