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