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