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

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

Changed behaviour of clean routine. Removed conflict between toolchain and binaries.

  • Property mode set to 100644
File size: 7.2 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
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.
44REDIST_DIR = ./redist
45
46# File to detect the presence of binutils source tree.
47REDIST_DETECT = $(REDIST_DIR)/configure
48
49# Directory for resulting binutils binaries.
50BIN_DIR = ./bin
51
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.
55USPACE_PREFIX = $(subst $(space),\ ,$(shell pwd))/../..
56
57# Ensure static configuration of Makefile.common.
58STATIC_ONLY = y
59
60# Link with POSIX runtime library.
61POSIX_COMPAT = y
62
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.
70MAKEFILE_PATCH = ./patch.awk
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.
76-include $(COMMON_MAKEFILE_PATCHED)
77
78# Patch $PATH to intercept toolchain calls.
79PATH := $(shell pwd):$(PATH)
80export PATH
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
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
105# Required by libposix on RISC platforms.
106BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
107
108# Map the HelenOS target to binutils target.
109ifeq ($(PLATFORM),amd64)
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
138endif
139
140# Binutils configure flags.
141CONF_FLAGS = --disable-nls --disable-shared --enable-static \
142 --with-zlib=no --with-ppl=no --with-cloog=no \
143 --with-gmp=no --with-mpfr=no --with-mpc=no
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)))
152all: $(COMMON_MAKEFILE_PATCHED) all_ $(TOOLCHAIN) $(BINUTILS_PATCHED) \
153 $(CONFOBJ_OBJECT) $(BINUTILS_CONFIGURED) $(REDIST_DETECT)
154 make -C $(REDIST_DIR) $(MAKE_TARGETS)
155 cp -f $(REDIST_DIR)/gas/as-new $(BIN_DIR)/as
156 cp -f $(REDIST_DIR)/ld/ld-new $(BIN_DIR)/ld
157else
158all:
159 # Skipped: Cannot build binutils with unsupported compiler.
160endif
161
162# Create patched Makefile.common from native Makefile.common.
163$(COMMON_MAKEFILE_PATCHED): $(MAKEFILE_PATCH) $(COMMON_MAKEFILE_NATIVE)
164 awk -f $^ > $@
165
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 $<
173 mv -f -T $(REDIST_NAME) $(REDIST_DIR)
174 touch $@
175
176# Generate stubs for libposix functions without posix_ prefix.
177$(CONFOBJ_SOURCE):
178 echo '/* GENERATED FILE. DO NOT MODIFY. */' > $@; \
179 $(OBJDUMP) -t $(LIBPOSIX_PREFIX)/libposix.a | \
180 grep F | grep -o -h -I -E 'posix_.*$$' | sort -u | \
181 sed 's/posix_\([^ ]*\)/char \1() { return 0; }/g' >> $@
182
183# Compile dummy object for configure script tests.
184$(CONFOBJ_OBJECT): $(CONFOBJ_SOURCE) $(TOOLCHAIN)
185 ./gcc -c -o $@ $<
186
187# Generate false toolchain scripts.
188$(TOOLCHAIN): $(TOOLCHAIN_SCRIPT)
189 ./$< gcc $(CC) \
190 '$(CFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS) $(CONFOBJ_OBJECT)'
191 ./$< as $(AS)
192 ./$< ar $(AR)
193 ./$< ranlib
194 ./$< ld $(LD) \
195 '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
196 ./$< objdump $(OBJDUMP)
197 ./$< objcopy $(OBJCOPY)
198 ./$< strip $(STRIP)
199
200# Patch binutils source tree.
201$(BINUTILS_PATCHED): $(BINUTILS_PATCH) $(REDIST_DETECT)
202 ./$< do $(REDIST_DIR)
203 touch $@
204
205# Configure binutils.
206# $LD variable have to exported to override configure script caching.
207$(BINUTILS_CONFIGURED): $(REDIST_DIR)/configure $(REDIST_DETECT)
208 export LD=ld; \
209 cd $(REDIST_DIR); \
210 ./configure --target=$(TARGET) $(CONF_FLAGS)
211
212# Delete binaries.
213# Clean binutils.
214# Unpatch binutils.
215# Delete everything in redist folder.
216# Delete generated scripts.
217clean: $(BINUTILS_PATCH) clean_
218 rm -f $(BIN_DIR)/as $(BIN_DIR)/ld
219 rm -f $(CONFOBJ_SOURCE) $(CONFOBJ_OBJECT)
220ifeq ($(MAINTAIN_BINUTILS),y)
221 if [ -e $(REDIST_DIR)/Makefile ]; then \
222 make -C $(REDIST_DIR) distclean; \
223 fi
224 if [ -e $(BINUTILS_PATCHED) ]; then \
225 ./intrusive.sh undo $(REDIST_DIR); \
226 rm -f $(BINUTILS_PATCHED); \
227 fi
228else
229 rm -r -f redist/*
230 rm -f $(BINUTILS_PATCHED)
231endif
232 rm -f $(TOOLCHAIN)
233 rm -f $(COMMON_MAKEFILE_PATCHED)
234
Note: See TracBrowser for help on using the repository browser.