2003/02/28 04:50:57
[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 -not -path src/org/xwt/plat/\*) src/org/xwt/plat/GCJ.java $(platform_java_sources)
10 xwar_sources           := $(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/$(target)-gcjh
25 ar                     := $(gcc_path)/$(target)/bin/ar
26 strip                  := $(gcc_path)/$(target)/bin/strip
27 jikes                  := jikes -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         (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 Win32:
124         echo -e "\\n=== Win32 ========================================="
125         make gcj \
126                 platform=Win32 \
127                 target=i686-pc-mingw32 \
128                 target_bin=xwt.exe \
129                 platform_link="-Wl,--subsystem,windows -lcomdlg32" \
130                 platform_java_sources=src/org/xwt/plat/Win32.java
131
132 Java2: $(jikes_java_objects) bin/org/xwt/builtin.xwar
133         echo -e "\\n=== Java2 ========================================="
134         echo "archiving .class -> .jar"
135         mkdir -p bin-Java2
136         echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > bin/.manifest
137         cd bin; fastjar cvf ../bin-Java2/xwt.jar -m .manifest \
138                 org/xwt/builtin.xwar \
139                 `find . -name \*.class | grep -v org/xwt/plat/` \
140                 org/xwt/plat/AWT*.class org/xwt/plat/Java2*.class | tr \\012 \\015
141         echo
142
143 $(java2_objects:bin/%=%)
144
145 PalmOS:
146         echo "PalmOS is not yet supported"
147         false
148
149
150 ## master.dist.xwt.org ############################################################################
151
152 current_build         := $(shell cat next.build)
153
154 dist:
155         # this will fail if we haven't checked-in since the comment is null; we want this.
156         cvs commit -m '' > /dev/null
157
158         echo "***********************************************************"
159         echo "*  This build is $(current_build)"
160         echo "***********************************************************"
161
162         ifeq ($(shell uname -n),gosset.megacz.com)
163                 (make $(silent) dist-private 2>&1) >> .make-dist.out || \
164                         (tail -n 200 .make-dist.out | mail -s "Build $(current_build) FAILED" cvs@xwt.org; false)
165                 tail -n 200 .make-dist.out | \
166                         mail -s "Unsigned binaries of $(current_build) are now available" cvs@xwt.org
167         else
168                 ssh xwt@xwt.org verbose=$(verbose) /home/xwt/dist \
169                         | grep -v "make...:.\(Entering\|Leaving\).directory"
170         endif
171
172
173 dist-private:
174         make $(silent) update-build
175
176         # preserve gcc across builds so we don't have to remake it
177         mv gcc/Makefile Makefile.gcc
178         mkdir -p $(HOME)/dist.xwt.org-gcc
179         rm -rf gcc
180         ln -s $(HOME)/dist.xwt.org-gcc gcc
181         mv Makefile.gcc gcc/Makefile
182
183         # build it
184         nice -n 19 make all
185
186         echo
187         echo === master.dist.xwt.org ==================================
188
189         echo "copying xwt.jar to distribution area..."
190         cp bin-Java2/xwt.jar /var/www/master.dist.xwt.org/xwt-$(current_build).jar.unsigned
191
192         echo "stripping xwt.exe and copying it to the distribution area..."
193         $(strip) bin-Win32/xwt.exe -o /var/www/master.dist.xwt.org/xwt-$(current_build).exe.unsigned
194
195         echo "copying xwt.linux to distribution area..."
196         $(strip) bin-Linux/xwt.linux -o /var/www/master.dist.xwt.org/xwt-$(current_build).linux.unsigned
197
198         echo
199         echo "*** DONE ******************************************"