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