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