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