commit | author | age
|
d6b4a7
|
1 |
#!/bin/bash |
G |
2 |
|
|
3 |
# library name and version |
|
4 |
# Official: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git |
01a9d8
|
5 |
LIB_NAME=libgpiod-1.6.2 |
d6b4a7
|
6 |
PACK_SUFIX=tar.gz |
G |
7 |
|
|
8 |
# LingYun source code FTP server |
|
9 |
LY_FTP=http://main.iot-yun.club:2211/src/ |
|
10 |
|
|
11 |
# library download URL address |
|
12 |
LIB_URL=$LY_FTP |
|
13 |
|
|
14 |
# Cross compiler for cross compile on Linux server |
|
15 |
CROSS_COMPILE=arm-linux-gnueabihf- |
|
16 |
|
|
17 |
# compile jobs |
|
18 |
JOBS=`cat /proc/cpuinfo |grep "processor"|wc -l` |
|
19 |
|
|
20 |
# this project absolute path |
|
21 |
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) |
|
22 |
|
|
23 |
# top project absolute path |
|
24 |
TOP_PATH=$(realpath $PRJ_PATH/..) |
|
25 |
|
|
26 |
# binaries install path |
|
27 |
PREFIX_PATH=$TOP_PATH/install |
|
28 |
BIN_PATH=$PREFIX_PATH/bin |
|
29 |
LIB_PATH=$PREFIX_PATH/lib |
|
30 |
INC_PATH=$PREFIX_PATH/include |
|
31 |
|
|
32 |
# check installed or not file |
|
33 |
INST_FILE=$PREFIX_PATH/lib/libgpiod.so |
|
34 |
|
|
35 |
# shell script will exit once get command error |
|
36 |
set -e |
|
37 |
|
|
38 |
#+-------------------------+ |
|
39 |
#| Shell script functions | |
|
40 |
#+-------------------------+ |
|
41 |
|
|
42 |
function pr_error() { |
|
43 |
echo -e "\033[40;31m $1 \033[0m" |
|
44 |
} |
|
45 |
|
|
46 |
function pr_warn() { |
|
47 |
echo -e "\033[40;33m $1 \033[0m" |
|
48 |
} |
|
49 |
|
|
50 |
function pr_info() { |
|
51 |
echo -e "\033[40;32m $1 \033[0m" |
|
52 |
} |
|
53 |
|
|
54 |
function check_result() |
|
55 |
{ |
|
56 |
if [ $? != 0 ] ; then |
|
57 |
pr_error $1 |
|
58 |
fi |
|
59 |
} |
|
60 |
# decompress a packet to destination path |
|
61 |
function do_unpack() |
|
62 |
{ |
|
63 |
tarball=$1 |
|
64 |
dstpath=`pwd` |
|
65 |
|
|
66 |
if [[ $# == 2 ]] ; then |
|
67 |
dstpath=$2 |
|
68 |
fi |
|
69 |
|
|
70 |
pr_info "decompress $tarball => $dstpath" |
|
71 |
|
|
72 |
mkdir -p $dstpath |
|
73 |
case $tarball in |
|
74 |
*.tar.gz) |
|
75 |
tar -xzf $tarball -C $dstpath |
|
76 |
;; |
|
77 |
|
|
78 |
*.tar.bz2) |
|
79 |
tar -xjf $tarball -C $dstpath |
|
80 |
;; |
|
81 |
|
|
82 |
*.tar.xz) |
|
83 |
tar -xJf $tarball -C $dstpath |
|
84 |
;; |
|
85 |
|
|
86 |
*.tar.zst) |
|
87 |
tar -I zstd -xf $tarball -C $dstpath |
|
88 |
;; |
|
89 |
|
|
90 |
*.tar) |
|
91 |
tar -xf $tarball -C $dstpath |
|
92 |
;; |
|
93 |
|
|
94 |
*.zip) |
|
95 |
unzip -qo $tarball -d $dstpath |
|
96 |
;; |
|
97 |
|
|
98 |
*) |
|
99 |
pr_error "decompress Unsupport packet: $tarball" |
|
100 |
return 1; |
|
101 |
;; |
|
102 |
esac |
|
103 |
} |
|
104 |
|
|
105 |
function do_export() |
|
106 |
{ |
|
107 |
BUILD_ARCH=$(uname -m) |
|
108 |
if [[ $BUILD_ARCH =~ "arm" ]] ; then |
|
109 |
pr_warn "local($BUILD_ARCH) compile $LIB_NAME" |
|
110 |
return ; |
|
111 |
fi |
|
112 |
|
|
113 |
pr_warn "cross(${CROSS_COMPILE}) compile $LIB_NAME" |
|
114 |
|
|
115 |
# export cross toolchain |
|
116 |
export CC=${CROSS_COMPILE}gcc |
|
117 |
export CXX=${CROSS_COMPILE}g++ |
|
118 |
export AS=${CROSS_COMPILE}as |
|
119 |
export AR=${CROSS_COMPILE}ar |
|
120 |
export LD=${CROSS_COMPILE}ld |
|
121 |
export NM=${CROSS_COMPILE}nm |
|
122 |
export RANLIB=${CROSS_COMPILE}ranlib |
|
123 |
export OBJDUMP=${CROSS_COMPILE}objdump |
|
124 |
export STRIP=${CROSS_COMPILE}strip |
|
125 |
|
|
126 |
# export cross configure |
|
127 |
export CONFIG_CROSS=" --build=i686-pc-linux --host=arm-linux " |
|
128 |
|
|
129 |
# Clear LDFLAGS and CFLAGS |
|
130 |
export LDFLAGS= |
|
131 |
export CFLAGS= |
|
132 |
} |
|
133 |
|
|
134 |
function do_fetch() |
|
135 |
{ |
|
136 |
if [ -e ${INST_FILE} ] ; then |
|
137 |
pr_warn "$LIB_NAME compile and installed alredy" |
|
138 |
exit ; |
|
139 |
fi |
|
140 |
|
|
141 |
if [ -d $LIB_NAME ] ; then |
|
142 |
pr_warn "$LIB_NAME fetch already" |
|
143 |
return ; |
|
144 |
fi |
|
145 |
|
|
146 |
if [ ! -f ${LIB_NAME}.${PACK_SUFIX} ] ; then |
|
147 |
wget ${LIB_URL}/${LIB_NAME}.${PACK_SUFIX} |
|
148 |
check_result "ERROR: download ${LIB_NAME} failure" |
|
149 |
fi |
|
150 |
|
|
151 |
do_unpack ${LIB_NAME}.${PACK_SUFIX} |
|
152 |
} |
|
153 |
|
|
154 |
function do_build() |
|
155 |
{ |
|
156 |
cd $LIB_NAME |
|
157 |
|
|
158 |
./autogen.sh |
|
159 |
|
|
160 |
do_export |
|
161 |
|
|
162 |
echo "ac_cv_func_malloc_0_nonnull=yes" > arm-linux.cache |
|
163 |
./configure --prefix=${PREFIX_PATH} ${CONFIG_CROSS} --enable-static \ |
|
164 |
--cache-file=arm-linux.cache --enable-tools |
|
165 |
check_result "ERROR: configure ${LIB_NAME} failure" |
|
166 |
|
|
167 |
make -j ${JOBS} && make install |
|
168 |
check_result "ERROR: compile ${LIB_NAME} failure" |
|
169 |
} |
|
170 |
|
|
171 |
function do_clean() |
|
172 |
{ |
|
173 |
rm -rf *${LIB_NAME}* |
|
174 |
} |
|
175 |
|
|
176 |
if [[ $# == 1 && $1 == -c ]] ;then |
|
177 |
pr_warn "start clean ${LIB_NAME}" |
|
178 |
do_clean |
|
179 |
exit; |
|
180 |
fi |
|
181 |
|
|
182 |
do_fetch |
|
183 |
|
|
184 |
do_build |
|
185 |
|