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