summaryrefslogtreecommitdiffstats
path: root/lib/buildsystem/kbuild.sh
blob: 362fe05bed18cb62dc7ddb14b7ee01ed8cfd2a77 (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
# opkhelper
# lib/buildsystem/kbuild
# Build system plugin for kbuild.
#
# Copyright (C) 2012 Patrick "P. J." McDermott
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

[ -n "${_OH_BUILDSYSTEM_KBUILD_SM}" ] && return 0
_OH_BUILDSYSTEM_KBUILD_SM='true'

_oh_kbuild_can_configure()
{
	[ -d "${_OH_BUILDSYSTEM_SOURCE_DIR}/scripts/kconfig" -a \
		-r "${_OH_BUILDSYSTEM_SOURCE_DIR}/Makefile" ]
}

_oh_kbuild_configure()
{
	return 0
}

_oh_kbuild_can_build()
{
	_oh_kbuild_can_configure
}

_oh_kbuild_build()
{
	_oh_kbuild_update_target '' "${@}"
}

_oh_kbuild_can_clean()
{
	_oh_kbuild_can_configure
}

_oh_kbuild_clean()
{
	_oh_kbuild_update_target 'clean' "${@}"
}

_oh_kbuild_can_test()
{
	return 1
}

_oh_kbuild_can_install()
{
	_oh_kbuild_can_configure
}

_oh_kbuild_install()
{
	_oh_kbuild_update_target 'install' \
		"${@}" "DESTDIR=${_OH_BUILDSYSTEM_DESTDIR}"
}

_oh_kbuild_update_target()
{
	_oh_local _ohbskut_target _ohbskut_arch _ohbskut_rc

	_ohbskut_target="${1}"
	shift

	if ! _ohbskut_arch="$(oh_buildsystem_arch "${OPK_HOST_ARCH}" 'kbuild')"
	then
		_oh_return 1
		return ${?}
	fi

	mkdir -p "${_OH_BUILDSYSTEM_BUILD_DIR}"
	cd "${_OH_BUILDSYSTEM_BUILD_DIR}"

	if [ -n "${_OH_BUILDSYSTEM_BUILD_TARGET}" ]; then
		make ARCH="${_ohbskut_arch}" CROSS_COMPILE="${OPK_TOOL_PREFIX}" \
			"${@}" "${_OH_BUILDSYSTEM_BUILD_TARGET}"
		_ohbskut_rc=${?}
	elif [ -n "${_ohbskut_target}" ]; then
		make ARCH="${_ohbskut_arch}" CROSS_COMPILE="${OPK_TOOL_PREFIX}" \
			"${@}" "${_ohbskut_target}"
		_ohbskut_rc=${?}
	else
		make ARCH="${_ohbskut_arch}" CROSS_COMPILE="${OPK_TOOL_PREFIX}" \
			"${@}"
		_ohbskut_rc=${?}
	fi

	cd "${_OH_BUILDSYSTEM_WORK_AREA}"

	_oh_return ${_ohbskut_rc}
	return ${?}
}

_oh_kbuild_test_arch()
{
	_oh_local _ohbskta_arch

	_ohbskta_arch="${1}"

	make -n ARCH="${_ohbskta_arch}" help >/dev/null 2>&1

	_oh_return ${?}
	return ${?}
}