summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_lib_kconfig.sh
blob: 7c7c728b8dab37ae4ef3d49bd426a35914f3103a (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
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
#
# Copyright (C) 2018 by Michael Olbrich <m.olbrich@pengutronix.de>
#
# 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.
#


#
# migrate a config file
# look in PTX_MIGRATEDIR for a migration handler and call it
#
# $1	part identifier ("ptx", "platform", "collection", "board", "user")
#
ptxd_kconfig_migrate() {
    local part="${1}"
    local assistent="${PTX_MIGRATEDIR}/migrate_${part}"

    if [ \! -f "${assistent}" ]; then
	return 0
    fi

    cp -- ".config" ".config.old" || return
    sed -f "${assistent}" ".config.old" > ".config"
    retval=$?

    if [ $retval -ne 0 ]; then
	ptxd_dialog_msgbox "error: error occured during migration"
	return ${retval}
    fi

    if ! diff -u ".config.old" ".config" >/dev/null; then
	ptxd_dialog_msgbox "info: successfully migrated '${file_dotconfig}'"
    fi

    return ${retval}
}


#
# $1	what kind of config ("oldconfig", "menuconfig", "dep")
# $2	part identifier ("ptx", "platform", "collection", "board", "user")
# $...	optional parameters
#
ptxd_kconfig() {
    local config="${1}"
    local part="${2}"
    local copy_back="true"

    ptxd_kgen "${part}" || ptxd_bailout "error in kgen"

    local file_kconfig file_dotconfig

    case "${part}" in
    ptx)
	if [ -e "${PTXDIST_WORKSPACE}/Kconfig" ]; then
	    file_kconfig="${PTXDIST_WORKSPACE}/Kconfig"
	else
	    file_kconfig="config/Kconfig"
	fi
	file_dotconfig="${PTXDIST_PTXCONFIG}"
	;;
    platform)
	if [ -e "${PTXDIST_WORKSPACE}/platforms/Kconfig" ]; then
	    file_kconfig="${PTXDIST_WORKSPACE}/platforms/Kconfig"
	else
	    file_kconfig="${PTXDIST_TOPDIR}/platforms/Kconfig"
	fi
	file_dotconfig="${PTXDIST_PLATFORMCONFIG}"
	;;
    collection)
	ptxd_dgen || ptxd_bailout "error in dgen"

	#
	# "PTXDIST_COLLECTIONCONFIG" would overwrite
	# certain "m" packages with "y".
	#
	# but "menuconfig collection" works only on the
	# "m" packages, so unset PTXDIST_COLLECTIONCONFIG
	# here.
	#
	PTXDIST_COLLECTIONCONFIG="" ptxd_colgen || ptxd_bailout "error in colgen"

	file_kconfig="${PTXDIST_TOPDIR}/config/collection/Kconfig"
	file_dotconfig="${3}"
	;;
    board)
	if [ -e "${PTXDIST_WORKSPACE}/boardsetup/Kconfig" ]; then
	    file_kconfig="${PTXDIST_WORKSPACE}/boardsetup/Kconfig"
	else
	    file_kconfig="${PTXDIST_TOPDIR}/config/boardsetup/Kconfig"
	fi
	file_dotconfig="${PTXDIST_BOARDSETUP}"
	;;
    user)
	file_kconfig="${PTXDIST_TOPDIR}/config/setup/Kconfig"
	file_dotconfig="${PTXDIST_PTXRC}"
	;;
    *)
	echo
	echo "${PTXDIST_LOG_PROMPT}error: invalid use of '${FUNCNAME} ${@}'"
	echo
	exit 1
	;;
    esac

    local confdir="${PTXDIST_TEMPDIR}/kconfig"
    if [ ! -d "${confdir}" ]; then
	mkdir -p "${confdir}" || ptxd_bailout "unable to create tmpdir"
	pushd "${confdir}" > /dev/null

	ln -sf "${PTXDIST_TOPDIR}/rules" &&
	mkdir config &&
	ptxd_in_path PTXDIST_PATH config &&
	for dir in "${ptxd_reply[@]}"; do
	    local tmp
	    for tmp in $( ( cd "${dir}" && ls ) 2>/dev/null); do
		if [ ! -e "config/${tmp}" ]; then
		    ln -sfT "${dir}/${tmp}" "config/${tmp}" || break
		fi
	    done
	done &&
	ln -sf "${PTXDIST_TOPDIR}/platforms" &&
	ln -sf "${PTXDIST_WORKSPACE}" workspace &&
	ln -sf "${PTX_KGEN_DIR}/generated"
    else
	pushd "${confdir}" > /dev/null
    fi &&

    if [ -e "${file_dotconfig}" ]; then
	cp -- "${file_dotconfig}" ".config" || return
    fi

    local conf="${PTXDIST_TOPDIR}/scripts/kconfig/conf"
    local mconf="${PTXDIST_TOPDIR}/scripts/kconfig/mconf"
    local nconf="${PTXDIST_TOPDIR}/scripts/kconfig/nconf"

    export \
	KCONFIG_NOTIMESTAMP="1" \
	PROJECT="ptxdist" \
	FULLVERSION="${PTXDIST_VERSION_FULL}"

    case "${config}" in
    menuconfig)
	"${mconf}" "${file_kconfig}"
	;;
    nconfig)
	"${nconf}" "${file_kconfig}"
	;;
    oldconfig)
	#
	# In silent mode, we cannot redirect input. So use
	# oldconfig instead of silentoldconfig if somebody
	# tries to automate us.
	#
	ptxd_kconfig_migrate "${part}" &&
	if tty -s; then
	    "${conf}" --silentoldconfig "${file_kconfig}"
	else
	    "${conf}" --oldconfig "${file_kconfig}"
	fi
	;;
    all*config|randconfig)
	"${conf}" --${config} "${file_kconfig}"
	;;
    dep)
	copy_back="false"
	KCONFIG_ALLCONFIG=".config" "${conf}" \
	    --writedepend --alldefconfig "${file_kconfig}" &&
	mv -- ".config" "${PTXDIST_DGEN_DIR}/${part}config"
	;;
    *)
	echo
	echo "${PTXDIST_LOG_PROMPT}error: invalid use of '${FUNCNAME} ${@}'"
	echo
	exit 1
	;;
    esac

    local retval=${?}
    unset \
	KCONFIG_NOTIMESTAMP \
	PROJECT \
	FULLVERSION

    if [ ${retval} -eq 0 -a "${copy_back}" = "true" ]; then
	cp -- .config "${file_dotconfig}" || return
	if [ -f .config.old ]; then
	    cp -- .config.old "$(readlink -f "${file_dotconfig}").old" || return
	fi
    fi

    popd > /dev/null

    return $retval
}
export -f ptxd_kconfig