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