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