source: mainline/uspace/app/binutils/Makefile@ 78de7be2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 78de7be2 was 8afa52c, checked in by Petr Koupy <petr.koupy@…>, 14 years ago

Port upgraded to version 2.21.1. Added mirror fallback for download.

  • Property mode set to 100644
File size: 7.4 KB
Line 
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
29nullstring =
30space = $(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.
34MAINTAIN_BINUTILS = n
35
36# Information for obtaining specific binutils redistributable package.
37# Might be subject to change in the future.
38REDIST_VERSION = 2.21.1
39REDIST_NAME = binutils-$(REDIST_VERSION)
40REDIST_FILENAME = $(REDIST_NAME).tar.bz2
41REDIST_SOURCE = ftp://ftp.gnu.org/gnu/binutils/
42REDIST_MIRROR = http://www.helenos.org/binutils/
43
44# Directory for the binutils source tree.
45REDIST_DIR = ./redist
46
47# File to detect the presence of binutils source tree.
48REDIST_DETECT = $(REDIST_DIR)/configure
49
50# Directory for resulting binutils binaries.
51BIN_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.
56USPACE_PREFIX = $(subst $(space),\ ,$(shell pwd))/../..
57
58# Ensure static configuration of Makefile.common.
59STATIC_ONLY = y
60
61# Link with POSIX runtime library.
62POSIX_COMPAT = y
63
64# Makefile.common for native applications.
65COMMON_MAKEFILE_NATIVE = $(USPACE_PREFIX)/Makefile.common
66
67# Generated from native Makefile.common.
68COMMON_MAKEFILE_PATCHED = ./Makefile.common
69
70# AWK script which generates patched Makefile.common.
71MAKEFILE_PATCH = ./patch.awk
72
73# Compilers that can be used to build binutils.
74SUPPORTED_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.
80PATH := $(shell pwd):$(PATH)
81export PATH
82
83# Shell script for false toolchain generation.
84TOOLCHAIN_SCRIPT = ./toolchain.sh
85
86# False toolchain.
87TOOLCHAIN = ./gcc ./as ./ar ./ranlib ./ld ./objdump ./objcopy ./strip
88
89# Stamp indicating whether the binutils source tree is patched.
90BINUTILS_PATCHED = ./done
91
92# Shell script for instrusive patches of binutils source tree.
93BINUTILS_PATCH = ./intrusive.sh
94
95# Detection whether the binutils are already configured.
96BINUTILS_CONFIGURED = $(REDIST_DIR)/Makefile
97
98# Generated source file for libposix function stubs without posix_ prefix.
99CONFOBJ_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).
104CONFOBJ_OBJECT = $(subst $(space),\ ,$(shell pwd))/confobj.o
105
106# Required by libposix on RISC platforms.
107BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
108
109# Map the HelenOS target to binutils target.
110ifeq ($(PLATFORM),amd64)
111TARGET = amd64-linux-gnu
112endif
113ifeq ($(PLATFORM),arm32)
114TARGET = arm-linux-gnu
115endif
116ifeq ($(PLATFORM),ia32)
117TARGET = i686-pc-linux-gnu
118endif
119ifeq ($(PLATFORM),ia64)
120TARGET = ia64-pc-linux-gnu
121endif
122ifeq ($(PLATFORM),mips32)
123TARGET = mipsel-linux-gnu
124endif
125ifeq ($(PLATFORM),mips32eb)
126TARGET = mips-linux-gnu
127endif
128ifeq ($(PLATFORM),mips64)
129TARGET = mips64el-linux-gnu
130endif
131ifeq ($(PLATFORM),ppc32)
132TARGET = ppc-linux-gnu
133endif
134ifeq ($(PLATFORM),ppc64)
135TARGET = ppc64-linux-gnu
136endif
137ifeq ($(PLATFORM),sparc64)
138TARGET = sparc64-linux-gnu
139endif
140
141# Binutils configure flags.
142CONF_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.
147MAKE_TARGETS = all-gas all-ld
148
149# Check presence of gcc compiler.
150# Make binutils.
151# Copy binaries.
152ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
153all: $(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
158else
159all:
160 # Skipped: Cannot build binutils with unsupported compiler.
161endif
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.
222clean: $(BINUTILS_PATCH) clean_
223 rm -f $(BIN_DIR)/as $(BIN_DIR)/ld
224 rm -f $(CONFOBJ_SOURCE) $(CONFOBJ_OBJECT)
225ifeq ($(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
233else
234 rm -r -f redist/*
235 rm -f $(BINUTILS_PATCHED)
236endif
237 rm -f $(TOOLCHAIN)
238 rm -f $(COMMON_MAKEFILE_PATCHED)
239
Note: See TracBrowser for help on using the repository browser.