attempt to fix parallel build, improve AM logic

The formerly existing make rule caused a race condition in parallel builds and
wrongly stated the .c files as targets, which caused make to execute the
rule twice (once for each target). This was actually only fallout of the
attempt to express the fact that those two files are generated by the rule.

The generated file ranap_ies_defs.h was moved by one make job, another
job then tried to access the file in the old location and failed.

parallel build verified with:
$ for i in $(seq 1 10)
do
	echo "XXXX iteration $i"
	git clean -xfd
	autoreconf -i
	./configure
	make -j${i} || break
done

Coauthored by Andreas Rottmann <mail@rotty.xx.vu>

Change-Id: I439edcb4b7742de861c99ed401114f51061f8088
Reviewed-on: https://gerrit.osmocom.org/65
Tested-by: Jenkins Builder
Reviewed-by: Harald Welte <laforge@gnumonks.org>
diff --git a/src/Makefile.am b/src/Makefile.am
index 87d181a..3709cd0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,7 @@
 # Build {hnbap,rua,ranap}_{encoder,decoder}.c using asn1tostruct
 ASN1_ROOT = $(top_builddir)/asn1/
 ASN1TOSTRUCT = $(ASN1_ROOT)/utils/asn1tostruct.py
-BUILT_SOURCES = hnbap_decoder.c hnbap_encoder.c rua_decoder.c rua_encoder.c ranap_decoder.c ranap_encoder.c
+BUILT_SOURCES = hnbap_decoder.c hnbap_encoder.c rua_decoder.c rua_encoder.c gen_ranap.stamp
 
 hnbap_encoder.c hnbap_decoder.c hnbap_ies_defs.h: $(ASN1_ROOT)/hnbap/HNBAP-PDU-Contents.asn $(ASN1TOSTRUCT)
 	$(ASN1TOSTRUCT) -f $<
@@ -11,7 +11,7 @@
 rua_encoder.c rua_decoder.c rua_ies_defs.h: $(ASN1_ROOT)/rua/RUA-PDU-Contents.asn $(ASN1TOSTRUCT)
 	$(ASN1TOSTRUCT) -p RUA_ -f $<
 
-ranap_encoder.c ranap_decoder.c: $(ASN1_ROOT)/ranap/RANAP-PDU-Contents.asn $(ASN1TOSTRUCT)
+gen_ranap.stamp: $(ASN1_ROOT)/ranap/RANAP-PDU-Contents.asn $(ASN1TOSTRUCT)
 	$(ASN1TOSTRUCT) -p RANAP_ -f $<
 #	We also need to replace the include in the newly generated .c files:
 	sed -i 's,^#include "ranap_ies_defs.h",#include <osmocom/ranap/ranap_ies_defs.h>,' ranap_encoder.c ranap_decoder.c
@@ -19,6 +19,7 @@
 	mv ranap_ies_defs.h $(top_srcdir)/include/osmocom/ranap/
 #	this is ugly ^. ranap_ies_defs.h is generated from asn1tostruct.py here, but
 #	it should live in include/osmocom/ranap/.
+	touch $(top_builddir)/$@
 
 AM_CFLAGS = -I$(top_srcdir)/include $(OSMOCORE_CFLAGS) $(OSMOVTY_CFLAGS) $(OSMOGSM_CFLAGS) $(OSMONETIF_CFLAGS) $(ASN1C_CFLAGS) $(OSMOSIGTRAN_CFLAGS)
 COMMON_LDADD = -lsctp