2003/03/05 07:40:25
[org.ibex.core.git] / Makefile
1 #           
2 # The XWT Makefile
3 #
4
5 ## Configurables ###########################################################################
6
7 # inputs
8 jikes_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 jikes_java_objects     := $(jikes_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 jikes                  := jikes -bootclasspath /System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Classes/classes.jar -extdirs ${JAVA_HOME}/jre/lib -nowarn
28
29 # platforms
30 all_platforms          := Win32 Linux Java2 Darwin
31
32
33 ## Platform-Neutral ###########################################################################
34
35 ifneq ($(verbose),true)
36 .SILENT: $(jikes_java_objects) .headers $(gcj_java_objects) $(all_platforms) bin/org/xwt/builtin.xwar
37 silent := --silent
38 endif
39
40 compile: $(jikes_java_objects) bin/org/xwt/builtin.xwar
41
42 all: $(all_platforms)
43
44 $(jikes_java_objects): $(jikes_java_sources)
45         test "$(JAVA_HOME)"x != x || (echo "you forgot to set your JAVA_HOME environment variable"; false)
46         echo "compiling  .java -> .class:"
47         mkdir -p bin
48         $(jikes) -sourcepath src/ -classpath lib/libgcj-minimal.jar $(jikes_java_sources) -d bin/
49         echo "compiling  .java -> .class: done"
50
51 bin/org/xwt/builtin.xwar: $(xwar_sources)
52         mkdir -p bin/org/xwt
53         cd src; fastjar cf ../bin/org/xwt/builtin.xwar $(xwar_sources:src/%=%)
54
55 clean:
56         rm -rf bin-* bin
57         find . -name \*~ | xargs rm -f
58         find . -name \#\*\# | xargs rm -f
59
60 update-build:
61         (echo -n 0000; (echo "10k16o16i"; cat next.build | tr a-z A-Z; echo "1+f") | dc) | tail --bytes=5 > next.build-
62         mv next.build- next.build
63         echo -n "Next build will be "
64         cat next.build
65         cvs update CHANGES
66         echo "" >> CHANGES
67         echo `date +%d-%b`" =========== build $(current_build) ================================================" >> CHANGES
68         echo committing...
69         cvs commit -m 'this comment should not appear in CHANGES' next.build CHANGES
70         echo committed.
71
72
73 ## GCJ-Derived Platforms #######################################################################
74
75 # if the user doesn't change gcc_path, and it's not built, then we'll try to build it
76 $(shell pwd)/gcc/bin/$(target)-gcj:
77         cd gcc; make
78
79 gcj: compile $(gcc_path)/bin/$(target)-gcj .headers link
80
81 link: $(gcj_java_objects) $(cc_objects) bin-$(platform)/org/xwt/builtin.o
82         echo "linking       .o -> $(target_bin)"
83         $(ar) r bin-$(platform)/org/xwt/plat/platform.ar bin-$(platform)/org/xwt/plat/*.o
84         $(gcj) --main=org.xwt.Main -o bin-$(platform)/$(target_bin) $^ $(platform_link) bin-$(platform)/org/xwt/plat/platform.ar
85
86 .headers: $(jikes_java_objects)
87         cd bin; for A in `find * -name \*.class`; do \
88                 echo "extracting .class -> .h:     $$A"; \
89                 $(gcjh) --classpath . `echo $$A | sed s_/_._g | sed s/.class$$//`; \
90                 done
91         echo "extracting .class -> .h:     done"
92         touch .headers
93
94 # turn off optimization of Trap.java due to a compiler bug
95 bin-$(platform)/org/xwt/Trap.o: gcj_flags := -O0 -g
96
97 $(gcj_java_objects): bin-$(platform)/%.o: src/%.java $(jikes_java_objects)
98         echo -ne "compiling  .java -> .o:     $<"
99         mkdir -p `dirname $@`
100         $(gcj) -c $< -o $@
101
102 $(cc_objects): bin-$(platform)/%-nat.o: src/%.cc
103         echo -ne "compiling  .cc -> .o:     $$A"
104         $(gcc) -Ibin -c $< -o $@
105
106 bin-$(platform)/org/xwt/builtin.o: bin/org/xwt/builtin.xwar
107         echo "wrapping   .xwar -> .o"
108         $(gcj) --resource org/xwt/builtin.xwar -c $< -o $@
109
110
111
112 ## Platforms ##############################################################################
113
114 Linux:
115         echo -e "\\n=== Linux ========================================="
116         make gcj \
117                 platform=Linux \
118                 target=i686-pc-linux-gnu \
119                 target_bin=xwt.linux \
120                 platform_link="-L$(gcc-path)/lib -L/usr/X11R6/lib -lX11 -lXext --static" \
121                 platform_java_sources="src/org/xwt/plat/POSIX.java src/org/xwt/plat/X11.java"
122
123 Darwin:
124         echo -e "\\n=== Darwin ========================================="
125         make gcj \
126                 platform=Darwin \
127                 target=powerpc-apple-darwin \
128                 target_bin=xwt-x11.darwin \
129                 platform_link="-L$(gcc-path)/lib -L/usr/X11R6/lib -lX11 -lXext --static" \
130                 platform_java_sources="src/org/xwt/plat/POSIX.java src/org/xwt/plat/X11.java"
131
132 Win32:
133         echo -e "\\n=== Win32 ========================================="
134         make gcj \
135                 platform=Win32 \
136                 target=i686-pc-mingw32 \
137                 target_bin=xwt.exe \
138                 platform_link="-Wl,--subsystem,windows -lcomdlg32" \
139                 platform_java_sources=src/org/xwt/plat/Win32.java
140
141 Java2: $(jikes_java_objects) bin/org/xwt/builtin.xwar
142         echo -e "\\n=== Java2 ========================================="
143         echo "archiving .class -> .jar"
144         mkdir -p bin-Java2
145         echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > bin/.manifest
146         cd bin; fastjar cvf ../bin-Java2/xwt.jar -m .manifest \
147                 org/xwt/builtin.xwar \
148                 `find . -name \*.class | grep -v org/xwt/plat/` \
149                 org/xwt/plat/AWT*.class org/xwt/plat/Java2*.class | tr \\012 \\015
150         echo
151
152 $(java2_objects:bin/%=%)
153
154 PalmOS:
155         echo "PalmOS is not yet supported"
156         false
157
158
159 ## master.dist.xwt.org ############################################################################
160
161 current_build         := $(shell cat next.build)
162
163 dist:
164         # this will fail if we haven't checked-in since the comment is null; we want this.
165         cvs commit -m '' > /dev/null
166
167         echo "***********************************************************"
168         echo "*  This build is $(current_build)"
169         echo "***********************************************************"
170
171         ifeq ($(shell uname -n),gosset.megacz.com)
172                 (make $(silent) dist-private 2>&1) >> .make-dist.out || \
173                         (tail -n 200 .make-dist.out | mail -s "Build $(current_build) FAILED" cvs@xwt.org; false)
174                 tail -n 200 .make-dist.out | \
175                         mail -s "Unsigned binaries of $(current_build) are now available" cvs@xwt.org
176         else
177                 ssh xwt@xwt.org verbose=$(verbose) /home/xwt/dist \
178                         | grep -v "make...:.\(Entering\|Leaving\).directory"
179         endif
180
181
182 dist-private:
183         make $(silent) update-build
184
185         # preserve gcc across builds so we don't have to remake it
186         mv gcc/Makefile Makefile.gcc
187         mkdir -p $(HOME)/dist.xwt.org-gcc
188         rm -rf gcc
189         ln -s $(HOME)/dist.xwt.org-gcc gcc
190         mv Makefile.gcc gcc/Makefile
191
192         # build it
193         nice -n 19 make all
194
195         echo
196         echo === master.dist.xwt.org ==================================
197
198         echo "copying xwt.jar to distribution area..."
199         cp bin-Java2/xwt.jar /var/www/master.dist.xwt.org/xwt-$(current_build).jar.unsigned
200
201         echo "stripping xwt.exe and copying it to the distribution area..."
202         $(strip) bin-Win32/xwt.exe -o /var/www/master.dist.xwt.org/xwt-$(current_build).exe.unsigned
203
204         echo "copying xwt.linux to distribution area..."
205         $(strip) bin-Linux/xwt.linux -o /var/www/master.dist.xwt.org/xwt-$(current_build).linux.unsigned
206
207         echo
208         echo "*** DONE ******************************************"