2003/09/04 05:04:04
[org.ibex.core.git] / Makefile
1 #############################################################################
2 #
3 # The XWT Makefile
4 #
5
6 all:                   JVM Linux Win32 Java2 #Solaris
7 .SILENT: $(cc_objects) $(java_objects) $(java_headers) all build/xwar/builtin.xwar $(target_bin) compile
8
9
10 #############################################################################
11 # Configurables:
12 #
13 target_bin             := xwt.$(shell echo $(target) | tr A-Z a-z)
14 jikes_flags            := -verbose -nowarn -sourcepath src/
15 gcc_path               := upstream/install
16 gcc_optimizations      := -O2
17 #gcc_optimizations      := -O9 -ffast-math -fomit-frame-pointer -foptimize-sibling-calls -finline-functions -funroll-loops -ffunction-sections -fdata-sections
18 gcc_flags              := $(gcc_optimizations)
19 gcj_flags              := -fCLASSPATH=src
20 gcj                    := $(gcc_path)/bin/$(target)-gcj $(gcc_flags) $(gcj_flags)
21 g++                    := $(gcc_path)/bin/$(target)-g++ $(gcc_flags)
22 gcc                    := $(gcc_path)/bin/$(target)-gcc $(gcc_flags)
23 gcjh                   := $(gcc_path)/bin/$(target)-gcjh
24 as                     := $(gcc_path)/$(target)/bin/as
25 ar                     := $(gcc_path)/$(target)/bin/ar
26 ranlib                 := $(gcc_path)/$(target)/bin/ranlib
27 strip                  := $(gcc_path)/$(target)/bin/strip
28 jar                    := $(shell ((type fastjar &>/dev/null) && echo fastjar) || echo jar)
29
30
31
32 #############################################################################
33 # Overview:
34
35 # The Makefile has been divided into phases; each phase depends on the
36 # previous one.  Subphases of the same phase (ie 1a, 1b) are not
37 # interdependent.  You can think of the build process as proceeding
38 # through the phases in order, but processing subphases within a given
39 # phase in any order.
40 #
41
42
43 # PHASE 1a: human-written inputs
44 handwritten_java_sources      := $(shell find src -name \*.java)
45 handwritten_java_pp_sources   := $(shell find src -name \*.java.pp)
46 handwritten_mips_sources      := $(shell find src -name \*.mips.c)
47 handwritten_cc_sources        := src/org/xwt/plat/$(platform).cc
48 handwritten_c_sources         := $(jpeg_c_sources:%.c=src/org/ijg/%.c)
49 handwritten_xwar_sources      := $(shell ls src/org/xwt/builtin/*.png src/org/xwt/builtin/*.xwt src/org/xwt/builtin/*.xwf)
50
51
52 # PHASE 1b: upstream code
53 jpeg_c_sources    := jdapimin.c jdapistd.c jcomapi.c jcparam.c jdmaster.c jdinput.c jdmainct.c jdcoefct.c jdpostct.c jdmarker.c
54 jpeg_c_sources    += jdhuff.c jdphuff.c jddctmgr.c jidctint.c jidctfst.c jidctflt.c jidctred.c jdsample.c jdcolor.c jdmerge.c
55 jpeg_c_sources    += jquant1.c jquant2.c jerror.c jutils.c jmemnobs.c jmemmgr.c
56 jpeg_sources      := $(jpeg_c_sources:%.c=upstream/jpeg-6b/src/%.c)
57 $(jpeg_sources):
58         make -sC upstream jpeg-6b/.installed
59
60 freetype_sources    := $(patsubst %,upstream/freetype-2.1.4/src/src/base/%,ftsystem.c ftmm.c ftbbox.c ftinit.c ftdebug.c ftbase.c ftglyph.c)
61 freetype_sources    += $(patsubst %,upstream/freetype-2.1.4/src/src/%,smooth/smooth.c autohint/autohint.c sfnt/sfnt.c truetype/truetype.c)
62 $(freetype_sources):
63         make -sC upstream freetype-2.1.4/.installed
64
65 upstream/.jikes:
66         make -sC upstream .jikes
67
68 $(gcc_path)/bin/$(target)-gcj:
69         make -sC upstream gcc-3.3-$(target)
70
71
72 # PHASE 2: ready-to-compile java files (either symlinked to phase 1a sources or else generated from them)
73 java_sources    := $(handwritten_java_sources:src/%.java=build/java/%.java)
74 java_sources    += $(handwritten_java_pp_sources:src/%.java.pp=build/java/%.java)
75 java_sources    += $(handwritten_mips_sources:src/%.mips.c=build/java/%.java)
76 java_sources    += build/java/org/xwt/Builtin.java
77 $(handwritten_java_sources:src/%.java=build/java/%.java): build/java/%.java: src/%.java
78         @echo "symlinking                    :     $<"
79         @mkdir -p `dirname $@`;  \
80         cd `dirname $@`;                        \
81         A=`echo $@ | sed 's_[^/]*/_../_g'`;     \
82         B=`dirname $$A`;                        \
83         C=$$B/$<;                               \
84         ln -s $$C
85
86
87 # PHASE 3: class files
88 class_files           := $(java_sources:build/java/%.java=build/class/%.class)
89 class_files           += build/class/org/xwt/imp/Freetype.class
90
91 $(class_files): build/class/%.class: build/java/%.java upstream/.jikes
92         @echo "compiling          .java -> .class: $<"
93         @mkdir -p build/class
94         @upstream/.jikes $<
95
96 compile: $(java_sources)
97         @echo "compiling          .java -> .class: src/**/*.java"
98         @mkdir -p build/class
99         @upstream/.jikes $(java_sources)
100
101 # PHASE 4: gcj-generated headers
102 java_headers          := $(build_java_sources:build/java/%.java=build/h/%.h)
103 $(java_headers): build/h/%.h: build/%.class
104         @echo "extracting        .class -> .h:     $<"
105         cd build; find `echo $< | sed s/.class$$// | sed s_^build/__ `*.class |\
106                 sed s_/_._g | sed s/.class$$// | sed s/.java$$// |\
107                         xargs $(gcjh) --classpath .
108
109 # PHASE 4: object files
110 java_object_files          := $(filter-out build/$(platform)/org/xwt/plat/%, $(java_sources:src/%.java=build/$(platform)/%.java.o))
111 java_object_files          += $(pathsubst %,build/$(platform)/org/xwt/plat/%.java.o,GCJ $(platform_java_sources))
112 java_object_files          += build/$(platform)/org/xwt/imp/Freetype.java.o
113 cc_object_files            := $(handwritten_cc_sources:src/%.cc=build/$(platform)/%.cc.o)
114 c_object_files             := $(handwritten_c_sources:src/%.c=build/$(platform)/%.c.o)
115 $(java_objects): build/$(platform)/%.java.o: build/java/%.java
116         @echo "compiling          .java -> .o:     $<"
117         @mkdir -p `dirname $@`
118         $(gcj) -c $< -o $@
119 $(cc_object_files): build/$(platform)/%.cc.o: src/%.cc $(java_headers) src/org/ijg/jmorecfg.h
120         @echo "compiling            .cc -> .o:     $<"
121         @mkdir -p `dirname $@`
122         $(g++) -I/usr/X11R6/include/ -I$(gcc_path)/include -Ibuild/h -Iupstream/$(platform)/include -Wno-multichar -c $< -o $@
123 $(c_object_files): build/$(platform)/%.c.o: src/%.c src/org/ijg/jmorecfg.h
124         @echo "compiling             .c -> .o:     $<"
125         @mkdir -p `dirname $@`
126         $(gcc) -Ibuild/h -c $< -o $@
127
128 # PHASE 5: linking
129 $(target_bin): $(objects)
130         @echo "linking               .o -> $(target_bin)"
131         $(gcj) --main=org.xwt.Main -o build/$(platform)/$(target_bin) $^ $(platform_link) 
132
133
134 ##############################################################################
135 # Special treatment:
136 #
137
138 build/java/org/xwt/Builtin.java:: $(handwritten_xwar_sources)
139         @mkdir -p `dirname $@` build build/java build/class build/h build
140         @echo "zipping/uuencoding  .xwt -> .java:  build/java/org/xwt/Builtin.java"
141         @echo "package org.xwt;"                  >  build/java/org/xwt/Builtin.java
142         @echo "class Builtin {"                   >> build/java/org/xwt/Builtin.java
143         @echo "public static String encoded = "   >> build/java/org/xwt/Builtin.java
144         @cd src; $(jar) cf - $(handwritten_xwar_sources:src/%=%) | \
145                 uuencode foo | tail -n +2 | grep -v '^end$$' | grep -v '^`$$' | \
146                 sed 's_\(.+\)_"\1" +_' >> ../build/java/org/xwt/Builtin.java
147         @echo "\"\"; }"                           >> build/java/org/xwt/Builtin.java
148
149 postprocessed_sources   := $(handwritten_java_pp_sources:src/%.pp=build/java/%)
150 $(postprocessed_sources):  build/java/%.java: src/%.java.pp build/class/org/xwt/util/Preprocessor.class
151         @echo "preprocessing   .java.pp -> .java:  $<"
152         @mkdir -p `dirname $@`
153         @rm -f $@
154         @java -cp build/class org.xwt.util.Preprocessor < $< > $@
155
156 build/java/org/xwt/imp/Freetype.java:: build/mips/freetype.mips build/class/org/xwt/imp/MIPS.class
157         @echo "translating        .mips -> .java:  $@"
158         @mkdir -p build/java/org/xwt/imp/
159         @rm -f $@
160         @java -cp build/class org.xwt.imp.MIPS org.xwt.imp.Freetype build/mips/freetype.mips > build/java/org/xwt/imp/Freetype.java
161
162 build/mips/freetype.mips: $(freetype_mips_objects)
163         @echo "compiling             .c -> .mips:  $@"
164         @mkdir -p build/mips
165         @make -sC upstream newlib-1.11.0/src newlib-1.11.0/build-mips/.installed gcc-3.3-mips freetype-2.1.4/src .headers target=mips
166         @$(gcc_path)/bin/mips-gcc \
167                 --static \
168                 -mabi=32 \
169                 -mips1 \
170                 -msoft-float \
171                 -o $@ \
172                 -I upstream/freetype-2.1.4/src/include \
173                 $(freetype_sources) \
174                 -mno-crt0 \
175                 -Tnullmon.ld \
176                 -Wl,--warn-once \
177                 src/org/xwt/imp/Freetype.c \
178                 -Wl,-s
179
180
181
182 ##############################################################################
183 # Supported Platforms:
184 #
185
186 # compile is here to force compilation of the .class files (they get used via -Ibuild) without
187 # having the individual .o's depend on the .java's (otherwise every .o gets recompiled when one .java changes)
188 gcj: $(gcc_path)/bin/$(target)-gcj compile $(target_bin)
189         @echo -e "\\n=== $(target) ========================================="
190
191 Linux:
192         @make gcj platform=Linux target=i686-pc-linux-gnu platform_link="-L$(gcc_path)/lib -L/usr/X11R6/lib -lX11 -lXext --static" platform_java_sources="POSIX X11"
193
194 Solaris:
195         @make gcj platform=Solaris target=sparc-sun-solaris2.7 platform_link="-L$(gcc_path)/lib -lX11 -lXext" platform_java_sources="POSIX X11"
196
197 Win32:
198         @make gcj platform=Win32 target=i686-pc-mingw32 target_bin=xwt.exe platform_link="-Wl,--subsystem,windows -lcomdlg32" platform_java_sources=Win32
199
200 Carbon:
201         @make gcj platform=Carbon arget=powerpc-apple-darwin platform_link="$(gcc_path)/lib/libgcj.a -Xlinker -framework -Xlinker Carbon" platform_java_sources="POSIX Carbon"
202
203 JVM: compile
204         @echo -e "\\n=== JVM ========================================="
205         @echo "archiving         .class -> .jar:  build/JVM/xwt.jar"
206         @mkdir -p build/JVM
207         @echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > build/JVM/.manifest
208         @cd build/class; $(jar) cvfm ../JVM/xwt.jar ../JVM/.manifest \
209                 `find . -name \*.class | grep -v org/xwt/plat/` \
210                 org/xwt/plat/AWT*.class org/xwt/plat/Java2*.class | tr \\012 \\015 | \
211                 sed '_$$_                                                   _'
212         @echo
213
214
215
216 ##############################################################################
217 # Misc
218 #
219
220 clean:
221         find . -name \*~ | xargs rm -f
222         find . -name \#\*\# | xargs rm -f
223
224
225
226 ##############################################################################
227 # Maintainer stuff: generating numbered builds, proposing patches
228 #
229
230 update-build:
231         cvs tag -F xwt-$(current_build)
232         (echo -n 0000; (echo "10k16o16i"; cat next.build | tr a-z A-Z; echo "1+f") | dc) | tail --bytes=5 > next.build-
233         mv next.build- next.build
234         echo -n "Next build will be "
235         cat next.build
236         cvs update CHANGES
237         echo "" >> CHANGES
238         echo `date +%d-%b`" =========== build $(current_build) ================================================" >> CHANGES
239         echo committing...
240         cvs commit -m 'this comment should not appear in CHANGES' next.build CHANGES
241         echo committed.
242
243 propose-patch:
244         @echo -n "Please type a one-line description of this bug: "; \
245         read A; \
246         echo; \
247         echo "Please type any additional comments that explain this patch."; \
248         echo "If this patch fixes a bug, include a link to bugs.xwt.org."; \
249         echo "When you are done, press control-d on a new line."; \
250         echo; \
251         (       echo -e "HELO patcher"; \
252                 echo -e "MAIL FROM:$(USER)@xwt.org"; \
253                 echo -e "RCPT TO: patches@xwt.org"; \
254                 echo -e "DATA"; \
255                 echo -e "From: $(USER)@xwt.org"; \
256                 echo -e "To: patches@xwt.org"; \
257                 echo -e "Subject: proposed patch to $(this_branch): $$A"; \
258                 echo -e ""; \
259                 cat; \
260                 echo; \
261                 cvs diff -Bud; \
262                 echo .; \
263         ) > .message
264         bash -c "cat .message > /dev/tcp/mail.xwt.org/25"     # /dev/tcp is faked by bash; not part of the os
265
266 current_build         := $(shell cat next.build)
267 this_branch           := $(shell tail -c +2 CVS/Tag 2>/dev/null || echo HEAD)
268 this_branch_flag      := $(shell test $(this_branch) = HEAD && echo || echo -r $(this_branch))
269
270 # pre-depend on compile as a sanity check
271 dist: compile
272         # this will fail if we haven't checked-in since the comment is null; we want this.
273         cvs commit -m '' > /dev/null
274         cvs tag -F xwt-$(current_build)
275
276         echo "***********************************************************"
277         echo "*  This build is $(current_build)"
278         echo "***********************************************************"
279
280         ifeq ($(shell uname -n),serverbeach.megacz.com)
281                 (make $(silent) dist-private 2>&1) >> .make-dist.out || \
282                         (tail -n 200 .make-dist.out | mail -s "Build $(current_build) FAILED" cvs@xwt.org; false)
283                 tail -n 200 .make-dist.out | \
284                         mail -s "Unsigned binaries of $(current_build) are now available" cvs@xwt.org
285         else
286                 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"
287         endif
288
289 dist-private:
290         make $(silent) update-build
291
292         # preserve gcc across builds so we don't have to remake it
293         mkdir -p $(HOME)/dist.xwt.org-gcc
294         mv gcc gcc-
295         ln -s $(HOME)/dist.xwt.org-gcc gcc
296         mv -f gcc-/Makefile gcc/
297         mv -f gcc-/*.patch gcc/
298
299         # build it
300         nice -n 19 make all
301
302         echo
303         echo === master.dist.xwt.org ==================================
304
305         echo "copying xwt.jar to distribution area..."
306         cp xwt.jar /var/www/master.dist.xwt.org/xwt-$(current_build).jar.unsigned
307
308         echo "stripping xwt.exe and copying it to the distribution area..."
309         $(strip) build/Win32/xwt.exe -o /var/www/master.dist.xwt.org/xwt-$(current_build).exe.unsigned
310
311         echo "copying xwt.linux to distribution area..."
312         $(strip) build/Linux/xwt.linux -o /var/www/master.dist.xwt.org/xwt-$(current_build).linux.unsigned
313
314         echo "creating source tarball in distribution area..."
315         CVSROOT=/cvs cvs export -r xwt-$(current_build) xwt
316         mv xwt xwt-$(current_build)
317         tar cvzf /var/www/master.dist.xwt.org/xwt-$(current_build).tgz xwt-$(current_build)
318
319         echo
320         echo "*** DONE ******************************************"
321
322
323
324
325
326
327
328 #mips: $(prefix)/mips/lib/libm.a
329 #$(prefix)/mips/lib/libm.a: src/.newlib $(prefix)/bin/mips-gcc
330 #       mkdir -p build/$(target)/newlib
331 #       cd build/$(target)/newlib; PATH=$(prefix)/bin:$$PATH \
332 #               ../../../src/newlib-1.11.0/configure --nfp --enable-multilib --prefix=$(prefix) --target=mips
333 #       cd build/$(target)/newlib; PATH=$(prefix)/bin:$$PATH EXTRA_CFLAGS=-mstrict-align make
334 #       cd build/$(target)/newlib; make install
335 # FIXME: this is probably going to cause problems... figure out how to get by without it
336 #       touch .empty.c
337 #       $(prefix)/bin/mips-gcc -c .empty.c -o $(prefix)/mips/lib/crt0.o