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