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