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: Id7be6220d32e457b1171d5d98123c6d8f317b380
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..3aa8cf8
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,36 @@
+sbin_PROGRAMS = mapper
+
+mapper_SOURCES = libmapper/app.c
+mapper_LDFLAGS = $(SYSTEMD_LIBS)
+mapper_CFLAGS = $(SYSTEMD_CFLAGS)
+mapper_LDADD = libmapper.la
+
+libmapperdir = ${libdir}
+libmapper_LTLIBRARIES = libmapper.la
+libmapper_la_SOURCES = libmapper/mapper.c
+libmapper_la_LDFLAGS = $(SYSTEMD_LIBS) -version-info 1:0:0 -shared
+libmapper_la_CFLAGS = $(SYSTEMD_CFLAGS)
+
+oldinclude_HEADERS = libmapper/mapper.h
+
+if HAVE_PYTHON
+
+all-local:
+	$(AM_V_at)$(PYTHON) ${top_builddir}/setup.py build
+
+clean-local:
+	rm -rfv ${top_builddir}/build
+
+install-exec-hook:
+	$(AM_V_at)$(PYTHON) ${top_builddir}/setup.py install \
+	--prefix=$(DESTDIR)${prefix} \
+	--install-data=$(DESTDIR)${datadir} \
+	--install-lib=$(DESTDIR)$(PYTHONDIR) \
+	--install-scripts=$(DESTDIR)${sbindir} \
+	--record=${top_builddir}/python_install.log
+
+uninstall-hook:
+	cat ${top_builddir}/python_install.log \
+	| awk '{print "$(DESTDIR)"$$1}' | xargs rm -fv
+
+endif
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5318177
--- /dev/null
+++ b/README.md
@@ -0,0 +1,10 @@
+## To Build
+```
+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`.
+```
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100755
index 0000000..09670d3
--- /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 m4"
+
+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..c54b16c
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,61 @@
+# Initialization
+AC_PREREQ([2.69])
+AC_INIT([phosphor-objmgr], [1.0], [https://github.com/openbmc/phosphor-objmgr/issues])
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_MACRO_DIR([m4])
+AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
+AM_SILENT_RULES([yes])
+
+# Checks for programs.
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_INSTALL
+AC_PROG_MAKE_SET
+# Python
+AM_PATH_PYTHON([2.7], [AC_SUBST([PYTHON], [echo "$PYTHON"])], [AC_MSG_ERROR([Could not find python-2.7 installed...python-2.7 is required])])
+AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
+AC_SUBST([HAVE_PYTHON])
+AC_SUBST([PYTHONDIR], ${pythondir})
+
+# 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])])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AX_APPEND_COMPILE_FLAGS([-fpic -Wall -Werror], [CFLAGS])
+
+# Checks for library functions.
+LT_INIT([disable-static shared])
+
+# Check/set gtest specific functions.
+AX_PTHREAD([GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"],[GTEST_CPPFLAGS="-DGTEST_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])
+)
+
+# Add defines to config header
+AC_DEFINE([MAPPER_BUSNAME], ["xyz.openbmc_project.ObjectMapper"], [Object mapper bus name])
+AC_DEFINE([MAPPER_INTERFACE], ["xyz.openbmc_project.ObjectMapper"], [Object mapper interface])
+AC_DEFINE([MAPPER_PATH], ["/xyz/openbmc_project/ObjectMapper"], [Object mapper DBUS path])
+
+# Create configured output
+AC_CONFIG_FILES([Makefile setup.py])
+AC_OUTPUT
diff --git a/libmapper/Makefile b/libmapper/Makefile
deleted file mode 100644
index ae6a895..0000000
--- a/libmapper/Makefile
+++ /dev/null
@@ -1,41 +0,0 @@
-libdir=/usr/lib
-sbindir=/usr/sbin
-includedir=/usr/include
-
-PACKAGE_DEPS=libsystemd
-SONAME=libmapper.so
-VERSION=2
-LIBMAPPER=$(SONAME).$(VERSION)
-BIN=mapper
-INCLUDES=mapper.h
-
-LDLIBS+=$(shell pkg-config --libs $(PACKAGE_DEPS))
-ALL_CFLAGS+=$(shell pkg-config --cflags $(PACKAGE_DEPS)) \
-	-fPIC -Wall -Werror $(CFLAGS)
-
-all: $(SONAME) $(BIN)
-
-%.o: %.c
-	$(CC) -c $(ALL_CFLAGS) -o $@ $<
-
-$(SONAME): $(LIBMAPPER)
-	ln -sf $^ $@
-
-$(LIBMAPPER): lib%.so.$(VERSION): %.o
-	$(CC) -shared $(CFLAGS) $(LDFLAGS) -Wl,-soname,$(SONAME) \
-		-o $@ $^ $(LDLIBS)
-
-$(BIN): app.o $(LIBMAPPER)
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
-
-install: $(SONAME) $(LIBMAPPER) $(BIN)
-	@mkdir -p $(DESTDIR)$(includedir)
-	install $(INCLUDES) $(DESTDIR)$(includedir)
-	@mkdir -p $(DESTDIR)$(libdir)
-	install $(LIBMAPPER) $(DESTDIR)$(libdir)
-	ln -sf $(LIBMAPPER) $(DESTDIR)$(libdir)/$(SONAME)
-	@mkdir -p $(DESTDIR)$(sbindir)
-	install $(BIN) $(DESTDIR)$(sbindir)
-
-clean:
-	rm -f *.o $(LIBMAPPER) $(SONAME) $(BIN)
diff --git a/setup.cfg b/setup.cfg
deleted file mode 100644
index 483ca76..0000000
--- a/setup.cfg
+++ /dev/null
@@ -1,2 +0,0 @@
-[install]
-install_scripts = /usr/sbin
diff --git a/setup.py b/setup.py
deleted file mode 100644
index 9967f98..0000000
--- a/setup.py
+++ /dev/null
@@ -1,6 +0,0 @@
-from distutils.core import setup
-setup(name='phosphor-mapper',
-      version='1.0',
-      packages=['obmc.mapper'],
-      scripts=['phosphor-mapper']
-      )
diff --git a/setup.py.in b/setup.py.in
new file mode 100644
index 0000000..93bd8a6
--- /dev/null
+++ b/setup.py.in
@@ -0,0 +1,7 @@
+from distutils.core import setup
+setup(name='phosphor-mapper',
+      version='1.0',
+      package_dir={'':'@top_srcdir@'},
+      packages=['obmc.mapper'],
+      scripts=['@top_srcdir@/phosphor-mapper']
+      )