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