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