commit | author | age
|
1e563e
|
1 |
#!/bin/bash |
G |
2 |
|
|
3 |
# library name and version |
|
4 |
# Official: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git |
|
5 |
LIB_NAME=libgpiod-2.0 |
|
6 |
PACK_SUFIX=tar.gz |
|
7 |
|
|
8 |
# Cross compiler for cross compile on Linux server |
|
9 |
CROSS_COMPILE=arm-linux-gnueabihf- |
|
10 |
|
|
11 |
# this project absolute path |
|
12 |
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) |
|
13 |
|
|
14 |
# binaries install path |
|
15 |
PREFIX_PATH=$PRJ_PATH/install |
|
16 |
|
|
17 |
# check installed or not file |
|
18 |
INST_FILE=$PREFIX_PATH/lib/libgpiod.so |
|
19 |
|
|
20 |
#+-------------------------+ |
|
21 |
#| Shell script functions | |
|
22 |
#+-------------------------+ |
|
23 |
|
|
24 |
function pr_error() { |
|
25 |
echo -e "\033[40;31m $1 \033[0m" |
|
26 |
} |
|
27 |
|
|
28 |
function pr_warn() { |
|
29 |
echo -e "\033[40;33m $1 \033[0m" |
|
30 |
} |
|
31 |
|
|
32 |
function pr_info() { |
|
33 |
echo -e "\033[40;32m $1 \033[0m" |
|
34 |
} |
|
35 |
|
|
36 |
function check_result() |
|
37 |
{ |
|
38 |
if [ $? != 0 ] ; then |
|
39 |
pr_error $1 |
|
40 |
fi |
|
41 |
} |
|
42 |
|
|
43 |
function do_export() |
|
44 |
{ |
|
45 |
pr_warn "set cross(${CROSS_COMPILE})" |
|
46 |
|
|
47 |
# export cross toolchain |
|
48 |
export CC=${CROSS_COMPILE}gcc |
|
49 |
export CXX=${CROSS_COMPILE}g++ |
|
50 |
export AS=${CROSS_COMPILE}as |
|
51 |
export AR=${CROSS_COMPILE}ar |
|
52 |
export LD=${CROSS_COMPILE}ld |
|
53 |
export NM=${CROSS_COMPILE}nm |
|
54 |
export RANLIB=${CROSS_COMPILE}ranlib |
|
55 |
export OBJDUMP=${CROSS_COMPILE}objdump |
|
56 |
export STRIP=${CROSS_COMPILE}strip |
|
57 |
|
|
58 |
# export cross configure |
|
59 |
export CONFIG_CROSS=" --build=i686-pc-linux --host=arm-linux " |
|
60 |
|
|
61 |
# Clear LDFLAGS and CFLAGS |
|
62 |
export LDFLAGS= |
|
63 |
export CFLAGS= |
|
64 |
} |
|
65 |
|
|
66 |
function do_fetch() |
|
67 |
{ |
|
68 |
if [ -e ${INST_FILE} ] ; then |
|
69 |
pr_warn "$LIB_NAME compile and installed alredy" |
|
70 |
exit ; |
|
71 |
fi |
|
72 |
|
|
73 |
if [ -d $LIB_NAME ] ; then |
|
74 |
pr_warn "$LIB_NAME fetch already" |
|
75 |
return ; |
|
76 |
fi |
|
77 |
|
|
78 |
if [ ! -f ${LIB_NAME}.${PACK_SUFIX} ] ; then |
|
79 |
wget https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/snapshot/${LIB_NAME}.${PACK_SUFIX} |
|
80 |
check_result "ERROR: download ${LIB_NAME} failure" |
|
81 |
fi |
|
82 |
|
|
83 |
pr_warn "$LIB_NAME download already, decompress it now" |
|
84 |
tar -xzf ${LIB_NAME}.${PACK_SUFIX} |
|
85 |
} |
|
86 |
|
|
87 |
function do_build() |
|
88 |
{ |
|
89 |
cd $LIB_NAME |
|
90 |
|
|
91 |
./autogen.sh |
|
92 |
|
|
93 |
do_export |
|
94 |
|
|
95 |
echo "ac_cv_func_malloc_0_nonnull=yes" > arm-linux.cache |
|
96 |
./configure --prefix=${PREFIX_PATH} ${CONFIG_CROSS} --enable-static \ |
|
97 |
--cache-file=arm-linux.cache --enable-tools |
|
98 |
check_result "ERROR: configure ${LIB_NAME} failure" |
|
99 |
|
|
100 |
make -j ${JOBS} && make install |
|
101 |
check_result "ERROR: compile ${LIB_NAME} failure" |
|
102 |
} |
|
103 |
|
|
104 |
function do_clean() |
|
105 |
{ |
|
106 |
rm -rf ${LIB_NAME}* |
|
107 |
rm -rf install |
|
108 |
} |
|
109 |
|
|
110 |
if [[ $# == 1 && $1 == -c ]] ;then |
|
111 |
pr_warn "start clean $LIB_NAME" |
|
112 |
do_clean |
|
113 |
exit; |
|
114 |
fi |
|
115 |
|
|
116 |
do_fetch |
|
117 |
|
|
118 |
do_build |