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