Skip to content

Commit 3a706a5

Browse files
committed
Build debs without install in build-wolfprovider.sh
1 parent dec159a commit 3a706a5

File tree

4 files changed

+91
-16
lines changed

4 files changed

+91
-16
lines changed

debian/install-openssl.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ main() {
171171
exit 0
172172
fi
173173

174+
if [ -n "output_dir" ]; then
175+
output_dir=$(realpath $output_dir)
176+
fi
177+
174178
work_dir=$(mktemp -d)
175179
printf "Working directory: $work_dir\n"
176180
pushd $work_dir 2>&1 > /dev/null
@@ -183,13 +187,13 @@ main() {
183187
openssl_install
184188
fi
185189

186-
if [ -n "$output_dir" ] && [ "$output_dir" != ".." ]; then
190+
if [ -n "$output_dir" ]; then
187191
if [ ! -d "$output_dir" ]; then
188192
printf "Creating output directory: $output_dir\n"
189193
mkdir -p "$output_dir"
190194
fi
191-
cp ../openssl*.deb $output_dir
192-
cp ../libssl*.deb $output_dir
195+
cp ../openssl*.deb $output_dir || true
196+
cp ../libssl*.deb $output_dir || true
193197
else
194198
printf "No output directory specified, packages stored in $work_dir\n"
195199
fi

debian/install-wolfprov.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ main() {
188188
exit 1
189189
fi
190190

191+
if [ -n "output_dir" ]; then
192+
output_dir=$(realpath $output_dir)
193+
fi
194+
191195
work_dir=$(mktemp -d)
192196
printf "Working directory: $work_dir\n"
193197
pushd $work_dir 2>&1 > /dev/null
@@ -199,12 +203,12 @@ main() {
199203
wolfprov_install
200204
fi
201205

202-
if [ -n "$output_dir" ] && [ "$output_dir" != ".." ]; then
206+
if [ -n "$output_dir" ]; then
203207
if [ ! -d "$output_dir" ]; then
204208
printf "Creating output directory: $output_dir\n"
205209
mkdir -p "$output_dir"
206210
fi
207-
cp ../*.* $output_dir
211+
cp ../*.* $output_dir || true
208212
else
209213
printf "No output directory specified, packages stored in $work_dir\n"
210214
fi

debian/rules

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,35 @@ endif
3232

3333
# Debug build flag
3434
WOLFPROV_DEBUG?=0
35+
DEBUG_FLAG=
3536
ifeq ($(WOLFPROV_DEBUG),1)
3637
VARIANT := $(VARIANT)-debug
3738
VARIANT_DESC := $(VARIANT_DESC) with debug logs
3839
VERSION := $(VERSION)-debug
40+
DEBUG_FLAG := --enable-debug
41+
endif
42+
43+
ifeq ($(DEB_CFLAGS_APPEND),)
44+
export PKG_CONFIG_LIBDIR # value comes from outer environment
45+
export PKG_CONFIG_DIR :=
46+
export PKG_CONFIG_PATH :=
3947
endif
4048

4149
override_dh_auto_configure:
4250
./autogen.sh
43-
ifneq ($(WOLFPROV_DEBUG),0)
44-
./configure --enable-debug
45-
else
46-
./configure
47-
endif
51+
@if [ -n "$(DEB_CFLAGS_APPEND)" ]; then \
52+
printf "DEB_CFLAGS_APPEND: %s\n" $(DEB_CFLAGS_APPEND); \
53+
printf "DEB_CPPFLAGS_APPEND: %s\n" $(DEB_CPPFLAGS_APPEND); \
54+
printf "DEB_CXXFLAGS_APPEND: %s\n" $(DEB_CXXFLAGS_APPEND); \
55+
printf "DEB_LDFLAGS_APPEND: %s\n" $(DEB_LDFLAGS_APPEND); \
56+
@echo "PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR)" \
57+
# ensure only our .pc dirs are searched: \
58+
PKG_CONFIG_DIR= PKG_CONFIG_PATH= \
59+
PKG_CONFIG_LIBDIR="$(PKG_CONFIG_LIBDIR)" \
60+
dh_auto_configure -- $(DEBUG_FLAG); \
61+
else \
62+
./configure $(DEBUG_FLAG); \
63+
fi
4864

4965
override_dh_auto_build:
5066
$(MAKE)
@@ -82,4 +98,23 @@ override_dh_auto_clean:
8298
rm -rf test/standalone/tests/.libs
8399

84100
override_dh_auto_test:
85-
$(MAKE) test
101+
@if [ -n "$(DEB_LDFLAGS_APPEND)" ]; then \
102+
# If DEB_LDFLAGS_APPEND is set, it usually means the \
103+
# build system is using a custom library path, rather \
104+
# than the system path. So let's set up LD_LIBRARY_PATH \
105+
# to use it when running `make test`. \
106+
echo "Setting up LD_LIBRARY_PATH from DEB_LDFLAGS_APPEND"; \
107+
LD_LIBRARY_PATH="$$(echo $(DEB_LDFLAGS_APPEND) | \
108+
grep -oE -- '-L[^ ]+' | sed 's/^-L//' | awk '!seen[$$0]++' | paste -sd: -)" \
109+
$(MAKE) test; \
110+
else \
111+
$(MAKE) test; \
112+
fi
113+
114+
override_dh_shlibdeps:
115+
@if [ -n "$(DEB_LDFLAGS_APPEND)" ]; then \
116+
# Skip shlibdeps for now since we're using a custom library path \
117+
: \
118+
else \
119+
dh_shlibdeps; \
120+
fi

scripts/build-wolfprovider.sh

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ fi
148148
if [ -n "$build_debian" ]; then
149149
set -e
150150

151+
DEB_OUTPUT_DIR=$(realpath '..')
152+
151153
echo "Building Debian package..."
152154
WOLFSSL_OPTS=
153155
WOLFPROV_OPTS=
@@ -161,12 +163,42 @@ if [ -n "$build_debian" ]; then
161163
WOLFSSL_OPTS+=" --fips"
162164
WOLFPROV_OPTS+=" --fips"
163165
fi
166+
if [ "$WOLFPROV_REPLACE_DEFAULT" = "1" ]; then
167+
OPENSSL_OPTS+=" --replace-default"
168+
fi
169+
170+
# wolfSSL and OpenSSL are independent and must be built first
171+
debian/install-wolfssl.sh $WOLFSSL_OPTS --no-install -r $DEB_OUTPUT_DIR
172+
debian/install-openssl.sh $OPENSSL_OPTS --no-install $DEB_OUTPUT_DIR
173+
174+
# wolfProvider depends on wolfSSL and OpenSSL headers and libraries.
175+
# We don't want to install them locally, so we unpack them to
176+
# temp dirs and reference those in the build.
177+
178+
# Unpack the wolfssl packages to a temporary directory
179+
wolfssl_dev_dir=$(mktemp -d)
180+
dpkg -x $DEB_OUTPUT_DIR/libwolfssl_*.deb $wolfssl_dev_dir
181+
dpkg -x $DEB_OUTPUT_DIR/libwolfssl-dev_*.deb $wolfssl_dev_dir
182+
# Unpack the libssl-dev package to a temporary directory
183+
openssl_dev_dir=$(mktemp -d)
184+
dpkg -x $DEB_OUTPUT_DIR/openssl_*.deb $openssl_dev_dir
185+
dpkg -x $DEB_OUTPUT_DIR/libssl-dev_*.deb $openssl_dev_dir
186+
187+
export DEB_HOST_MULTIARCH=$(dpkg-architecture -qDEB_HOST_MULTIARCH)
188+
189+
printf "wolfssl_dev_dir: %s\n" $wolfssl_dev_dir
190+
printf "wolfssl_dev_dir libs: %s\n" $(ls $wolfssl_dev_dir/usr/lib/$DEB_HOST_MULTIARCH)
191+
printf "openssl_dev_dir: %s\n" $openssl_dev_dir
192+
printf "openssl_dev_dir libs: %s\n" $(ls $openssl_dev_dir/usr/lib/$DEB_HOST_MULTIARCH)
193+
194+
export DEB_CFLAGS_APPEND="-I$wolfssl_dev_dir/usr/include -I$openssl_dev_dir/usr/include"
195+
export DEB_CPPFLAGS_APPEND="-I$wolfssl_dev_dir/usr/include -I$openssl_dev_dir/usr/include"
196+
export DEB_CXXFLAGS_APPEND="-I$wolfssl_dev_dir/usr/include -I$openssl_dev_dir/usr/include"
197+
export DEB_LDFLAGS_APPEND="-L$wolfssl_dev_dir/usr/lib/$DEB_HOST_MULTIARCH -L$openssl_dev_dir/usr/lib/$DEB_HOST_MULTIARCH"
198+
export PKG_CONFIG_LIBDIR=$wolfssl_dev_dir/usr/lib/$DEB_HOST_MULTIARCH/pkgconfig:$openssl_dev_dir/usr/lib/$DEB_HOST_MULTIARCH/pkgconfig
199+
debian/install-wolfprov.sh $WOLFPROV_OPTS --no-install $DEB_OUTPUT_DIR
164200

165-
# Must install wolfSSL locally since it is needed to build wolfProvider
166-
debian/install-wolfssl.sh $WOLFSSL_OPTS -r ..
167-
# Always build replace-default mode for openssl. Use the standard one from apt.
168-
debian/install-openssl.sh $OPENSSL_OPTS --replace-default ..
169-
debian/install-wolfprov.sh $WOLFPROV_OPTS --no-install
201+
printf "Debian packages built in: %s\n" $DEB_OUTPUT_DIR
170202

171203
exit 0
172204
fi

0 commit comments

Comments
 (0)