fixed bug 460
[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-static --enable-libgcj
72 configure_gcc-3.3                       += --disable-shared --enable-static
73 configure_gcc-3.3_powerpc-apple-darwin  += --enable-threads=posix --disable-hash-synchronization --disable-multilib
74 configure_gcc-3.3_i686-pc-mingw32       += --enable-threads=win32 --enable-hash-synchronization
75 configure_gcc-3.3_i686-pc-linux-gnu     += --enable-threads=posix --enable-hash-synchronization
76 configure_gcc-3.3_sparc-sun-solaris2.7  += --enable-threads=posix --disable-hash-synchronization --disable-multilib
77
78 configure_WindowMaker-0.80.2_$(target)  += --prefix=$(shell pwd)/upstream/install/$(target)
79 configure_WindowMaker-0.80.2_$(target)  += --host=i686-pc-linux-gnu --x-libraries=$(shell pwd)/upstream/install/$(target)/lib
80
81 .install_jode-1.1.1_java: .download_java-getopt-1.0.9
82
83 configure_jode-1.1.1_java               := --with-java=$(JAVA_HOME)/bin/java --with-javac=$(JAVA_HOME)/bin/javac
84 ifeq ($(shell uname),Darwin)
85 environment_jode-1.1.1_java             := CLASSLIB=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes/classes.jar
86 else
87 environment_jode-1.1.1_java             := CLASSLIB=${JAVA_HOME}/jre/lib/rt.jar
88 endif
89 environment_jode-1.1.1_java             += CLASSPATH=${CLASSPATH}:$(shell pwd)/upstream/java-getopt-1.0.9/
90
91 #environment_gcc-3.3_i686-pc-linux-gnu   += CFLAGS="-Wl,-ldl"
92
93 # libjpeg's configury doesn't obey --target
94 environment_jpeg-6b_$(target)           += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
95 environment_jpeg-6b_$(target)           += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
96 environment_jpeg-6b_$(target)           += AR="$(shell pwd)/upstream/install/$(target)/bin/ar rc"
97 environment_jpeg-6b_$(target)           += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
98
99 # libmspack configury doesn't obey --target
100 environment_libmspack-20030726_$(target) += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
101 environment_libmspack-20030726_$(target) += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
102 environment_libmspack-20030726_$(target) += AR="$(shell pwd)/upstream/install/$(target)/bin/ar"
103 environment_libmspack-20030726_$(target) += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
104 environment_libmspack-20030726_$(target) += OPTIM="-ffunction-sections -fdata-sections -O3"
105
106 # WindowMaker configury doesn't obey --target
107 environment_WindowMaker-0.80.2_$(target) += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
108 environment_WindowMaker-0.80.2_$(target) += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
109 environment_WindowMaker-0.80.2_$(target) += AR="$(shell pwd)/upstream/install/$(target)/bin/ar"
110 environment_WindowMaker-0.80.2_$(target) += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
111 environment_WindowMaker-0.80.2_$(target) += LDFLAGS="-lXext -ldl"
112 make_install_WindowMaker-0.80.2_$(target) := -C WINGs install; make -C wrlib
113 make_WindowMaker-0.80.2_$(target) := WINGs
114
115 environment_gcc_3.3_$(target)           += PATH=$(shell pwd)/upstream/install/bin:$$PATH
116
117 .PRECIOUS: .vendor .download_% .configure_%_$(target) .install_%_$(target)
118
119 # vendor-supplied binaries and headers; this is stuff that comes with various OSes
120 vendor: .vendor; @true
121 .vendor:
122         @echo -e "\n\033[1mdownloading vendor-supplied headers and libraries...\033[0m"
123         mkdir -p upstream/install
124         curl http://www.megacz.com/vendor.tgz | tar xzf - -C upstream/install
125         mkdir -p upstream/install/i686-pc-mingw32
126         curl $(url_w32api-2.3) | tar xzf - -C upstream/install/i686-pc-mingw32
127         curl $(url_mingw-runtime-3.0) | tar xzf - -C upstream/install/i686-pc-mingw32
128 ifeq ($(shell uname),Linux)
129         cd upstream/install/i686-pc-linux-gnu/include; rm -rf *; ln -sf /usr/include/* .
130 endif
131         touch .vendor
132
133 .download_gcc-3.3_powerpc-apple-darwin:
134         @echo -e "\n\033[1mdownloading $*...\033[0m"
135         mkdir -p upstream/gcc-3.3
136         curl $(url_gcc-3.3) | tar xzf - -C upstream/gcc-3.3
137         mv upstream/gcc-3.3/gcc-3.3 upstream/gcc-3.3/src-darwin; true
138         mv upstream/gcc-3.3/libmspack upstream/gcc-3.3/src-darwin; true
139         (cd upstream/gcc-3.3/src-darwin && for A in ../patches/*.patch; do patch -p0 -l < $$A; done); true
140         (cd upstream/gcc-3.3/src-darwin && for A in ../patches-darwin/*.patch; do patch -p0 -l < $$A; done); true
141         touch $@
142
143 .download_%:
144         @echo -e "\n\033[1mdownloading $*...\033[0m"
145         mkdir -p upstream/$*
146         curl $(url_$*) | tar xzf - -C upstream/$*
147         mv upstream/$*/$* upstream/$*/src; true
148         mv upstream/$*/libmspack upstream/$*/src; true
149         (test -e upstream/$*/patches && cd upstream/$*/src && for A in ../patches/*.patch; do patch -p0 -l < $$A; done); true
150         touch $@
151
152 .configure_gcc-3.3_powerpc-apple-darwin: .download_gcc-3.3_powerpc-apple-darwin .install_binutils-2.13.2.1_powerpc-apple-darwin
153         @echo -e "\n\033[1mconfiguring gcc...\033[0m"
154         mkdir -p upstream/gcc-3.3/build-$(target)
155         cd upstream/gcc-3.3/build-$(target); \
156                 $(setcc) $(environment_gcc-3.3_$(target)) ../src-darwin/configure \
157                 --target=$(target) \
158                 --prefix=`cd ../..; pwd`/install \
159                 $(configure_gcc-3.3) \
160                 $(configure_gcc-3.3_$(target))
161         touch $@
162
163 .configure_gcc-3.3_$(target): .install_binutils-2.13.2.1_$(target)
164
165 .configure_%_$(target): .vendor .download_%
166         @echo -e "\n\033[1mconfiguring $*...\033[0m"
167         mkdir -p upstream/$*/build-$(target)
168         cd upstream/$*/build-$(target); \
169                 $(setcc) $(environment_$*_$(target)) ../src/configure \
170                 --target=$(target) \
171                 --prefix=`cd ../..; pwd`/install \
172                 $(configure_$*) \
173                 $(configure_$*_$(target))
174         touch $@
175
176 .configure_libmspack-20030726_$(target): .download_libmspack-20030726 .install_gcc-3.3_$(target)
177         mkdir -p upstream/libmspack-20030726/build-$(target)
178         cd upstream/libmspack-20030726/build-$(target); ln -sf ../src/mspack/* .
179         touch $@
180
181 .install_binutils-2.13.2.1_mips-unknown-elf: .install_mips2java; touch $@
182 .install_gcc-3.3_mips-unknown-elf:           .install_mips2java; touch $@
183
184 .download_mips2java:
185         mkdir -p upstream/install
186         curl http://www.megacz.com/tmp/mips.snapshot.tgz | tar -C upstream -xvzf -
187 #       echo '/1 :pserver:cvs@cvs.ibex.org:2401/ A' >> ~/.cvspass
188 #       cd upstream; cvs -d :pserver:cvs@cvs.ibex.org:/ co mips
189         cd upstream/mips/upstream; ln -sf `cd ../..; pwd`/install
190         touch $@
191
192 .install_mips2java: .download_mips2java
193         (cd upstream/mips; make)
194         touch $@
195
196 .install_freetype-2.1.4_mips-unknown-elf: .install_mips2java .download_freetype-2.1.4
197         cd upstream/freetype-2.1.4/src; \
198            make setup ansi; \
199            PATH=$$PATH:`pwd`/../../install/bin make \
200               CC=mips-unknown-elf-gcc \
201               AR=mips-unknown-elf-ar \
202               CFLAGS="-c -ffunction-sections -fdata-sections -O3"
203         upstream/install/bin/mips-unknown-elf-ranlib upstream/freetype-2.1.4/src/objs/libfreetype.a
204         touch $@
205
206 .build_%_$(target): .configure_%_$(target)
207         @echo -e "\n\033[1mbuilding $*...\033[0m"
208         cd upstream/$*/build-$(target); \
209                 $(setcc) PATH=$$PATH:`pwd`/../../install/bin \
210                 $(environment_$*_$(target)) \
211                 make $(make_$*_$(target)) $(setcc) $(environment_$*_$(target))
212         touch $@
213
214 .install_libmspack-20030726_$(target): .build_libmspack-20030726_$(target); true
215
216 .install_%_$(target): .build_%_$(target)
217         @echo -e "\n\033[1minstalling $*...\033[0m"
218         cd upstream/$*/build-$(target); \
219                 $(setcc) PATH=$$PATH:`pwd`/../../install/bin \
220                 $(environment_$*_$(target)) \
221                 make $(make_install_$*_$(target)) install $(setcc) $(environment_$*_$(target))
222         touch $@
223
224 # jikes has a special target to autodetect a pre-installed jikes, and to autodetect the JVM's $CLASSPATH
225 .jikes:
226         @echo -e "\n\033[1mdetecting your jikes installation...\033[0m"
227         echo "#!/bin/sh" > .jikes
228         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
229         (type jikes && (jikes --version | grep "Version 1.18")) || make .install_jikes-1.18_ target=
230         echo -n "$(jikes_flags) -bootclasspath " >> .jikes
231         echo "public class GetBootClassPath { public static void main(String[] s) { " > GetBootClassPath.java
232         echo "System.out.println(System.getProperty(\"sun.boot.class.path\")); } }"  >> GetBootClassPath.java
233         javac GetBootClassPath.java
234         java -cp . GetBootClassPath >> .jikes
235         rm GetBootClassPath.*
236         echo 'EXIT=$$?' >> .jikes
237         echo 'exit $$EXIT' >> .jikes
238         mv .jikes .jikes+
239         cp .jikes+ .jikes
240         chmod +x .jikes