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