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