2003/08/23 05:43:39
[org.ibex.core.git] / Makefile
1 #           
2 # The XWT Makefile
3 #
4
5 ## Configurables ###########################################################################
6
7 jpeg_headers := jpeglib.h jconfig.h jmorecfg.h jerror.h jinclude.h jpegint.h jchuff.h jdhuff.h jdct.h jmemsys.h jversion.h
8 jpeg_c_sources := jdapimin.c jdapistd.c jcomapi.c jcparam.c jdmaster.c jdinput.c jdmainct.c jdcoefct.c jdpostct.c jdmarker.c
9 jpeg_c_sources += jdhuff.c jdphuff.c jddctmgr.c jidctint.c jidctfst.c jidctflt.c jidctred.c jdsample.c jdcolor.c jdmerge.c
10 jpeg_c_sources += jquant1.c jquant2.c jerror.c jutils.c jmemnobs.c jmemmgr.c
11
12 # inputs
13 java_pp_sources        := $(shell find src -name \*.java.pp)
14 java_pp_postproc       := $(java_pp_sources:src/%.java.pp=build/java/%.java)
15 java_generated_sources := $(java_pp_postproc) build/java/org/xwt/imp/Freetype.java
16 java_sources           := $(shell find src -name \*.java)
17 java_headers           := $(java_sources:src/%.java=build/h/%.h) $(java_generated_sources:build/java/%.java=build/h/%.h)
18 xwar_sources           := $(shell ls src/org/xwt/builtin/*.png src/org/xwt/builtin/*.xwt src/org/xwt/builtin/*.xwf)
19 cc_sources             := src/org/xwt/plat/$(platform).cc
20 c_sources              := $(jpeg_c_sources:%.c=src/org/ijg/%.c)
21
22 # freetype inputs
23 freetype_base_sources  := ftsystem.c ftmm.c ftbbox.c ftinit.c ftdebug.c ftbase.c ftglyph.c
24 freetype_other_sources := smooth/smooth.c autohint/autohint.c sfnt/sfnt.c truetype/truetype.c
25 freetype_sources       := $(freetype_base_sources:%=gcc/src/freetype-2.1.4/src/base/%)
26 freetype_sources       += $(freetype_other_sources:%=gcc/src/freetype-2.1.4/src/%)
27
28 # outputs
29 java_objects           := $(filter-out build/$(platform)/org/xwt/plat/%, $(java_sources:src/%.java=build/$(platform)/%.java.o))
30 java_objects           += $(java_generated_sources:build/java/%.java=build/$(platform)/%.java.o)
31 java_objects           += build/$(platform)/org/xwt/plat/GCJ.java.o
32 java_objects           += $(platform_java_sources:%=build/$(platform)/org/xwt/plat/%.java.o)
33 cc_objects             := $(cc_sources:src/%.cc=build/$(platform)/%.cc.o)
34 c_objects              := $(c_sources:src/%.c=build/$(platform)/%.c.o)
35
36 # tools
37 gcc_path               := $(shell pwd)/gcc/install
38 #gcc_optimizations      := -O9 -ffast-math -fomit-frame-pointer -foptimize-sibling-calls -finline-functions
39 #gcc_optimzations       += -funroll-loops -ffunction-sections -fdata-sections
40 gcc_optimizations      := -O2
41 debug                  := 
42 gcc_flags              := $(gcc_optimizations) $(debug) -Isrc/org/ijg
43 gcj_flags              := -fCLASSPATH=src
44 gcj                    := $(gcc_path)/bin/$(target)-gcj $(gcj_flags) $(gcc_flags)
45 g++                    := $(gcc_path)/bin/$(target)-g++ $(gcc_flags)
46 gcc                    := $(gcc_path)/bin/$(target)-gcc $(gcc_flags)
47 gcjh                   := $(gcc_path)/bin/$(target)-gcjh
48
49 as                     := $(gcc_path)/$(target)/bin/as
50 ar                     := $(gcc_path)/$(target)/bin/ar
51 ranlib                 := $(gcc_path)/$(target)/bin/ranlib
52 strip                  := $(gcc_path)/$(target)/bin/strip
53 jar                    := $(shell ((type fastjar &>/dev/null) && echo fastjar) || echo jar)
54
55 # path
56 PATH                   := jikes-1.18/bin:$(PATH)
57
58
59 ## Platform-Neutral ###########################################################################
60
61 ifneq ($(verbose),true)
62 .SILENT: $(cc_objects) $(java_objects) $(java_headers) all build/xwar/builtin.xwar $(target_bin) compile
63 silent := --silent
64 endif
65
66 compile: .javac $(java_generated_sources) build/xwar/builtin.xwar
67         echo "compiling          .java -> .class: [all]"
68         mkdir -p build
69         $(shell cat .javac) -classpath lib/libgcj-minimal.jar $(java_sources) $(java_generated_sources) -d build/ 2>&1 | \
70                 grep -v ^\\[read | sed s_^\\[write\ build/__ | sed s_.class\\]_.java_ | sed "s_^_compiling          .java -> .class: src/_"
71
72 build/%.class: src/%.java .javac
73         @echo "compiling          .java -> .class: $<"
74         @mkdir -p build
75         @$(shell cat .javac) -classpath lib/libgcj-minimal.jar $< -d build/ 2>&1 | \
76                 grep -v ^\\[read | sed s_^\\[write\ build/__ | sed s_.class\\]_.java_ | sed "s_^_compiling          .java -> .class: src/_"
77
78 $(java_pp_postproc): build/java/%.java: src/%.java.pp build/org/xwt/util/Preprocessor.class
79         @echo "preprocessing   .java.pp -> .java:  $<"
80         @mkdir -p `dirname $@`
81         @java -cp build org.xwt.util.Preprocessor < $< > $@
82
83 # platforms
84 all: Win32 Linux Java2 #Solaris
85
86 .javac:
87         @if \
88                 type jikes && (jikes --version | grep "Version 1.18"); \
89         then \
90                 echo "public class GetBootClassPath { public static void main(String[] s) { " > GetBootClassPath.java; \
91                 echo "System.out.println(System.getProperty(\"sun.boot.class.path\")); } }" >> GetBootClassPath.java; \
92                 javac GetBootClassPath.java; \
93                 java -cp . GetBootClassPath > .bootclasspath; \
94                 rm GetBootClassPath.*; \
95                 echo -n "jikes -verbose -nowarn -sourcepath src/ -bootclasspath " > .javac; \
96                 cat .bootclasspath >> .javac; \
97         else \
98                 echo "WARNING: You do not have jikes; falling back to javac.  Compiles will be very slow."; \
99                 echo javac > .javac; \
100         fi
101
102 jikes:
103         curl ftp://www-126.ibm.com/pub/jikes/1.18/jikes-1.18.tar.bz2 | tar xjvf -
104         cd jikes-1.18; ./configure --prefix=`pwd` && make && make install
105         ln -sf jikes-1.18/bin/jikes .jikes
106
107 build/xwar/builtin.xwar: $(xwar_sources)
108         mkdir -p build/xwar
109         cd src; $(jar) cf ../build/xwar/builtin.xwar $(xwar_sources:src/%=%)
110
111 clean:
112         rm -rf build
113         find . -name \*~ | xargs rm -f
114         find . -name \#\*\# | xargs rm -f
115
116 update-build:
117         cvs tag -F xwt-$(current_build)
118         (echo -n 0000; (echo "10k16o16i"; cat next.build | tr a-z A-Z; echo "1+f") | dc) | tail --bytes=5 > next.build-
119         mv next.build- next.build
120         echo -n "Next build will be "
121         cat next.build
122         cvs update CHANGES
123         echo "" >> CHANGES
124         echo `date +%d-%b`" =========== build $(current_build) ================================================" >> CHANGES
125         echo committing...
126         cvs commit -m 'this comment should not appear in CHANGES' next.build CHANGES
127         echo committed.
128
129 propose-patch:
130         @echo -n "Please type a one-line description of this bug: "; \
131         read A; \
132         echo; \
133         echo "Please type any additional comments that explain this patch."; \
134         echo "If this patch fixes a bug, include a link to bugs.xwt.org."; \
135         echo "When you are done, press control-d on a new line."; \
136         echo; \
137         (       echo -e "HELO patcher"; \
138                 echo -e "MAIL FROM:$(USER)@xwt.org"; \
139                 echo -e "RCPT TO: patches@xwt.org"; \
140                 echo -e "DATA"; \
141                 echo -e "From: $(USER)@xwt.org"; \
142                 echo -e "To: patches@xwt.org"; \
143                 echo -e "Subject: proposed patch to $(this_branch): $$A"; \
144                 echo -e ""; \
145                 cat; \
146                 echo; \
147                 cvs diff -Bud; \
148                 echo .; \
149         ) > .message
150         bash -c "cat .message > /dev/tcp/mail.xwt.org/25"     # /dev/tcp is faked by bash; not part of the os
151
152 ## GCJ-Derived Platforms #######################################################################
153
154 # if the user doesn't change gcc_path, and it's not built, then we'll try to build it
155 $(shell pwd)/gcc/install/bin/$(target)-gcj: .upstream
156         make -C gcc
157
158 gcc/src/.freetype:
159         mkdir -p gcc/src
160         curl http://umn.dl.sourceforge.net/sourceforge/freetype/freetype-2.1.4.tar.gz | tar xvzf - -C gcc/src
161         cd gcc/src; patch -p0 < freetype.patch
162         touch gcc/src/.freetype
163
164 build/mips/freetype.mips: gcc/src/.freetype
165         mkdir -p build/mips
166         make -C gcc mips target=mips
167         $(gcc_path)/bin/mips-gcc \
168                 --static \
169                 -mabi=32 \
170                 -mips1 \
171                 -msoft-float \
172                 -o $@ \
173                 -I gcc/src/freetype-2.1.4/include \
174                 $(freetype_sources) \
175                 -Wl,--warn-once \
176                 src/org/xwt/imp/Freetype.c \
177                 $(gcc_path)/mips/lib/libm.a \
178                 -Wl,-s,-T,$(gcc_path)/mips/lib/nullmon.ld
179
180 build/java/org/xwt/imp/Freetype.java: build/mips/freetype.mips build/org/xwt/imp/MIPS.class
181         @echo "translating        .mips -> .java:  $<"
182         @mkdir -p build/java/org/xwt/imp/
183         @java -cp build org.xwt.imp.MIPS org.xwt.imp.Freetype build/mips/freetype.mips > build/java/org/xwt/imp/Freetype.java
184
185 # compile is here to force compilation of the .class files (they get used via -Ibuild) without
186 # having the individual .o's depend on the .java's (otherwise every .o gets recompiled when one .java changes)
187 gcj: $(gcc_path)/bin/$(target)-gcj compile $(target_bin)
188
189 $(target_bin): $(java_objects) $(cc_objects) $(c_objects) build/$(platform)/org/xwt/builtin.o
190         @echo "linking               .o -> $(target_bin)"
191         $(gcj) --main=org.xwt.Main -o build/$(platform)/$(target_bin) $^ $(platform_link) 
192
193 build/$(platform)/org/xwt/builtin.o: build/xwar/builtin.xwar
194         @echo "wrapping           .xwar -> .o:     build/$(platform)/org/xwt/builtin.o"
195         @(echo "unsigned int builtin_xwar_length = ";\
196           (wc -c build/xwar/builtin.xwar | sed "s_build.*__");\
197           echo \;;\
198           echo "unsigned char builtin_xwar[] = {";\
199           hexdump -ve '"0x" 1/1 "%x,\n"' build/xwar/builtin.xwar;\
200           echo "};") > .builtin.c
201         $(gcc) -c .builtin.c -o build/$(platform)/org/xwt/builtin.o
202
203 $(java_headers): build/h/%.h: build/%.class
204         @echo "extracting        .class -> .h:     $<"
205         cd build; find `echo $< | sed s/.class$$// | sed s_^build/__ `*.class |\
206                 sed s_/_._g | sed s/.class$$// | sed s/.java$$// |\
207                         xargs $(gcjh) --classpath .
208
209 $(java_objects): build/$(platform)/%.java.o: src/%.java
210         @echo "compiling          .java -> .o:     $<"
211         mkdir -p `dirname $@`
212         $(gcj) -c $< -o $@
213
214 # unpack and patch the ijg library
215 src/org/ijg/jmorecfg.h: src/org/ijg/jpegsrc.v6b.tar.gz src/org/ijg/jmorecfg.h.patch
216         cd src/org/ijg/; tar xzf jpegsrc.v6b.tar.gz
217         cd src/org/ijg/jpeg-6b; ./configure --target=$(target)
218         cd src/org/ijg/jpeg-6b; mv $(jpeg_c_sources) $(jpeg_headers) ..
219         cd src/org/ijg; patch -l -p0 < jmorecfg.h.patch
220         rm -rf src/org/ijg/jpeg-6b
221
222 $(cc_objects): build/$(platform)/%.cc.o: src/%.cc $(java_headers) src/org/ijg/jmorecfg.h
223         @echo "compiling            .cc -> .o:     $<"
224         @mkdir -p `dirname $@`
225         $(g++) -I/usr/X11R6/include/ -I$(gcc_path)/include -Ibuild/h -Iupstream/$(platform)/include -Wno-multichar -c $< -o $@
226
227 $(c_objects): build/$(platform)/%.c.o: src/%.c src/org/ijg/jmorecfg.h
228         @echo "compiling             .c -> .o:     $<"
229         @mkdir -p `dirname $@`
230         $(gcc) -Ibuild/h -c $< -o $@
231
232 .upstream:
233         mkdir -p gcc/install; curl http://www.megacz.com/upstream.tgz | tar xvzhf - -C gcc/install
234         touch .upstream
235
236
237 ## Platforms ##############################################################################
238
239 Linux:
240         echo -e "\\n=== Linux ========================================="
241         make gcj \
242                 platform=Linux \
243                 target=i686-pc-linux-gnu \
244                 target_bin=xwt.linux \
245                 platform_link="-L$(gcc_path)/lib -L/usr/X11R6/lib -lX11 -lXext --static" \
246                 platform_java_sources="POSIX X11"
247
248 Solaris:
249         echo -e "\\n=== Solaris ========================================="
250         make gcj \
251                 platform=Solaris \
252                 target=sparc-sun-solaris2.7 \
253                 target_bin=xwt.solaris \
254                 platform_link="-L$(gcc_path)/lib -lX11 -lXext" \
255                 platform_java_sources="POSIX X11"
256
257 Win32:
258         echo -e "\\n=== Win32 ========================================="
259         make gcj \
260                 platform=Win32 \
261                 target=i686-pc-mingw32 \
262                 target_bin=xwt.exe \
263                 platform_link="-Wl,--subsystem,windows -lcomdlg32" \
264                 platform_java_sources="Win32"
265
266 Darwin:
267         echo -e "\\n=== Darwin ========================================="
268         ranlib upstream/Darwin/lib/*.a
269         ar x /usr/lib/libcc_dynamic.a upstream/Darwin/lib/darwin-fpsave.o
270         make gcj \
271                 platform=Darwin \
272                 target=powerpc-apple-darwin \
273                 target_bin=xwt.darwin \
274                 platform_link="upstream/Darwin/lib/*.[oa] $(gcc_path)/lib/libgcj.a" \
275                 platform_java_sources="POSIX X11"
276
277 Carbon:
278         echo -e "\\n=== Carbon ========================================="
279         make gcj \
280                 platform=Carbon \
281                 target=powerpc-apple-darwin \
282                 target_bin=xwt.carbon \
283                 platform_link="$(gcc_path)/lib/libgcj.a -Xlinker -framework -Xlinker Carbon" \
284                 platform_java_sources="POSIX Carbon"
285
286 JVM: compile build/xwar/builtin.xwar
287         echo -e "\\n=== JVM ========================================="
288         echo "archiving         .class -> .jar"
289         mkdir -p build/JVM
290         echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > bin/.manifest
291         cd build; $(jar) cvfm ../xwt.jar .manifest \
292                 org/xwt/builtin.xwar \
293                 `find . -name \*.class | grep -v org/xwt/plat/` \
294                 org/xwt/plat/AWT*.class org/xwt/plat/Java2*.class | tr \\012 \\015
295         echo
296
297 PalmOS:
298         echo "PalmOS is not yet supported"
299         false
300
301
302 ## master.dist.xwt.org ############################################################################
303
304 current_build         := $(shell cat next.build)
305 this_branch           := $(shell tail -c +2 CVS/Tag 2>/dev/null || echo HEAD)
306 this_branch_flag      := $(shell test $(this_branch) = HEAD && echo || echo -r $(this_branch))
307
308 # pre-depend on compile as a sanity check
309 dist: compile
310         # this will fail if we haven't checked-in since the comment is null; we want this.
311         cvs commit -m '' > /dev/null
312         cvs tag -F xwt-$(current_build)
313
314         echo "***********************************************************"
315         echo "*  This build is $(current_build)"
316         echo "***********************************************************"
317
318         ifeq ($(shell uname -n),serverbeach.megacz.com)
319                 (make $(silent) dist-private 2>&1) >> .make-dist.out || \
320                         (tail -n 200 .make-dist.out | mail -s "Build $(current_build) FAILED" cvs@xwt.org; false)
321                 tail -n 200 .make-dist.out | \
322                         mail -s "Unsigned binaries of $(current_build) are now available" cvs@xwt.org
323         else
324                 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"
325         endif
326
327
328 dist-private:
329         make $(silent) update-build
330
331         # preserve gcc across builds so we don't have to remake it
332         mkdir -p $(HOME)/dist.xwt.org-gcc
333         mv gcc gcc-
334         ln -s $(HOME)/dist.xwt.org-gcc gcc
335         mv -f gcc-/Makefile gcc/
336         mv -f gcc-/*.patch gcc/
337
338         # build it
339         nice -n 19 make all
340
341         echo
342         echo === master.dist.xwt.org ==================================
343
344         echo "copying xwt.jar to distribution area..."
345         cp xwt.jar /var/www/master.dist.xwt.org/xwt-$(current_build).jar.unsigned
346
347         echo "stripping xwt.exe and copying it to the distribution area..."
348         $(strip) build/Win32/xwt.exe -o /var/www/master.dist.xwt.org/xwt-$(current_build).exe.unsigned
349
350         echo "copying xwt.linux to distribution area..."
351         $(strip) build/Linux/xwt.linux -o /var/www/master.dist.xwt.org/xwt-$(current_build).linux.unsigned
352
353         echo "creating source tarball in distribution area..."
354         CVSROOT=/cvs cvs export -r xwt-$(current_build) xwt
355         mv xwt xwt-$(current_build)
356         tar cvzf /var/www/master.dist.xwt.org/xwt-$(current_build).tgz xwt-$(current_build)
357
358         echo
359         echo "*** DONE ******************************************"