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