summaryrefslogtreecommitdiff
path: root/meta/recipes-devtools/gcc/gcc-cross.inc
blob: a09fd543271f0e5a877a93756790872dcfdf5fe6 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
inherit cross

INHIBIT_DEFAULT_DEPS = "1"
EXTRADEPENDS = ""
DEPENDS = "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}libc-for-gcc ${EXTRADEPENDS} ${NATIVEDEPS}"
PROVIDES = "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}g++"
python () {
    if d.getVar("TARGET_OS", True).startswith("linux"):
        d.setVar("EXTRADEPENDS", "linux-libc-headers")
}

require gcc-configure-common.inc

EXTRA_OECONF += " --enable-poison-system-directories"
EXTRA_OECONF_append_sh4 = " --with-multilib-list= --enable-incomplete-targets "

EXTRA_OECONF += "--disable-libunwind-exceptions \
                 --with-mpfr=${STAGING_DIR_NATIVE}${prefix_native} \
                 --with-system-zlib "

EXTRA_OECONF_PATHS = " \
                      --with-gxx-include-dir=${STAGING_DIR_TARGET}${target_includedir}/c++ \
                      --with-sysroot=${STAGING_DIR_TARGET} \
                      --with-build-sysroot=${STAGING_DIR_TARGET}"

ARCH_FLAGS_FOR_TARGET += "-isystem${STAGING_DIR_TARGET}${target_includedir}"

LIBGCCS_VAR = "-lgcc_s"
LIBGCCS_VAR_avr32 = ""

do_configure_prepend () {
	sed -i 's/BUILD_INFO=info/BUILD_INFO=/' ${S}/gcc/configure
}

do_compile () {
	export CC="${BUILD_CC}"
	export AR_FOR_TARGET="${TARGET_SYS}-ar"
	export RANLIB_FOR_TARGET="${TARGET_SYS}-ranlib"
	export LD_FOR_TARGET="${TARGET_SYS}-ld"
	export NM_FOR_TARGET="${TARGET_SYS}-nm"
	export CC_FOR_TARGET="${CCACHE} ${TARGET_SYS}-gcc ${TARGET_CC_ARCH}"
	export CFLAGS_FOR_TARGET="${TARGET_CFLAGS}"
	export CPPFLAGS_FOR_TARGET="${TARGET_CPPFLAGS}"
	export CXXFLAGS_FOR_TARGET="${TARGET_CXXFLAGS}"
	export LDFLAGS_FOR_TARGET="${TARGET_LDFLAGS}"

	oe_runmake all-host all-target-libgcc
	# now generate script to drive testing
	echo "#!/usr/bin/env sh" >${B}/${TARGET_PREFIX}testgcc
	set >> ${B}/${TARGET_PREFIX}testgcc
	# prune out the unneeded vars
	sed -i -e "/^BASH/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^USER/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^OPT/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^DIRSTACK/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^EUID/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^FUNCNAME/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^GROUPS/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^HOST/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^HOME/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^IFS/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^LC_ALL/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^LOGNAME/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^MACHTYPE/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^OSTYPE/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^PIPE/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^SHELL/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^'/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^UID/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^TERM/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^PATCH_GET/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^PKG_/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^POSIXLY_/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^PPID/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^PS4/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^Q/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^SHLVL/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^STAGING/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^LD_LIBRARY_PATH/d" ${B}/${TARGET_PREFIX}testgcc
	sed -i -e "/^PSEUDO/d" ${B}/${TARGET_PREFIX}testgcc

	# append execution part of the script
cat >> ${B}/${TARGET_PREFIX}testgcc << STOP
target="\$1"
usage () {
	echo "Usage:"
	echo "\$0 user@target 'extra options to dejagnu'"
	echo "\$0 target 'extra options to dejagnu'"
	echo "\$0 target"
	echo "e.g. \$0 192.168.7.2 ' dg.exp=visibility-d.c'"
	echo "will only run visibility-d.c test case"
	echo "e.g. \$0 192.168.7.2 '/-mthumb dg.exp=visibility-d.c'"
	echo "will only run visibility-d.c test case in thumb mode"
	echo "You need to have dejagnu autogen expect installed"
	echo "on the build host"
    }
if [ "x\$target" = "x" ]
then
	echo "Please specify the target machine and remote user in form of user@target\n"
	usage
	exit 1;
fi

shift

echo "\$target" | grep "@" 2>&1 > /dev/null
if [ "x\$?" = "x0" ]
then
   user=\$(echo \$target | cut -d '@' -f 1)
   target=\$(echo \$target | cut -d '@' -f 2)
else
   user=\$USER
fi
ssh \$user@\$target date 2>&1 > /dev/null
if [ "x\$?" != "x0" ]
then
	echo "Failed connecting to \$user@\$target it could be because"
	echo "you don't have passwordless ssh setup to access \$target"
	echo "or sometimes host key has been changed"
	echo "in such case do something like below on build host"
	echo "ssh-keygen -f "~/.ssh/known_hosts" -R \$target"
	echo "and then try ssh \$user@\$target"

	usage
	exit 1
fi
	echo "lappend boards_dir [pwd]/../../.." > ${B}/site.exp
	echo "load_generic_config \"unix\"" > ${B}/${PACKAGE_ARCH}.exp
	echo "set_board_info username \$user" >> ${B}/${PACKAGE_ARCH}.exp
	echo "set_board_info rsh_prog ssh" >> ${B}/${PACKAGE_ARCH}.exp
	echo "set_board_info rcp_prog scp" >> ${B}/${PACKAGE_ARCH}.exp
	echo "set_board_info hostname \$target" >> ${B}/${PACKAGE_ARCH}.exp
	DEJAGNU=${B}/site.exp make -k check RUNTESTFLAGS="--target_board=${PACKAGE_ARCH}\$@"

STOP

	chmod +x ${B}/${TARGET_PREFIX}testgcc

}

INHIBIT_PACKAGE_STRIP = "1"

# Compute how to get from libexecdir to bindir in python (easier than shell)
BINRELPATH = "${@oe.path.relative(d.expand("${libexecdir}/gcc/${TARGET_SYS}/${BINV}"), d.expand("${STAGING_DIR_NATIVE}${prefix_native}/bin/${MULTIMACH_TARGET_SYS}"))}"

do_install () {
	oe_runmake 'DESTDIR=${D}' install-host

	install -d ${D}${target_base_libdir}
	install -d ${D}${target_libdir}
    
	# Link gfortran to g77 to satisfy not-so-smart configure or hard coded g77
	# gfortran is fully backwards compatible. This is a safe and practical solution. 
	ln -sf ${STAGING_DIR_NATIVE}${prefix_native}/bin/${TARGET_PREFIX}gfortran ${STAGING_DIR_NATIVE}${prefix_native}/bin/${TARGET_PREFIX}g77 || true

	
	# Insert symlinks into libexec so when tools without a prefix are searched for, the correct ones are
	# found. These need to be relative paths so they work in different locations.
	dest=${D}${libexecdir}/gcc/${TARGET_SYS}/${BINV}/
	install -d $dest
	for t in ar as ld nm objcopy objdump ranlib strip g77 gcc cpp gfortran; do
		ln -sf ${BINRELPATH}/${TARGET_PREFIX}$t $dest$t
		ln -sf ${BINRELPATH}/${TARGET_PREFIX}$t ${dest}${TARGET_PREFIX}$t
	done

	# Remove things we don't need but keep share/java
	for d in info man share/doc share/locale share/man share/info; do
		rm -rf ${D}${STAGING_DIR_NATIVE}${prefix_native}/$d
	done

	# We use libiberty from binutils
	find ${D}${exec_prefix}/lib -name libiberty.a | xargs rm -f
	find ${D}${exec_prefix}/lib -name libiberty.h | xargs rm -f

	# gcc-runtime installs libgcc into a special location in staging since it breaks doing a standalone build
	case ${PN} in
		*gcc-cross|*gcc-crosssdk)
			dest=${D}/${includedir}/gcc-build-internal-${MULTIMACH_TARGET_SYS}
			cp -fpPR . $dest
		;;
	esac
}

do_package[noexec] = "1"
do_packagedata[noexec] = "1"
do_package_write_ipk[noexec] = "1"
do_package_write_rpm[noexec] = "1"
do_package_write_deb[noexec] = "1"