-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
configure.sh
executable file
·225 lines (191 loc) · 6.57 KB
/
configure.sh
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
#!/usr/bin/env bash
#
# Copyright (c) 2021-2024 Siddharth Chandrasekaran <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#
usage() {
cat >&2<<----
LibOSDP build configure script
Configures a bare minimum build environemt for LibOSDP. This is not a
replacement for cmake and intended only for those users who don't care
about all the bells and whistles and need only the library.
OPTIONS:
--packet-trace Enable raw packet trace for diagnostics
--data-trace Enable command/reply data buffer tracing
--skip-mark Don't send the leading mark byte (0xFF)
--crypto LIB Use methods from LIB (openssl/mbedtls/*tinyaes)
--crypto-include-dir DIR Include directory for crypto LIB if not in system path
--crypto-ld-flags Args to pass to linker for the crypto LIB
--no-colours Don't colourize log ouputs
--static-pd Setup PD single statically
--lib-only Only build the library
--cross-compile PREFIX Use to pass a compiler prefix
--prefix PATH Install path prefix (default: /usr)
--build-dir Build output directory (default: ./build)
-d, --debug Enable debug builds
-f, --force Use this flags to override some checks
-h, --help Print this help
---
}
BUILD_DIR="build"
SCRIPT_DIR="$(dirname $(readlink -f "$0"))"
while [ $# -gt 0 ]; do
case $1 in
--packet-trace) PACKET_TRACE=1;;
--data-trace) DATA_TRACE=1;;
--skip-mark) SKIP_MARK_BYTE=1;;
--cross-compile) CROSS_COMPILE=$2; shift;;
--prefix) PREFIX=$2; shift;;
--crypto) CRYPTO=$2; shift;;
--crypto-include-dir) CRYPTO_INCLUDE_DIR=$2; shift;;
--crypto-ld-flags) CRYPTO_LD_FLAGS=$2; shift;;
--no-colours) NO_COLOURS=1;;
--static-pd) STATIC_PD=1;;
--lib-only) LIB_ONLY=1;;
--build-dir) BUILD_DIR=$2; shift;;
-d|--debug) DEBUG=1;;
-f|--force) FORCE=1;;
-h|--help) usage; exit 0;;
*) echo -e "Unknown option $1\n"; usage; exit 1;;
esac
shift
done
mkdir -p ${BUILD_DIR}/include
if [ -f config.make ] && [ -z "$FORCE" ]; then
echo "LibOSDP already configured! Use --force to re-configure"
exit 1
fi
if [[ ("$OSTYPE" == "cygwin") || ("$OSTYPE" == "win32") ]]; then
echo "Warning: unsuported platform. Expect issues!"
fi
## Toolchains
CC=${CC:-${CROSS_COMPILE}gcc}
CXX=${CXX:-${CROSS_COMPILE}g++}
AR=${AR:-${CROSS_COMPILE}ar}
## check if submodules are initialized
if [[ -z "$(ls -A utils)" ]]; then
"Initializing git-submodule utils"
git submodule update --init
fi
## Build options
if [[ ! -z "${NO_COLOURS}" ]]; then
CCFLAGS+=" -DCONFIG_DISABLE_PRETTY_LOGGING"
fi
if [[ ! -z "${PACKET_TRACE}" ]]; then
CCFLAGS+=" -DCONFIG_OSDP_PACKET_TRACE"
fi
if [[ ! -z "${DATA_TRACE}" ]]; then
CCFLAGS+=" -DCONFIG_OSDP_DATA_TRACE"
fi
if [[ ! -z "${SKIP_MARK_BYTE}" ]]; then
CCFLAGS+=" -DCONFIG_OSDP_SKIP_MARK_BYTE"
fi
if [[ ! -z "${STATIC_PD}" ]]; then
CCFLAGS+=" -DCONFIG_OSDP_STATIC_PD"
fi
if [[ ! -z "${DEBUG}" ]]; then
CCFLAGS+=" -g"
fi
## Repo meta data
echo "Extracting source code meta information"
PROJECT_VERSION=$(perl -ne 'print if s/^project\(libosdp VERSION ([0-9.]+)\)$/\1/' CMakeLists.txt)
if [[ -z "${PROJECT_VERSION}" ]]; then
echo "Failed to parse PROJECT_VERSION!"
exit -1
fi
PROJECT_NAME=libosdp
if [[ -d .git ]]; then
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
GIT_REV=$(git log --pretty=format:'%h' -n 1)
GIT_TAG=$(git describe --exact-match --tags 2>/dev/null)
GIT_DIFF=$(git diff --quiet --exit-code || echo +)
fi
if [[ "${CRYPTO}" == "openssl" ]]; then
LIBOSDP_SOURCES+=" src/crypto/openssl.c"
elif [[ "${CRYPTO}" == "mbedtls" ]]; then
LIBOSDP_SOURCES+=" src/crypto/mbedtls.c"
LDFLAGS+=" -lmbedcrypto -lmbedtls"
else
echo "Using in-tree AES methods. Consider using openssl/mbedtls (see --crypto)"
LIBOSDP_SOURCES+=" src/crypto/tinyaes_src.c src/crypto/tinyaes.c"
fi
if [[ ! -z "${CRYPTO_INCLUDE_DIR}" ]]; then
CCFLAGS+=" -I${CRYPTO_INCLUDE_DIR}"
CXXFLAGS+=" -I${CRYPTO_INCLUDE_DIR}"
fi
if [[ ! -z "${CRYPTO_LD_FLAGS}" ]]; then
LDFLAGS+=" -I${CRYPTO_LD_FLAGS}"
fi
## Declare sources
LIBOSDP_SOURCES+=" src/osdp_common.c src/osdp_phy.c src/osdp_sc.c src/osdp_file.c src/osdp_pd.c"
LIBOSDP_SOURCES+=" utils/src/list.c utils/src/queue.c utils/src/slab.c utils/src/utils.c"
LIBOSDP_SOURCES+=" utils/src/disjoint_set.c utils/src/logger.c"
if [[ ! -z "${PACKET_TRACE}" ]] || [[ ! -z "${DATA_TRACE}" ]]; then
LIBOSDP_SOURCES+=" src/osdp_diag.c utils/src/pcap_gen.c"
fi
if [[ -z "${STATIC_PD}" ]]; then
LIBOSDP_SOURCES+=" src/osdp_cp.c"
TARGETS="cp_app pd_app"
else
TARGETS="pd_app"
fi
TEST_SOURCES="tests/unit-tests/test.c tests/unit-tests/test-cp-phy.c"
TEST_SOURCES+=" tests/unit-tests/test-commands.c"
TEST_SOURCES+=" tests/unit-tests/test-cp-fsm.c tests/unit-tests/test-file.c"
TEST_SOURCES+=" ${LIBOSDP_SOURCES} utils/src/workqueue.c utils/src/circbuf.c"
TEST_SOURCES+=" utils/src/event.c utils/src/fdutils.c"
if [[ ! -z "${LIB_ONLY}" ]]; then
TARGETS=""
fi
if [[ -z "${PREFIX}" ]]; then
PREFIX="/usr"
fi
## Generate libosdp.pc
echo "Generating libosdp.pc"
sed -e "s|@CMAKE_INSTALL_PREFIX@|${PREFIX}|" \
-e "s|@PROJECT_NAME@|${PROJECT_NAME}|" \
-e "s|@PROJECT_DESCRIPTION@|Open Supervised Device Protocol (OSDP) Library|" \
-e "s|@PROJECT_URL@|https://github.com/goToMain/libosdp|" \
-e "s|@PROJECT_VERSION@|${PROJECT_VERSION}|" \
misc/libosdp.pc.in > ${BUILD_DIR}/libosdp.pc
## Generate osdp_config.h
echo "Generating osdp_config.h"
sed -e "s|@PROJECT_VERSION@|${PROJECT_VERSION}|" \
-e "s|@PROJECT_NAME@|${PROJECT_NAME}|" \
-e "s|@GIT_BRANCH@|${GIT_BRANCH}|" \
-e "s|@GIT_REV@|${GIT_REV}|" \
-e "s|@GIT_TAG@|${GIT_TAG}|" \
-e "s|@GIT_DIFF@|${GIT_DIFF}|" \
-e "s|@REPO_ROOT@|${SCRIPT_DIR}|" \
src/osdp_config.h.in > ${BUILD_DIR}/include/osdp_config.h
## Generate osdp_exports.h
echo "Generating osdp_exports.h"
cat > ${BUILD_DIR}/include/osdp_export.h <<----
#ifndef OSDP_EXPORT_H
#define OSDP_EXPORT_H
#define OSDP_EXPORT
#define OSDP_NO_EXPORT
#define OSDP_DEPRECATED_EXPORT
#endif /* OSDP_EXPORT_H */
---
CCFLAGS+=" -I${BUILD_DIR}/include"
## Generate Makefile
echo "Generating config.make"
cat > config.make << ---
CC=${CC}
CXX=${CXX}
AR=${AR}
SYSROOT=${SYSROOT}
CCFLAGS=${CCFLAGS}
CXXFLAGS=${CXXFLAGS}
LDFLAGS=${LDFLAGS}
SRC_LIBOSDP=${LIBOSDP_SOURCES}
SRC_TEST=${TEST_SOURCES}
TARGETS=${TARGETS}
BUILD_DIR=$(realpath ${BUILD_DIR})
PREFIX=${PREFIX}
---
echo
echo "LibOSDP lean build system configured!"
echo "Invoke 'make' to build."