From 9abd36e3af5876f67c633f27496ad5660ab7fe24 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Sun, 18 Oct 2020 22:14:03 -0500
Subject: [PATCH] modify nc build to link libcompat objects directly

Rather than assuming the static version of libcrypto exists for pulling in the compatibility functions, link the compat objects directly. This modifies the object file generation script a bit to handle the empty-case properly as well.
---
 apps/nc/Makefile.am | 8 ++++++--
 crypto/Makefile.am  | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/apps/nc/Makefile.am b/apps/nc/Makefile.am
index d678f1eda..58b5c0118 100644
--- a/apps/nc/Makefile.am
+++ b/apps/nc/Makefile.am
@@ -1,5 +1,7 @@
 include $(top_srcdir)/Makefile.am.common
 
+-include $(abs_top_builddir)/crypto/libcrypto_la_objects.mk
+
 if BUILD_NC
 
 if ENABLE_NC
@@ -12,11 +14,13 @@ endif
 EXTRA_DIST = nc.1
 EXTRA_DIST += CMakeLists.txt
 
-nc_LDFLAGS = $(abs_top_builddir)/crypto/.libs/libcrypto.a
-
 nc_LDADD = $(abs_top_builddir)/tls/libtls.la
 nc_LDADD += $(PLATFORM_LDADD) $(PROG_LDADD)
 
+nc_LDADD += $(libcrypto_la_objects)
+nc_LDADD += $(libcompat_la_objects)
+nc_LDADD += $(libcompatnoopt_la_objects)
+
 AM_CPPFLAGS += -I$(top_srcdir)/apps/nc/compat
 
 nc_SOURCES = atomicio.c
diff --git a/crypto/Makefile.am b/crypto/Makefile.am
index 97a84e1a7..e32ca96c3 100644
--- a/crypto/Makefile.am
+++ b/crypto/Makefile.am
@@ -99,10 +99,10 @@ libcrypto_la_objects.mk: Makefile
 	  | sed 's/  */ $$\(abs_top_builddir\)\/crypto\//g' \
 	  > libcrypto_la_objects.mk
 	@echo "libcompat_la_objects= $(libcompat_la_OBJECTS)" \
-	  | sed 's/  */ $$\(abs_top_builddir\)\/crypto\//g' \
+	  | sed 's/compat\// $$\(abs_top_builddir\)\/crypto\/&/g' \
 	  >> libcrypto_la_objects.mk
 	@echo "libcompatnoopt_la_objects= $(libcompatnoopt_la_OBJECTS)" \
-	  | sed 's/  */ $$\(abs_top_builddir\)\/crypto\//g' \
+	  | sed 's/compat\// $$\(abs_top_builddir\)\/crypto\/&/g' \
 	  >> libcrypto_la_objects.mk
 
 libcrypto_la_LDFLAGS = -version-info @LIBCRYPTO_VERSION@ -no-undefined -export-symbols crypto_portable.sym
