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