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