Convert build process to autotools
Replaced the use of a manual Makefile with the use of autotools to
automatically verify and generate the necessary build files. Follow the
steps outlined within the README.md file to build the package.
Change-Id: I25437239b3f575a5495773be49605fdf598d2054
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 2c03541..0000000
--- a/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-CXX ?= $(CROSS_COMPILE)g++
-
-LIB_OEM_OBJ = oemhandler.o
-LIB_OEM = liboemhandler.so
-
-LDFLAGS += -rdynamic -ldl
-CXXFLAGS += -fPIC -Wall -Werror
-
-
-all: $(LIB_OEM)
-
-%.o: %.C
- $(CXX) -std=c++14 -c $< $(CXXFLAGS) -o $@
-
-$(LIB_OEM): $(LIB_OEM_OBJ)
- $(CXX) $^ -shared $(LDFLAGS) -o $@
-
-clean:
- $(RM) $(LIB_OEM_OBJ) $(LIB_OEM)
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..2d7a18d
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,5 @@
+liboemhandlerdir = ${libdir}/host-ipmid
+liboemhandler_LTLIBRARIES = liboemhandler.la
+liboemhandler_la_SOURCES = oemhandler.cpp
+liboemhandler_la_LDFLAGS = $(SYSTEMD_LIBS) -version-info 0:0:0 -shared
+liboemhandler_la_CXXFLAGS = $(SYSTEMD_CFLAGS) $(AM_CXXFLAGS)
diff --git a/README.md b/README.md
index 703d48b..dcd7626 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,15 @@
-This .so file is designed to support the OpenPOWER's BIOS OEM commands. Documentation can be found by contacting the OpenPOWER mailing list https://github.com/open-power/op-build
+This .so file is designed to support the OpenPOWER's BIOS OEM commands.
+Documentation can be found by contacting the OpenPOWER mailing list @ https://github.com/open-power/op-build
## To Build
```
-make
+To build this package, do the following steps:
+
+ 1. ./bootstrap.sh
+ 2. ./configure ${CONFIGURE_FLAGS}
+ 3. make
+
+To full clean the repository again run `./bootstrap.sh clean`.
```
## Supported Commands
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100755
index 0000000..50b75b7
--- /dev/null
+++ b/bootstrap.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+AUTOCONF_FILES="Makefile.in aclocal.m4 ar-lib autom4te.cache compile \
+ config.guess config.h.in config.sub configure depcomp install-sh \
+ ltmain.sh missing *libtool test-driver"
+
+case $1 in
+ clean)
+ test -f Makefile && make maintainer-clean
+ for file in ${AUTOCONF_FILES}; do
+ find -name "$file" | xargs -r rm -rf
+ done
+ exit 0
+ ;;
+esac
+
+autoreconf -i
+echo 'Run "./configure ${CONFIGURE_FLAGS} && make"'
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..cdd0292
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,52 @@
+# Initialization
+AC_PREREQ([2.69])
+AC_INIT([openpower-host-ipmi-oem], [1.0], [https://github.com/openbmc/openpower-host-ipmi-oem/issues])
+AC_CONFIG_HEADERS([config.h])
+AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
+AM_SILENT_RULES([yes])
+
+# Checks for programs.
+AC_PROG_CXX
+AM_PROG_AR
+AC_PROG_INSTALL
+AC_PROG_MAKE_SET
+
+# Checks for libraries.
+PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 221])
+
+# Checks for header files.
+AC_CHECK_HEADER(systemd/sd-bus.h, ,[AC_MSG_ERROR([Could not find systemd/sd-bus.h...systemd development package required])])
+AC_CHECK_HEADER(host-ipmid/ipmid-api.h, ,[AC_MSG_ERROR([Could not find host-ipmid/ipmid-api.h...host-ipmid package required])])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AX_CXX_COMPILE_STDCXX(14, [noext])
+AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
+
+# Checks for library functions.
+LT_INIT([disable-static shared])
+
+# Check/set gtest specific functions.
+AX_PTHREAD([GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"],[GTEST_CPPFLAGS="-GTEST_HAS_PTHREAD=0"])
+AC_SUBST(GTEST_CPPFLAGS)
+
+AC_ARG_ENABLE([oe-sdk],
+ AS_HELP_STRING([--enable-oe-sdk], [Link testcases absolutely against OE SDK so they can be ran within it.])
+)
+AC_ARG_VAR(OECORE_TARGET_SYSROOT,
+ [Path to the OE SDK SYSROOT])
+AS_IF([test "x$enable_oe_sdk" == "xyes"],
+ AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
+ AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
+ )
+ AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
+ [
+ testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
+ testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
+ testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
+ ]
+ AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
+)
+
+# Create configured output.
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/oemhandler.C b/oemhandler.cpp
similarity index 99%
rename from oemhandler.C
rename to oemhandler.cpp
index 8d522c2..ed26e93 100644
--- a/oemhandler.C
+++ b/oemhandler.cpp
@@ -1,4 +1,4 @@
-#include "oemhandler.h"
+#include "oemhandler.hpp"
#include <host-ipmid/ipmid-api.h>
#include <fstream>
#include <stdio.h>
diff --git a/oemhandler.h b/oemhandler.hpp
similarity index 100%
rename from oemhandler.h
rename to oemhandler.hpp