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