source: mainline/uspace/app/binutils/Makefile@ 2431f30

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

Build process debugged and improved.
Added intrusive patches to pass configure scripts.

  • Property mode set to 100644
File size: 5.8 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# Map the HelenOS target to binutils target.
91ifeq ($(PLATFORM),amd64)
92TARGET = amd64-linux-gnu
93endif
94ifeq ($(PLATFORM),arm32)
95TARGET = arm-linux-gnu
96endif
97ifeq ($(PLATFORM),ia32)
98TARGET = i686-pc-linux-gnu
99endif
100ifeq ($(PLATFORM),ia64)
101TARGET = ia64-pc-linux-gnu
102endif
103ifeq ($(PLATFORM),mips32)
104TARGET = mipsel-linux-gnu
105endif
106ifeq ($(PLATFORM),mips32eb)
107TARGET = mips-linux-gnu
108endif
109ifeq ($(PLATFORM),mips64)
110TARGET = mips64el-linux-gnu
111endif
112ifeq ($(PLATFORM),ppc32)
113TARGET = ppc-linux-gnu
114endif
115ifeq ($(PLATFORM),ppc64)
116TARGET = ppc64-linux-gnu
117endif
118ifeq ($(PLATFORM),sparc64)
119TARGET = sparc64-linux-gnu
120endif
121
122# Binutils configure flags.
123CONF_FLAGS = --disable-nls --disable-shared --enable-static \
124 --with-zlib=no --with-ppl=no --with-cloog=no \
125 --with-gmp=no --with-mpfr=no --with-mpc=no
126
127# Binutils make targets.
128MAKE_TARGETS = all-gas all-ld
129
130# Check presence of gcc compiler.
131# Make binutils.
132# Copy binaries.
133ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
134all: $(COMMON_MAKEFILE_PATCHED) all_ $(TOOLCHAIN) $(BINUTILS_PATCHED) \
135 $(BINUTILS_CONFIGURED) $(REDIST_DETECT)
136 make -C $(REDIST_DIR) $(MAKE_TARGETS)
137 cp -f $(REDIST_DIR)/gas/as-new ./as
138 cp -f $(REDIST_DIR)/ld/ld-new ./ld
139else
140all:
141 # Skipped: Cannot build binutils with unsupported compiler.
142endif
143
144# Create patched Makefile.common from native Makefile.common.
145$(COMMON_MAKEFILE_PATCHED): $(MAKEFILE_PATCH) $(COMMON_MAKEFILE_NATIVE)
146 awk -f $^ > $@
147
148# Download binutils redistributable package.
149$(REDIST_FILENAME):
150 wget -c $(REDIST_SOURCE)$(REDIST_FILENAME)
151
152# Extract binutils source tree.
153$(REDIST_DETECT): $(REDIST_FILENAME)
154 tar -x -j -f $<
155 mv -f -T $(REDIST_NAME) $(REDIST_DIR)
156 touch $@
157
158# Generate false toolchain scripts.
159$(TOOLCHAIN): $(TOOLCHAIN_SCRIPT)
160 ./$< gcc $(CC) '$(CFLAGS)'
161 ./$< as $(AS)
162 ./$< ar $(AR)
163 ./$< ranlib
164 ./$< ld $(LD) '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
165 ./$< objdump $(OBJDUMP)
166 ./$< objcopy $(OBJCOPY)
167 ./$< strip $(STRIP)
168
169# Patch binutils source tree.
170$(BINUTILS_PATCHED): $(BINUTILS_PATCH) $(REDIST_DETECT)
171 ./$< do $(REDIST_DIR)
172 touch $@
173
174# Configure binutils.
175# $LD variable have to exported to override configure script caching.
176$(BINUTILS_CONFIGURED): $(REDIST_DIR)/configure $(REDIST_DETECT)
177 export LD=ld; \
178 cd $(REDIST_DIR); \
179 ./configure --target=$(TARGET) $(CONF_FLAGS)
180
181# Delete binaries.
182# Clean binutils.
183# Unpatch binutils.
184# Delete generated scripts.
185clean: $(BINUTILS_PATCH) clean_
186 rm -f as ld
187 if [ -e $(REDIST_DIR)/Makefile ]; then \
188 make -C $(REDIST_DIR) distclean; \
189 fi
190 if [ -e $(BINUTILS_PATCHED) ]; then \
191 ./intrusive.sh undo $(REDIST_DIR); \
192 rm -f $(BINUTILS_PATCHED); \
193 fi
194 rm -f $(TOOLCHAIN)
195 rm -f $(COMMON_MAKEFILE_PATCHED)
196
Note: See TracBrowser for help on using the repository browser.