source: mainline/uspace/app/binutils/Makefile@ 4d4988e

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

Improved reliability of confobj.o creation.

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