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