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