1 | #
|
---|
2 | # Copyright (c) 2011 Petr Koupy
|
---|
3 | # All rights reserved.
|
---|
4 | #
|
---|
5 | # Redistribution and use in source and binary forms, with or without
|
---|
6 | # modification, are permitted provided that the following conditions
|
---|
7 | # are met:
|
---|
8 | #
|
---|
9 | # - Redistributions of source code must retain the above copyright
|
---|
10 | # notice, this list of conditions and the following disclaimer.
|
---|
11 | # - Redistributions in binary form must reproduce the above copyright
|
---|
12 | # notice, this list of conditions and the following disclaimer in the
|
---|
13 | # documentation and/or other materials provided with the distribution.
|
---|
14 | # - The name of the author may not be used to endorse or promote products
|
---|
15 | # derived from this software without specific prior written permission.
|
---|
16 | #
|
---|
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | #
|
---|
28 |
|
---|
29 | nullstring =
|
---|
30 | space = $(nullstring) # space
|
---|
31 |
|
---|
32 | # When redefined to 'y' on the command line, certain areas of this Makefile
|
---|
33 | # behave slightly differently to simplify the maintenance of binutils port.
|
---|
34 | MAINTAIN_BINUTILS = n
|
---|
35 |
|
---|
36 | # Information for obtaining specific binutils redistributable package.
|
---|
37 | # Might be subject to change in the future.
|
---|
38 | REDIST_VERSION = 2.21.1
|
---|
39 | REDIST_NAME = binutils-$(REDIST_VERSION)
|
---|
40 | REDIST_FILENAME = $(REDIST_NAME).tar.bz2
|
---|
41 | REDIST_SOURCE = ftp://ftp.gnu.org/gnu/binutils/
|
---|
42 | REDIST_MIRROR = http://www.helenos.org/binutils/
|
---|
43 |
|
---|
44 | # Directory for the binutils source tree.
|
---|
45 | REDIST_DIR = ./redist
|
---|
46 |
|
---|
47 | # File to detect the presence of binutils source tree.
|
---|
48 | REDIST_DETECT = $(REDIST_DIR)/configure
|
---|
49 |
|
---|
50 | # Directory for resulting binutils binaries.
|
---|
51 | BIN_DIR = ./bin
|
---|
52 |
|
---|
53 | # $USPACE_PREFIX have to be based on the absolute path,
|
---|
54 | # because targets derived from it will be referenced from
|
---|
55 | # other than the current directory.
|
---|
56 | USPACE_PREFIX = $(subst $(space),\ ,$(shell pwd))/../..
|
---|
57 |
|
---|
58 | # Ensure static configuration of Makefile.common.
|
---|
59 | STATIC_ONLY = y
|
---|
60 |
|
---|
61 | # Link with POSIX runtime library.
|
---|
62 | POSIX_COMPAT = y
|
---|
63 |
|
---|
64 | # Makefile.common for native applications.
|
---|
65 | COMMON_MAKEFILE_NATIVE = $(USPACE_PREFIX)/Makefile.common
|
---|
66 |
|
---|
67 | # Generated from native Makefile.common.
|
---|
68 | COMMON_MAKEFILE_PATCHED = ./Makefile.common
|
---|
69 |
|
---|
70 | # AWK script which generates patched Makefile.common.
|
---|
71 | MAKEFILE_PATCH = ./patch.awk
|
---|
72 |
|
---|
73 | # Compilers that can be used to build binutils.
|
---|
74 | SUPPORTED_COMPILERS = gcc_cross gcc_native
|
---|
75 |
|
---|
76 | # Patched Makefile.common for ported user space applications.
|
---|
77 | -include $(COMMON_MAKEFILE_PATCHED)
|
---|
78 |
|
---|
79 | # Patch $PATH to intercept toolchain calls.
|
---|
80 | PATH := $(shell pwd):$(PATH)
|
---|
81 | export PATH
|
---|
82 |
|
---|
83 | # Shell script for false toolchain generation.
|
---|
84 | TOOLCHAIN_SCRIPT = ./toolchain.sh
|
---|
85 |
|
---|
86 | # False toolchain.
|
---|
87 | TOOLCHAIN = ./gcc ./as ./ar ./ranlib ./ld ./objdump ./objcopy ./strip
|
---|
88 |
|
---|
89 | # Stamp indicating whether the binutils source tree is patched.
|
---|
90 | BINUTILS_PATCHED = ./done
|
---|
91 |
|
---|
92 | # Shell script for instrusive patches of binutils source tree.
|
---|
93 | BINUTILS_PATCH = ./intrusive.sh
|
---|
94 |
|
---|
95 | # Detection whether the binutils are already configured.
|
---|
96 | BINUTILS_CONFIGURED = $(REDIST_DIR)/Makefile
|
---|
97 |
|
---|
98 | # Generated source file for libposix function stubs without posix_ prefix.
|
---|
99 | CONFOBJ_SOURCE = ./confobj.c
|
---|
100 |
|
---|
101 | # Dummy object file for libposix function stubs without posix_ prefix..
|
---|
102 | # Required by binutils configure script tests that links against symbols
|
---|
103 | # without including headers (which means that symbols are not prefixed).
|
---|
104 | CONFOBJ_OBJECT = $(subst $(space),\ ,$(shell pwd))/confobj.o
|
---|
105 |
|
---|
106 | # Required by libposix on RISC platforms.
|
---|
107 | BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
|
---|
108 |
|
---|
109 | # Map the HelenOS target to binutils target.
|
---|
110 | ifeq ($(PLATFORM),amd64)
|
---|
111 | TARGET = amd64-linux-gnu
|
---|
112 | endif
|
---|
113 | ifeq ($(PLATFORM),arm32)
|
---|
114 | TARGET = arm-linux-gnu
|
---|
115 | endif
|
---|
116 | ifeq ($(PLATFORM),ia32)
|
---|
117 | TARGET = i686-pc-linux-gnu
|
---|
118 | endif
|
---|
119 | ifeq ($(PLATFORM),ia64)
|
---|
120 | TARGET = ia64-pc-linux-gnu
|
---|
121 | endif
|
---|
122 | ifeq ($(PLATFORM),mips32)
|
---|
123 | TARGET = mipsel-linux-gnu
|
---|
124 | endif
|
---|
125 | ifeq ($(PLATFORM),mips32eb)
|
---|
126 | TARGET = mips-linux-gnu
|
---|
127 | endif
|
---|
128 | ifeq ($(PLATFORM),mips64)
|
---|
129 | TARGET = mips64el-linux-gnu
|
---|
130 | endif
|
---|
131 | ifeq ($(PLATFORM),ppc32)
|
---|
132 | TARGET = ppc-linux-gnu
|
---|
133 | endif
|
---|
134 | ifeq ($(PLATFORM),ppc64)
|
---|
135 | TARGET = ppc64-linux-gnu
|
---|
136 | endif
|
---|
137 | ifeq ($(PLATFORM),sparc64)
|
---|
138 | TARGET = sparc64-linux-gnu
|
---|
139 | endif
|
---|
140 |
|
---|
141 | # Binutils configure flags.
|
---|
142 | CONF_FLAGS = --disable-nls --disable-shared --enable-static \
|
---|
143 | --with-zlib=no --with-ppl=no --with-cloog=no \
|
---|
144 | --with-gmp=no --with-mpfr=no --with-mpc=no
|
---|
145 |
|
---|
146 | # Binutils make targets.
|
---|
147 | MAKE_TARGETS = all-gas all-ld
|
---|
148 |
|
---|
149 | # Check presence of gcc compiler.
|
---|
150 | # Make binutils.
|
---|
151 | # Copy binaries.
|
---|
152 | ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
|
---|
153 | all: $(COMMON_MAKEFILE_PATCHED) all_ $(TOOLCHAIN) $(BINUTILS_PATCHED) \
|
---|
154 | $(CONFOBJ_OBJECT) $(BINUTILS_CONFIGURED) $(REDIST_DETECT)
|
---|
155 | $(MAKE) -C $(REDIST_DIR) $(MAKE_TARGETS)
|
---|
156 | cp -f $(REDIST_DIR)/gas/as-new $(BIN_DIR)/as
|
---|
157 | cp -f $(REDIST_DIR)/ld/ld-new $(BIN_DIR)/ld
|
---|
158 | else
|
---|
159 | all:
|
---|
160 | # Skipped: Cannot build binutils with unsupported compiler.
|
---|
161 | endif
|
---|
162 |
|
---|
163 | # Create patched Makefile.common from native Makefile.common.
|
---|
164 | $(COMMON_MAKEFILE_PATCHED): $(MAKEFILE_PATCH) $(COMMON_MAKEFILE_NATIVE)
|
---|
165 | awk -f $^ > $@
|
---|
166 |
|
---|
167 | # Download binutils redistributable package.
|
---|
168 | $(REDIST_FILENAME):
|
---|
169 | wget -c $(REDIST_SOURCE)$(REDIST_FILENAME)
|
---|
170 | if [ ! -e $(REDIST_FILENAME) ]; then \
|
---|
171 | wget -c $(REDIST_MIRROR)$(REDIST_FILENAME); \
|
---|
172 | fi
|
---|
173 |
|
---|
174 | # Extract binutils source tree.
|
---|
175 | $(REDIST_DETECT): $(REDIST_FILENAME)
|
---|
176 | tar -x -j -f $<
|
---|
177 | mv -f -T $(REDIST_NAME) $(REDIST_DIR)
|
---|
178 | touch $@
|
---|
179 |
|
---|
180 | # Generate stubs for libposix functions without posix_ prefix.
|
---|
181 | $(CONFOBJ_SOURCE):
|
---|
182 | echo '/* GENERATED FILE. DO NOT MODIFY. */' > $@; \
|
---|
183 | $(OBJDUMP) -t $(LIBPOSIX_PREFIX)/libposix.a | \
|
---|
184 | grep 'F .text' | grep -o -h -I -E 'posix_[^.]*$$' | sort -u | \
|
---|
185 | sed 's/posix_\([^ ]*\)/char \1() { return 0; }/g' >> $@
|
---|
186 |
|
---|
187 | # Compile dummy object for configure script tests.
|
---|
188 | $(CONFOBJ_OBJECT): $(CONFOBJ_SOURCE) $(TOOLCHAIN)
|
---|
189 | ./gcc -c -o $@ $<
|
---|
190 |
|
---|
191 | # Generate false toolchain scripts.
|
---|
192 | $(TOOLCHAIN): $(TOOLCHAIN_SCRIPT) $(COMMON_MAKEFILE_PATCHED)
|
---|
193 | ./$< gcc $(CC) \
|
---|
194 | '$(CFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS) $(CONFOBJ_OBJECT)'
|
---|
195 | ./$< as $(AS)
|
---|
196 | ./$< ar $(AR)
|
---|
197 | ./$< ranlib
|
---|
198 | ./$< ld $(LD) \
|
---|
199 | '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
|
---|
200 | ./$< objdump $(OBJDUMP)
|
---|
201 | ./$< objcopy $(OBJCOPY)
|
---|
202 | ./$< strip $(STRIP)
|
---|
203 |
|
---|
204 | # Patch binutils source tree.
|
---|
205 | $(BINUTILS_PATCHED): $(BINUTILS_PATCH) $(REDIST_DETECT)
|
---|
206 | ./$< do $(REDIST_DIR)
|
---|
207 | touch $@
|
---|
208 |
|
---|
209 | # Configure binutils.
|
---|
210 | # $LD variable have to exported to override configure script caching.
|
---|
211 | $(BINUTILS_CONFIGURED): $(REDIST_DETECT) $(BINUTILS_PATCHED) \
|
---|
212 | $(TOOLCHAIN) $(CONFOBJ_OBJECT)
|
---|
213 | export LD=ld; \
|
---|
214 | cd $(REDIST_DIR); \
|
---|
215 | ./configure --target=$(TARGET) $(CONF_FLAGS)
|
---|
216 |
|
---|
217 | # Delete binaries.
|
---|
218 | # Clean binutils.
|
---|
219 | # Unpatch binutils.
|
---|
220 | # Delete everything in redist folder.
|
---|
221 | # Delete generated scripts.
|
---|
222 | clean: $(BINUTILS_PATCH) clean_
|
---|
223 | rm -f $(BIN_DIR)/as $(BIN_DIR)/ld
|
---|
224 | rm -f $(CONFOBJ_SOURCE) $(CONFOBJ_OBJECT)
|
---|
225 | ifeq ($(MAINTAIN_BINUTILS),y)
|
---|
226 | if [ -e $(REDIST_DIR)/Makefile ]; then \
|
---|
227 | make -C $(REDIST_DIR) distclean; \
|
---|
228 | fi
|
---|
229 | if [ -e $(BINUTILS_PATCHED) ]; then \
|
---|
230 | ./intrusive.sh undo $(REDIST_DIR); \
|
---|
231 | rm -f $(BINUTILS_PATCHED); \
|
---|
232 | fi
|
---|
233 | else
|
---|
234 | rm -r -f redist/*
|
---|
235 | rm -f $(BINUTILS_PATCHED)
|
---|
236 | endif
|
---|
237 | rm -f $(TOOLCHAIN)
|
---|
238 | rm -f $(COMMON_MAKEFILE_PATCHED)
|
---|
239 |
|
---|