2004/01/20 06:42:17
[org.ibex.core.git] / Makefile
1 #############################################################################
2 #
3 # The XWT Makefile
4 #
5
6 target_Darwin := powerpc-apple-darwin
7 target_Win32  := i686-pc-mingw32
8 target_Solaris := sparc-sun-solaris2.7
9 target_Linux := i686-pc-linux-gnu
10 target := $(target_$(platform))
11
12 all:         JVM Linux Win32 Darwin Solaris
13
14 clean:      ; rm -rf build
15 dist-clean:
16         rm -rf .jikes .configure* .install* build .compile .build*
17         find upstream -name config.cache -exec rm {} \;
18         test -e upstream/mips && make -C upstream/mips clean
19
20 JVM:        build/JVM/xwt.jar
21 Linux:    ; make gcj platform=Linux   link_flags="-lX11 -lXext"
22 Solaris:  ; make gcj platform=Solaris link_flags="-lX11 -lXext -lpthread"
23 Win32:    ; make gcj platform=Win32   link_flags="-Wl,--subsystem,windows -lcomdlg32"
24 Darwin:   ; make gcj platform=Darwin  link_flags="$(darwin_linker_flags)"
25
26 darwin_libdir       := upstream/install/powerpc-apple-darwin/lib
27 darwin_linker_flags := -Wl,-dylib_file,/usr/lib/libSystem.B.dylib:$(darwin_libdir)/libSystem.B.dylib
28 darwin_linker_flags += -Wl,-dylib_file,/usr/lib/system/libmathCommon.A.dylib:$(darwin_libdir)/libmathCommon.A.dylib
29 darwin_ogl_libdir   := /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries
30 darwin_linker_flags += -Wl,-dylib_file,$(darwin_ogl_libdir)/libGL.dylib:$(darwin_libdir)/libGL.dylib
31 darwin_linker_flags += -Wl,-dylib_file,$(darwin_ogl_libdir):$(darwin_libdir)/libGLU.dylib
32 darwin_linker_flags += -lSystem.B -lmathCommon.A -lGL -lGLU
33
34 # stupid broke-ass darwin linker...
35 darwin_linker_flags += build/Darwin/org/xwt/plat/OpenGL.java.o build/Darwin/org/xwt/plat/POSIX.java.o
36
37 target_bin_extension_$(platform) := $(shell echo $(platform) | tr A-Z a-z)
38 target_bin_extension_Win32       := exe
39 target_bin_extension_JVM         := jar
40 target_bin_extension             := $(target_bin_extension_$(platform))
41 target_bin                       := xwt.$(target_bin_extension)
42
43 jikes_flags        := -nowarn
44 gcc_optimizations  := -O2
45 #gcc_optimizations  := -O9 -ffast-math -fomit-frame-pointer -foptimize-sibling-calls
46 #gcc_optimizations  += -finline-functions -funroll-loops -ffunction-sections -fdata-sections
47
48 gcc_flags          := -nostdinc $(gcc_optimizations) -Ibuild/h -Iupstream/jpeg-6b/src -Iupstream/jpeg-6b/build-$(target)
49 gcc_flags          += -Iupstream/install/lib/gcc-lib/$(target)/3.3/include -Iupstream/install/$(target)/include
50 gcj                := upstream/install/bin/$(target)-gcj $(gcc_flags) -fCLASSPATH=build/java
51 gcjh               := $(shell pwd)/upstream/install/bin/$(shell test -e upstream/install/bin/$(target)-gcjh && echo $(target)-)gcjh
52 g++                := upstream/install/bin/$(target)-gcj $(gcc_flags) -Iupstream/install/include -Wno-multichar
53 gcc                := upstream/install/bin/$(target)-gcc $(gcc_flags)
54 jar                := $(shell ((type fastjar &>/dev/null) && echo fastjar) || echo jar)
55
56 gcj: .install_gcc-3.3_$(target); make build/$(platform)/$(target_bin) link_flags="$(link_flags)" platform=$(platform)
57
58 include Makefile.upstream
59
60 java_sources              := $(patsubst src/%.java,     build/java/%.java, $(shell find src -name '*.java' | grep -v Preprocessor))
61 java_sources              += build/java/org/xwt/mips/Errno.java
62 java_sources              += build/java/org/xwt/mips/Unistd.java
63 java_sources              += build/java/org/xwt/mips/Syscalls.java
64 java_sources              += build/java/org/xwt/mips/Registers.java
65 java_sources              += build/java/org/xwt/mips/Runtime.java
66 java_sources              += build/java/org/xwt/mips/UnixRuntime.java
67 java_sources              += build/java/org/xwt/mips/util/SeekableByteArray.java
68 java_sources              += build/java/org/xwt/mips/util/SeekableData.java
69 java_sources              += build/java/org/xwt/mips/util/SeekableFile.java
70 java_sources              += build/java/org/xwt/mips/util/SeekableInputStream.java
71
72 build/java/org/xwt/mips/util/%: .install_mips2java
73         @echo linking $@
74         @mkdir -p $(@D)
75         @cd $(@D); ln -sf ../../../../../../upstream/mips/org/xwt/mips/util/$*
76 build/java/org/xwt/mips/%: .install_mips2java
77         @echo linking $@
78         @mkdir -p $(@D)
79         @test -e upstream/mips/build/org/xwt/mips/$* && (cd $(@D); \
80                 ln -sf ../../../../../upstream/mips/build/org/xwt/mips/$*); true
81         @test -e upstream/mips/org/xwt/mips/$* && (cd $(@D); \
82                 ln -sf ../../../../../upstream/mips/org/xwt/mips/$*); true
83
84
85 ### Java Class Files ##############################################################################
86
87 build/class/org/xwt/translators/MIPSApps.class: build/mips/mipsapps.mips .jikes
88         mkdir -p build/java/org/xwt/translators
89         @echo -e "\n\033[1mtranslating        .mips -> .java:  $<\033[0m"
90         (echo -e 'package org.xwt.translators;\nimport org.xwt.mips.*;\n';                           \
91          java -Xint -cp upstream/mips/build org.xwt.mips.Compiler MIPSApps build/mips/mipsapps.mips) \
92          | sed 's,//.*$$,,;'| tr -d '\n') > build/java/org/xwt/translators/MIPSApps.java
93         @echo -e "\n\033[1mcompiling          .java -> .class: $<\033[0m"
94         ./.jikes -g:none build/java/org/xwt/translators/MIPSApps.java
95
96 build/java/org/xwt/%.java: src/org/xwt/%.java
97         make build/class/org/xwt/util/Preprocessor.class
98         @echo -e "\n\033[1mpreprocessing      .java -> .java:  $<\033[0m"
99         mkdir -p `dirname $@`; java -cp build/class org.xwt.util.Preprocessor < $< > $@
100
101 build/java/%.java: src/%.java ; @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
102 build/cc/%.cc:     src/%.c    ; @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
103 build/res/%:       src/%      ; @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
104
105 build/class/org/xwt/util/Preprocessor.class: src/org/xwt/util/Preprocessor.java .jikes
106         @echo -e "\n\033[1mcompiling          .java -> .class: $<\033[0m"
107         mkdir -p build/class/org/xwt/util/
108         ./.jikes $<
109
110 oldcompile:; CLASSPATH=$$CLASSPATH:lib/libgcj-minimal.jar:upstream/mips/build javac -d build/class `find build/java/ -name \*.java`
111 compile: .compile
112 .compile: $(java_sources) .jikes .install_mips2java
113         @echo -e "\n\033[1mcompiling          .java -> .class: src/**/*.java\033[0m"
114         @rm -f $(java_sources:build/java/%.java=build/class/%.class)
115         mkdir -p build/class
116         @./.jikes $(java_sources)
117         touch .compile
118
119 build/JVM/xwt.jar: .compile build/res/builtin.jar
120         @echo -e "\n\033[1marchiving         .class -> .jar:   build/JVM/xwt.jar\033[0m"
121         mkdir -p build/JVM
122         echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > build/JVM/.manifest
123         cd build/class/org/xwt; ln -sf ../../../res/builtin.jar
124         cd build/class; $(jar) cfm ../JVM/xwt.jar ../JVM/.manifest \
125                 `find . \! -type d \! -path './org/xwt/mips/*'` \
126                 $(patsubst %,../../upstream/mips/build/org/xwt/mips/%*.class, Runtime Registers Syscalls Errno)
127
128
129 ### GCJH Headers ##############################################################################
130
131 java_headers          := $(java_sources:build/java/%.java=build/h/%.h) 
132 build/h/edu/stanford/ejalbert/BrowserLauncher.h:; mkdir -p $(@D); touch $@
133 build/h/%.h: build/class/%.class .compile
134         @echo -e "\n\033[1mextracting        .class -> .h:     $<\033[0m"
135         mkdir -p `dirname $@`
136         ls `echo $< | sed s/.class\$$//`*.class |\
137                  sed s_build/class/__ | sed s/.class\$$//g | sed s_/_._g | (cd build/class; xargs $(gcjh) -d ../h --classpath .)
138
139
140 ### Native Code ##############################################################################
141
142 # a hack since we've disabled gcj's awt implementation
143 build/$(platform)/org/xwt/plat/Java2.java.o: ; touch .empty.c; mkdir -p $(@D); $(gcc) -c .empty.c -o $@;
144 build/$(platform)/org/xwt/plat/AWT.java.o:   ; touch .empty.c; mkdir -p $(@D); $(gcc) -c .empty.c -o $@;
145
146 build/$(platform)/org/xwt/translators/MIPSApps.java.o: build/class/org/xwt/translators/MIPSApps.class
147         @echo -e "\n\033[1mcompiling         .class -> .o:     $<\033[0m"
148         mkdir -p `dirname $@`
149         $(gcj) -Os -c $< -o $@
150
151 build/$(platform)/%.java.o: build/java/%.java
152         @echo -e "\n\033[1mcompiling          .java -> .o:     $<\033[0m"
153         mkdir -p `dirname $@`
154         $(gcj) -c $< -o $@
155
156 build/$(platform)/org/xwt/plat/$(platform).cc.o: src/org/xwt/plat/$(platform).cc src/org/xwt/plat/*.cc .configure_jpeg-6b_$(target)
157         @make $(java_headers)
158         @echo -e "\n\033[1mcompiling            .cc -> .o:     $<\033[0m"
159         mkdir -p `dirname $@`
160         $(g++) -c $< -o $@
161
162 nonplat_java_sources := $(filter-out build/java/org/xwt/plat/$(platform).java,$(java_sources))
163 build/$(platform)/$(platform).ar: $(nonplat_java_sources:build/java/%.java=build/$(platform)/%.java.o)
164         @echo -e "\n\033[1marchiving             .o -> .a\033[0m"
165         mkdir -p build/$(platform)
166         rm -f $@
167         upstream/install/$(target)/bin/ar rc $@ $^
168         upstream/install/$(target)/bin/ranlib $@
169
170 upstream/jpeg-6b/build-$(target)/libjpeg.a: .install_jpeg-6b_$(target)
171 build/$(platform)/$(target_bin): build/$(platform)/org/xwt/plat/$(platform).cc.o upstream/jpeg-6b/build-$(target)/libjpeg.a build/$(platform)/builtin.o build/$(platform)/$(platform).ar build/$(platform)/org/xwt/plat/$(platform).java.o
172         @echo -e "\n\033[1mlinking               .o -> $(target_bin)\033[0m"
173         mkdir -p build/$(platform)
174         PATH=upstream/install/bin:$$PATH $(gcj) -v --main=org.xwt.Main -o $@ -Lupstream/install/$(target)/lib $^ $(link_flags)
175
176
177 ### Builtin Resources ##############################################################################
178
179 builtin_src := $(shell find src/org/xwt/builtin -name '*.*' \! -name '*.xcf')
180 build/res/fonts/vera: .download_vera-1.10
181         mkdir -p build/res/fonts/vera
182         cd build/res/fonts/vera; ln -s ../../../../upstream/vera-1.10/ttf-bitstream-vera-1.10/Vera.ttf
183         cd build/res/fonts/vera; ln -s ../../../../upstream/vera-1.10/ttf-bitstream-vera-1.10/VeraMono.ttf
184         cd build/res/fonts/vera; ln -s ../../../../upstream/vera-1.10/ttf-bitstream-vera-1.10/VeraSe.ttf
185 build/res/builtin.jar: $(builtin_src:src/%=build/res/%) build/res/fonts/vera
186         @echo -e "\n\033[1mzipping            res/* -> .jar: builtin.jar\033[0m"
187         cd build/res; $(jar) cf builtin.jar $(^:build/res/%=%)
188 build/$(platform)/builtin.o: build/res/builtin.jar
189         @echo -e "\n\033[1mwrapping            .jar -> .o: resources.o\033[0m"
190         @(echo "unsigned int builtin_length = ";                                \
191                 (wc -c build/res/builtin.jar | sed "s_build.*__");              \
192                 echo \;;                                                        \
193                 echo "unsigned char builtin_bytes[] = {";                       \
194                 hexdump -ve '"0x" 1/1 "%x,\n"' build/res/builtin.jar;           \
195                 echo "};") > .builtin.c
196         $(gcc) -c .builtin.c -o build/$(platform)/builtin.o
197
198
199 build/mips/%.c.o: src/%.c .download_libmspack-20030726
200         make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
201         make .install_libmspack-20030726_mips-unknown-elf target=mips-unknown-elf
202         mkdir -p $(@D)
203         echo -e "\n\033[1mcompiling $< -> $@ (mips)\033[0m"
204         upstream/install/bin/mips-unknown-elf-gcc -march=r3000 \
205                 -Iupstream/freetype-2.1.4/src/include  \
206                 -Iupstream/libmspack-20030726/src/mspack \
207                 -c -o $@ $<
208
209 build/mips/mipsapps.mips: build/mips/org/xwt/translators/Freetype.c.o build/mips/org/xwt/translators/MSPack.c.o build/mips/org/xwt/translators/main.c.o 
210         make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
211         make .install_libmspack-20030726_mips-unknown-elf target=mips-unknown-elf
212         @echo -e "\n\033[1mlinking               .o -> .mips:  $@\033[0m"
213         mkdir -p build/mips build/res
214         upstream/install/bin/mips-unknown-elf-gcc \
215                 --static \
216                 -march=mips1 \
217                 -T upstream/mips/org/xwt/mips/linker.ld \
218                 -L upstream/mips/build/org/xwt/mips/ \
219                 -L upstream/freetype-2.1.4/src/objs \
220                 -L upstream/libmspack-20030726/build-mips-unknown-elf/ \
221                 -o $@ \
222                 $^ \
223                 -lfreetype \
224                 -lmspack   \
225                 -Wl,--gc-sections
226
227
228 ### Maintainer ######################################################################################
229
230 propose-patch:
231         @echo -n "Please type a one-line description of this bug: "; \
232         read A; \
233         echo; \
234         echo "Please type any additional comments that explain this patch."; \
235         echo "If this patch fixes a bug, include a link to bugs.xwt.org."; \
236         echo "When you are done, press control-d on a new line."; \
237         echo; \
238         (       echo -e "HELO patcher"; \
239                 echo -e "MAIL FROM:$(USER)@xwt.org"; \
240                 echo -e "RCPT TO: patches@xwt.org"; \
241                 echo -e "DATA"; \
242                 echo -e "From: $(USER)@xwt.org"; \
243                 echo -e "To: patches@xwt.org"; \
244                 echo -e "Subject: proposed patch to $(this_branch): $$A"; \
245                 echo -e ""; \
246                 cat; \
247                 echo; \
248                 cvs diff -Bud; \
249                 echo .; \
250         ) > .message
251         bash -c "cat .message > /dev/tcp/mail.xwt.org/25"     # /dev/tcp is faked by bash; not part of the os
252
253 current_build         := $(shell cat next.build)
254 this_branch           := $(shell tail -c +2 CVS/Tag 2>/dev/null || echo HEAD)
255 this_branch_flag      := $(shell test $(this_branch) = HEAD && echo || echo -r $(this_branch))
256
257 strip_$(target) := upstream/install/$(target)/bin/strip build/$(platform)/$(target_bin) -o 
258 strip_JVM       := cp build/$(platform)/$(target_bin)
259 install-dist:;     $(strip_$(target)) /var/www/master.dist.xwt.org/xwt-$(current_build).$(target_bin_extension).unsigned
260 dist: compile
261 ifneq ($(shell uname -n),megacz.com)
262         echo "***********************************************************"
263         echo "*  This build is $(current_build)                                     *"
264         echo "***********************************************************"
265         cvs commit -m '' > /dev/null     # this will fail if we haven't checked-in since the comment is null; we want this.
266         echo -e 'cd /home/xwt/\nrm -rf xwt\n/usr/bin/cvs -d /cvs co xwt\nnohup make -C xwt dist 2>&1 >> .make-dist.out &\n' |\
267                  ssh xwt@xwt.org | grep -v "make...:.\(Entering\|Leaving\).directory"
268 else
269         (echo -n 0000; (echo "10k16o16i"; cat next.build | tr a-z A-Z; echo "1+f") | dc) | tail --bytes=5 > next.build-
270         mv next.build- next.build
271         echo -n "Next build will be "; cat next.build
272         cvs update CHANGES; echo -e \n`date +%d-%b`" =========== build $(current_build) ================" >> CHANGES
273         cvs commit -m 'this comment should not appear in CHANGES' next.build CHANGES
274         nice -n 19 make all
275         make install-dist platform=Win32
276         make install-dist platform=Linux
277         make install-dist platform=Solaris
278         make install-dist platform=Darwin
279         make install-dist platform=JVM
280         echo -e "\n\n\n*** DONE ******************************************"
281 endif