2003/09/26 03:21:29
[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_newlib-1.11.0      := ftp://sources.redhat.com/pub/newlib/newlib-1.11.0.tar.gz
11 url_binutils-2.13.2.1  := ftp://ftp.gnu.org/gnu/binutils/binutils-2.13.2.1.tar.gz 
12 url_w32api-2.3         := http://umn.dl.sourceforge.net/sourceforge/mingw/w32api-2.3.tar.gz
13 url_mingw-runtime-3.0  := http://umn.dl.sourceforge.net/sourceforge/mingw/mingw-runtime-3.0.tar.gz
14 url_freetype-2.1.4     := http://umn.dl.sourceforge.net/sourceforge/freetype/freetype-2.1.4.tar.gz
15 url_gcc-3.3            := http://mirrors.rcn.net/pub/sourceware/gcc/releases/gcc-3.3/gcc-3.3.tar.gz 
16 url_jpeg-6b            := http://www.ijg.org/files/jpegsrc.v6b.tar.gz
17 url_jikes-1.18         := http://www.megacz.com/tmp/jikes-1.18.tgz       #ftp://www-126.ibm.com/pub/jikes/1.18/jikes-1.18.tar.gz
18
19 .install_binutils-2.13.2.1_powerpc-apple-darwin: .vendor
20         rm -rf upstream/darwin-linker/src
21         cd upstream/darwin-linker; tar xvzf ../install/powerpc-apple-darwin/cctools-478.tgz
22 ifneq ($(shell uname),Darwin)
23         cd upstream/darwin-linker/src/cctools; for A in ../../patches/*.patch; do patch -p0 < $$A; done
24         cp upstream/darwin-linker/src/cctools/ld/fake-mach.c upstream/darwin-linker/src/cctools/libstuff
25         cd upstream/darwin-linker/src/; mkdir macosx-include; cd macosx-include; ../../links.sh
26 endif
27         make -C upstream/darwin-linker/src/cctools/libstuff
28         make -C upstream/darwin-linker/src/cctools/misc
29         touch upstream/darwin-linker/src/cctools/misc/makeUser.c upstream/darwin-linker/src/cctools/misc/make.h
30         make -C upstream/darwin-linker/src/cctools/misc libtool.NEW
31         make -C upstream/darwin-linker/src/cctools/ld; true
32         make -C upstream/darwin-linker/src/cctools/as
33         make -C upstream/darwin-linker/src/cctools/ar
34         mkdir -p upstream/install/powerpc-apple-darwin/bin
35         cp upstream/darwin-linker/src/cctools/ld/ld_dir/ld.NEW upstream/install/powerpc-apple-darwin/bin/ld.NEW
36         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
37         chmod +x upstream/install/powerpc-apple-darwin/bin/ld
38         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
39         chmod +x upstream/install/powerpc-apple-darwin/bin/ranlib
40         cp upstream/darwin-linker/src/cctools/misc/libtool.NEW upstream/install/powerpc-apple-darwin/bin/apple-libtool
41         cp upstream/darwin-linker/src/cctools/misc/strip.NEW upstream/install/powerpc-apple-darwin/bin/strip
42         cp upstream/darwin-linker/src/cctools/as/appc_dir/as upstream/install/powerpc-apple-darwin/bin/as
43         cp upstream/darwin-linker/src/cctools/ar/ar.NEW upstream/install/powerpc-apple-darwin/bin/ar
44         mkdir -p upstream/install/bin
45         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/ld powerpc-apple-darwin-ld
46         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/as powerpc-apple-darwin-as
47         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/ar powerpc-apple-darwin-ar
48         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/ranlib powerpc-apple-darwin-ranlib
49         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/strip powerpc-apple-darwin-strip
50         echo -e "#!/bin/sh\nc++filt \$$@\n" > upstream/install/bin/c++filt3; chmod +x upstream/install/bin/c++filt3
51         cd upstream/install/powerpc-apple-darwin/bin; ln -sf ../../bin/c++filt3
52         touch $@
53
54 # building gcc requires binutils
55 .configure_gcc-3.3_$(target): .install_binutils-2.13.2.1_$(target)      
56         test -e upstream/install/bin/$(target)-ar || ln -s ../$(target)/bin/ar upstream/install/bin/$(target)-ar
57         test -e upstream/install/bin/$(target)-ranlib || ln -s ../$(target)/bin/ar upstream/install/bin/$(target)-ranlib
58
59 # building newlib requires gcc
60 .configure_newlib-1.11.0_$(target): .install_gcc-3.3_$(target)
61
62 # how to configure it
63 configure_gcc-3.3                       += --enable-languages=c,c++,java --enable-gc-type=boehm
64 configure_gcc-3.3                       += --disable-shared --disable-jvmpi
65 configure_gcc-3.3                       += --disable-java-awt --disable-interpreter --enable-static --enable-libgcj
66 ifneq ($(shell uname),$(platform))
67 configure_gcc-3.3                       += --with-gnu-ld=$(shell pwd)/upstream/install/bin/$(target)-ld
68 configure_gcc-3.3                       += --with-as=$(shell pwd)/upstream/install/bin/$(target)-as
69 configure_gcc-3.3_powerpc-apple-darwin  += --with-headers=$(shell pwd)/upstream/install/$(target)/include
70 endif
71 configure_gcc-3.3_powerpc-apple-darwin  += --enable-threads=posix --disable-hash-synchronization --disable-multilib
72 configure_gcc-3.3_i686-pc-mingw32       += --with-headers=$(shell pwd)/upstream/install/$(target)/include
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-multilib
76 configure_gcc-3.3_mips-unknown-elf      += --with-gnu-ld=$(shell pwd)/upstream/install/bin/$(target)-ld
77 configure_gcc-3.3_mips-unknown-elf      += --with-as=$(shell pwd)/upstream/install/bin/$(target)-as
78 configure_gcc-3.3_mips-unknown-elf      += --enable-languages=c --nfp --enable-multilib --disable-threads
79
80 # libjpeg's configury doesn't obey --target
81 environment_jpeg-6b_$(target)           += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
82 environment_jpeg-6b_$(target)           += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
83 environment_jpeg-6b_$(target)           += AR="$(shell pwd)/upstream/install/$(target)/bin/ar rc"
84 environment_jpeg-6b_$(target)           += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
85
86 environment_gcc_3.3_$(target)           += PATH=$(shell pwd)/upstream/install/bin:$$PATH
87
88 .PRECIOUS: .vendor .download_% .configure_%_$(target) .install_%_$(target)
89
90 # vendor-supplied binaries and headers; this is stuff that comes with various OSes
91 vendor: .vendor; @true
92 .vendor:
93         @echo -e "\n\033[1mdownloading vendor-supplied headers and libraries...\033[0m"
94         mkdir -p upstream/install
95         curl http://www.megacz.com/vendor.tgz | tar xzf - -C upstream/install
96         mkdir -p upstream/install/i686-pc-mingw32
97         curl $(url_w32api-2.3) | tar xzf - -C upstream/install/i686-pc-mingw32
98         curl $(url_mingw-runtime-3.0) | tar xzf - -C upstream/install/i686-pc-mingw32
99         touch .vendor
100
101 .download_%:
102         @echo -e "\n\033[1mdownloading $*...\033[0m"
103         mkdir -p upstream/$*
104         curl $(url_$*) | tar xzf - -C upstream/$*
105         mv upstream/$*/$* upstream/$*/src; true
106         (test -e upstream/$*/patches && cd upstream/$*/src && for A in ../patches/*.patch; do patch -p0 < $$A; done); true
107         touch $@
108
109 .configure_%_$(target): .download_% 
110         @echo -e "\n\033[1mconfiguring $*...\033[0m"
111         mkdir -p upstream/$*/build-$(target)
112         cd upstream/$*/build-$(target); \
113                 $(setcc) $(environment_$*_$(target)) ../src/configure \
114                 --target=$(target) \
115                 --prefix=`cd ../..; pwd`/install \
116                 $(configure_$*) \
117                 $(configure_$*_$(target))
118         touch $@
119
120 .install_freetype-2.1.4_mips-unknown-elf: .install_gcc-3.3_mips-unknown-elf .install_newlib-1.11.0_mips-unknown-elf .download_freetype-2.1.4
121         cd upstream/freetype-2.1.4/src; make setup ansi; PATH=$$PATH:`pwd`/../../install/bin make CC=mips-unknown-elf-gcc AR=mips-unknown-elf-ar
122         upstream/install/bin/mips-unknown-elf-ranlib upstream/freetype-2.1.4/src/objs/libfreetype.a
123         touch $@
124
125 .install_%_$(target): .configure_%_$(target)
126         @echo -e "\n\033[1mbuilding $*...\033[0m"
127         cd upstream/$*/build-$(target); \
128                 $(setcc) PATH=$$PATH:`pwd`/../../install/bin \
129                 $(environment_$*_$(target)) \
130                 make $(setcc) $(environment_$*_$(target))
131         @echo -e "\n\033[1minstalling $*...\033[0m"
132         cd upstream/$*/build-$(target); \
133                 $(setcc) PATH=$$PATH:`pwd`/../../install/bin \
134                 $(environment_$*_$(target)) \
135                 make install $(setcc) $(environment_$*_$(target))
136         touch $@
137
138 # jikes has a special target to autodetect a pre-installed jikes, and to autodetect the JVM's $CLASSPATH
139 .jikes:
140         @echo -e "\n\033[1mdetecting your jikes installation...\033[0m"
141         echo "#!/bin/sh" > .jikes
142         echo 'for A in `find build/class -name \*.class`; do mv $$A $$A.old; done;' >> .jikes
143         echo -n 'PATH=upstream/install/bin:$$PATH jikes -classpath lib/libgcj-minimal.jar $$@ -d build/class/ -sourcepath build/java/ ' >> .jikes
144         (type jikes && (jikes --version | grep "Version 1.18")) || make .install_jikes-1.18_ target=
145         echo -n "$(jikes_flags) -bootclasspath " >> .jikes
146         echo "public class GetBootClassPath { public static void main(String[] s) { " > GetBootClassPath.java
147         echo "System.out.println(System.getProperty(\"sun.boot.class.path\")); } }"  >> GetBootClassPath.java
148         javac GetBootClassPath.java
149         java -cp . GetBootClassPath >> .jikes
150         rm GetBootClassPath.*
151         echo 'EXIT=$$?' >> .jikes
152         echo 'for A in `find build/class -name \*.class`; do test -e $$A.old && cmp -s $$A $$A.old && mv $$A.old $$A; done' >> .jikes
153         echo 'for A in `find build/class -name \*.class`; do test -e $$A.old && rm $$A.old; done' >> .jikes
154         echo 'exit $$EXIT' >> .jikes
155         mv .jikes .jikes+
156         cp .jikes+ .jikes
157         chmod +x .jikes