questionable patch: merge of a lot of stuff from the svg branch
[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://unc.dl.sourceforge.net/sourceforge/mingw/w32api-2.3.tar.gz
12 url_mingw-runtime-3.0  := http://unc.dl.sourceforge.net/sourceforge/mingw/mingw-runtime-3.0.tar.gz
13 url_freetype-2.1.4     := http://unc.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_libmspack-20030726 := http://www.kyz.uklinux.net/downloads/libmspack-20030726.tar.gz
17 url_vera-1.10          := http://fgo-temp.acc.umu.se/pub/GNOME/sources/ttf-bitstream-vera/1.10/ttf-bitstream-vera-1.10.tar.gz
18 url_WindowMaker-0.80.2 := http://windowmaker.org/pub/source/release/WindowMaker-0.80.2.tar.gz
19 url_bcel-5.1           := http://www.apache.org/dist/jakarta/bcel/binaries/bcel-5.1.tar.gz
20 url_gnu.regexp-1.1.4   := http://21cma.bao.ac.cn/gentoo/distfiles/gnu.regexp-1.1.4.tar.gz
21
22 .install_binutils-2.13.2.1_powerpc-apple-darwin: .vendor
23         rm -rf upstream/darwin-linker/src
24         cd upstream/darwin-linker; tar xvzf ../install/powerpc-apple-darwin/cctools-478.tgz
25 ifneq ($(shell uname),Darwin)
26         cd upstream/darwin-linker/src/cctools; for A in ../../patches/*.patch; do patch -p0 < $$A; done
27         cp upstream/darwin-linker/src/cctools/ld/fake-mach.c upstream/darwin-linker/src/cctools/libstuff
28         cd upstream/darwin-linker/src/; mkdir macosx-include; cd macosx-include; chmod +x ../../links.sh; ../../links.sh
29 endif
30         make -C upstream/darwin-linker/src/cctools/libstuff
31         make -C upstream/darwin-linker/src/cctools/misc
32         touch upstream/darwin-linker/src/cctools/misc/makeUser.c upstream/darwin-linker/src/cctools/misc/make.h
33         make -C upstream/darwin-linker/src/cctools/misc libtool.NEW
34         make -C upstream/darwin-linker/src/cctools/ld; true
35         make -C upstream/darwin-linker/src/cctools/as
36         make -C upstream/darwin-linker/src/cctools/ar
37         mkdir -p upstream/install/powerpc-apple-darwin/bin
38         cp upstream/darwin-linker/src/cctools/ld/ld_dir/ld.NEW upstream/install/powerpc-apple-darwin/bin/ld.NEW
39         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
40         chmod +x upstream/install/powerpc-apple-darwin/bin/ld
41         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
42         chmod +x upstream/install/powerpc-apple-darwin/bin/ranlib
43         cp upstream/darwin-linker/src/cctools/misc/libtool.NEW upstream/install/powerpc-apple-darwin/bin/apple-libtool
44         cp upstream/darwin-linker/src/cctools/misc/strip.NEW upstream/install/powerpc-apple-darwin/bin/strip
45         cp upstream/darwin-linker/src/cctools/as/appc_dir/as upstream/install/powerpc-apple-darwin/bin/as
46         cp upstream/darwin-linker/src/cctools/ar/ar.NEW upstream/install/powerpc-apple-darwin/bin/ar.NEW
47         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
48         chmod +x upstream/install/powerpc-apple-darwin/bin/ar
49         mkdir -p upstream/install/bin
50         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/ld powerpc-apple-darwin-ld
51         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/as powerpc-apple-darwin-as
52         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/ar powerpc-apple-darwin-ar
53         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/ranlib powerpc-apple-darwin-ranlib
54         cd upstream/install/bin; ln -sf ../powerpc-apple-darwin/bin/strip powerpc-apple-darwin-strip
55         echo -e "#!/bin/sh\nc++filt \$$@\n" > upstream/install/bin/c++filt3; chmod +x upstream/install/bin/c++filt3
56         cd upstream/install/powerpc-apple-darwin/bin; ln -sf ../../bin/c++filt3
57         touch $@
58
59
60 # how to configure it
61 ifneq ($(shell uname),$(platform))
62 configure_gcc-3.3                       += --with-headers=$(shell pwd)/upstream/install/$(target)/include
63 endif
64 configure_gcc-3.3                       += --enable-languages=c,c++,java --enable-gc-type=boehm --disable-jvmpi --without-libffi
65 configure_gcc-3.3                       += --with-ld=$(shell pwd)/upstream/install/bin/$(target)-ld
66 configure_gcc-3.3                       += --with-as=$(shell pwd)/upstream/install/bin/$(target)-as
67 ifneq ($(platform),Darwin)
68 configure_gcc-3.3                       += --with-gnu-ld --with-gnu-as
69 endif
70 configure_gcc-3.3                       += --disable-java-awt --disable-interpreter --enable-libgcj
71 configure_gcc-3.3                       += --disable-shared --enable-static --disable-jni
72 configure_binutils-2.13.2.1             += --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 #environment_gcc-3.3_i686-pc-linux-gnu   += CFLAGS="-Wl,-ldl"
82
83 # libjpeg's configury doesn't obey --target
84 environment_jpeg-6b_$(target)           += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
85 environment_jpeg-6b_$(target)           += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
86 environment_jpeg-6b_$(target)           += CFLAGS="-Os -ffunction-sections -fdata-sections -I ."
87 environment_jpeg-6b_$(target)           += AR="$(shell pwd)/upstream/install/$(target)/bin/ar rc"
88 environment_jpeg-6b_$(target)           += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
89
90 # libmspack configury doesn't obey --target
91 environment_libmspack-20030726_$(target) += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
92 environment_libmspack-20030726_$(target) += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
93 environment_libmspack-20030726_$(target) += AR="$(shell pwd)/upstream/install/$(target)/bin/ar"
94 environment_libmspack-20030726_$(target) += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
95 environment_libmspack-20030726_$(target) += OPTIM="-ffunction-sections -fdata-sections -O3"
96
97 # WindowMaker configury doesn't obey --target
98 environment_WindowMaker-0.80.2_$(target) += PATH=$(shell pwd)/upstream/install/$(target)/bin:$$PATH
99 environment_WindowMaker-0.80.2_$(target) += CC=$(shell pwd)/upstream/install/bin/$(target)-gcc
100 environment_WindowMaker-0.80.2_$(target) += AR="$(shell pwd)/upstream/install/$(target)/bin/ar"
101 environment_WindowMaker-0.80.2_$(target) += AR2=$(shell pwd)/upstream/install/$(target)/bin/ranlib
102 environment_WindowMaker-0.80.2_$(target) += LDFLAGS="-lXext -ldl"
103 make_install_WindowMaker-0.80.2_$(target) := -C WINGs install; make -C wrlib
104 make_WindowMaker-0.80.2_$(target) := WINGs
105
106 environment_gcc_3.3_$(target)           += PATH=$(shell pwd)/upstream/install/bin:$$PATH
107
108 .PRECIOUS: .vendor .download_% .configure_%_$(target) .install_%_$(target)
109
110 .download_org.ibex.nestedvm:
111         @mkdir -p upstream; cd upstream; rm -rf org.ibex.$*; rm -rf org.ibex.$*_*
112         @cd upstream; git clone http://nestedvm.ibex.org/.git org.ibex.nestedvm
113         @touch $@
114
115 .download_org.ibex.%:
116         @echo -e "\033[1mfetching repository                 org.ibex.$*\033[0m"
117         @mkdir -p upstream; cd upstream; rm -rf org.ibex.$*; rm -rf org.ibex.$*_*
118         @cd upstream; darcs get --verbose --partial --repo-name=org.ibex.$* http://$*.ibex.org
119         @rm -f src/org/ibex/$*
120         @ln -s ../../../upstream/org.ibex.$*/src/org/ibex/$* src/org/ibex/$*
121         @touch $@
122
123 .build_org.ibex.nestedvm: .vendor .download_org.ibex.nestedvm
124         cd upstream/org.ibex.nestedvm; make usr=$(shell pwd)/upstream/install all env.sh
125         touch $@
126
127 .install_org.ibex.nestedvm: .build_org.ibex.nestedvm
128         touch $@
129
130 # vendor-supplied binaries and headers; this is stuff that comes with various OSes
131 vendor: .vendor; @true
132 .vendor:
133         @echo -e "\n\033[1mdownloading vendor-supplied headers and libraries...\033[0m"
134         mkdir -p upstream/install
135         curl http://www.megacz.com/vendor.tgz | tar xzf - -C upstream/install
136         mkdir -p upstream/install/i686-pc-mingw32
137         curl $(url_w32api-2.3) | tar xzf - -C upstream/install/i686-pc-mingw32
138         curl $(url_mingw-runtime-3.0) | tar xzf - -C upstream/install/i686-pc-mingw32
139 ifeq ($(shell uname),Linux)
140         cd upstream/install/i686-pc-linux-gnu/include; rm -rf *; ln -sf /usr/include/* .
141 endif
142         touch .vendor
143
144 .download_gcc-3.3_powerpc-apple-darwin:
145         @echo -e "\n\033[1mdownloading $*...\033[0m"
146         mkdir -p upstream/gcc-3.3
147         curl $(url_gcc-3.3) | tar xzf - -C upstream/gcc-3.3
148         mv upstream/gcc-3.3/gcc-3.3 upstream/gcc-3.3/src-darwin; true
149         mv upstream/gcc-3.3/libmspack upstream/gcc-3.3/src-darwin; true
150         (cd upstream/gcc-3.3/src-darwin && for A in ../patches/[a-y]*.patch; do patch -p0 -l < $$A; done); true
151         (cd upstream/gcc-3.3/src-darwin && for A in ../patches-darwin/*.patch; do patch -p0 -l < $$A; done); true
152         touch $@
153
154 .download_%:
155         @echo -e "\n\033[1mdownloading $*...\033[0m"
156         mkdir -p upstream/$*
157         curl $(url_$*) | tar xzf - -C upstream/$*
158         mv upstream/$*/$* upstream/$*/src; true
159         mv upstream/$*/libmspack upstream/$*/src; true
160         (test -e upstream/$*/patches && cd upstream/$*/src && for A in ../patches/*.patch; do patch -p0 -l < $$A; done); true
161         touch $@
162
163 .configure_gcc-3.3_powerpc-apple-darwin: .download_gcc-3.3_powerpc-apple-darwin .install_binutils-2.13.2.1_powerpc-apple-darwin
164         @echo -e "\n\033[1mconfiguring gcc...\033[0m"
165         mkdir -p upstream/gcc-3.3/build-$(target)
166         cd upstream/gcc-3.3/build-$(target); \
167                 $(setcc) $(environment_gcc-3.3_$(target)) ../src-darwin/configure \
168                 --target=$(target) \
169                 --prefix=`cd ../..; pwd`/install \
170                 $(configure_gcc-3.3) \
171                 $(configure_gcc-3.3_$(target))
172         touch $@
173
174 .configure_gcc-3.3_$(target): .install_binutils-2.13.2.1_$(target)
175
176 .configure_%_$(target): .vendor .download_%
177         @echo -e "\n\033[1mconfiguring $*...\033[0m"
178         mkdir -p upstream/$*/build-$(target)
179         cd upstream/$*/build-$(target); \
180                 $(setcc) $(environment_$*_$(target)) ../src/configure \
181                 --target=$(target) \
182                 --prefix=`cd ../..; pwd`/install \
183                 $(configure_$*) \
184                 $(configure_$*_$(target))
185         touch $@
186
187 .configure_libmspack-20030726_$(target): .download_libmspack-20030726 .install_gcc-3.3_$(target)
188         mkdir -p upstream/libmspack-20030726/build-$(target)
189         cd upstream/libmspack-20030726/build-$(target); ln -sf ../src/mspack/* .
190         touch $@
191
192 .install_freetype-2.1.4_mips-unknown-elf: .install_org.ibex.nestedvm .download_freetype-2.1.4
193         cd upstream/freetype-2.1.4/src; \
194            make setup ansi; \
195            PATH=$$PATH:`pwd`/../../install/bin make \
196               CC=mips-unknown-elf-gcc \
197               AR=mips-unknown-elf-ar \
198               CFLAGS="-c -ffunction-sections -fdata-sections -O3"
199         upstream/install/bin/mips-unknown-elf-ranlib upstream/freetype-2.1.4/src/objs/libfreetype.a
200         touch $@
201
202 .build_%_$(target): .configure_%_$(target)
203         @echo -e "\n\033[1mbuilding $*...\033[0m"
204         cd upstream/$*/build-$(target); \
205                 $(setcc) PATH=$$PATH:`pwd`/../../install/bin \
206                 $(environment_$*_$(target)) \
207                 make $(make_$*_$(target)) $(setcc) $(environment_$*_$(target))
208         touch $@
209
210 .install_libmspack-20030726_$(target): .build_libmspack-20030726_$(target); true
211
212 .install_gcc-3.3_mips-unknown-elf: .install_org.ibex.nestedvm
213         touch $@
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
224