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