summaryrefslogtreecommitdiffstats
path: root/rules/xchain-binutils.make
blob: 9a2f6ed21e33a5b5ea45dd2bf10b933ed42d8754 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# -*-makefile-*-
# $Id: xchain-binutils.make,v 1.9 2003/10/23 15:01:19 mkl Exp $
#
# Copyright (C) 2002, 2003 by Pengutronix e.K., Hildesheim, Germany
# See CREDITS for details about who has contributed to this project. 
#
# For further information about the PTXdist project and license conditions
# see the README file.
#

ifdef PTXCONF_BUILD_CROSSCHAIN
XCHAIN += xchain-binutils
endif

#
# Paths and names 
#
XCHAIN_BINUTILS_VERSION	= $(BINUTILS_VERSION)
XCHAIN_BINUTILS		= $(BINUTILS)
XCHAIN_BINUTILS_SOURCE	= $(BINUTILS_SOURCE)
XCHAIN_BINUTILS_DIR	= $(XCHAIN_BUILDDIR)/$(XCHAIN_BINUTILS)

# ----------------------------------------------------------------------------
# Get
# ----------------------------------------------------------------------------

xchain-binutils_get: $(STATEDIR)/xchain-binutils.get

xchain-binutils_get_deps = \
	$(XCHAIN_BINUTILS_SOURCE) \
	$(STATEDIR)/xchain-binutils-patches.get

$(STATEDIR)/xchain-binutils.get: $(binutils_get_deps)
	@$(call targetinfo, $@)
	touch $@

$(STATEDIR)/xchain-binutils-patches.get:
	@$(call targetinfo, $@)
	@$(call get_patches, $(XCHAIN_BINUTILS))
	touch $@

# ----------------------------------------------------------------------------
# Extract
# ----------------------------------------------------------------------------

xchain-binutils_extract: $(STATEDIR)/xchain-binutils.extract

$(STATEDIR)/xchain-binutils.extract: $(STATEDIR)/xchain-binutils.get
	@$(call targetinfo, $@)
	@$(call clean, $(XCHAIN_BINUTILS_DIR))
	@$(call extract, $(XCHAIN_BINUTILS_SOURCE), $(XCHAIN_BUILDDIR))
	@$(call patchin, $(BINUTILS), $(XCHAIN_BINUTILS_DIR))
#
# inspired by Erik Andersen's buildroot
#

#
# Enable combreloc, since it is such a nice thing to have...
#
	perl -i -p -e "s,link_info.combreloc = false,link_info.combreloc = true,g;" $(XCHAIN_BINUTILS_DIR)/ld/ldmain.c

#
# Hack binutils to use the correct shared lib loader
#
	cd $(XCHAIN_BINUTILS_DIR) && \
		perl -i -p -e "s,#.*define.*ELF_DYNAMIC_INTERPRETER.*\".*\",#define ELF_DYNAMIC_INTERPRETER \"$(DYNAMIC_LINKER)\",;" \
		`grep -lr "#define ELF_DYNAMIC_INTERPRETER" $(XCHAIN_BINUTILS_DIR)`

#
# Hack binutils to prevent it from searching the host system
# for libraries.  We only want libraries for the target system.
#
	cd $(XCHAIN_BINUTILS_DIR) && \
		perl -i -p -e "s,^NATIVE_LIB_DIRS.*,NATIVE_LIB_DIRS='$(CROSS_LIB_DIR)/usr/lib $(CROSS_LIB_DIR)/lib',;" \
		$(XCHAIN_BINUTILS_DIR)/ld/configure.host
	touch $@

# ----------------------------------------------------------------------------
# Prepare
# ----------------------------------------------------------------------------

xchain-binutils_prepare: $(STATEDIR)/xchain-binutils.prepare

XCHAIN_XCHAIN_BINUTILS_AUTOCONF = \
	--target=$(PTXCONF_GNU_TARGET) \
	--host=$(GNU_HOST) \
	--build=$(GNU_HOST) \
	--prefix=$(PTXCONF_PREFIX) \
	--enable-targets=$(PTXCONF_GNU_TARGET) \
	--disable-nls \
	--enable-shared \
	--enable-commonbfdlib \
	--enable-install-libiberty \
	--with-sysroot=$(CROSS_LIB_DIR) \
	--with-lib-path="$(CROSS_LIB_DIR)/usr/lib:$(CROSS_LIB_DIR)/lib"

XCHAIN_XCHAIN_BINUTILS_ENV	= $(HOSTCC_ENV)

$(STATEDIR)/xchain-binutils.prepare: $(STATEDIR)/xchain-binutils.extract
	@$(call targetinfo, $@)
	@$(call clean, $(XCHAIN_BINUTILS_DIR)/config.cache)
	cd $(XCHAIN_BINUTILS_DIR) && $(XCHAIN_XCHAIN_BINUTILS_ENV) \
		./configure $(XCHAIN_XCHAIN_BINUTILS_AUTOCONF)
	touch $@

# ----------------------------------------------------------------------------
# Compile
# ----------------------------------------------------------------------------

xchain-binutils_compile: $(STATEDIR)/xchain-binutils.compile

$(STATEDIR)/xchain-binutils.compile: $(STATEDIR)/xchain-binutils.prepare 
	@$(call targetinfo, $@)
	make -C $(XCHAIN_BINUTILS_DIR)
	touch $@

# ----------------------------------------------------------------------------
# Install
# ----------------------------------------------------------------------------

xchain-binutils_install: $(STATEDIR)/xchain-binutils.install

$(STATEDIR)/xchain-binutils.install: $(STATEDIR)/xchain-binutils.compile
	@$(call targetinfo, $@)
	make install -C $(XCHAIN_BINUTILS_DIR)
#
# here we convert the static libiberty.a into a
# shared one (.so)
#
	cd $(XCHAIN_BINUTILS_DIR)/libiberty && \
		ld --whole-archive libiberty.a -r -o libiberty-$(XCHAIN_BINUTILS_VERSION).so

	install -m 755 $(XCHAIN_BINUTILS_DIR)/libiberty/libiberty-$(XCHAIN_BINUTILS_VERSION).so \
		$(PTXCONF_PREFIX)/$(GNU_HOST)/$(PTXCONF_GNU_TARGET)/lib
	ln -sf libiberty-$(XCHAIN_BINUTILS_VERSION).so $(PTXCONF_PREFIX)/$(GNU_HOST)/$(PTXCONF_GNU_TARGET)/lib/libiberty.so

#
# ksymoops want's to have libiberty.a, we copy it into the dir where ksymoops
# expects them
#
	install -m 644 $(XCHAIN_BINUTILS_DIR)/libiberty/libiberty.a \
		$(PTXCONF_PREFIX)/$(GNU_HOST)/$(PTXCONF_GNU_TARGET)/lib

	touch $@

# ----------------------------------------------------------------------------
# Target-Install
# ----------------------------------------------------------------------------

xchain-binutils_targetinstall: $(STATEDIR)/xchain-binutils.targetinstall

$(STATEDIR)/xchain-binutils.targetinstall: $(STATEDIR)/xchain-binutils.install
	@$(call targetinfo, $@)
	touch $@

# ----------------------------------------------------------------------------
# Clean
# ----------------------------------------------------------------------------

xchain-binutils_clean: 
	rm -rf $(STATEDIR)/xchain-binutils.* $(XCHAIN_BINUTILS_DIR)

# vim: syntax=make