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