Autotoolize the build

Use Autoconf/make for building and autotest for tests
diff --git a/src/tests/Makefile b/src/tests/Makefile
deleted file mode 100644
index 0cedab9..0000000
--- a/src/tests/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
-
-PKG_INCLUDES:=$(shell pkg-config --cflags libosmocore libosmovty libosmogsm libasn1c)
-PKG_LDFLAGS:=$(shell pkg-config --libs libosmocore libosmovty libosmogsm libasn1c)
-
-CFLAGS:=-g -Wall $(PKG_INCLUDES) -I.. -I../hnbap
-LDFLAGS:=$(PKG_LDFLAGS) -lsctp
-
-test-helpers: ../iu_helpers.o ../asn1helpers.o test-helpers.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
-
-test-hnbap: ../iu_helpers.o ../asn1helpers.o ../hnbap_common.o ../hnbap_decoder.o test-hnbap.c ../hnbap/libosmo-asn1-hnbap.a
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
-
-HNBAP_OBJS=../hnbap_encoder.o ../hnbap_decoder.o ../hnbap_common.o
-RUA_OBJS=../rua_encoder.o ../rua_decoder.o ../rua_common.o
-RANAP_OBJS=../ranap_common.o #ranap_encoder.o ranap_decoder.o
-
-LIBS=../hnbap/libosmo-asn1-hnbap.a ../rua/libosmo-asn1-rua.a ../ranap/libosmo-asn1-ranap.a
-
-hnb-test: 	$(HNBAP_OBJS) $(RUA_OBJS) $(RANAP_OBJS) ../iu_helpers.o ../asn1helpers.o hnb-test.o $(LIBS)
-	$(CC) $(LDFLAGS) -o $@ $^
-
-clean:
-	@rm -f hnb-test test-helpers test-hnbap *.o
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
new file mode 100644
index 0000000..f7a9670
--- /dev/null
+++ b/src/tests/Makefile.am
@@ -0,0 +1,51 @@
+AM_CFLAGS = $(OSMOVTY_CFLAGS) $(OSMOCORE_CFLAGS) $(OSMOGSM_CFLAGS) $(ASN1C_CFLAGS) -g -I$(top_builddir)/src -I$(top_builddir)/src/hnbap/
+
+COMMON_LIBS = $(OSMOVTY_LIBS) $(OSMOCORE_LIBS) $(OSMOGSM_LIBS) $(ASN1C_LIBS) -lsctp
+
+check_PROGRAMS = test-helpers test-hnbap hnb-test
+
+HNBAP_FILES = $(top_builddir)/src/hnbap_common.c $(top_builddir)/src/hnbap_decoder.c $(top_builddir)/src/hnbap_encoder.c
+RUA_FILES = $(top_builddir)/src/rua_common.c $(top_builddir)/src/rua_decoder.c $(top_builddir)/src/rua_encoder.c
+RANAP_FILES = $(top_builddir)/src/ranap_common.c ### $(top_builddir)/src/ranap_decoder.c $(top_builddir)/src/ranap_encoder.c
+
+test_helpers_SOURCES = $(top_builddir)/src/iu_helpers.c $(top_builddir)/src/asn1helpers.c test-helpers.c
+test_helpers_LDADD = $(COMMON_LIBS)
+
+test_hnbap_SOURCES = $(top_builddir)/src/iu_helpers.c $(top_builddir)/src/asn1helpers.c $(top_builddir)/src/hnbap_common.c $(top_builddir)/src/hnbap_decoder.c test-hnbap.c
+test_hnbap_LDADD = $(COMMON_LIBS) $(top_builddir)/src/hnbap/libosmo-asn1-hnbap.a
+
+hnb_test_SOURCES = $(top_builddir)/src/iu_helpers.c $(top_builddir)/src/asn1helpers.c $(HNBAP_FILES) $(RUA_FILES) $(RANAP_FILES) hnb-test.c
+hnb_test_LDADD = $(COMMON_LIBS) $(top_builddir)/src/hnbap/libosmo-asn1-hnbap.a $(top_builddir)/src/rua/libosmo-asn1-rua.a $(top_builddir)/src/ranap/libosmo-asn1-ranap.a
+
+
+
+# The `:;' works around a Bash 3.2 bug when the output is not writeable.
+$(srcdir)/package.m4: $(top_srcdir)/configure.ac
+	:;{ \
+               echo '# Signature of the current package.' && \
+               echo 'm4_define([AT_PACKAGE_NAME],' && \
+               echo '  [$(PACKAGE_NAME)])' && \
+               echo 'm4_define([AT_PACKAGE_TARNAME],' && \
+               echo '  [$(PACKAGE_TARNAME)])' && \
+               echo 'm4_define([AT_PACKAGE_VERSION],' && \
+               echo '  [$(PACKAGE_VERSION)])' && \
+               echo 'm4_define([AT_PACKAGE_STRING],' && \
+               echo '  [$(PACKAGE_STRING)])' && \
+               echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \
+               echo '  [$(PACKAGE_BUGREPORT)])'; \
+               echo 'm4_define([AT_PACKAGE_URL],' && \
+               echo '  [$(PACKAGE_URL)])'; \
+             } >'$(srcdir)/package.m4'
+
+TESTSUITE = $(srcdir)/testsuite
+
+check-local: atconfig $(TESTSUITE)
+	$(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
+
+AUTOM4TE = $(SHELL) $(top_srcdir)/missing --run autom4te
+AUTOTEST = $(AUTOM4TE) --language=autotest
+
+$(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4
+	$(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at
+	mv $@.tmp $@
+
diff --git a/src/tests/test-helpers.ok b/src/tests/test-helpers.ok
new file mode 100644
index 0000000..4ba4d54
--- /dev/null
+++ b/src/tests/test-helpers.ok
@@ -0,0 +1,12 @@
+Testing Iu helper functions
+pre-encoded: 10325476f8
+decoded: 012345678
+re-encoded: 10325476f8
+Testing asn.1 helper functions
+Encoding 0xdeadbeef to asn.1 bitstring
+Encoded: 20deadbeef
+Decoding back to uint32_t: 0xdeadbeef
+Encoding efbead to 24-bit asn.1 bitstring
+Encoded: 18adbeef
+Decoding string from asn.1: 0123456789012345
+Decoding large string from asn1: 0123456789012345678901234567890
diff --git a/src/tests/test-hnbap.ok b/src/tests/test-hnbap.ok
new file mode 100644
index 0000000..03331c4
--- /dev/null
+++ b/src/tests/test-hnbap.ok
@@ -0,0 +1,4 @@
+Testing asn.1 HNBAP decoding
+HNBAP register request for HNB 10005B9-0010942050@
+HNBAP UE Register request from IMSI 262011234567890
+HNBAP UE Register accept to IMSI 262011234567890
diff --git a/src/tests/testsuite.at b/src/tests/testsuite.at
new file mode 100644
index 0000000..bcea93a
--- /dev/null
+++ b/src/tests/testsuite.at
@@ -0,0 +1,15 @@
+AT_INIT
+AT_BANNER([Regression tests.])
+
+
+AT_SETUP([helpers])
+AT_KEYWORDS([helpers])
+cat $abs_srcdir/test-helpers.ok > expout
+AT_CHECK([$abs_top_builddir/src/tests/test-helpers], [0], [expout])
+AT_CLEANUP
+
+AT_SETUP([hnbap])
+AT_KEYWORDS([hnbap])
+cat $abs_srcdir/test-hnbap.ok > expout
+AT_CHECK([$abs_top_builddir/src/tests/test-hnbap], [0], [expout])
+AT_CLEANUP