build: fix ranap gen, use same for gen hnbap and rua gen

fix extraneous rebuild for each make invocation: touch the ranap.stamp file in
src/ as the make target suggests.

fix for 'make distcheck': ranap gen: move generated sources to builddir, not
srcdir. Thus we also -I the builddir include to pick up those headers.

hnbap and rua have the same situation as ranap (they generate numerous files
from a single make rule). Use the same makefile semantics for those two
(commit for ranap gen omitted the same changes for hnbap and rua).

The generated headers are thus moved to include/osmocom/*/, so adjust #include
statements accordingly (*_common.h, *_ies_defs.h).

Also move hnbap_common.h to include/osmocom/hnbap and rua_common.h to
include/osmocom/rua, since the *_ies_defs.h want to include them; and since
*_ies_defs.h are now in include/osmocom/*, we want a '<foo>' include now.

Also adjust gitignore.

Change-Id: I32213666fcdfc144008fa7d46497c0938d093e86
diff --git a/src/.gitignore b/src/.gitignore
index 9384c58..55bca01 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,13 +1,10 @@
 hnbap_decoder.c
 hnbap_encoder.c
-hnbap_ies_defs.h
 
 rua_decoder.c
 rua_encoder.c
-rua_ies_defs.h
 
 ranap_decoder.c
 ranap_encoder.c
-ranap_ies_defs.h
 
 hnbgw
diff --git a/src/Makefile.am b/src/Makefile.am
index 17e60e2..ffdfef8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,25 +3,48 @@
 # 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 gen_ranap.stamp
+BUILT_SOURCES = hnbap_decoder.c hnbap_encoder.c rua_decoder.c rua_encoder.c \
+	gen_hnbap.stamp gen_rua.stamp gen_ranap.stamp
 
-hnbap_encoder.c hnbap_decoder.c hnbap_ies_defs.h: $(ASN1_ROOT)/hnbap/HNBAP-PDU-Contents.asn $(ASN1TOSTRUCT)
+gen_hnbap.stamp: $(ASN1_ROOT)/hnbap/HNBAP-PDU-Contents.asn $(ASN1TOSTRUCT)
 	$(ASN1TOSTRUCT) -f $<
+#	We also need to replace the include in the newly generated .c files:
+	sed -i 's,^#include "hnbap_ies_defs.h",#include <osmocom/hnbap/hnbap_ies_defs.h>,' hnbap_encoder.c hnbap_decoder.c
+	sed -i 's,^#include "hnbap_common.h",#include <osmocom/hnbap/hnbap_common.h>,' hnbap_encoder.c hnbap_decoder.c hnbap_ies_defs.h
+	mv hnbap_ies_defs.h $(top_builddir)/include/osmocom/hnbap/
+#	this is ugly ^. hnbap_ies_defs.h is generated from asn1tostruct.py here, but
+#	it should live in include/osmocom/hnbap/.
+	touch $(top_builddir)/src/$@
 
-rua_encoder.c rua_decoder.c rua_ies_defs.h: $(ASN1_ROOT)/rua/RUA-PDU-Contents.asn $(ASN1TOSTRUCT)
+hnbap_decoder.c hnbap_encoder.c: gen_hnbap.stamp
+
+gen_rua.stamp: $(ASN1_ROOT)/rua/RUA-PDU-Contents.asn $(ASN1TOSTRUCT)
 	$(ASN1TOSTRUCT) -p RUA_ -f $<
+#	We also need to replace the include in the newly generated .c files:
+	sed -i 's,^#include "rua_ies_defs.h",#include <osmocom/rua/rua_ies_defs.h>,' rua_encoder.c rua_decoder.c
+	sed -i 's,^#include "rua_common.h",#include <osmocom/rua/rua_common.h>,' rua_encoder.c rua_decoder.c rua_ies_defs.h
+	mv rua_ies_defs.h $(top_builddir)/include/osmocom/rua/
+#	this is ugly ^. rua_ies_defs.h is generated from asn1tostruct.py here, but
+#	it should live in include/osmocom/rua/.
+	touch $(top_builddir)/src/$@
+
+rua_decoder.c rua_encoder.c: gen_rua.stamp
 
 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
 	sed -i 's,^#include "ranap_common.h",#include <osmocom/ranap/ranap_common.h>,' ranap_encoder.c ranap_decoder.c ranap_ies_defs.h
-	mv ranap_ies_defs.h $(top_srcdir)/include/osmocom/ranap/
+	mv ranap_ies_defs.h $(top_builddir)/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)/$@
+	touch $(top_builddir)/src/$@
 
-AM_CFLAGS = -I$(top_srcdir)/include $(OSMOCORE_CFLAGS) $(OSMOVTY_CFLAGS) $(OSMOGSM_CFLAGS) $(OSMONETIF_CFLAGS) $(ASN1C_CFLAGS) $(OSMOSIGTRAN_CFLAGS)
+ranap_decoder.c ranap_encoder.c: gen_ranap.stamp
+
+AM_CFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include \
+	    $(OSMOCORE_CFLAGS) $(OSMOVTY_CFLAGS) $(OSMOGSM_CFLAGS) \
+	    $(OSMONETIF_CFLAGS) $(ASN1C_CFLAGS) $(OSMOSIGTRAN_CFLAGS)
 COMMON_LDADD = -lsctp
 
 # build the shared RANAP library
@@ -37,9 +60,7 @@
 #
 bin_PROGRAMS = osmo-hnbgw
 
-noinst_HEADERS = hnbap_common.h hnbap_ies_defs.h \
-		 rua_common.h rua_ies_defs.h \
-		 context_map.h hnbgw.h hnbgw_cn.h \
+noinst_HEADERS = context_map.h hnbgw.h hnbgw_cn.h \
 		 hnbgw_hnbap.h hnbgw_rua.h hnbgw_ranap.h
 
 osmo_hnbgw_SOURCES = hnbap_encoder.c hnbap_decoder.c hnbap_common.c \
diff --git a/src/hnbap_common.c b/src/hnbap_common.c
index f321a1c..2cd6519 100644
--- a/src/hnbap_common.c
+++ b/src/hnbap_common.c
@@ -24,7 +24,7 @@
 #include <osmocom/core/msgb.h>
 
 #include <osmocom/hnbap/HNBAP-PDU.h>
-#include "hnbap_common.h"
+#include <osmocom/hnbap/hnbap_common.h>
 #include "hnbgw.h"
 
 static const struct value_string hnbap_cause_radio_vals[] = {
diff --git a/src/hnbap_common.h b/src/hnbap_common.h
deleted file mode 100644
index 25cb2f0..0000000
--- a/src/hnbap_common.h
+++ /dev/null
@@ -1,159 +0,0 @@
-#pragma once
-
-#include "asn_application.h"
-
-#include <ANY.h>
-#include <BIT_STRING.h>
-#include <INTEGER.h>
-#include <NativeEnumerated.h>
-#include <NativeInteger.h>
-#include <OBJECT_IDENTIFIER.h>
-#include <OCTET_STRING.h>
-
-#include <osmocom/hnbap/Access-stratum-release-indicator.h>
-#include <osmocom/hnbap/AccessResult.h>
-#include <osmocom/hnbap/AdditionalNeighbourInfoList.h>
-#include <osmocom/hnbap/AltitudeAndDirection.h>
-#include <osmocom/hnbap/BackoffTimer.h>
-#include <osmocom/hnbap/BindingID.h>
-#include <osmocom/hnbap/CELL-FACHMobilitySupport.h>
-#include <osmocom/hnbap/CGI.h>
-#include <osmocom/hnbap/CI.h>
-#include <osmocom/hnbap/CN-DomainIndicator.h>
-#include <osmocom/hnbap/CSG-Capability.h>
-#include <osmocom/hnbap/CSG-ID.h>
-#include <osmocom/hnbap/CSGMembershipStatus.h>
-#include <osmocom/hnbap/CSGMembershipUpdate.h>
-#include <osmocom/hnbap/Cause.h>
-#include <osmocom/hnbap/CauseMisc.h>
-#include <osmocom/hnbap/CauseProtocol.h>
-#include <osmocom/hnbap/CauseRadioNetwork.h>
-#include <osmocom/hnbap/CauseTransport.h>
-#include <osmocom/hnbap/CellIdentity.h>
-#include <osmocom/hnbap/ConfigurationInformation.h>
-#include <osmocom/hnbap/Context-ID.h>
-#include <osmocom/hnbap/Criticality.h>
-#include <osmocom/hnbap/CriticalityDiagnostics-IE-List.h>
-#include <osmocom/hnbap/CriticalityDiagnostics.h>
-#include <osmocom/hnbap/ESN.h>
-#include <osmocom/hnbap/ErrorIndication.h>
-#include <osmocom/hnbap/GTP-TEI.h>
-#include <osmocom/hnbap/GeographicalCoordinates.h>
-#include <osmocom/hnbap/GeographicalLocation.h>
-#include <osmocom/hnbap/HNB-Cell-Access-Mode.h>
-#include <osmocom/hnbap/HNB-Cell-Identifier.h>
-#include <osmocom/hnbap/HNB-GWResponse.h>
-#include <osmocom/hnbap/HNB-Identity-Info.h>
-#include <osmocom/hnbap/HNB-Identity.h>
-#include <osmocom/hnbap/HNB-Location-Information.h>
-#include <osmocom/hnbap/HNB-RNL-Identity.h>
-#include <osmocom/hnbap/HNBAP-PDU.h>
-#include <osmocom/hnbap/HNBCapacity.h>
-#include <osmocom/hnbap/HNBConfigInfo.h>
-#include <osmocom/hnbap/HNBConfigTransferRequest.h>
-#include <osmocom/hnbap/HNBConfigTransferResponse.h>
-#include <osmocom/hnbap/HNBConfigurationInformationMissing.h>
-#include <osmocom/hnbap/HNBConfigurationInformationProvided.h>
-#include <osmocom/hnbap/HNBDe-Register.h>
-#include <osmocom/hnbap/HNBRegisterAccept.h>
-#include <osmocom/hnbap/HNBRegisterReject.h>
-#include <osmocom/hnbap/HNBRegisterRequest.h>
-#include <osmocom/hnbap/IE-Extensions.h>
-#include <osmocom/hnbap/IE.h>
-#include <osmocom/hnbap/IMEI.h>
-#include <osmocom/hnbap/IMSI.h>
-#include <osmocom/hnbap/IMSIDS41.h>
-#include <osmocom/hnbap/IMSIESN.h>
-#include <osmocom/hnbap/IP-Address.h>
-#include <osmocom/hnbap/InitiatingMessage.h>
-#include <osmocom/hnbap/Ipv4Address.h>
-#include <osmocom/hnbap/Ipv6Address.h>
-#include <osmocom/hnbap/Iurh-Signalling-TNL-AddressList.h>
-#include <osmocom/hnbap/LAC.h>
-#include <osmocom/hnbap/LAI.h>
-#include <osmocom/hnbap/MacroCellID.h>
-#include <osmocom/hnbap/MacroCoverageInformation.h>
-#include <osmocom/hnbap/MuxPortNumber.h>
-#include <osmocom/hnbap/NeighbourCellIdentityList.h>
-#include <osmocom/hnbap/NeighbourIdentity.h>
-#include <osmocom/hnbap/NeighbourInfoList.h>
-#include <osmocom/hnbap/NeighbourInfoRequestItem.h>
-#include <osmocom/hnbap/NeighbourInfoRequestList.h>
-#include <osmocom/hnbap/PLMNidentity.h>
-#include <osmocom/hnbap/PSC.h>
-#include <osmocom/hnbap/PTMSI.h>
-#include <osmocom/hnbap/PTMSIRAI.h>
-#include <osmocom/hnbap/Presence.h>
-#include <osmocom/hnbap/PrivateIE-ID.h>
-#include <osmocom/hnbap/PrivateMessage.h>
-#include <osmocom/hnbap/ProcedureCode.h>
-#include <osmocom/hnbap/ProtocolIE-ID.h>
-#include <osmocom/hnbap/RAB-ID.h>
-#include <osmocom/hnbap/RABList.h>
-#include <osmocom/hnbap/RABListItem.h>
-#include <osmocom/hnbap/RAC.h>
-#include <osmocom/hnbap/RAI.h>
-#include <osmocom/hnbap/RNC-ID.h>
-#include <osmocom/hnbap/Registration-Cause.h>
-#include <osmocom/hnbap/RelocationComplete.h>
-#include <osmocom/hnbap/S-RNTIPrefix.h>
-#include <osmocom/hnbap/SAC.h>
-#include <osmocom/hnbap/SuccessfulOutcome.h>
-#include <osmocom/hnbap/TMSIDS41.h>
-#include <osmocom/hnbap/TMSILAI.h>
-#include <osmocom/hnbap/TNLUpdateFailure.h>
-#include <osmocom/hnbap/TNLUpdateRequest.h>
-#include <osmocom/hnbap/TNLUpdateResponse.h>
-#include <osmocom/hnbap/TransportInfo.h>
-#include <osmocom/hnbap/TransportLayerAddress.h>
-#include <osmocom/hnbap/TriggeringMessage.h>
-#include <osmocom/hnbap/Tunnel-Information.h>
-#include <osmocom/hnbap/TypeOfError.h>
-#include <osmocom/hnbap/U-RNTI.h>
-#include <osmocom/hnbap/U-RNTIQueryRequest.h>
-#include <osmocom/hnbap/U-RNTIQueryResponse.h>
-#include <osmocom/hnbap/UDP-Port-Number.h>
-#include <osmocom/hnbap/UE-Capabilities.h>
-#include <osmocom/hnbap/UE-Identity.h>
-#include <osmocom/hnbap/UEDe-Register.h>
-#include <osmocom/hnbap/UERegisterAccept.h>
-#include <osmocom/hnbap/UERegisterReject.h>
-#include <osmocom/hnbap/UERegisterRequest.h>
-#include <osmocom/hnbap/URAIdentity.h>
-#include <osmocom/hnbap/URAIdentityList.h>
-#include <osmocom/hnbap/UTRANCellID.h>
-#include <osmocom/hnbap/UnknownU-RNTIIndication.h>
-#include <osmocom/hnbap/UnsuccessfulOutcome.h>
-#include <osmocom/hnbap/Update-cause.h>
-
-#if (ASN1C_ENVIRONMENT_VERSION < 924)
-# error "You are compiling with the wrong version of ASN1C"
-#endif
-
-#include <osmocom/core/logging.h>
-
-#define HNBAP_DEBUG(x, args ...) DEBUGP(1, x, ## args)
-
-extern int asn1_xer_print;
-
-struct msgb *hnbap_generate_initiating_message(
-					 e_ProcedureCode procedureCode,
-					 Criticality_t criticality,
-					 asn_TYPE_descriptor_t * td, void *sptr);
-
-struct msgb *hnbap_generate_successful_outcome(
-					   e_ProcedureCode procedureCode,
-					   Criticality_t criticality,
-					   asn_TYPE_descriptor_t * td,
-					   void *sptr);
-
-struct msgb *hnbap_generate_unsuccessful_outcome(
-					   e_ProcedureCode procedureCode,
-					   Criticality_t criticality,
-					   asn_TYPE_descriptor_t * td,
-					   void *sptr);
-
-IE_t *hnbap_new_ie(ProtocolIE_ID_t id, Criticality_t criticality,
-		  asn_TYPE_descriptor_t *type, void *sptr);
-
-char *hnbap_cause_str(Cause_t *cause);
diff --git a/src/hnbgw_hnbap.c b/src/hnbgw_hnbap.c
index 5246b81..c329fe4 100644
--- a/src/hnbgw_hnbap.c
+++ b/src/hnbgw_hnbap.c
@@ -28,11 +28,11 @@
 #include <string.h>
 
 #include "asn1helpers.h"
+#include <osmocom/hnbap/hnbap_common.h>
 #include <osmocom/ranap/iu_helpers.h>
 
 #include "hnbgw.h"
-#include "hnbap_common.h"
-#include "hnbap_ies_defs.h"
+#include <osmocom/hnbap/hnbap_ies_defs.h>
 
 #define IU_MSG_NUM_IES		32
 #define IU_MSG_NUM_EXT_IES	32
diff --git a/src/hnbgw_rua.c b/src/hnbgw_rua.c
index a6f0100..fc22bfc 100644
--- a/src/hnbgw_rua.c
+++ b/src/hnbgw_rua.c
@@ -34,8 +34,8 @@
 
 #include "hnbgw.h"
 #include "hnbgw_ranap.h"
-#include "rua_common.h"
-#include "rua_ies_defs.h"
+#include <osmocom/rua/rua_common.h>
+#include <osmocom/rua/rua_ies_defs.h>
 #include "context_map.h"
 
 static int hnbgw_rua_tx(struct hnb_context *ctx, struct msgb *msg)
diff --git a/src/rua_common.c b/src/rua_common.c
index fcb873e..a5ab044 100644
--- a/src/rua_common.c
+++ b/src/rua_common.c
@@ -23,7 +23,7 @@
 
 #include <osmocom/core/msgb.h>
 
-#include "rua_common.h"
+#include <osmocom/rua/rua_common.h>
 #include "hnbgw.h"
 
 extern int asn1_xer_print;
diff --git a/src/rua_common.h b/src/rua_common.h
deleted file mode 100644
index 9b3a65c..0000000
--- a/src/rua_common.h
+++ /dev/null
@@ -1,71 +0,0 @@
-#pragma once
-
-#include <asn_application.h>
-
-#include <osmocom/rua/RUA_Ansi-41-IDNNS.h>
-#include <osmocom/rua/RUA_CN-DomainIndicator.h>
-#include <osmocom/rua/RUA_CSGMembershipStatus.h>
-#include <osmocom/rua/RUA_Cause.h>
-#include <osmocom/rua/RUA_CauseMisc.h>
-#include <osmocom/rua/RUA_CauseProtocol.h>
-#include <osmocom/rua/RUA_CauseRadioNetwork.h>
-#include <osmocom/rua/RUA_CauseTransport.h>
-#include <osmocom/rua/RUA_Connect.h>
-#include <osmocom/rua/RUA_ConnectionlessTransfer.h>
-#include <osmocom/rua/RUA_Context-ID.h>
-#include <osmocom/rua/RUA_Criticality.h>
-#include <osmocom/rua/RUA_CriticalityDiagnostics-IE-List.h>
-#include <osmocom/rua/RUA_CriticalityDiagnostics.h>
-#include <osmocom/rua/RUA_DirectTransfer.h>
-#include <osmocom/rua/RUA_Disconnect.h>
-#include <osmocom/rua/RUA_ErrorIndication.h>
-#include <osmocom/rua/RUA_Establishment-Cause.h>
-#include <osmocom/rua/RUA_Gsm-map-IDNNS.h>
-#include <osmocom/rua/RUA_IE-Extensions.h>
-#include <osmocom/rua/RUA_IE.h>
-#include <osmocom/rua/RUA_InitiatingMessage.h>
-#include <osmocom/rua/RUA_IntraDomainNasNodeSelector.h>
-#include <osmocom/rua/RUA_Presence.h>
-#include <osmocom/rua/RUA_PrivateIE-ID.h>
-#include <osmocom/rua/RUA_PrivateMessage.h>
-#include <osmocom/rua/RUA_ProcedureCode.h>
-#include <osmocom/rua/RUA_ProtocolIE-ID.h>
-#include <osmocom/rua/RUA_RANAP-Message.h>
-#include <osmocom/rua/RUA_RUA-PDU.h>
-#include <osmocom/rua/RUA_RoutingParameter.h>
-#include <osmocom/rua/RUA_SuccessfulOutcome.h>
-#include <osmocom/rua/RUA_TriggeringMessage.h>
-#include <osmocom/rua/RUA_TypeOfError.h>
-#include <osmocom/rua/RUA_UnsuccessfulOutcome.h>
-
-#if (ASN1C_ENVIRONMENT_VERSION < 924)
-# error "You are compiling with the wrong version of ASN1C"
-#endif
-
-#include <osmocom/core/logging.h>
-
-#define RUA_DEBUG(x, args ...) DEBUGP(0, x, ## args)
-
-extern int asn1_xer_print;
-
-struct msgb *rua_generate_initiating_message(
-					e_RUA_ProcedureCode procedureCode,
-					RUA_Criticality_t criticality,
-					asn_TYPE_descriptor_t * td, void *sptr);
-
-struct msgb *rua_generate_successful_outcome(
-					   e_RUA_ProcedureCode procedureCode,
-					   RUA_Criticality_t criticality,
-					   asn_TYPE_descriptor_t * td,
-					   void *sptr);
-
-struct msgb *rua_generate_unsuccessful_outcome(
-					   e_RUA_ProcedureCode procedureCode,
-					   RUA_Criticality_t criticality,
-					   asn_TYPE_descriptor_t * td,
-					   void *sptr);
-
-RUA_IE_t *rua_new_ie(RUA_ProtocolIE_ID_t id, RUA_Criticality_t criticality,
-		     asn_TYPE_descriptor_t *type, void *sptr);
-
-char *rua_cause_str(RUA_Cause_t *cause);
diff --git a/src/rua_msg_factory.c b/src/rua_msg_factory.c
index b664509..0bce326 100644
--- a/src/rua_msg_factory.c
+++ b/src/rua_msg_factory.c
@@ -1,8 +1,8 @@
 #include <stdint.h>
 #include <osmocom/netif/stream.h>
 
-#include "rua_common.h"
-#include "rua_ies_defs.h"
+#include <osmocom/rua/rua_common.h>
+#include <osmocom/rua/rua_ies_defs.h>
 #include "rua_msg_factory.h"
 #include "asn1helpers.h"
 #include "hnbgw.h"
diff --git a/src/tests/hnb-test-rua.c b/src/tests/hnb-test-rua.c
index 69c41eb..a218852 100644
--- a/src/tests/hnb-test-rua.c
+++ b/src/tests/hnb-test-rua.c
@@ -1,6 +1,6 @@
 
 #include <asn1c/ANY.h>
-#include "../rua_ies_defs.h"
+#include <osmocom/rua/rua_ies_defs.h>
 
 #include "hnb-test-layers.h"
 
diff --git a/src/tests/hnb-test.c b/src/tests/hnb-test.c
index af87376..2c41199 100644
--- a/src/tests/hnb-test.c
+++ b/src/tests/hnb-test.c
@@ -52,8 +52,8 @@
 
 #include "hnb-test.h"
 #include "hnb-test-layers.h"
-#include "hnbap_common.h"
-#include "hnbap_ies_defs.h"
+#include <osmocom/hnbap/hnbap_common.h>
+#include <osmocom/hnbap/hnbap_ies_defs.h>
 #include "rua_msg_factory.h"
 #include "asn1helpers.h"
 #include <osmocom/ranap/iu_helpers.h>
diff --git a/src/tests/test-hnbap.c b/src/tests/test-hnbap.c
index c6e7d94..ef46070 100644
--- a/src/tests/test-hnbap.c
+++ b/src/tests/test-hnbap.c
@@ -22,8 +22,8 @@
 #include <osmocom/ranap/iu_helpers.h>
 #include "asn1helpers.h"
 
-#include "hnbap_common.h"
-#include "hnbap_ies_defs.h"
+#include <osmocom/hnbap/hnbap_common.h>
+#include <osmocom/hnbap/hnbap_ies_defs.h>
 #include "test_common.h"
 
 #include <assert.h>