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