OSDN Git Service

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