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