2004/01/17 23:07:20
[org.ibex.core.git] / Makefile
1 #############################################################################
2 #
3 # The XWT Makefile
4
5 #
6
7 all:      JVM Linux Win32 Darwin Solaris
8
9 clean:
10         rm -rf build
11
12 dist-clean:
13         rm -rf .jikes .configure* .install* build .compile .build*
14         find upstream -name config.cache -exec rm {} \;
15
16 JVM:        build/JVM/xwt.jar
17 Linux:    ; make gcj platform=Linux   link_flags="-lX11 -lXext"
18 Solaris:  ; make gcj platform=Solaris link_flags="-lX11 -lXext -lpthread"
19 Win32:    ; make gcj platform=Win32   link_flags="-Wl,--subsystem,windows -lcomdlg32"
20 Darwin:   ; make gcj platform=Darwin  link_flags="$(darwin_linker_flags)"
21
22 # default
23 platform            := JVM
24
25 darwin_libdir       := upstream/install/powerpc-apple-darwin/lib
26 darwin_linker_flags := -Wl,-dylib_file,/usr/lib/libSystem.B.dylib:$(darwin_libdir)/libSystem.B.dylib
27 darwin_linker_flags += -Wl,-dylib_file,/usr/lib/system/libmathCommon.A.dylib:$(darwin_libdir)/libmathCommon.A.dylib
28 darwin_linker_flags += -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:$(darwin_libdir)/libGL.dylib
29 darwin_linker_flags += -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib:$(darwin_libdir)/libGLU.dylib
30 darwin_linker_flags += -lSystem.B -lmathCommon.A -lGL -lGLU
31
32 target_Darwin := powerpc-apple-darwin
33 target_Win32  := i686-pc-mingw32
34 target_Solaris := sparc-sun-solaris2.7
35 target_Linux := i686-pc-linux-gnu
36 target := $(target_$(platform))
37
38 gcj: .install_gcc-3.3_$(target); make $(target_bin) link_flags="$(link_flags)" platform=$(platform)
39
40 #############################################################################
41 # Configurables:
42 #
43 ifeq ($(platform),Win32)
44 target_bin             := build/$(platform)/xwt.exe
45 else
46 target_bin             := build/$(platform)/xwt.$(shell echo $(platform) | tr A-Z a-z)
47 endif
48 jikes_flags            := -nowarn -sourcepath src/
49 gcc_optimizations      := -O2
50 #gcc_optimizations      := -O9 -ffast-math -fomit-frame-pointer -foptimize-sibling-calls
51 #gcc_optimizations      += -finline-functions -funroll-loops -ffunction-sections -fdata-sections
52 gcc_flags              := -nostdinc $(gcc_optimizations) -Ibuild/h -Iupstream/jpeg-6b/src/ -Iupstream/jpeg-6b/build-$(target)/
53 gcj_flags              := -fCLASSPATH=build/java
54 gcj                    := upstream/install/bin/$(target)-gcj $(gcc_flags) $(gcj_flags)
55 gcjh                   := $(shell test -e `pwd`/upstream/install/bin/$(target)-gcjh && echo `pwd`/upstream/install/bin/$(target)-gcjh || echo `pwd`/upstream/install/bin/gcjh)
56 g++                    := upstream/install/bin/$(target)-gcj $(gcc_flags)
57 gcc                    := upstream/install/bin/$(target)-gcc $(gcc_flags)
58 jar                    := $(shell ((type fastjar &>/dev/null) && echo fastjar) || echo jar)
59
60 include Makefile.upstream
61
62 # figure out what stuff in org.xwt.plat.* this platform requires (its superclasses)
63 java_sources      := $(patsubst src/%.java,     build/java/%.java, $(shell find src -name '*.java' | grep -v Preprocessor))
64 all_java_sources  := $(java_sources)
65
66 nonplat_java_sources      := $(filter-out build/java/org/xwt/plat/%, $(java_sources)) build/java/org/xwt/translators/Freetype.java build/java/org/xwt/translators/MSPack.java build/java/org/xwt/translators/MIPSApps.java 
67 plat_java_sources         := $(filter build/java/org/xwt/plat/%, $(java_sources))
68
69 build/java/org/xwt/translators/MIPSApps.java: build/mips/mipsapps.mips
70         make build/class/org/xwt/mips/Compiler.class
71         mkdir -p build/java/org/xwt/translators
72         @echo -e "\n\033[1mtranslating        .mips -> .java:  $<\033[0m"
73         (echo -e 'package org.xwt.translators;\nimport org.xwt.mips.*;\n'; \
74          java -Xint -cp build/class org.xwt.mips.Compiler MIPSApps build/mips/mipsapps.mips)\
75          | sed 's,//.*$$,,;'|tr -d '\n'  > $@
76
77 build/java/org/xwt/%.java: src/org/xwt/%.java
78         make build/class/org/xwt/util/Preprocessor.class
79         @echo -e "\n\033[1mpreprocessing      .java -> .java:  $<\033[0m"
80         mkdir -p `dirname $@`; java -cp build/class org.xwt.util.Preprocessor < $< > $@
81
82 build/java/%.java: src/%.java ; @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
83
84 build/cc/%.cc:     src/%.c    ; @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
85 build/c/jpeg/%.c:     upstream/jpeg-6b/src/%.c
86         @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
87 build/res/%:       src/%      ; @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
88
89 build/class/org/xwt/translators/MIPSApps.class: build/java/org/xwt/translators/MIPSApps.java .jikes
90         @echo -e "\n\033[1mcompiling          .java -> .class: $<\033[0m"
91         mkdir -p build/class/org/xwt/translators
92         ./.jikes -g:none $<
93
94 build/class/org/xwt/util/Preprocessor.class: src/org/xwt/util/Preprocessor.java .jikes
95         @echo -e "\n\033[1mcompiling          .java -> .class: $<\033[0m"
96         mkdir -p build/class/org/xwt/util/
97         ./.jikes $<
98
99 build/class/org/xwt/mips/Compiler.class: src/org/xwt/mips/*.java
100         make .jikes
101         @echo -e "\n\033[1mcompiling          .java -> .class: $<\033[0m"
102         mkdir -p build/class/org/xwt/mips/
103         ./.jikes $<
104
105 # this forces a clean build every time because jikes is so damn buggy
106 preprocess: $(java_sources)
107 compile: .compile
108 .compile: build/class/org/xwt/translators/MIPSApps.class $(java_sources) .jikes 
109         @echo -e "\n\033[1mcompiling          .java -> .class: src/**/*.java\033[0m"
110         @rm -f $(java_sources:build/java/%.java=build/class/%.class)
111         mkdir -p build/class
112         @./.jikes $(java_sources)
113         touch .compile
114
115 # PHASE 4: gcj-generated headers
116 java_headers          := $(all_java_sources:build/java/%.java=build/h/%.h) 
117 build/h/edu/stanford/ejalbert/BrowserLauncher.h:; mkdir -p $(@D); touch $@
118 build/h/%.h: build/class/%.class .compile
119         @echo -e "\n\033[1mextracting        .class -> .h:     $<\033[0m"
120         mkdir -p `dirname $@`
121         ls `echo $< | sed s/.class\$$//`*.class |\
122                  sed s_build/class/__ | sed s/.class\$$//g | sed s_/_._g | (cd build/class; xargs $(gcjh) -d ../h --classpath .)
123
124 # a hack since we've disabled gcj's awt implementation
125 build/$(platform)/org/xwt/plat/Java2.java.o:
126         touch .empty.c; mkdir -p $(@D); $(gcc) -c .empty.c -o $@;
127 build/$(platform)/org/xwt/translators/MIPSApps.java.o: build/class/org/xwt/translators/MIPSApps.class .install_gcc-3.3_$(target)
128         @echo -e "\n\033[1mcompiling         .class -> .o:     $<\033[0m"
129         mkdir -p `dirname $@`
130         $(gcj) -Os -c $< -o $@
131 build/$(platform)/org/xwt/plat/AWT.java.o:
132         touch .empty.c; mkdir -p $(@D); $(gcc) -c .empty.c -o $@;
133 build/$(platform)/%.java.o: build/java/%.java .install_gcc-3.3_$(target)
134         @echo -e "\n\033[1mcompiling          .java -> .o:     $<\033[0m"
135         mkdir -p `dirname $@`
136         $(gcj) -c $< -o $@
137
138 headers: $(java_headers)
139
140 build/$(platform)/org/xwt/plat/$(platform).cc.o: src/org/xwt/plat/$(platform).cc src/org/xwt/plat/*.cc .configure_jpeg-6b_$(target)
141         @make headers
142         @echo -e "\n\033[1mcompiling            .cc -> .o:     $<\033[0m"
143         mkdir -p `dirname $@`
144         $(g++) -Iupstream/install/lib/gcc-lib/$(target)/3.3/include/ -Iupstream/install/$(target)/include -I/usr/X11R6/include/  -Ibuild/h -Wno-multichar -Iupstream/install/include -c $< -o $@
145
146 build/$(platform)/jpeg-6b/%.c.o: upstream/jpeg-6b/src/%.c
147         @echo -e "\n\033[1mcompiling             .c -> .o:     $<\033[0m"
148         mkdir -p `dirname $@`
149         $(gcc) -Ibuild/h -c $< -o $@
150
151 # PHASE 5: linking
152 # FIXME use libjpeg
153 jpeg_sources    := jdapimin.c jdapistd.c jcomapi.c jcparam.c jdmaster.c jdinput.c jdmainct.c jdcoefct.c jdpostct.c jdmarker.c
154 jpeg_sources    += jdhuff.c jdphuff.c jddctmgr.c jidctint.c jidctfst.c jidctflt.c jidctred.c jdsample.c jdcolor.c jdmerge.c
155 jpeg_sources    += jquant1.c jquant2.c jerror.c jutils.c jmemnobs.c jmemmgr.c
156
157 upstream/jpeg-6b/build-$(target)/libjpeg.a: .install_jpeg-6b_$(target)
158 java_objects := $(nonplat_java_sources:build/java/%.java=build/$(platform)/%.java.o)
159
160 build/$(platform)/$(platform).ar: $(java_objects) $(plat_java_sources:build/java/%.java=build/$(platform)/%.java.o)
161         @echo -e "\n\033[1marchiving             .o -> .a\033[0m"
162         mkdir -p build/$(platform)
163         rm -f $@
164         upstream/install/$(target)/bin/ar rc $@ $^
165         upstream/install/$(target)/bin/ranlib $@
166
167 $(target_bin): build/$(platform)/org/xwt/plat/$(platform).cc.o upstream/jpeg-6b/build-$(target)/libjpeg.a build/$(platform)/builtin.o build/$(platform)/$(platform).ar 
168         @echo -e "\n\033[1mlinking               .o -> $(target_bin)\033[0m"
169         mkdir -p build/$(platform)
170         PATH=upstream/install/bin:$$PATH $(gcj) -v --main=org.xwt.Main -o $@ -Lupstream/install/$(target)/lib build/$(platform)/org/xwt/plat/$(platform).java.o $^ $(link_flags)
171
172
173 ##############################################################################
174 # Special treatment:
175 #
176
177 builtin_src := $(shell find src/org/xwt/builtin -name '*.*' \! -name '*.xcf')
178 build/res/fonts/vera: .download_vera-1.10
179         mkdir -p build/res/fonts/vera
180         cd build/res/fonts/vera; ln -s ../../../../upstream/vera-1.10/ttf-bitstream-vera-1.10/Vera.ttf
181         cd build/res/fonts/vera; ln -s ../../../../upstream/vera-1.10/ttf-bitstream-vera-1.10/VeraMono.ttf
182         cd build/res/fonts/vera; ln -s ../../../../upstream/vera-1.10/ttf-bitstream-vera-1.10/VeraSe.ttf
183 build/res/builtin.jar: $(builtin_src:src/%=build/res/%) build/res/fonts/vera
184         @echo -e "\n\033[1mzipping            res/* -> .jar: builtin.jar\033[0m"
185         cd build/res; $(jar) cf builtin.jar $(^:build/res/%=%)
186
187 build/$(platform)/builtin.o: build/res/builtin.jar
188         @echo -e "\n\033[1mwrapping            .jar -> .o: resources.o\033[0m"
189         @(echo "unsigned int builtin_length = ";                                \
190                 (wc -c build/res/builtin.jar | sed "s_build.*__");              \
191                 echo \;;                                                        \
192                 echo "unsigned char builtin_bytes[] = {";                       \
193                 hexdump -ve '"0x" 1/1 "%x,\n"' build/res/builtin.jar;           \
194                 echo "};") > .builtin.c
195         $(gcc) -c .builtin.c -o build/$(platform)/builtin.o
196
197 build/JVM/xwt.jar: .compile build/res/builtin.jar
198         @echo -e "\n\033[1marchiving         .class -> .jar:   build/JVM/xwt.jar\033[0m"
199         mkdir -p build/JVM
200         echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > build/JVM/.manifest
201         cd build/class/org/xwt; ln -sf ../../../res/builtin.jar
202         cd build/class; $(jar) cfm ../JVM/xwt.jar ../JVM/.manifest \
203                 `find . \! -type d \! -path './org/xwt/mips/*'` \
204                 $(patsubst %,org/xwt/mips/%*.class, Runtime Registers Syscalls Errno)
205
206
207
208 ##############################################################################
209 # Freetype
210 #
211
212 build/mips/%.c.o: src/%.c .download_libmspack-20030726
213         make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
214         make .install_libmspack-20030726_mips-unknown-elf target=mips-unknown-elf
215         mkdir -p $(@D)
216         echo -e "\n\033[1mcompiling $< -> $@ (mips)\033[0m"
217         upstream/install/bin/mips-unknown-elf-gcc -march=r3000 \
218                 -Iupstream/freetype-2.1.4/src/include  \
219                 -Iupstream/libmspack-20030726/src/mspack \
220                 -c -o $@ $<
221
222 build/mips/mipsapps.mips: build/mips/org/xwt/translators/Freetype.c.o build/mips/org/xwt/translators/MSPack.c.o build/mips/org/xwt/translators/main.c.o
223         make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
224         make .install_libmspack-20030726_mips-unknown-elf target=mips-unknown-elf
225         @echo -e "\n\033[1mlinking               .o -> .mips:  $@\033[0m"
226         mkdir -p build/mips build/res
227         upstream/install/bin/mips-unknown-elf-gcc \
228                 --static \
229                 -march=mips1 \
230                 -T upstream/mips/org/xwt/mips/linker.ld \
231                 -L upstream/mips/build/org/xwt/mips/ \
232                 -L upstream/freetype-2.1.4/src/objs \
233                 -L upstream/libmspack-20030726/build-mips-unknown-elf/ \
234                 -o $@ \
235                 $^ \
236                 -lfreetype \
237                 -lmspack \
238                 -Wl,--gc-sections
239
240 ##############################################################################
241 # Maintainer stuff: generating numbered builds, proposing patches
242 #
243
244 update-build:
245         cvs tag -F xwt-$(current_build)
246         (echo -n 0000; (echo "10k16o16i"; cat next.build | tr a-z A-Z; echo "1+f") | dc) | tail --bytes=5 > next.build-
247         mv next.build- next.build
248         echo -n "Next build will be "
249         cat next.build
250         cvs update CHANGES
251         echo "" >> CHANGES
252         echo `date +%d-%b`" =========== build $(current_build) ================================================" >> CHANGES
253         echo committing...
254         cvs commit -m 'this comment should not appear in CHANGES' next.build CHANGES
255         echo committed.
256
257 propose-patch:
258         @echo -n "Please type a one-line description of this bug: "; \
259         read A; \
260         echo; \
261         echo "Please type any additional comments that explain this patch."; \
262         echo "If this patch fixes a bug, include a link to bugs.xwt.org."; \
263         echo "When you are done, press control-d on a new line."; \
264         echo; \
265         (       echo -e "HELO patcher"; \
266                 echo -e "MAIL FROM:$(USER)@xwt.org"; \
267                 echo -e "RCPT TO: patches@xwt.org"; \
268                 echo -e "DATA"; \
269                 echo -e "From: $(USER)@xwt.org"; \
270                 echo -e "To: patches@xwt.org"; \
271                 echo -e "Subject: proposed patch to $(this_branch): $$A"; \
272                 echo -e ""; \
273                 cat; \
274                 echo; \
275                 cvs diff -Bud; \
276                 echo .; \
277         ) > .message
278         bash -c "cat .message > /dev/tcp/mail.xwt.org/25"     # /dev/tcp is faked by bash; not part of the os
279
280 current_build         := $(shell cat next.build)
281 this_branch           := $(shell tail -c +2 CVS/Tag 2>/dev/null || echo HEAD)
282 this_branch_flag      := $(shell test $(this_branch) = HEAD && echo || echo -r $(this_branch))
283
284 # pre-depend on compile as a sanity check
285 dist: compile
286         echo "***********************************************************"
287         echo "*  This build is $(current_build)"
288         echo "***********************************************************"
289
290         ifeq ($(shell uname -n),megacz.com)
291                 (make $(silent) dist-private 2>&1) >> .make-dist.out || \
292                         (tail -n 200 .make-dist.out | mail -s "Build $(current_build) FAILED" cvs@xwt.org; false)
293                 tail -n 200 .make-dist.out | \
294                         mail -s "Unsigned binaries of $(current_build) are now available" cvs@xwt.org
295         else
296                 # this will fail if we haven't checked-in since the comment is null; we want this.
297                 cvs commit -m '' > /dev/null
298                 cvs tag -F xwt-$(current_build)
299
300 #               echo -e 'export JAVA_HOME=/usr/lib/j2sdk1.4\n cd /home/xwt\n date=`date +%d-%b-%H%M`\n mkdir xwt-$$date\n cd xwt-$$date\n /usr/bin/cvs -d /cvs co $(this_branch_flag) xwt\n mv xwt/* .\n mv xwt/.* .\n rmdir xwt\n touch .make-dist.out\n nohup make dist &\n echo\n cat .make-dist.out' | ssh xwt@xwt.org | grep -v "make...:.\(Entering\|Leaving\).directory"
301                 echo -e 'export JAVA_HOME=/usr/lib/j2sdk1.4\n cd /home/xwt/dist\n/usr/bin/cvs update $(this_branch_flag)\ntouch .make-dist.out\n make clean\n nohup make dist &\n' | ssh xwt@xwt.org | grep -v "make...:.\(Entering\|Leaving\).directory"
302         endif
303
304 dist-private:
305         make $(silent) update-build
306
307         # build it
308         nice -n 19 make all
309
310         echo
311         echo === master.dist.xwt.org ==================================
312
313         echo "copying xwt.jar to distribution area..."
314         cp build/JVM/xwt.jar /var/www/master.dist.xwt.org/xwt-$(current_build).jar.unsigned
315
316         echo "stripping xwt.exe and copying it to the distribution area..."
317         upstream/install/i686-pc-mingw32/bin/strip build/Win32/xwt.exe \
318                 -o /var/www/master.dist.xwt.org/xwt-$(current_build).exe.unsigned
319
320         echo "copying xwt.linux to distribution area..."
321         upstream/install/i686-pc-linux-gnu/bin/strip build/Linux/xwt.linux \
322                 -o /var/www/master.dist.xwt.org/xwt-$(current_build).linux.unsigned
323
324 #       echo "copying xwt.solaris to distribution area..."
325 #       upstream/install/sparc-sun-solaris2.7/bin/strip build/Solaris/xwt.solaris \
326 #               -o /var/www/master.dist.xwt.org/xwt-$(current_build).solaris.unsigned
327
328         echo "copying xwt.darwin to distribution area..."
329         upstream/install/powerpc-apple-darwin/bin/strip build/Darwin/xwt.darwin \
330                 -o /var/www/master.dist.xwt.org/xwt-$(current_build).darwin.unsigned
331
332         echo "creating source tarball in distribution area..."
333         CVSROOT=/cvs cvs export -r xwt-$(current_build) xwt
334         mv xwt xwt-$(current_build)
335         tar cvzf /var/www/master.dist.xwt.org/xwt-$(current_build).tgz xwt-$(current_build)
336
337         echo
338         echo "*** DONE ******************************************"
339
340
341 # this is for Adam; don't mess with it
342 #test: JVM; /System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Commands/java -jar build/JVM/xwt.jar http://localhost/demo.xwar
343 test: JVM; java -jar build/JVM/xwt.jar http://localhost/demo.xwar
344
345 oldcompile: preprocess; CLASSPATH=$$CLASSPATH:lib/libgcj-minimal.jar javac -d build/class `find build/java/ -name \*.java`