2003/03/11 10:41:17
[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
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         cvs tag -F xwt-$(current_build)
62         (echo -n 0000; (echo "10k16o16i"; cat next.build | tr a-z A-Z; echo "1+f") | dc) | tail --bytes=5 > next.build-
63         mv next.build- next.build
64         echo -n "Next build will be "
65         cat next.build
66         cvs update CHANGES
67         echo "" >> CHANGES
68         echo `date +%d-%b`" =========== build $(current_build) ================================================" >> CHANGES
69         echo committing...
70         cvs commit -m 'this comment should not appear in CHANGES' next.build CHANGES
71         echo committed.
72
73
74 ## GCJ-Derived Platforms #######################################################################
75
76 # if the user doesn't change gcc_path, and it's not built, then we'll try to build it
77 $(shell pwd)/gcc/bin/$(target)-gcj:
78         cd gcc; make
79
80 gcj: compile $(gcc_path)/bin/$(target)-gcj .headers link
81
82 link: $(gcj_java_objects) $(cc_objects) bin-$(platform)/org/xwt/builtin.o
83         echo "linking       .o -> $(target_bin)"
84         $(ar) r bin-$(platform)/org/xwt/plat/platform.ar bin-$(platform)/org/xwt/plat/*.o
85         $(gcj) --main=org.xwt.Main -o bin-$(platform)/$(target_bin) $^ $(platform_link) bin-$(platform)/org/xwt/plat/platform.ar
86
87 .headers: $(jikes_java_objects)
88         cd bin; for A in `find * -name \*.class`; do \
89                 echo "extracting .class -> .h:     $$A"; \
90                 $(gcjh) --classpath . `echo $$A | sed s_/_._g | sed s/.class$$//`; \
91                 done
92         echo "extracting .class -> .h:     done"
93         touch .headers
94
95 # turn off optimization of Trap.java due to a compiler bug
96 bin-$(platform)/org/xwt/Trap.o: gcj_flags := -O0 -g
97
98 $(gcj_java_objects): bin-$(platform)/%.o: src/%.java $(jikes_java_objects)
99         echo -ne "compiling  .java -> .o:     $<"
100         mkdir -p `dirname $@`
101         $(gcj) -c $< -o $@
102
103 $(cc_objects): bin-$(platform)/%-nat.o: src/%.cc
104         echo -ne "compiling  .cc -> .o:     $$A"
105         $(gcc) -Ibin -c $< -o $@
106
107 bin-$(platform)/org/xwt/builtin.o: bin/org/xwt/builtin.xwar
108         echo "wrapping   .xwar -> .o"
109         $(gcj) --resource org/xwt/builtin.xwar -c $< -o $@
110
111
112
113 ## Platforms ##############################################################################
114
115 Linux:
116         echo -e "\\n=== Linux ========================================="
117         make gcj \
118                 platform=Linux \
119                 target=i686-pc-linux-gnu \
120                 target_bin=xwt.linux \
121                 platform_link="-L$(gcc-path)/lib -L/usr/X11R6/lib -lX11 -lXext --static" \
122                 platform_java_sources="src/org/xwt/plat/POSIX.java src/org/xwt/plat/X11.java"
123
124 Win32:
125         echo -e "\\n=== Win32 ========================================="
126         make gcj \
127                 platform=Win32 \
128                 target=i686-pc-mingw32 \
129                 target_bin=xwt.exe \
130                 platform_link="-Wl,--subsystem,windows -lcomdlg32" \
131                 platform_java_sources=src/org/xwt/plat/Win32.java
132
133 Java2: $(jikes_java_objects) bin/org/xwt/builtin.xwar
134         echo -e "\\n=== Java2 ========================================="
135         echo "archiving .class -> .jar"
136         mkdir -p bin-Java2
137         echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > bin/.manifest
138         cd bin; fastjar cvf ../bin-Java2/xwt.jar -m .manifest \
139                 org/xwt/builtin.xwar \
140                 `find . -name \*.class | grep -v org/xwt/plat/` \
141                 org/xwt/plat/AWT*.class org/xwt/plat/Java2*.class | tr \\012 \\015
142         echo
143
144 $(java2_objects:bin/%=%)
145
146 PalmOS:
147         echo "PalmOS is not yet supported"
148         false
149
150
151 ## master.dist.xwt.org ############################################################################
152
153 current_build         := $(shell cat next.build)
154
155 dist:
156         # this will fail if we haven't checked-in since the comment is null; we want this.
157         cvs commit -m '' > /dev/null
158         cvs tag -F xwt-$(current_build)
159
160         echo "***********************************************************"
161         echo "*  This build is $(current_build)"
162         echo "***********************************************************"
163
164         ifeq ($(shell uname -n),gosset.megacz.com)
165                 (make $(silent) dist-private 2>&1) >> .make-dist.out || \
166                         (tail -n 200 .make-dist.out | mail -s "Build $(current_build) FAILED" cvs@xwt.org; false)
167                 tail -n 200 .make-dist.out | \
168                         mail -s "Unsigned binaries of $(current_build) are now available" cvs@xwt.org
169         else
170                 ssh xwt@xwt.org verbose=$(verbose) /home/xwt/dist $(current_build) \
171                         | grep -v "make...:.\(Entering\|Leaving\).directory"
172         endif
173
174
175 dist-private:
176         make $(silent) update-build
177
178         # preserve gcc across builds so we don't have to remake it
179         mv gcc/Makefile Makefile.gcc
180         mkdir -p $(HOME)/dist.xwt.org-gcc
181         rm -rf gcc
182         ln -s $(HOME)/dist.xwt.org-gcc gcc
183         mv Makefile.gcc gcc/Makefile
184
185         # build it
186         nice -n 19 make all
187
188         echo
189         echo === master.dist.xwt.org ==================================
190
191         echo "copying xwt.jar to distribution area..."
192         cp bin-Java2/xwt.jar /var/www/master.dist.xwt.org/xwt-$(current_build).jar.unsigned
193
194         echo "stripping xwt.exe and copying it to the distribution area..."
195         $(strip) bin-Win32/xwt.exe -o /var/www/master.dist.xwt.org/xwt-$(current_build).exe.unsigned
196
197         echo "copying xwt.linux to distribution area..."
198         $(strip) bin-Linux/xwt.linux -o /var/www/master.dist.xwt.org/xwt-$(current_build).linux.unsigned
199
200         echo "creating source tarball in distribution area..."
201         CVSROOT=/cvs cvs export -r xwt-$(current_build) xwt
202         mv xwt xwt-$(current_build)
203         tar cvzf /var/www/master.dist.xwt.org/xwt-$(current_build).tgz xwt-$(current_build)
204
205         echo
206         echo "*** DONE ******************************************"