summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-01-01 22:02:56 -0800
committerKeith Packard <keithp@keithp.com>2014-01-01 22:02:56 -0800
commit8bff2822c242d2878b408b9c0d8a7647108ea4b1 (patch)
tree88d29b0cc1a9488d05657119f5fda5a4fa221f7c
parent95d77eaff708397d8b1e29904dc47d8ea09e8754 (diff)
libaltos: Build -m64 and -m32 for fat tarball when possible
Check to see if we can compile libaltos for both 32 bit and 64 bit systems, and then use those when generating the linux tarball. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--altosui/Makefile.am16
-rw-r--r--altosuilib/AltosUILib.java16
-rw-r--r--configure.ac54
-rw-r--r--libaltos/Makefile.am30
4 files changed, 105 insertions, 11 deletions
diff --git a/altosui/Makefile.am b/altosui/Makefile.am
index 71e96004..dc34c444 100644
--- a/altosui/Makefile.am
+++ b/altosui/Makefile.am
@@ -175,7 +175,13 @@ WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe
FAT_FILES=$(FATJAR) $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS) $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS)
-LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) $(DOC)
+if MULTI_ARCH
+LINUX_LIBS=libaltos32.so libaltos64.so
+else
+LINUX_LIBS=libaltos.so
+endif
+
+LINUX_FILES=$(FAT_FILES) $(LINUX_LIBS) $(FIRMWARE) $(DOC)
LINUX_EXTRA=altosui-fat
MACOSX_INFO_PLIST=Info.plist
@@ -269,6 +275,14 @@ libaltos.so: build-libaltos
-rm -f "$@"
$(LN_S) ../libaltos/.libs/"$@" .
+libaltos32.so: build-libaltos
+ -rm -f "$@"
+ $(LN_S) ../libaltos/.libs/"$@" .
+
+libaltos64.so: build-libaltos
+ -rm -f "$@"
+ $(LN_S) ../libaltos/.libs/"$@" .
+
libaltos.dylib:
-rm -f "$@"
$(LN_S) ../libaltos/"$@" .
diff --git a/altosuilib/AltosUILib.java b/altosuilib/AltosUILib.java
index 307ef19d..18c4c3d9 100644
--- a/altosuilib/AltosUILib.java
+++ b/altosuilib/AltosUILib.java
@@ -81,18 +81,20 @@ public class AltosUILib extends AltosLib {
static public boolean initialized = false;
static public boolean loaded_library = false;
+ static final String[] library_names = { "altos", "altos32", "altos64" };
+
public static boolean load_library() {
if (!initialized) {
- try {
- System.loadLibrary("altos");
- libaltos.altos_init();
- loaded_library = true;
- } catch (UnsatisfiedLinkError e) {
+ for (String name : library_names) {
try {
- System.loadLibrary("altos64");
+ System.out.printf ("Trying library %s\n", name);
+ System.loadLibrary(name);
libaltos.altos_init();
loaded_library = true;
- } catch (UnsatisfiedLinkError e2) {
+ System.out.printf ("Using library %s\n", name);
+ break;
+ } catch (UnsatisfiedLinkError e) {
+ System.out.printf("Link error %s\n", e.getMessage());
loaded_library = false;
}
}
diff --git a/configure.ac b/configure.ac
index 1214564b..20acdf5f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -430,7 +430,58 @@ if test x"$HAVE_STLINK" = "xyes"; then
AC_DEFINE(HAVE_STLINK,1,[Using STlink library])
fi
-AM_CONDITIONAL([LIBSTLINK], [test x$HAVE_STLINK == xyes])
+AM_CONDITIONAL([LIBSTLINK], [test x$HAVE_STLINK = xyes])
+
+AC_ARG_ENABLE([multi-arch],
+ [AS_HELP_STRING([--enable-multi-arch],
+ [enable building both i386 and amd64 libraries (default=auto)])],
+ [MULTI_ARCH=$enableval],
+ [MULTI_ARCH=auto])
+
+case x"$MULTI_ARCH" in
+xauto)
+ arch=`uname -m`
+ case x"$arch" in
+ xx86_64|xi*86)
+ save_CFLAGS="$CFLAGS"
+ save_LIBS="$LIBS"
+ LIBS="-lbluetooth"
+ CFLAGS="-m64"
+ AC_MSG_CHECKING([if ]$CC[ ]$CFLAGS[ can link programs])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+ [M64_LINK=yes],
+ [M64_LINK=no])
+ AC_MSG_RESULT([$M64_LINK])
+ CFLAGS="-m32"
+ AC_MSG_CHECKING([if ]$CC[ ]$CFLAGS[ can link programs])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+ [M32_LINK=yes],
+ [M32_LINK=no])
+ AC_MSG_RESULT([$M32_LINK])
+ CFLAGS="$save_CFLAGS"
+ LIBS="$save_LIBS"
+ case x"$M64_LINK"x"$M32_LINK" in
+ xyesxyes)
+ MULTI_ARCH=yes
+ ;;
+ *)
+ MULTI_ARCH=no
+ ;;
+ esac
+ ;;
+ *)
+ MULTI_ARCH=no
+ ;;
+ esac
+ ;;
+xyes|xno)
+ ;;
+*)
+ MULTI_ARCH="no"
+ ;;
+esac
+
+AM_CONDITIONAL([MULTI_ARCH], [test x$MULTI_ARCH = xyes])
AC_OUTPUT([
Makefile
@@ -483,6 +534,7 @@ echo " AVR support.................: ${HAVE_AVR_CC}"
echo " Android support.............: ${HAVE_ANDROID_SDK}"
echo " STlink support..............: ${HAVE_STLINK}"
echo " Local pdclib................: ${HAVE_PDCLIB}"
+echo " i386 and amd64 libaltos.....: ${MULTI_ARCH}"
echo ""
echo " Java paths"
echo " freetts.....................: ${FREETTS}"
diff --git a/libaltos/Makefile.am b/libaltos/Makefile.am
index 831432fc..969aa8ad 100644
--- a/libaltos/Makefile.am
+++ b/libaltos/Makefile.am
@@ -5,8 +5,7 @@ AM_JAVACFLAGS=-target 1.6 -encoding UTF-8 -Xlint:deprecation -source 6
altoslibdir=$(libdir)/altos
altoslib_LTLIBRARIES=libaltos.la
-
-libaltos_la_LDFLAGS = -version-info 1:0:1
+libaltos_la_LDFLAGS=-version-info 1:0:1
libaltos_la_SOURCES=\
libaltos.c \
@@ -14,8 +13,35 @@ libaltos_la_SOURCES=\
noinst_PROGRAMS=cjnitest
+cjnitest_SOURCES=cjnitest.c
cjnitest_LDADD=libaltos.la
+if MULTI_ARCH
+altoslib_LTLIBRARIES+=libaltos32.la libaltos64.la
+
+libaltos32_la_LDFLAGS=$(libaltos_la_LDFLAGS)
+libaltos64_la_LDFLAGS=$(libaltos_la_LDFLAGS)
+
+libaltos32_la_CFLAGS=-m32 $(AM_CFLAGS)
+libaltos64_la_CFLAGS=-m64 $(AM_CFLAGS)
+
+libaltos32_la_SOURCES=$(libaltos_la_SOURCES)
+libaltos64_la_SOURCES=$(libaltos_la_SOURCES)
+
+noinst_PROGRAMS+=cjnitest32 cjnitest64
+
+cjnitest32_CFLAGS=-m32
+cjnitest64_CFLAGS=-m64
+
+cjnitest32_SOURCES=$(cjnitest_SOURCES)
+cjnitest64_SOURCES=$(cjnitest_SOURCES)
+
+cjnitest32_LDADD=libaltos32.la
+cjnitest64_LDADD=libaltos64.la
+
+endif
+
+
LIBS=-lbluetooth
HFILES=libaltos.h