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