circumvent jikes if jdk
[org.ibex.core.git] / Makefile.upstream
1 ############################################################################# 
2 #
3 # The Ibex upstream code Makefile
4 #
5
6 # deal with Apple's brokenness
7 setcc := $(shell test `uname` = Darwin && echo "CC=\"/usr/bin/gcc3 -no-cpp-precomp\"")
8
9 # where to get stuff
10 url_binutils-2.13.2.1  := ftp://ftp.gnu.org/gnu/binutils/binutils-2.13.2.1.tar.gz 
11 url_w32api-2.3         := http://umn.dl.sourceforge.net/sourceforge/mingw/w32api-2.3.tar.gz
12 url_mingw-runtime-3.0  := http://umn.dl.sourceforge.net/sourceforge/mingw/mingw-runtime-3.0.tar.gz
13 url_freetype-2.1.4     := http://umn.dl.sourceforge.net/sourceforge/freetype/freetype-2.1.4.tar.gz
14 url_gcc-3.3            := http://mirrors.rcn.net/pub/sourceware/gcc/releases/gcc-3.3/gcc-3.3.tar.gz 
15 url_jpeg-6b            := http://www.ijg.org/files/jpegsrc.v6b.tar.gz
16 url_jikes-1.18         := http://dist.ibex.org/jikes-1.18.tgz
17 url_libmspack-20030726 := http://www.kyz.uklinux.net/downloads/libmspack-20030726.tar.gz
18 url_vera-1.10          := http://ftp.gnome.org/pub/GNOME/sources/ttf-bitstream-vera/1.10/ttf-bitstream-vera-1.10.tar.gz
19 url_jode-1.1.1         := http://umn.dl.sourceforge.net/sourceforge/jode/jode-1.1.1.tar.gz
20 url_java-getopt-1.0.9  := ftp://ftp.urbanophile.com/pub/arenn/software/sources/java-getopt-1.0.9.tar.gz
21 url_WindowMaker-0.80.2 := http://windowmaker.org/pub/source/release/WindowMaker-0.80.2.tar.gz
22
23 .install_binutils-2.13.2.1_powerpc-apple-darwin: .vendor
24         rm -rf upstream/darwin-linker/src
25         cd upstream/darwin-linker; tar xvzf ../install/powerpc-apple-darwin/cctools-478.tgz
26 ifneq ($(shell uname),Darwin)
27         cd upstream/darwin-linker/src/cctools; for A in ../../patches/*.patch; do patch -p0 < $$A; done
28         cp upstream/darwin-linker/src/cctools/ld/fake-mach.c upstream/darwin-linker/src/cctools/libstuff
29         cd upstream/darwin-linker/src/; mkdir macosx-include; cd macosx-include; chmod +x ../../links.sh; ../../links.sh
30 endif
31         make -C upstream/darwin-linker/src/cctools/libstuff
32         make -C upstream/darwin-linker/src/cctools/misc
33         touch upstream/darwin-linker/src/cctools/misc/makeUser.c upstream/darwin-linker/src/cctools/misc/make.h
34         make -C upstream/darwin-linker/src/cctools/misc libtool.NEW
35         make -C upstream/darwin-linker/src/cctools/ld; true
36         make -C upstream/darwin-linker/src/cctools/as
37         make -C upstream/darwin-linker/src/cctools/ar
38         mkdir -p upstream/install/powerpc-apple-darwin/bin
39         cp upstream/darwin-linker/src/cctools/ld/ld_dir/ld.NEW upstream/install/powerpc-apple-darwin/bin/ld.NEW
40         echo -e "#!/bin/sh\n"`pwd`"/upstream/install/powerpc-apple-darwin/bin/ld.NEW -dylib_file /usr/lib/system/libmathCommon.A.dylib:"`pwd`"/upstream/install/powerpc-apple-darwin/lib/libmathCommon.A.dylib -L"`pwd`"/upstream/install/powerpc-apple-darwin/lib \$$@\n" > upstream/install/powerpc-apple-darwin/bin/ld
41         chmod +x upstream/install/powerpc-apple-darwin/bin/ld
42         echo -e "#!/bin/sh\n"`pwd`"/upstream/install/powerpc-apple-darwin/bin/apple-libtool \$$1 -o \$$1\n" > upstream/install/powerpc-apple-darwin/bin/ranlib
43         chmod +x upstream/install/powerpc-apple-darwin/bin/ranlib
44         cp upstream/darwin-linker/src/cctools/misc/libtool.NEW upstream/install/powerpc-apple-darwin/bin/apple-libtool
45         cp upstream/darwin-linker/src/cctools/misc/strip.NEW upstream/install/powerpc-apple-darwin/bin/strip
46         cp upstream/darwin-linker/src/cctools/as/appc_dir/as upstream/install/powerpc-apple-darwin/bin/as
47         cp upstream/darwin-linker/src/cctools/ar/ar.NEW upstream/install/powerpc-apple-darwin/bin/ar.NEW
48         echo -e "#!/bin/sh\n"`pwd`"/upstream/install/powerpc-apple-darwin/bin/ar.NEW \$$@\n"`pwd`"/upstream/install/powerpc-apple-darwin/bin/ranlib \$$2\n" > upstream/install/powerpc-apple-darwin/bin/ar
49         chmod +x upstream/install/powerpc-apple-darwin/bin/ar
50         mkdir -p upstream/install/bin
51         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/ld powerpc-apple-darwin-ld
52         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/as powerpc-apple-darwin-as
53         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/ar powerpc-apple-darwin-ar
54         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/ranlib powerpc-apple-darwin-ranlib
55         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/strip powerpc-apple-darwin-strip
56         echo -e "#!/bin/sh\nc++filt \$$@\n" > upstream/install/bin/c++filt3; chmod +x upstream/install/bin/c++filt3
57         cd upstream/install/powerpc-apple-darwin/bin; ln -sf ../../bin/c++filt3
58         touch $@
59
60
61 # how to configure it
62 ifneq ($(shell uname),$(platform))
63 configure_gcc-3.3                       += --with-headers=$(shell pwd)/upstream/install/$(target)/include
64 endif
65 configure_gcc-3.3                       += --enable-languages=c,c++,java --enable-gc-type=boehm --disable-jvmpi
66 configure_gcc-3.3                       += --with-ld=$(shell pwd)/upstream/install/bin/$(target)-ld
67 configure_gcc-3.3                       += --with-as=$(shell pwd)/upstream/install/bin/$(target)-as
68 ifneq ($(platform),Darwin)
69 configure_gcc-3.3                       += --with-gnu-ld --with-gnu-as
70 endif
71 configure_gcc-3.3                       += --disable-java-awt --disable-interpreter --enable-libgcj
72 configure_gcc-3.3                       += --disable-shared --enable-static
73 configure_binutils-2.13.2.1             += --disable-shared --enable-static
74 configure_gcc-3.3_powerpc-apple-darwin  += --enable-threads=posix --disable-hash-synchronization --disable-multilib
75 configure_gcc-3.3_i686-pc-mingw32       += --enable-threads=win32 --enable-hash-synchronization
76 configure_gcc-3.3_i686-pc-linux-gnu     += --enable-threads=posix --enable-hash-synchronization
77 configure_gcc-3.3_sparc-sun-solaris2.7  += --enable-threads=posix --disable-hash-synchronization --disable-multilib
78
79 configure_WindowMaker-0.80.2_$(target)  += --prefix=$(shell pwd)/upstream/install/$(target)
80 configure_WindowMaker-0.80.2_$(target)  += --host=i686-pc-linux-gnu --x-libraries=$(shell pwd)/upstream/install/$(target)/lib
81
82 .install_jode-1.1.1_java: .download_java-getopt-1.0.9
83
84 configure_jode-1.1.1_java               := --with-java=$(JAVA_HOME)/bin/java --with-javac=$(JAVA_HOME)/bin/javac
85 ifeq ($(shell uname),Darwin)
86 environment_jode-1.1.1_java             := CLASSLIB=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes/classes.jar
87 else
88 environment_jode-1.1.1_java             := CLASSLIB=${JAVA_HOME}/jre/lib/rt.jar
89 endif
90 environment_jode-1.1.1_java             += CLASSPATH=${CLASSPATH}:$(shell pwd)/upstream/java-getopt-1.0.9/
91
92 #environment_gcc-3.3_i686-pc-linux-gnu   += CFLAGS="-Wl,-ldl"
93
94 # libjpeg's configury doesn't obey --target
95 environment_jpeg-6b_$(target)           += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
96 environment_jpeg-6b_$(target)           += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
97 environment_jpeg-6b_$(target)           += AR="$(shell pwd)/upstream/install/$(target)/bin/ar rc"
98 environment_jpeg-6b_$(target)           += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
99
100 # libmspack configury doesn't obey --target
101 environment_libmspack-20030726_$(target) += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
102 environment_libmspack-20030726_$(target) += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
103 environment_libmspack-20030726_$(target) += AR="$(shell pwd)/upstream/install/$(target)/bin/ar"
104 environment_libmspack-20030726_$(target) += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
105 environment_libmspack-20030726_$(target) += OPTIM="-ffunction-sections -fdata-sections -O3"
106
107 # WindowMaker configury doesn't obey --target
108 environment_WindowMaker-0.80.2_$(target) += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
109 environment_WindowMaker-0.80.2_$(target) += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
110 environment_WindowMaker-0.80.2_$(target) += AR="$(shell pwd)/upstream/install/$(target)/bin/ar"
111 environment_WindowMaker-0.80.2_$(target) += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
112 environment_WindowMaker-0.80.2_$(target) += LDFLAGS="-lXext -ldl"
113 make_install_WindowMaker-0.80.2_$(target) := -C WINGs install; make -C wrlib
114 make_WindowMaker-0.80.2_$(target) := WINGs
115
116 environment_gcc_3.3_$(target)           += PATH=$(shell pwd)/upstream/install/bin:$$PATH
117
118 .PRECIOUS: .vendor .download_% .configure_%_$(target) .install_%_$(target)
119
120 # vendor-supplied binaries and headers; this is stuff that comes with various OSes
121 vendor: .vendor; @true
122 .vendor:
123         @echo -e "\n\033[1mdownloading vendor-supplied headers and libraries...\033[0m"
124         mkdir -p upstream/install
125         curl http://www.megacz.com/vendor.tgz | tar xzf - -C upstream/install
126         mkdir -p upstream/install/i686-pc-mingw32
127         curl $(url_w32api-2.3) | tar xzf - -C upstream/install/i686-pc-mingw32
128         curl $(url_mingw-runtime-3.0) | tar xzf - -C upstream/install/i686-pc-mingw32
129 ifeq ($(shell uname),Linux)
130         cd upstream/install/i686-pc-linux-gnu/include; rm -rf *; ln -sf /usr/include/* .
131 endif
132         touch .vendor
133
134 .download_gcc-3.3_powerpc-apple-darwin:
135         @echo -e "\n\033[1mdownloading $*...\033[0m"
136         mkdir -p upstream/gcc-3.3
137         curl $(url_gcc-3.3) | tar xzf - -C upstream/gcc-3.3
138         mv upstream/gcc-3.3/gcc-3.3 upstream/gcc-3.3/src-darwin; true
139         mv upstream/gcc-3.3/libmspack upstream/gcc-3.3/src-darwin; true
140         (cd upstream/gcc-3.3/src-darwin && for A in ../patches/*.patch; do patch -p0 -l < $$A; done); true
141         (cd upstream/gcc-3.3/src-darwin && for A in ../patches-darwin/*.patch; do patch -p0 -l < $$A; done); true
142         touch $@
143
144 .download_%:
145         @echo -e "\n\033[1mdownloading $*...\033[0m"
146         mkdir -p upstream/$*
147         curl $(url_$*) | tar xzf - -C upstream/$*
148         mv upstream/$*/$* upstream/$*/src; true
149         mv upstream/$*/libmspack upstream/$*/src; true
150         (test -e upstream/$*/patches && cd upstream/$*/src && for A in ../patches/*.patch; do patch -p0 -l < $$A; done); true
151         touch $@
152
153 .configure_gcc-3.3_powerpc-apple-darwin: .download_gcc-3.3_powerpc-apple-darwin .install_binutils-2.13.2.1_powerpc-apple-darwin
154         @echo -e "\n\033[1mconfiguring gcc...\033[0m"
155         mkdir -p upstream/gcc-3.3/build-$(target)
156         cd upstream/gcc-3.3/build-$(target); \
157                 $(setcc) $(environment_gcc-3.3_$(target)) ../src-darwin/configure \
158                 --target=$(target) \
159                 --prefix=`cd ../..; pwd`/install \
160                 $(configure_gcc-3.3) \
161                 $(configure_gcc-3.3_$(target))
162         touch $@
163
164 .configure_gcc-3.3_$(target): .install_binutils-2.13.2.1_$(target)
165
166 .configure_%_$(target): .vendor .download_%
167         @echo -e "\n\033[1mconfiguring $*...\033[0m"
168         mkdir -p upstream/$*/build-$(target)
169         cd upstream/$*/build-$(target); \
170                 $(setcc) $(environment_$*_$(target)) ../src/configure \
171                 --target=$(target) \
172                 --prefix=`cd ../..; pwd`/install \
173                 $(configure_$*) \
174                 $(configure_$*_$(target))
175         touch $@
176
177 .configure_libmspack-20030726_$(target): .download_libmspack-20030726 .install_gcc-3.3_$(target)
178         mkdir -p upstream/libmspack-20030726/build-$(target)
179         cd upstream/libmspack-20030726/build-$(target); ln -sf ../src/mspack/* .
180         touch $@
181
182 .install_binutils-2.13.2.1_mips-unknown-elf: .install_mips2java; touch $@
183 .install_gcc-3.3_mips-unknown-elf:           .install_mips2java; touch $@
184
185 .download_mips2java:
186         mkdir -p upstream/install
187         curl http://www.megacz.com/tmp/mips.snapshot.tgz | tar -C upstream -xvzf -
188 #       echo '/1 :pserver:cvs@cvs.ibex.org:2401/ A' >> ~/.cvspass
189 #       cd upstream; cvs -d :pserver:cvs@cvs.ibex.org:/ co mips
190         cd upstream/mips/upstream; ln -sf `cd ../..; pwd`/install
191         touch $@
192
193 .install_mips2java: .download_mips2java
194         (cd upstream/mips; make)
195         touch $@
196
197 .install_freetype-2.1.4_mips-unknown-elf: .install_mips2java .download_freetype-2.1.4
198         cd upstream/freetype-2.1.4/src; \
199            make setup ansi; \
200            PATH=$$PATH:`pwd`/../../install/bin make \
201               CC=mips-unknown-elf-gcc \
202               AR=mips-unknown-elf-ar \
203               CFLAGS="-c -ffunction-sections -fdata-sections -O3"
204         upstream/install/bin/mips-unknown-elf-ranlib upstream/freetype-2.1.4/src/objs/libfreetype.a
205         touch $@
206
207 .build_%_$(target): .configure_%_$(target)
208         @echo -e "\n\033[1mbuilding $*...\033[0m"
209         cd upstream/$*/build-$(target); \
210                 $(setcc) PATH=$$PATH:`pwd`/../../install/bin \
211                 $(environment_$*_$(target)) \
212                 make $(make_$*_$(target)) $(setcc) $(environment_$*_$(target))
213         touch $@
214
215 .install_libmspack-20030726_$(target): .build_libmspack-20030726_$(target); true
216
217 .install_%_$(target): .build_%_$(target)
218         @echo -e "\n\033[1minstalling $*...\033[0m"
219         cd upstream/$*/build-$(target); \
220                 $(setcc) PATH=$$PATH:`pwd`/../../install/bin \
221                 $(environment_$*_$(target)) \
222                 make $(make_install_$*_$(target)) install $(setcc) $(environment_$*_$(target))
223         touch $@
224
225 # jikes has a special target to autodetect a pre-installed jikes, and to autodetect the JVM's $CLASSPATH
226 .jikes:
227         @echo -e "\n\033[1mdetecting your jikes installation...\033[0m"
228         echo "#!/bin/sh" > .jikes
229 ifeq ($(shell javac -version 2>&1 | head -n 1),javac 1.5.0-beta)
230         echo -n 'PATH=upstream/install/bin:$$PATH javac -classpath lib/libgcj-minimal.jar:build/class $$@ -d build/class/ -sourcepath build/java/:upstream/mips:upstream/mips/build:src' >> .jikes
231 else
232         echo -n 'PATH=upstream/install/bin:$$PATH jikes -classpath lib/libgcj-minimal.jar:build/class $$@ -d build/class/ -sourcepath build/java/:upstream/mips:upstream/mips/build:src ' >> .jikes
233         (type jikes && (jikes --version | grep "Version 1.18")) || make .install_jikes-1.18_ target=
234         echo -n "$(jikes_flags) -bootclasspath " >> .jikes
235         echo "public class GetBootClassPath { public static void main(String[] s) { " > GetBootClassPath.java
236         echo "System.out.println(System.getProperty(\"sun.boot.class.path\")); } }"  >> GetBootClassPath.java
237         javac GetBootClassPath.java
238         java -cp . GetBootClassPath >> .jikes
239         rm GetBootClassPath.*
240 endif
241         echo 'EXIT=$$?' >> .jikes
242         echo 'exit $$EXIT' >> .jikes
243         mv .jikes .jikes+
244         cp .jikes+ .jikes
245         chmod +x .jikes