blob: f9dbeb23d58e3f2c4a404476d18f13c2041c3c4b (
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
#!@@SHELL@@
#
# opkhelper
# src/opkbuild
# Build opkg packages.
#
# 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 3 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/>.
. @@LIBDIR@@/messages
. @@LIBDIR@@/locale
. @@LIBDIR@@/changelog
# Environment variables:
export OH_SOURCE=
export OH_SOURCE_VERSION=
export OH_SOURCE_VERSION_UPSTREAM=
export OH_BINARY_VERSION=
export OH_BUILD_ARCH=
export OH_BUILD_ARCH_CPU=
export OH_BUILD_ARCH_KERNEL=
export OH_BUILD_ARCH_LIBS=
export OH_BUILD_PLATFORM=
export OH_BUILD_ARCH_GNU=
export OH_HOST_ARCH=
export OH_HOST_ARCH_CPU=
export OH_HOST_ARCH_KERNEL=
export OH_HOST_ARCH_LIBS=
export OH_HOST_PLATFORM=
export OH_HOST_ARCH_GNU=
export OH_TOOL_PREFIX=
export AR=
export AS=
export CC=
export CPP=
export CXXLD=
export NM=
export OBJCOPY=
export OBJDUMP=
export RANLIB=
export READELF=
export SIZE=
export STRINGS=
export STRIP=
# Global parameters:
OPT_BUILD=
OPT_TARGET=
OPT_HOST_ARCH=
OPT_HOST_PLAT=
OPT_CHECK_BUILD_DEPS=
OPT_CLEAN=
OPT_UID0_CMD=
main()
{
oh_locale_set
oh_set_source_dir .
get_options
if [ "${#}" -ne 0 ]; then
oh_usage
exit 1
fi
test_uid0_cmd
find_sanity
oh_changelog_parse setup_package
if [ "${OPT_BUILD}" = 'source' -o "${OPT_BUILD}" = 'full' ]; then
build_source
fi
if [ "${OPT_BUILD}" != 'source' ]; then
"${OPT_CHECK_BUILD_DEPS}" && oh-checkbuilddeps
setup_build
print_arch_stats
if [ -n "${OH_CV_STEP}" ]; then
"step_${OH_CV_STEP}"
else
make_work_area
fi
fi
}
get_options()
{
# Parse and handle command-line options.
while getopts 'bBASFT:a:P:Ddr:hV' opt; do
case "${opt}" in
b)
if [ -n "${OPT_BUILD}" ]; then
oh_error "${oh_str_basf_mutex}"
fi
OPT_BUILD=binary
;;
B)
if [ -n "${OPT_BUILD}" ]; then
oh_error "${oh_str_basf_mutex}"
fi
OPT_BUILD=binary-arch
;;
A)
if [ -n "${OPT_BUILD}" ]; then
oh_error "${oh_str_basf_mutex}"
fi
OPT_BUILD=binary-indep
;;
S)
if [ -n "${OPT_BUILD}" ]; then
oh_error "${oh_str_basf_mutex}"
fi
OPT_BUILD=source
;;
F)
if [ -n "${OPT_BUILD}" ]; then
oh_error "${oh_str_basf_mutex}"
fi
OPT_BUILD=full
;;
T)
OPT_TARGET="${OPTARG}"
;;
a)
OPT_HOST_ARCH="${OPTARG}"
;;
P)
OPT_HOST_PLAT="${OPTARG}"
;;
D)
OPT_CHECK_BUILD_DEPS=true
;;
d)
OPT_CHECK_BUILD_DEPS=false
;;
C)
OPT_CLEAN=true
;;
c)
OPT_CLEAN=false
;;
r)
OPT_UID0_CMD="${OPTARG}"
;;
h)
oh_help
exit 0
;;
V)
oh_version
exit 0
;;
?)
oh_error "${oh_str_bad_opt}" "${opt}"
exit 1
;;
esac
done
shift $(($OPTIND - 1))
# Set default option values.
[ -z "${OPT_BUILD}" ] && OPT_BUILD=full
[ -z "${OPT_CHECK_BUILD_DEPS}" ] && OPT_CHECK_BUILD_DEPS=true
[ -z "${OPT_UID0_CMD}" ] && OPT_UID0_CMD=fakeroot
# Set default target and cleaning behavior.
if [ -n "${OPT_TARGET}" ]; then
[ -z "${OPT_CLEAN}" ] && OPT_CLEAN=false
else
if [ "${OPT_BUILD}" = 'full' ]; then
OPT_TARGET=binary
else
OPT_TARGET="${OPT_BUILD}"
fi
[ -z "${OPT_CLEAN}" ] && OPT_CLEAN=true
fi
}
test_uid0_cmd()
{
# Verify that the UID 0 command works.
test_uid=$("${OPT_UID_CMD}" id -u)
if [ "${?}" -ne 0 ]; then
oh_error "${oh_str_uid0_cmd_not_found}" "${OPT_UID_CMD}"
fi
if [ "${test_uid}" -ne 0 ]; then
oh_error "${oh_str_uid0_cmd_bad_uid}" "${OPT_UID_CMD}"
fi
}
find_sanity()
{
oh_info "${oh_str_find_sanity}"
format="$(cat format 2>/dev/null)"
if [ "${?}" -ne 0 ]; then
oh_error "${oh_str_no_format}"
fi
if [ "${format}" -ne 0 ]; then
oh_error "${oh_str_unsupported_format}"
fi
# Check for all files immediately required by SPF 2.0.
[ ! -f 'control' ] && oh_error "${oh_str_no_control}"
[ ! -x 'config' ] && oh_error "${oh_str_no_config}"
[ ! -f 'copyright' ] && oh_error "${oh_str_no_copyright}"
[ ! -f 'changelog' ] && oh_error "${oh_str_no_changelog}"
}
setup_package()
{
OH_SOURCE="${OH_CHANGELOG_SOURCE}"
OH_SOURCE_VERSION="${OH_CHANGELOG_VERSION}"
OH_SOURCE_VERSION_UPSTREAM="${OH_SOURCE_VERSION:%%-}"
OH_BINARY_VERSION="${OH_SOURCE_VERSION}"
return 1
}
build_source()
{
oh_info "${oh_str_installing_src_pkg_files}"
src_pkg_data_base="src:${OH_SOURCE}.data/usr/src"
src_pkg_data_base="${src_pkg_data_base}/${OH_SOURCE}_${OH_SOURCE_VERSION}"
"${OPT_UID0_CMD}" mkdir -p \
"${src_pkg_data_base}" || \
oh_error "${oh_str_cant_make_src_pkg_dir}"
for file in ../*; do
case "${file}" in
../tmp)
;;
../*)
"${OPT_UID0_CMD}" cp -R "${file}" "${src_pkg_data_base}" || \
oh_error "${oh_str_cant_install_src_pkg_file}"
;;
esac
done
# TODO: oh-gencontrol
# TODO: oh-buildopk
rm -Rf "src:${OH_SOURCE}.data" || oh_error "${oh_str_cant_rm_src_pkg_data}"
}
setup_build()
{
setup_build_arch
setup_build_flags
setup_build_platform
setup_host_arch
setup_host_platform
setup_toolchain
}
setup_build_arch()
{
# TODO: Get build arch from opkg.
# TODO: Get GNU system type from table.
IFS=- read OH_BUILD_ARCH_CPU OH_BUILD_ARCH_KERNEL OH_BUILD_ARCH_LIBS <<EOF
${OH_BUILD_ARCH}
EOF
}
setup_build_flags()
{
# TODO: Don't hardcode path.
if [ -f "/usr/local/share/opkhelper/buildflags/${OH_HOST_ARCH_CPU}" ]; then
. /usr/local/share/opkhelper/buildflags/${OH_HOST_ARCH_CPU}
fi
}
setup_build_platform()
{
# TODO: Get build platform from opkg.
}
setup_host_arch()
{
if [ -n "${OPT_HOST_ARCH}" ]; then
OH_HOST_ARCH="${OPT_HOST_ARCH}"
else
OH_HOST_ARCH="${OH_BUILD_ARCH}"
fi
IFS=- read OH_HOST_ARCH_CPU OH_HOST_ARCH_KERNEL OH_HOST_ARCH_LIBS <<EOF
${OH_HOST_ARCH}
EOF
}
setup_host_platform()
{
if [ -n "${OPT_HOST_PLAT}" ]; then
OH_HOST_PLATFORM="${OPT_HOST_PLAT}"
else
OH_HOST_PLATFORM="${OH_BUILD_PLATFORM}"
fi
}
setup_toolchain()
{
OH_TOOL_PREFIX="${OH_HOST_ARCH}-"
# Set toolchain environment variables.
# NB: This is written for GNU Binutils and GCC and won't work for, e.g., LLVM.
AR="${OH_TOOL_PREFIX}ar"
AS="${OH_TOOL_PREFIX}as"
CC="${OH_TOOL_PREFIX}gcc"
CPP="${OH_TOOL_PREFIX}cpp"
CXX="${OH_TOOL_PREFIX}g++"
LD="${OH_TOOL_PREFIX}ld"
NM="${OH_TOOL_PREFIX}nm"
OBJCOPY="${OH_TOOL_PREFIX}objcopy"
OBJDUMP="${OH_TOOL_PREFIX}objdump"
RANLIB="${OH_TOOL_PREFIX}ranlib"
READELF="${OH_TOOL_PREFIX}readelf"
SIZE="${OH_TOOL_PREFIX}size"
STRINGS="${OH_TOOL_PREFIX}strings"
STRIP="${OH_TOOL_PREFIX}strip"
}
print_arch_stats()
{
oh_info "${oh_str_build_arch_stat_header}"
oh_info "${oh_str_arch_stat_arch}" "${OH_BUILD_ARCH}"
oh_info "${oh_str_arch_stat_plat}" "${OH_BUILD_PLATFORM}"
oh_info "${oh_str_host_arch_stat_header}"
oh_info "${oh_str_arch_stat_arch}" "${OH_HOST_ARCH}"
oh_info "${oh_str_arch_stat_plat}" "${OH_HOST_PLATFORM}"
}
make_work_area()
{
mkdir tmp || oh_error "${oh_str_cant_make_work_area}"
cd tmp || oh_error "${oh_str_cant_enter_work_area}"
oh_set_source_dir ..
step_unpack
}
step_unpack()
{
oh_cv_set step unpack
oh-unpacksource
step_patch
}
step_patch()
{
oh_cv_set step patch
oh-applypatches
step_config
}
step_config()
{
oh_cv_set step config
./config
step_platconf
}
step_platconf()
{
oh_cv_set step platconf
oh-copyconfig
step_build
}
step_build()
{
oh_cv_set step build
./build "${OPT_TARGET}"
"${OPT_CLEAN}" && step_clean
}
step_clean()
{
oh_cv_set step clean
./config clean
step_cleanwork
}
step_cleanwork()
{
oh_cv_clear
cd ..
rm -Rf tmp
}
main "${@}"
|