source: mainline/uspace/app/binutils/Makefile@ bb285b4

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

Improved reliability and speed of the parallel build.

  • Property mode set to 100644
File size: 7.3 KB
RevLine 
[53d9ee9]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
[f5b2522]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.
[cc677f1]34MAINTAIN_BINUTILS = n
[f5b2522]35
[a0bb65af]36# Information for obtaining specific binutils redistributable package.
37# Might be subject to change in the future.
38REDIST_VERSION = 2.21
39REDIST_NAME = binutils-$(REDIST_VERSION)
40REDIST_FILENAME = $(REDIST_NAME).tar.bz2
41REDIST_SOURCE = ftp://ftp.gnu.org/gnu/binutils/
42
43# Directory for the binutils source tree.
[53d9ee9]44REDIST_DIR = ./redist
45
[a0bb65af]46# File to detect the presence of binutils source tree.
47REDIST_DETECT = $(REDIST_DIR)/configure
[53d9ee9]48
[f5b2522]49# Directory for resulting binutils binaries.
50BIN_DIR = ./bin
51
[53d9ee9]52# $USPACE_PREFIX have to be based on the absolute path,
53# because targets derived from it will be referenced from
54# other than the current directory.
[2431f30]55USPACE_PREFIX = $(subst $(space),\ ,$(shell pwd))/../..
[53d9ee9]56
57# Ensure static configuration of Makefile.common.
58STATIC_ONLY = y
59
[d1671a8]60# Link with POSIX runtime library.
61POSIX_COMPAT = y
62
[53d9ee9]63# Makefile.common for native applications.
64COMMON_MAKEFILE_NATIVE = $(USPACE_PREFIX)/Makefile.common
65
66# Generated from native Makefile.common.
67COMMON_MAKEFILE_PATCHED = ./Makefile.common
68
69# AWK script which generates patched Makefile.common.
[927af3af]70MAKEFILE_PATCH = ./patch.awk
[53d9ee9]71
72# Compilers that can be used to build binutils.
73SUPPORTED_COMPILERS = gcc_cross gcc_native
74
75# Patched Makefile.common for ported user space applications.
[17e4aec]76-include $(COMMON_MAKEFILE_PATCHED)
[53d9ee9]77
[927af3af]78# Patch $PATH to intercept toolchain calls.
[2431f30]79PATH := $(shell pwd):$(PATH)
80export PATH
[927af3af]81
82# Shell script for false toolchain generation.
83TOOLCHAIN_SCRIPT = ./toolchain.sh
84
85# False toolchain.
86TOOLCHAIN = ./gcc ./as ./ar ./ranlib ./ld ./objdump ./objcopy ./strip
87
88# Stamp indicating whether the binutils source tree is patched.
89BINUTILS_PATCHED = ./done
90
91# Shell script for instrusive patches of binutils source tree.
92BINUTILS_PATCH = ./intrusive.sh
93
94# Detection whether the binutils are already configured.
95BINUTILS_CONFIGURED = $(REDIST_DIR)/Makefile
96
[f3a605be]97# Generated source file for libposix function stubs without posix_ prefix.
98CONFOBJ_SOURCE = ./confobj.c
99
100# Dummy object file for libposix function stubs without posix_ prefix..
101# Required by binutils configure script tests that links against symbols
102# without including headers (which means that symbols are not prefixed).
103CONFOBJ_OBJECT = $(subst $(space),\ ,$(shell pwd))/confobj.o
104
[17e4aec]105# Required by libposix on RISC platforms.
106BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
107
[53d9ee9]108# Map the HelenOS target to binutils target.
109ifeq ($(PLATFORM),amd64)
[2431f30]110TARGET = amd64-linux-gnu
111endif
112ifeq ($(PLATFORM),arm32)
113TARGET = arm-linux-gnu
114endif
115ifeq ($(PLATFORM),ia32)
116TARGET = i686-pc-linux-gnu
117endif
118ifeq ($(PLATFORM),ia64)
119TARGET = ia64-pc-linux-gnu
120endif
121ifeq ($(PLATFORM),mips32)
122TARGET = mipsel-linux-gnu
123endif
124ifeq ($(PLATFORM),mips32eb)
125TARGET = mips-linux-gnu
126endif
127ifeq ($(PLATFORM),mips64)
128TARGET = mips64el-linux-gnu
129endif
130ifeq ($(PLATFORM),ppc32)
131TARGET = ppc-linux-gnu
132endif
133ifeq ($(PLATFORM),ppc64)
134TARGET = ppc64-linux-gnu
135endif
136ifeq ($(PLATFORM),sparc64)
137TARGET = sparc64-linux-gnu
[53d9ee9]138endif
139
140# Binutils configure flags.
141CONF_FLAGS = --disable-nls --disable-shared --enable-static \
[2431f30]142 --with-zlib=no --with-ppl=no --with-cloog=no \
143 --with-gmp=no --with-mpfr=no --with-mpc=no
[53d9ee9]144
145# Binutils make targets.
146MAKE_TARGETS = all-gas all-ld
147
148# Check presence of gcc compiler.
149# Make binutils.
150# Copy binaries.
151ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
[927af3af]152all: $(COMMON_MAKEFILE_PATCHED) all_ $(TOOLCHAIN) $(BINUTILS_PATCHED) \
[f3a605be]153 $(CONFOBJ_OBJECT) $(BINUTILS_CONFIGURED) $(REDIST_DETECT)
[bb285b4]154 $(MAKE) -C $(REDIST_DIR) $(MAKE_TARGETS)
[f5b2522]155 cp -f $(REDIST_DIR)/gas/as-new $(BIN_DIR)/as
156 cp -f $(REDIST_DIR)/ld/ld-new $(BIN_DIR)/ld
[53d9ee9]157else
[927af3af]158all:
159 # Skipped: Cannot build binutils with unsupported compiler.
[53d9ee9]160endif
161
162# Create patched Makefile.common from native Makefile.common.
[927af3af]163$(COMMON_MAKEFILE_PATCHED): $(MAKEFILE_PATCH) $(COMMON_MAKEFILE_NATIVE)
[53d9ee9]164 awk -f $^ > $@
165
[a0bb65af]166# Download binutils redistributable package.
167$(REDIST_FILENAME):
168 wget -c $(REDIST_SOURCE)$(REDIST_FILENAME)
169
170# Extract binutils source tree.
171$(REDIST_DETECT): $(REDIST_FILENAME)
172 tar -x -j -f $<
[2431f30]173 mv -f -T $(REDIST_NAME) $(REDIST_DIR)
174 touch $@
[a0bb65af]175
[f3a605be]176# Generate stubs for libposix functions without posix_ prefix.
177$(CONFOBJ_SOURCE):
178 echo '/* GENERATED FILE. DO NOT MODIFY. */' > $@; \
[de576907]179 $(OBJDUMP) -t $(LIBPOSIX_PREFIX)/libposix.a | \
[11809eab]180 grep 'F .text' | grep -o -h -I -E 'posix_[^.]*$$' | sort -u | \
[41e2118]181 sed 's/posix_\([^ ]*\)/char \1() { return 0; }/g' >> $@
[f3a605be]182
183# Compile dummy object for configure script tests.
184$(CONFOBJ_OBJECT): $(CONFOBJ_SOURCE) $(TOOLCHAIN)
185 ./gcc -c -o $@ $<
186
[927af3af]187# Generate false toolchain scripts.
[bb285b4]188$(TOOLCHAIN): $(TOOLCHAIN_SCRIPT) $(COMMON_MAKEFILE_PATCHED)
[f3a605be]189 ./$< gcc $(CC) \
190 '$(CFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS) $(CONFOBJ_OBJECT)'
[2431f30]191 ./$< as $(AS)
192 ./$< ar $(AR)
193 ./$< ranlib
[f3a605be]194 ./$< ld $(LD) \
195 '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
[2431f30]196 ./$< objdump $(OBJDUMP)
197 ./$< objcopy $(OBJCOPY)
198 ./$< strip $(STRIP)
[927af3af]199
200# Patch binutils source tree.
201$(BINUTILS_PATCHED): $(BINUTILS_PATCH) $(REDIST_DETECT)
[2431f30]202 ./$< do $(REDIST_DIR)
[927af3af]203 touch $@
204
205# Configure binutils.
[2431f30]206# $LD variable have to exported to override configure script caching.
[bb285b4]207$(BINUTILS_CONFIGURED): $(REDIST_DETECT) $(BINUTILS_PATCHED) \
208 $(TOOLCHAIN) $(CONFOBJ_OBJECT)
[2431f30]209 export LD=ld; \
210 cd $(REDIST_DIR); \
211 ./configure --target=$(TARGET) $(CONF_FLAGS)
[927af3af]212
[53d9ee9]213# Delete binaries.
214# Clean binutils.
215# Unpatch binutils.
[f5b2522]216# Delete everything in redist folder.
[53d9ee9]217# Delete generated scripts.
[2431f30]218clean: $(BINUTILS_PATCH) clean_
[f5b2522]219 rm -f $(BIN_DIR)/as $(BIN_DIR)/ld
[f3a605be]220 rm -f $(CONFOBJ_SOURCE) $(CONFOBJ_OBJECT)
[f5b2522]221ifeq ($(MAINTAIN_BINUTILS),y)
[2431f30]222 if [ -e $(REDIST_DIR)/Makefile ]; then \
223 make -C $(REDIST_DIR) distclean; \
[df56f5c]224 fi
[2431f30]225 if [ -e $(BINUTILS_PATCHED) ]; then \
226 ./intrusive.sh undo $(REDIST_DIR); \
227 rm -f $(BINUTILS_PATCHED); \
[df56f5c]228 fi
[f5b2522]229else
230 rm -r -f redist/*
231 rm -f $(BINUTILS_PATCHED)
232endif
[927af3af]233 rm -f $(TOOLCHAIN)
[53d9ee9]234 rm -f $(COMMON_MAKEFILE_PATCHED)
235
Note: See TracBrowser for help on using the repository browser.