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