Browse Source

Cleanup libblkmaker bundling code to mostly live in autoconf macros

Luke Dashjr 11 years ago
parent
commit
596bc45aba
4 changed files with 140 additions and 60 deletions
  1. 5 20
      Makefile.am
  2. 3 40
      configure.ac
  3. 98 0
      m4/bundled_lib.m4
  4. 34 0
      m4/custom_subdirs.m4

+ 5 - 20
Makefile.am

@@ -65,10 +65,6 @@ bfgminer_CPPFLAGS += $(NCURSES_CPPFLAGS)
 bfgminer_CPPFLAGS += $(AUTOSCAN_CPPFLAGS)
 bfgminer_LDADD += $(AUTOSCAN_LIBS)
 
-bfgminer_LDADD += $(libblkmaker_LIBS)
-bfgminer_LDFLAGS += $(libblkmaker_LDFLAGS)
-bfgminer_CPPFLAGS += $(libblkmaker_CFLAGS)
-
 # common sources
 bfgminer_SOURCES := miner.c
 
@@ -86,22 +82,11 @@ version.h: update-version
 bfgminer_SOURCES += version.h
 BUILT_SOURCES = version.h
 
-SUBDIRS += $(LIBBLKMAKER_SUBDIRS)
-LIBBLKMAKER_SUBDIRS =
-if NEED_LIBBLKMAKER
-LIBBLKMAKER_SUBDIRS         += libblkmaker
-EXTRA_bfgminer_DEPENDENCIES += libblkmaker_directory
-libblkmaker_directory:
-	cd libblkmaker && $(MAKE)
-
-if HAVE_CYGWIN
-EXTRA_bfgminer_DEPENDENCIES += cygblkmaker-0.1-0.dll cygblkmaker_jansson-0.1-0.dll
-
-cyg%.dll: libblkmaker/.libs/cyg%.dll
-	cp -p $< $@
-endif
-
-endif
+SUBDIRS += $(libblkmaker_SUBDIRS)
+bfgminer_LDADD += $(libblkmaker_LIBS)
+bfgminer_CPPFLAGS += $(libblkmaker_CFLAGS)
+EXTRA_bfgminer_DEPENDENCIES += $(libblkmaker_EXTRADEPS)
+@BUNDLED_LIB_RULES@
 
 bfgminer_SOURCES	+= logging.c
 

+ 3 - 40
configure.ac

@@ -1386,44 +1386,7 @@ else
 fi
 
 
-maybe_ldconfig=
-AC_ARG_WITH([system-libblkmaker], [AC_HELP_STRING([--with-system-libblkmaker], [Use system libblkmaker rather than bundled one (default disabled)])],[true],[with_system_libblkmaker=no])
-if test "x$with_system_libblkmaker" = "xyes"; then
-	PKG_CHECK_MODULES([libblkmaker],[libblkmaker_jansson-0.1],[
-		true
-	],[
-		AC_MSG_ERROR([Could not find system libblkmaker])
-	])
-else
-	save_LDFLAGS="$LDFLAGS"
-	LDFLAGS="$LDFLAGS -Wl,-zorigin"
-	origin_LDFLAGS=
-	AC_MSG_CHECKING([whether the linker recognizes the -zorigin option])
-	AC_TRY_LINK([],[],[
-		AC_MSG_RESULT([yes])
-		origin_LDFLAGS=',-zorigin'
-	],[
-		AC_MSG_RESULT([no])
-	])
-	LDFLAGS="$save_LDFLAGS"
-	
-	libblkmaker_CFLAGS='-Ilibblkmaker'
-	libblkmaker_LDFLAGS='-Llibblkmaker/.libs -Wl,-rpath,\$$ORIGIN/libblkmaker/.libs'"$origin_LDFLAGS"
-	libblkmaker_LIBS='-lblkmaker_jansson-0.1 -lblkmaker-0.1'
-	AC_CONFIG_SUBDIRS([libblkmaker])
-	_ROOTPATH=$PATH$PATH_SEPARATOR`echo $PATH | sed s/bin/sbin/g`
-	possible_ldconfigs="${target}-ldconfig"
-	if test "x$cross_compiling" != "xyes"; then
-		possible_ldconfigs="${possible_ldconfigs} ldconfig"
-	fi
-	AC_CHECK_PROGS([LDCONFIG],[${possible_ldconfigs}],[],[$_ROOTPATH])
-	if test "x$LDCONFIG" != "x"; then
-		maybe_ldconfig=" && $LDCONFIG"
-	fi
-fi
-AC_SUBST(libblkmaker_CFLAGS)
-AC_SUBST(libblkmaker_LDFLAGS)
-AC_SUBST(libblkmaker_LIBS)
+BFG_BUNDLED_LIB([libblkmaker],[libblkmaker_jansson-0.1],[no],[libblkmaker],[blkmaker_jansson-0.1 blkmaker-0.1])
 
 
 $have_udevrules || use_udevrules=false
@@ -1447,7 +1410,6 @@ if $use_udevrules; then
 fi
 
 
-AM_CONDITIONAL([NEED_LIBBLKMAKER], [test x$with_system_libblkmaker != xyes])
 AM_CONDITIONAL([NEED_BFG_BINLOADER], [test x$need_binloader = xyes])
 AM_CONDITIONAL([NEED_DYNCLOCK], [test x$need_dynclock = xyes])
 AM_CONDITIONAL([USE_GC3355], [test x$need_gc3355 = xyes])
@@ -1859,6 +1821,7 @@ if $use_udevrules; then
 fi
 
 AC_OUTPUT
+BFG_CUSTOM_SUBDIRS_OUTPUT
 
 
 wordfilter ()
@@ -1872,7 +1835,7 @@ echo "$PACKAGE $VERSION configuration options summary"
 echo "------------------------------------------------------------------------"
 echo
 echo "  CFLAGS...............: "`wordfilter "$CPPFLAGS $AUTOSCAN_CPPFLAGS $NCURSES_CPPFLAGS $PTHREAD_FLAGS $CFLAGS $LIBUSB_CFLAGS $JANSSON_CFLAGS $PTHREAD_FLAGS $libblkmaker_CFLAGS $hidapi_CFLAGS"`
-echo "  LDFLAGS..............: "`wordfilter "$LDFLAGS $AUTOSCAN_LIBS $PTHREAD_FLAGS $libblkmaker_LDFLAGS $PTHREAD_LIBS $LIBS $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS $LIBUSB_LIBS $RT_LIBS $sensors_LIBS $libblkmaker_LIBS"`
+echo "  LDFLAGS..............: "`wordfilter "$LDFLAGS $AUTOSCAN_LIBS $PTHREAD_FLAGS $PTHREAD_LIBS $LIBS $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS $LIBUSB_LIBS $RT_LIBS $sensors_LIBS $libblkmaker_LIBS"`
 echo "  Installation.prefix..: $prefix"
 echo
 echo "${lowllist_print}" | tr '~' '\n'

+ 98 - 0
m4/bundled_lib.m4

@@ -0,0 +1,98 @@
+dnl * Copyright 2014 Luke Dashjr
+dnl *
+dnl * This program is free software; you can redistribute it and/or modify it
+dnl * under the terms of the GNU General Public License as published by the Free
+dnl * Software Foundation; either version 3 of the License, or (at your option)
+dnl * any later version.  See COPYING for more details.
+
+m4_divert_text([DEFAULTS], [
+origin_LDFLAGS=
+origin_LDFLAGS_checked=false
+maybe_ldconfig=
+maybe_ldconfig_checked=false
+BUNDLED_LIB_RULES=
+])
+
+AC_SUBST(BUNDLED_LIB_RULES)
+AM_SUBST_NOTMAKE(BUNDLED_LIB_RULES)
+
+AC_DEFUN([BFG_CHECK_LD_ORIGIN],[
+if ! $origin_LDFLAGS_checked; then
+	save_LDFLAGS="$LDFLAGS"
+	LDFLAGS="$LDFLAGS -Wl,-zorigin"
+	AC_MSG_CHECKING([whether the linker recognizes the -zorigin option])
+	AC_TRY_LINK([],[],[
+		AC_MSG_RESULT([yes])
+		origin_LDFLAGS=',-zorigin'
+	],[
+		AC_MSG_RESULT([no])
+	])
+	LDFLAGS="$save_LDFLAGS"
+	origin_LDFLAGS_checked=true
+fi
+])
+
+AC_DEFUN([BFG_CHECK_LDCONFIG],[
+if ! $maybe_ldconfig_checked; then
+	_ROOTPATH=$PATH$PATH_SEPARATOR`echo $PATH | sed s/bin/sbin/g`
+	possible_ldconfigs="${target}-ldconfig"
+	if test "x$cross_compiling" != "xyes"; then
+		possible_ldconfigs="${possible_ldconfigs} ldconfig"
+	fi
+	AC_CHECK_PROGS([LDCONFIG],[${possible_ldconfigs}],[],[$_ROOTPATH])
+	if test "x$LDCONFIG" != "x"; then
+		maybe_ldconfig=" && $LDCONFIG"
+	fi
+	maybe_ldconfig_checked=true
+fi
+])
+
+AC_DEFUN([BFG_BUNDLED_LIB_VARS],[
+	BFG_CHECK_LD_ORIGIN
+	_AC_SRCDIRS(["$ac_dir"])
+	$1_CFLAGS='-I'"${ac_abs_top_srcdir}"'/$2'
+	$1_LIBS='-L'"${ac_abs_top_srcdir}"'/$2/.libs -Wl,-rpath,\$$ORIGIN/$2/.libs'"$origin_LDFLAGS"' m4_foreach_w([mylib],[$3],[ -l[]mylib])'
+	$1_SUBDIRS=$2
+	$1_EXTRADEPS=$1_directory
+	BUNDLED_LIB_RULES="$BUNDLED_LIB_RULES
+$1_directory:
+	\$(MAKE) -C $2
+"
+	if $have_cygwin; then
+		$1_EXTRADEPS="$$1_EXTRADEPS m4_foreach_w([mylib],[$3],[ cyg[]mylib[]-0.dll])"
+		BUNDLED_LIB_RULES="$BUNDLED_LIB_RULES[]m4_foreach_w([mylib],[$3],[
+cyg[]mylib[]-0.dll: $2/.libs/cyg[]mylib[]-0.dll
+	cp -p \$< \$[]@
+])"
+	fi
+])
+
+dnl BFG_BUNDLED_LIB([PKG-NAME],PKGCONF-NAME],[DEFAULT:YES/NO/AUTO],[PATH],[LIBS],[DEPENDENT-PKGS],[CONFIGURE-ARGS],[CONFIGURE-ARGS])
+AC_DEFUN([BFG_BUNDLED_LIB],[
+	AC_ARG_WITH([system-$1],[ifelse([$3],[no],AC_HELP_STRING([--with-system-$1], [Use system $1 rather than bundled one (default disabled)]),AC_HELP_STRING([--without-system-$1], [Use bundled $1 rather than system one]))],[true],[with_system_$1=$3])
+	if test "x$with_system_$1" != "xno"; then
+		PKG_CHECK_MODULES([$1],[$2],[
+			with_system_$1=yes
+		],[
+			if test "x$with_system_$1" = "xyes"; then
+				AC_MSG_ERROR([Could not find system $1])
+			else
+				AC_MSG_NOTICE([Didn't find system $1, using bundled copy])
+				with_system_$1=no
+			fi
+		])
+	fi
+	if test "x$with_system_$1" = "xno"; then
+		BFG_BUNDLED_LIB_VARS([$1],[$4],[$5])
+		BFG_CUSTOM_SUBDIR([$4],[$7],[$8 m4_foreach_w([mydep],[$6],[ mydep[]_LIBS='$mydep[]_LIBS' mydep[]_CFLAGS='$mydep[]_CFLAGS'])])
+		BFG_CHECK_LDCONFIG
+	else
+		$1_SUBDIRS=
+		$1_EXTRADEPS=
+	fi
+	AC_SUBST($1_CFLAGS)
+	AC_SUBST($1_LIBS)
+	AC_SUBST($1_SUBDIRS)
+	AC_SUBST($1_EXTRADEPS)
+	AM_CONDITIONAL(NEED_[]m4_toupper([$1]), [test x$with_system_$1 != xyes])
+])

+ 34 - 0
m4/custom_subdirs.m4

@@ -0,0 +1,34 @@
+dnl * Copyright 2014 Luke Dashjr
+dnl *
+dnl * This program is free software; you can redistribute it and/or modify it
+dnl * under the terms of the GNU General Public License as published by the Free
+dnl * Software Foundation; either version 3 of the License, or (at your option)
+dnl * any later version.  See COPYING for more details.
+
+m4_divert_text([DEFAULTS], [
+custom_subdirs=
+])
+
+AC_DEFUN([BFG_CUSTOM_SUBDIR],[
+	if false; then
+		AC_CONFIG_SUBDIRS([$1])
+	fi
+	custom_subdirs="$custom_subdirs $1"
+	custom_subdir_[]AS_TR_SH([$1])_args="$2"
+	custom_subdir_[]AS_TR_SH([$1])_forceargs="$3"
+])
+
+AC_DEFUN([BFG_CUSTOM_SUBDIRS_OUTPUT],[
+	if test "$no_recursion" != yes; then
+		orig_subdirs="$subdirs"
+		orig_ac_configure_args="$ac_configure_args"
+		for custom_subdir in $custom_subdirs; do
+			subdirs="$custom_subdir"
+			custom_subdir_base="AS_TR_SH([$custom_subdir])"
+			eval 'ac_configure_args="$custom_subdir_'"$custom_subdir_base"'_args $orig_ac_configure_args $custom_subdir_'"$custom_subdir_base"'_forceargs"'
+			_AC_OUTPUT_SUBDIRS
+		done
+		subdirs="$orig_subdirs"
+		ac_configure_args="$orig_ac_configure_args"
+	fi
+])