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