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