2004/01/16 10:21:31
[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://dist.xwt.org/jikes-1.18.tgz
18 url_libmspack-20030726 := http://www.kyz.uklinux.net/downloads/libmspack-20030726.tar.gz
19 url_vera-1.10          := http://ftp.gnome.org/pub/GNOME/sources/ttf-bitstream-vera/1.10/ttf-bitstream-vera-1.10.tar.gz
20
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 # building gcc requires binutils
59 .configure_gcc-3.3_$(target): .install_binutils-2.13.2.1_$(target)      
60
61 # building newlib requires gcc
62 .configure_newlib-1.11.0_$(target): .install_gcc-3.3_$(target)
63
64 # how to configure it
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 --with-gnu-ld
67 configure_gcc-3.3                       += --with-as=$(shell pwd)/upstream/install/bin/$(target)-as --with-gnu-as
68 ifneq ($(shell uname),$(platform))
69 configure_gcc-3.3                       += --with-headers=$(shell pwd)/upstream/install/$(target)/include
70 endif
71 configure_gcc-3.3                       += --disable-java-awt --disable-interpreter --enable-static --enable-libgcj
72 configure_gcc-3.3                       += --enable-shared 
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 --enable-hash-synchronization --disable-multilib
77
78 environment_newlib-1.11.0_mips-unknown-elf += TARGET_CFLAGS="-O3 -ffunction-sections -fdata-sections"
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 # libmspack configury doesn't obey --target
87 environment_libmspack-20030726_$(target) += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
88 environment_libmspack-20030726_$(target) += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
89 environment_libmspack-20030726_$(target) += AR="$(shell pwd)/upstream/install/$(target)/bin/ar"
90 environment_libmspack-20030726_$(target) += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
91 environment_libmspack-20030726_$(target) += OPTIM="-ffunction-sections -fdata-sections -O3"
92
93
94 environment_gcc_3.3_$(target)           += PATH=$(shell pwd)/upstream/install/bin:$$PATH
95
96 .PRECIOUS: .vendor .download_% .configure_%_$(target) .install_%_$(target)
97
98 # vendor-supplied binaries and headers; this is stuff that comes with various OSes
99 vendor: .vendor; @true
100 .vendor:
101         @echo -e "\n\033[1mdownloading vendor-supplied headers and libraries...\033[0m"
102         mkdir -p upstream/install
103         curl http://www.megacz.com/vendor.tgz | tar xzf - -C upstream/install
104         mkdir -p upstream/install/i686-pc-mingw32
105         curl $(url_w32api-2.3) | tar xzf - -C upstream/install/i686-pc-mingw32
106         curl $(url_mingw-runtime-3.0) | tar xzf - -C upstream/install/i686-pc-mingw32
107 ifeq ($(shell uname),Linux)
108         rm -rf upstream/install/i686-pc-linux-gnu/include
109         ln -sf /usr/include upstream/install/i686-pc-linux-gnu/include
110 endif
111         touch .vendor
112
113 .download_%:
114         @echo -e "\n\033[1mdownloading $*...\033[0m"
115         mkdir -p upstream/$*
116         curl $(url_$*) | tar xzf - -C upstream/$*
117         mv upstream/$*/$* upstream/$*/src; true
118         mv upstream/$*/libmspack upstream/$*/src; true
119         (test -e upstream/$*/patches && cd upstream/$*/src && for A in ../patches/*.patch; do patch -p0 -l < $$A; done); true
120         touch $@
121
122 .configure_%_$(target): .download_% 
123         @echo -e "\n\033[1mconfiguring $*...\033[0m"
124         mkdir -p upstream/$*/build-$(target)
125         cd upstream/$*/build-$(target); \
126                 $(setcc) $(environment_$*_$(target)) ../src/configure \
127                 --target=$(target) \
128                 --prefix=`cd ../..; pwd`/install \
129                 $(configure_$*) \
130                 $(configure_$*_$(target))
131         touch $@
132
133 .configure_libmspack-20030726_$(target): .download_libmspack-20030726 .install_gcc-3.3_$(target) .install_newlib-1.11.0_$(target)
134         mkdir -p upstream/libmspack-20030726/build-$(target)
135         cd upstream/libmspack-20030726/build-$(target); ln -sf ../src/mspack/* .
136         touch $@
137
138 .install_mips2java:
139         mkdir -p upstream/install
140         echo '/1 :pserver:cvs@cvs.xwt.org:2401/ A' >> ~/.cvspass
141         cd upstream; cvs -d :pserver:cvs@cvs.xwt.org:/ co mips
142         cd upstream/mips/upstream; ln -s `cd ../..; pwd`/install
143         make -C upstream/mips
144         touch $@
145
146 .install_binutils-2.13.2.1_mips-unknown-elf: .install_mips2java
147         touch $@
148
149 .install_newlib-1.11.0_mips-unknown-elf: .install_mips2java
150         touch $@
151
152 .install_gcc-3.3_mips-unknown-elf: .install_mips2java
153         touch $@
154
155 .install_freetype-2.1.4_mips-unknown-elf: .install_mips2java .download_freetype-2.1.4
156         cd upstream/freetype-2.1.4/src; \
157            make setup ansi; \
158            PATH=$$PATH:`pwd`/../../install/bin make \
159               CC=mips-unknown-elf-gcc \
160               AR=mips-unknown-elf-ar \
161               CFLAGS="-c -ffunction-sections -fdata-sections -O3"
162         upstream/install/bin/mips-unknown-elf-ranlib upstream/freetype-2.1.4/src/objs/libfreetype.a
163         touch $@
164
165 .build_%_$(target): .configure_%_$(target)
166         @echo -e "\n\033[1mbuilding $*...\033[0m"
167         cd upstream/$*/build-$(target); \
168                 $(setcc) PATH=$$PATH:`pwd`/../../install/bin \
169                 $(environment_$*_$(target)) \
170                 make $(setcc) $(environment_$*_$(target))
171         touch $@
172
173 .install_libmspack-20030726_$(target): .build_libmspack-20030726_$(target); true
174
175 .install_%_$(target): .build_%_$(target)
176         @echo -e "\n\033[1minstalling $*...\033[0m"
177         cd upstream/$*/build-$(target); \
178                 $(setcc) PATH=$$PATH:`pwd`/../../install/bin \
179                 $(environment_$*_$(target)) \
180                 make install $(setcc) $(environment_$*_$(target))
181         touch $@
182
183 # jikes has a special target to autodetect a pre-installed jikes, and to autodetect the JVM's $CLASSPATH
184 .jikes:
185         @echo -e "\n\033[1mdetecting your jikes installation...\033[0m"
186         echo "#!/bin/sh" > .jikes
187         #echo 'for A in `find build/class -name \*.class`; do mv $$A $$A.old; done;' >> .jikes
188         echo -n 'PATH=upstream/install/bin:$$PATH jikes -classpath lib/libgcj-minimal.jar:build/class $$@ -d build/class/ -sourcepath build/java/ ' >> .jikes
189         (type jikes && (jikes --version | grep "Version 1.18")) || make .install_jikes-1.18_ target=
190         echo -n "$(jikes_flags) -bootclasspath " >> .jikes
191         echo "public class GetBootClassPath { public static void main(String[] s) { " > GetBootClassPath.java
192         echo "System.out.println(System.getProperty(\"sun.boot.class.path\")); } }"  >> GetBootClassPath.java
193         javac GetBootClassPath.java
194         java -cp . GetBootClassPath >> .jikes
195         rm GetBootClassPath.*
196         echo 'EXIT=$$?' >> .jikes
197         #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
198         #echo 'for A in `find build/class -name \*.class`; do test -e $$A.old && rm $$A.old; done' >> .jikes
199         echo 'exit $$EXIT' >> .jikes
200         mv .jikes .jikes+
201         cp .jikes+ .jikes
202         chmod +x .jikes