source: mainline/uspace/app/binutils/Makefile@ 927af3af

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

Improved Makefile reentrancy.

  • Property mode set to 100644
File size: 5.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# 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),\ ,$(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 := $(PWD):$(PATH)
73
74# Shell script for false toolchain generation.
75TOOLCHAIN_SCRIPT = ./toolchain.sh
76
77# False toolchain.
78TOOLCHAIN = ./gcc ./as ./ar ./ranlib ./ld ./objdump ./objcopy ./strip
79
80# Stamp indicating whether the binutils source tree is patched.
81BINUTILS_PATCHED = ./done
82
83# Shell script for instrusive patches of binutils source tree.
84BINUTILS_PATCH = ./intrusive.sh
85
86# Detection whether the binutils are already configured.
87BINUTILS_CONFIGURED = $(REDIST_DIR)/Makefile
88
89# Map the HelenOS target to binutils target.
90ifeq ($(PLATFORM),amd64)
91TARGET=amd64-linux-gnu
92else ($(PLATFORM),arm32)
93TARGET=arm-linux-gnu
94else ($(PLATFORM),ia32)
95TARGET=i686-pc-linux-gnu
96else ($(PLATFORM),ia64)
97TARGET=ia64-pc-linux-gnu
98else ($(PLATFORM),mips32)
99TARGET=mipsel-linux-gnu
100else ($(PLATFORM),mips32eb)
101TARGET=mips-linux-gnu
102else ($(PLATFORM),mips64)
103TARGET=mips64el-linux-gnu
104else ($(PLATFORM),ppc32)
105TARGET=ppc-linux-gnu
106else ($(PLATFORM),ppc64)
107TARGET=ppc64-linux-gnu
108else ($(PLATFORM),sparc64)
109TARGET=sparc64-linux-gnu
110endif
111
112# Binutils configure flags.
113CONF_FLAGS = --disable-nls --disable-shared --enable-static \
114 --with-zlib=no
115
116# Binutils make targets.
117MAKE_TARGETS = all-gas all-ld
118
119# Check presence of gcc compiler.
120# Make binutils.
121# Copy binaries.
122ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
123all: $(COMMON_MAKEFILE_PATCHED) all_ $(TOOLCHAIN) $(BINUTILS_PATCHED) \
124 $(BINUTILS_CONFIGURED) $(REDIST_DETECT)
125 export PATH
126 make -C $(REDIST_DIR) $(MAKE_TARGETS)
127 cp -f $(REDIST_DIR)/gas/as-new ./as
128 cp -f $(REDIST_DIR)/ld/ld-new ./ld
129else
130all:
131 # Skipped: Cannot build binutils with unsupported compiler.
132endif
133
134# Create patched Makefile.common from native Makefile.common.
135$(COMMON_MAKEFILE_PATCHED): $(MAKEFILE_PATCH) $(COMMON_MAKEFILE_NATIVE)
136 awk -f $^ > $@
137
138# Download binutils redistributable package.
139$(REDIST_FILENAME):
140 wget -c $(REDIST_SOURCE)$(REDIST_FILENAME)
141
142# Extract binutils source tree.
143$(REDIST_DETECT): $(REDIST_FILENAME)
144 tar -x -j -f $<
145 mv -f $(REDIST_NAME) $(REDIST_DIR)
146
147# Generate false toolchain scripts.
148$(TOOLCHAIN): $(TOOLCHAIN_SCRIPT)
149 $^ gcc $(CC) '$(CFLAGS)'
150 $^ as $(AS)
151 $^ ar $(AR)
152 $^ ranlib
153 $^ ld $(LD) '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
154 $^ objdump $(OBJDUMP)
155 $^ objcopy $(OBJCOPY)
156 $^ strip $(STRIP)
157
158# Patch binutils source tree.
159$(BINUTILS_PATCHED): $(BINUTILS_PATCH) $(REDIST_DETECT)
160 $^ do $(REDIST_DIR)
161 touch $@
162
163# Configure binutils.
164$(BINUTILS_CONFIGURED): $(REDIST_DIR)/configure $(REDIST_DETECT)
165 $^ --target=$(TARGET) $(CONF_FLAGS)
166
167# Delete binaries.
168# Clean binutils.
169# Unpatch binutils.
170# Delete generated scripts.
171clean:
172 rm -f as ld
173 make -C $(REDIST_DIR) distclean
174 ./intrusive.sh undo $(REDIST_DIR)
175 rm -f $(BINUTILS_PATCHED)
176 rm -f $(TOOLCHAIN)
177 rm -f $(COMMON_MAKEFILE_PATCHED)
178
Note: See TracBrowser for help on using the repository browser.