forked from goToMain/libosdp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·166 lines (142 loc) · 4.55 KB
/
configure
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
#!/bin/bash
#
# Copyright (c) 2021 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
--skip-mark Don't send the leading mark byte (0xFF)
--use-openssl Use methods from openssl instead of in-tree ones
--openssl-include-dir DIR Include directory for openssl if not in system path
--no-colours Don't colourize log ouputs
--static-pd Setup PD single statically
--file Compile support for file tx command
-f, --force Use this flags to override some checks
-h, --help Print this help
---
}
while [ $# -gt 0 ]; do
case $1 in
--packet-trace) PACKET_TRACE=1;;
--skip-mark) SKIP_MARK_BYTE=1;;
--cross-compile) CROSS_COMPILE=$2; shift;;
--use-openssl) USE_OPENSSL=1;;
--openssl-include-dir) OPENSSL_INCLUDE_DIR=$2; shift;;
--no-colours) NO_COLOURS=1;;
--static-pd) STATIC_PD=1;;
--file) FILE=1;;
-f|--force) FORCE=1;;
-h|--help) usage; exit 0;;
*) echo -e "Unknown option $1\n"; usage; exit 1;;
esac
shift
done
if [ -f config.mak ] && [ -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 "${SKIP_MARK_BYTE}" ]]; then
CCFLAGS+=" -DCONFIG_OSDP_SKIP_MARK_BYTE"
fi
if [[ ! -z "${STATIC_PD}" ]]; then
CCFLAGS+=" -DCONFIG_OSDP_STATIC_PD"
fi
if [[ ! -z "${FILE}" ]]; then
CCFLAGS+=" -DCONFIG_OSDP_FILE"
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 [[ ! -z "${USE_OPENSSL}" ]]; then
CCFLAGS+=" -DCONFIG_OSDP_USE_OPENSSL"
if [[ ! -z "${OPENSSL_INCLUDE_DIR}" ]]; then
CCFLAGS+=" -I${OPENSSL_INCLUDE_DIR}"
CXXFLAGS+=" -I${OPENSSL_INCLUDE_DIR}"
fi
fi
## Declare sources
if [[ -z "${USE_OPENSSL}" ]]; then
echo "Using in-tree AES methods. Consider using openssl (--use-openssl)"
LIBOSDP_SOURCES+=" src/osdp_aes.c"
fi
LIBOSDP_SOURCES+=" src/osdp_common.c src/osdp_phy.c src/osdp_sc.c src/osdp_pd.c"
LIBOSDP_SOURCES+=" utils/src/list.c utils/src/queue.c utils/src/slab.c utils/src/utils.c"
if [[ -z "${STATIC_PD}" ]]; then
LIBOSDP_SOURCES+=" src/osdp_cp.c"
OSDP_SAMPLES="cp_app.out pd_app.out"
else
OSDP_SAMPLES="pd_app.out"
fi
if [[ ! -z "${FILE}" ]]; then
LIBOSDP_SOURCES+=" src/osdp_file.c"
fi
## Generate osdp_config.h
echo "Generating osdp_config.h"
cp src/osdp_config.h.in osdp_config.h
sed -i "" -e "s/@PROJECT_VERSION@/${PROJECT_VERSION}/" osdp_config.h
sed -i "" -e "s/@PROJECT_NAME@/${PROJECT_NAME}/" osdp_config.h
sed -i "" -e "s/@GIT_BRANCH@/${GIT_BRANCH}/" osdp_config.h
sed -i "" -e "s/@GIT_REV@/${GIT_REV}/" osdp_config.h
sed -i "" -e "s/@GIT_TAG@/${GIT_TAG}/" osdp_config.h
sed -i "" -e "s/@GIT_DIFF@/${GIT_DIFF}/" osdp_config.h
## Generate osdp_exports.h
echo "Generating osdp_exports.h"
cat > osdp_export.h <<----
#ifndef OSDP_EXPORT_H
#define OSDP_EXPORT_H
#define OSDP_EXPORT
#define OSDP_NO_EXPORT
#endif /* OSDP_EXPORT_H */
---
## Generate Makefile
echo "Generating config.mak"
cat > config.mak << ---
CC=${CC}
CXX=${CXX}
AR=${AR}
SYSROOT=${SYSROOT}
CCFLAGS=${CCFLAGS}
CXXFLAGS=${CXXFLAGS}
LDFLAGS=${LDFLAGS}
SRC=${LIBOSDP_SOURCES}
---
echo
echo "LibOSDP lean build system configured!"
echo "Invoke 'make' to build."