Skip to content

Commit 6a6dd2d

Browse files
author
Aleksandr Makarov
committed
Link against system libsafec using --with-system-libsafec
Running `./configure --with-system-libsafec` will allow the configuration program to search for and, if found, to link against the libsafec library that is installed in the system. Signed-off-by: Aleksandr Makarov <aleksandr.o.makarov@gmail.com>
1 parent d99e9e5 commit 6a6dd2d

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ examples = example/client example/client-simple example/client-brski example/ser
1212
endif
1313
endif
1414

15-
SUBDIRS = safe_c_stub src $(libest_jni) $(examples)
15+
if ! WITH_SYSTEM_LIBSAFEC
16+
builtin_libsafec = safe_c_stub
17+
endif
18+
19+
SUBDIRS = $(builtin_libsafec) src $(libest_jni) $(examples)
1620
EXTRA_DIST = autogen.sh example/util LICENSE README.brski $(srcdir)/build.gradle $(srcdir)/example/build_examples.gradle

configure.ac

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ AM_INIT_AUTOMAKE([subdir-objects])
1010

1111
AC_PROG_CC
1212
AM_PROG_CC_C_O
13+
PKG_PROG_PKG_CONFIG
1314
LT_INIT
1415
AC_CANONICAL_HOST
1516
case $host in
@@ -187,22 +188,39 @@ AC_ARG_WITH([libcoap-dir],
187188
]
188189
)
189190

190-
SAFEC_STUB_DIR='$(abs_top_builddir)/safe_c_stub'
191-
AC_SUBST(SAFEC_STUB_DIR)
192-
safecdir="$SAFEC_STUB_DIR"
193-
AC_SUBST([SAFEC_DIR], "$safecdir")
194-
AC_SUBST([SAFEC_CFLAGS], "$safecdir/include")
195-
AC_SUBST([SAFEC_LDFLAGS], "$safecdir/lib")
191+
AC_ARG_WITH(system-libsafec,
192+
AS_HELP_STRING([--with-system-libsafec],
193+
[select to use libsafec installed in the system]),
194+
[],
195+
[with_system_libsafec="no"])
196196

197-
CFLAGS="$CFLAGS -Wall -I$safecdir/include"
198-
LDFLAGS="$LDFLAGS -L$safecdir/lib"
199-
LIBS="$LIBS -lsafe_lib"
197+
AC_MSG_CHECKING(which libsafec to use)
198+
AM_CONDITIONAL([WITH_SYSTEM_LIBSAFEC], [test "$with_system_libsafec" = "yes"])
199+
AM_COND_IF([WITH_SYSTEM_LIBSAFEC], AC_MSG_RESULT([system]), AC_MSG_RESULT([built-in]))
200+
AM_COND_IF([WITH_SYSTEM_LIBSAFEC],
201+
[
202+
PKG_CHECK_MODULES([libsafec], [libsafec])
203+
LIBS="$LIBS $libsafec_LIBS"
204+
CFLAGS="$CFLAGS $libsafec_CFLAGS"
205+
CPPFLAGS="$CPPFLAGS $libsafec_CFLAGS"
206+
],[
207+
SAFEC_STUB_DIR='$(abs_top_builddir)/safe_c_stub'
208+
AC_SUBST(SAFEC_STUB_DIR)
209+
safecdir="$SAFEC_STUB_DIR"
210+
AC_SUBST([SAFEC_DIR], "$safecdir")
211+
AC_SUBST([SAFEC_CFLAGS], "$safecdir/include")
212+
AC_SUBST([SAFEC_LDFLAGS], "$safecdir/lib")
213+
214+
CFLAGS="$CFLAGS -Wall -I$safecdir/include"
215+
LDFLAGS="$LDFLAGS -L$safecdir/lib"
216+
LIBS="$LIBS -lsafe_lib"
217+
])
200218

201219
AC_PREFIX_DEFAULT([/usr/local/est])
202220

203221
cp confdefs.h est_config.h
204222

205-
AC_CONFIG_FILES([Makefile version safe_c_stub/Makefile safe_c_stub/lib/Makefile src/Makefile src/est/Makefile])
223+
AC_CONFIG_FILES([Makefile version src/Makefile src/est/Makefile])
206224
AM_COND_IF([ENABLE_JNI],
207225
[AC_CONFIG_FILES([java/jni/Makefile])])
208226
AM_COND_IF([ENABLE_EXAMPLES],
@@ -212,5 +230,8 @@ AM_COND_IF([ENABLE_EXAMPLES],
212230
[],
213231
[AC_CONFIG_FILES([example/server/Makefile example/proxy/Makefile])])
214232
])
233+
AM_COND_IF([WITH_SYSTEM_LIBSAFEC],
234+
[],
235+
[AC_CONFIG_FILES([safe_c_stub/Makefile safe_c_stub/lib/Makefile])])
215236

216237
AC_OUTPUT

0 commit comments

Comments
 (0)