ASN_MODULE_SRC = \
	gen/ANY_aper.c \
	gen/ANY.c \
	gen/aper_decoder.c \
	gen/aper_encoder.c \
	gen/aper_opentype.c \
	gen/aper_support.c \
	gen/asn_application.c \
	gen/asn_bit_data.c \
	gen/asn_codecs_prim.c \
	gen/asn_internal.c \
	gen/asn_random_fill.c \
	gen/asn_SEQUENCE_OF.c \
	gen/asn_SET_OF.c \
	gen/ber_tlv_length.c \
	gen/ber_tlv_tag.c \
	gen/BIT_STRING.c \
	gen/BIT_STRING_print.c \
	gen/BIT_STRING_rfill.c \
	gen/constraints.c \
	gen/constr_CHOICE_aper.c \
	gen/constr_CHOICE.c \
	gen/constr_CHOICE_print.c \
	gen/constr_CHOICE_rfill.c \
	gen/constr_SEQUENCE_aper.c \
	gen/constr_SEQUENCE.c \
	gen/constr_SEQUENCE_OF_aper.c \
	gen/constr_SEQUENCE_OF.c \
	gen/constr_SEQUENCE_print.c \
	gen/constr_SEQUENCE_rfill.c \
	gen/constr_SET_OF_aper.c \
	gen/constr_SET_OF.c \
	gen/constr_SET_OF_print.c \
	gen/constr_SET_OF_rfill.c \
	gen/constr_TYPE.c \
	gen/ENUMERATED.c \
	gen/ENUMERATED_aper.c \
	gen/GraphicString.c \
	gen/INTEGER_aper.c \
	gen/INTEGER.c \
	gen/INTEGER_print.c \
	gen/INTEGER_rfill.c \
	gen/NativeEnumerated_aper.c \
	gen/NativeEnumerated.c \
	gen/NativeInteger_aper.c \
	gen/NativeInteger.c \
	gen/NativeInteger_print.c \
	gen/NativeInteger_rfill.c \
	gen/ObjectDescriptor.c \
	gen/OBJECT_IDENTIFIER.c \
	gen/OBJECT_IDENTIFIER_print.c \
	gen/OBJECT_IDENTIFIER_rfill.c \
	gen/OCTET_STRING_aper.c \
	gen/OCTET_STRING.c \
	gen/OCTET_STRING_print.c \
	gen/OCTET_STRING_rfill.c \
	gen/OPEN_TYPE_aper.c \
	gen/OPEN_TYPE.c \
	gen/per_decoder.c \
	gen/per_encoder.c \
	gen/per_opentype.c \
	gen/per_support.c \
	gen/SBcAP_Broadcast-Cancelled-Area-List-5GS.c \
	gen/SBcAP_Broadcast-Cancelled-Area-List.c \
	gen/SBcAP_Broadcast-Empty-Area-List-5GS.c \
	gen/SBcAP_Broadcast-Empty-Area-List.c \
	gen/SBcAP_Broadcast-Scheduled-Area-List-5GS.c \
	gen/SBcAP_Broadcast-Scheduled-Area-List.c \
	gen/SBcAP_CancelledCellinEAI.c \
	gen/SBcAP_CancelledCellinEAI-Item.c \
	gen/SBcAP_CancelledCellinTAI-5GS.c \
	gen/SBcAP_CancelledCellinTAI.c \
	gen/SBcAP_CancelledCellinTAI-Item.c \
	gen/SBcAP_Cause.c \
	gen/SBcAP_CellId-Broadcast-List-5GS.c \
	gen/SBcAP_CellId-Broadcast-List.c \
	gen/SBcAP_CellId-Broadcast-List-Item.c \
	gen/SBcAP_CellID-Cancelled-Item.c \
	gen/SBcAP_CellID-Cancelled-List-5GS.c \
	gen/SBcAP_CellID-Cancelled-List.c \
	gen/SBcAP_CellIdentity.c \
	gen/SBcAP_Concurrent-Warning-Message-Indicator.c \
	gen/SBcAP_Criticality.c \
	gen/SBcAP_Criticality-Diagnostics.c \
	gen/SBcAP_CriticalityDiagnostics-IE-List.c \
	gen/SBcAP_Data-Coding-Scheme.c \
	gen/SBcAP_ECGIList.c \
	gen/SBcAP_EmergencyAreaID-Broadcast-List.c \
	gen/SBcAP_EmergencyAreaID-Broadcast-List-Item.c \
	gen/SBcAP_Emergency-Area-ID.c \
	gen/SBcAP_EmergencyAreaID-Cancelled-Item.c \
	gen/SBcAP_EmergencyAreaID-Cancelled-List.c \
	gen/SBcAP_Emergency-Area-ID-List.c \
	gen/SBcAP_ENB-ID.c \
	gen/SBcAP_Error-Indication.c \
	gen/SBcAP_EUTRAN-CGI.c \
	gen/SBcAP_Extended-Repetition-Period.c \
	gen/SBcAP_EXTERNAL.c \
	gen/SBcAP_Failed-Cell-List.c \
	gen/SBcAP_Failed-Cell-List-NR.c \
	gen/SBcAP_Global-ENB-ID.c \
	gen/SBcAP_Global-GNB-ID.c \
	gen/SBcAP_Global-NgENB-ID.c \
	gen/SBcAP_Global-RAN-Node-ID.c \
	gen/SBcAP_GNB-ID.c \
	gen/SBcAP_InitiatingMessage.c \
	gen/SBcAP_List-of-5GS-Cells-for-Failure.c \
	gen/SBcAP_List-of-5GS-TAI-for-Restart.c \
	gen/SBcAP_List-of-5GS-TAIs.c \
	gen/SBcAP_List-of-EAIs-Restart.c \
	gen/SBcAP_List-of-TAIs.c \
	gen/SBcAP_List-of-TAIs-Restart.c \
	gen/SBcAP_Message-Identifier.c \
	gen/SBcAP_NgENB-ID.c \
	gen/SBcAP_NRCellIdentity.c \
	gen/SBcAP_NR-CGI.c \
	gen/SBcAP_NR-CGIList.c \
	gen/SBcAP_NumberOfBroadcasts.c \
	gen/SBcAP_Number-of-Broadcasts-Requested.c \
	gen/SBcAP_Omc-Id.c \
	gen/SBcAP_PLMNidentity.c \
	gen/SBcAP_Presence.c \
	gen/SBcAP_ProcedureCode.c \
	gen/SBcAP_ProtocolExtensionContainer.c \
	gen/SBcAP_ProtocolExtensionField.c \
	gen/SBcAP_ProtocolExtensionID.c \
	gen/SBcAP_ProtocolIE-Container.c \
	gen/SBcAP_ProtocolIE-ContainerList.c \
	gen/SBcAP_ProtocolIE-Field.c \
	gen/SBcAP_ProtocolIE-ID.c \
	gen/SBcAP_PWS-Failure-Indication.c \
	gen/SBcAP_PWS-Restart-Indication.c \
	gen/SBcAP_RAT-Selector-5GS.c \
	gen/SBcAP_Repetition-Period.c \
	gen/SBcAP_Restarted-Cell-List.c \
	gen/SBcAP_Restarted-Cell-List-NR.c \
	gen/SBcAP_SBC-AP-PDU.c \
	gen/SBcAP_ScheduledCellinEAI.c \
	gen/SBcAP_ScheduledCellinEAI-Item.c \
	gen/SBcAP_ScheduledCellinTAI-5GS.c \
	gen/SBcAP_ScheduledCellinTAI.c \
	gen/SBcAP_ScheduledCellinTAI-Item.c \
	gen/SBcAP_Send-Stop-Warning-Indication.c \
	gen/SBcAP_Send-Write-Replace-Warning-Indication.c \
	gen/SBcAP_Serial-Number.c \
	gen/SBcAP_Stop-All-Indicator.c \
	gen/SBcAP_Stop-Warning-Indication.c \
	gen/SBcAP_Stop-Warning-Request.c \
	gen/SBcAP_Stop-Warning-Response.c \
	gen/SBcAP_SuccessfulOutcome.c \
	gen/SBcAP_TAC-5GS.c \
	gen/SBcAP_TAC.c \
	gen/SBcAP_TAI-5GS.c \
	gen/SBcAP_TAI-Broadcast-List-5GS.c \
	gen/SBcAP_TAI-Broadcast-List.c \
	gen/SBcAP_TAI-Broadcast-List-Item.c \
	gen/SBcAP_TAI.c \
	gen/SBcAP_TAI-Cancelled-List-5GS.c \
	gen/SBcAP_TAI-Cancelled-List.c \
	gen/SBcAP_TAI-Cancelled-List-Item.c \
	gen/SBcAP_TAI-List-for-Warning.c \
	gen/SBcAP_TBCD-STRING.c \
	gen/SBcAP_TriggeringMessage.c \
	gen/SBcAP_TypeOfError.c \
	gen/SBcAP_Unknown-5GS-Tracking-Area-List.c \
	gen/SBcAP_Unknown-Tracking-Area-List.c \
	gen/SBcAP_UnsuccessfulOutcome.c \
	gen/SBcAP_Warning-Area-Coordinates.c \
	gen/SBcAP_Warning-Area-List-5GS.c \
	gen/SBcAP_Warning-Area-List.c \
	gen/SBcAP_Warning-Message-Content.c \
	gen/SBcAP_Warning-Security-Information.c \
	gen/SBcAP_Warning-Type.c \
	gen/SBcAP_Write-Replace-Warning-Indication.c \
	gen/SBcAP_Write-Replace-Warning-Request.c \
	gen/SBcAP_Write-Replace-Warning-Response.c \
	$(NULL)

ASN_MODULE_INC = \
	SBcAP_Criticality.h \
	SBcAP_Presence.h \
	SBcAP_ProcedureCode.h \
	SBcAP_ProtocolExtensionID.h \
	SBcAP_ProtocolIE-ID.h \
	SBcAP_TriggeringMessage.h \
	SBcAP_ProtocolIE-Container.h \
	SBcAP_ProtocolIE-Field.h \
	SBcAP_ProtocolIE-ContainerList.h \
	SBcAP_ProtocolExtensionContainer.h \
	SBcAP_ProtocolExtensionField.h \
	SBcAP_Broadcast-Scheduled-Area-List.h \
	SBcAP_Broadcast-Scheduled-Area-List-5GS.h \
	SBcAP_Broadcast-Cancelled-Area-List.h \
	SBcAP_Broadcast-Cancelled-Area-List-5GS.h \
	SBcAP_Broadcast-Empty-Area-List.h \
	SBcAP_Broadcast-Empty-Area-List-5GS.h \
	SBcAP_CancelledCellinEAI.h \
	SBcAP_CancelledCellinEAI-Item.h\
	SBcAP_CancelledCellinTAI.h \
	SBcAP_CancelledCellinTAI-Item.h\
	SBcAP_CancelledCellinTAI-5GS.h \
	SBcAP_Cause.h \
	SBcAP_CellId-Broadcast-List.h \
	SBcAP_CellId-Broadcast-List-Item.h \
	SBcAP_CellId-Broadcast-List-5GS.h \
	SBcAP_CellID-Cancelled-List.h \
	SBcAP_CellID-Cancelled-Item.h \
	SBcAP_CellID-Cancelled-List-5GS.h \
	SBcAP_CellIdentity.h \
	SBcAP_Concurrent-Warning-Message-Indicator.h \
	SBcAP_Criticality-Diagnostics.h\
	SBcAP_CriticalityDiagnostics-IE-List.h \
	SBcAP_Data-Coding-Scheme.h \
	SBcAP_ECGIList.h \
	SBcAP_Emergency-Area-ID-List.h \
	SBcAP_Emergency-Area-ID.h \
	SBcAP_EmergencyAreaID-Broadcast-List.h \
	SBcAP_EmergencyAreaID-Broadcast-List-Item.h \
	SBcAP_EmergencyAreaID-Cancelled-List.h \
	SBcAP_EmergencyAreaID-Cancelled-Item.h \
	SBcAP_EUTRAN-CGI.h \
	SBcAP_Extended-Repetition-Period.h \
	SBcAP_ENB-ID.h \
	SBcAP_Failed-Cell-List.h \
	SBcAP_Failed-Cell-List-NR.h \
	SBcAP_Global-ENB-ID.h \
	SBcAP_Global-RAN-Node-ID.h \
	SBcAP_Global-GNB-ID.h \
	SBcAP_GNB-ID.h \
	SBcAP_Global-NgENB-ID.h\
	SBcAP_List-of-TAIs.h \
	SBcAP_List-of-TAIs-Restart.h \
	SBcAP_List-of-EAIs-Restart.h \
	SBcAP_List-of-5GS-TAIs.h \
	SBcAP_List-of-5GS-Cells-for-Failure.h \
	SBcAP_List-of-5GS-TAI-for-Restart.h \
	SBcAP_Message-Identifier.h \
	SBcAP_Number-of-Broadcasts-Requested.h \
	SBcAP_NumberOfBroadcasts.h \
	SBcAP_NR-CGIList.h \
	SBcAP_NR-CGI.h \
	SBcAP_NRCellIdentity.h \
	SBcAP_NgENB-ID.h \
	SBcAP_Omc-Id.h \
	SBcAP_PLMNidentity.h \
	SBcAP_Repetition-Period.h \
	SBcAP_Restarted-Cell-List.h \
	SBcAP_RAT-Selector-5GS.h \
	SBcAP_Restarted-Cell-List-NR.h \
	SBcAP_ScheduledCellinEAI.h \
	SBcAP_ScheduledCellinEAI-Item.h\
	SBcAP_ScheduledCellinTAI.h \
	SBcAP_ScheduledCellinTAI-Item.h\
	SBcAP_ScheduledCellinTAI-5GS.h \
	SBcAP_Send-Write-Replace-Warning-Indication.h \
	SBcAP_Send-Stop-Warning-Indication.h \
	SBcAP_Serial-Number.h \
	SBcAP_Stop-All-Indicator.h \
	SBcAP_TAC.h \
	SBcAP_TAC-5GS.h\
	SBcAP_TAI-Broadcast-List.h \
	SBcAP_TAI-Broadcast-List-Item.h\
	SBcAP_TAI-Broadcast-List-5GS.h \
	SBcAP_TAI-Cancelled-List.h \
	SBcAP_TAI-Cancelled-List-Item.h\
	SBcAP_TAI-Cancelled-List-5GS.h \
	SBcAP_TAI-List-for-Warning.h \
	SBcAP_TAI.h \
	SBcAP_TBCD-STRING.h \
	SBcAP_TypeOfError.h \
	SBcAP_TAI-5GS.h\
	SBcAP_Unknown-Tracking-Area-List.h \
	SBcAP_Unknown-5GS-Tracking-Area-List.h \
	SBcAP_Warning-Area-List.h \
	SBcAP_Warning-Message-Content.h\
	SBcAP_Warning-Area-Coordinates.h \
	SBcAP_Warning-Security-Information.h \
	SBcAP_Warning-Type.h \
	SBcAP_Warning-Area-List-5GS.h \
	SBcAP_Write-Replace-Warning-Request.h \
	SBcAP_Write-Replace-Warning-Response.h \
	SBcAP_Stop-Warning-Request.h \
	SBcAP_Stop-Warning-Response.h \
	SBcAP_Write-Replace-Warning-Indication.h \
	SBcAP_Stop-Warning-Indication.h\
	SBcAP_PWS-Restart-Indication.h \
	SBcAP_PWS-Failure-Indication.h \
	SBcAP_Error-Indication.h \
	SBcAP_SBC-AP-PDU.h \
	SBcAP_InitiatingMessage.h \
	SBcAP_SuccessfulOutcome.h \
	SBcAP_UnsuccessfulOutcome.h \
	SBcAP_EXTERNAL.h
	$(NULL)

SKEL_HEADER_FILES = \
	skel/ANY.h \
	skel/BIT_STRING.h \
	skel/BMPString.h \
	skel/BOOLEAN.h \
	skel/ENUMERATED.h \
	skel/GeneralString.h \
	skel/GeneralizedTime.h \
	skel/GraphicString.h \
	skel/IA5String.h \
	skel/INTEGER.h \
	skel/ISO646String.h \
	skel/NULL.h \
	skel/NativeEnumerated.h \
	skel/NativeInteger.h \
	skel/NativeReal.h \
	skel/NumericString.h \
	skel/OBJECT_IDENTIFIER.h \
	skel/OCTET_STRING.h \
	skel/OPEN_TYPE.h \
	skel/ObjectDescriptor.h \
	skel/PrintableString.h \
	skel/REAL.h \
	skel/RELATIVE-OID.h \
	skel/T61String.h \
	skel/TeletexString.h \
	skel/UTCTime.h \
	skel/UTF8String.h \
	skel/UniversalString.h \
	skel/VideotexString.h \
	skel/VisibleString.h \
	skel/aper_decoder.h \
	skel/aper_encoder.h \
	skel/aper_opentype.h \
	skel/aper_support.h \
	skel/asn_SEQUENCE_OF.h \
	skel/asn_SET_OF.h \
	skel/asn_application.h \
	skel/asn_bit_data.h \
	skel/asn_codecs.h \
	skel/asn_codecs_prim.h \
	skel/asn_config.h \
	skel/asn_internal.h \
	skel/asn_ioc.h \
	skel/asn_random_fill.h \
	skel/asn_system.h \
	skel/ber_decoder.h \
	skel/ber_tlv_length.h \
	skel/ber_tlv_tag.h \
	skel/constr_CHOICE.h \
	skel/constr_SEQUENCE.h \
	skel/constr_SEQUENCE_OF.h \
	skel/constr_SET.h \
	skel/constr_SET_OF.h \
	skel/constr_TYPE.h \
	skel/constraints.h \
	skel/der_encoder.h \
	skel/jer_decoder.h \
	skel/jer_encoder.h \
	skel/jer_support.h \
	skel/oer_decoder.h \
	skel/oer_encoder.h \
	skel/oer_support.h \
	skel/per_decoder.h \
	skel/per_encoder.h \
	skel/per_opentype.h \
	skel/per_support.h \
	skel/uper_decoder.h \
	skel/uper_encoder.h \
	skel/uper_opentype.h \
	skel/uper_support.h \
	skel/xer_decoder.h \
	skel/xer_encoder.h \
	skel/xer_support.h \
	$(NULL)

EXTRA_DIST = $(SKEL_HEADER_FILES)

AM_CPPFLAGS = $(all_includes)
AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src/sbcap/skel $(ASN_MODULE_CFLAGS) $(ASN1C_CFLAGS) $(LIBOSMOCORE_CFLAGS)

noinst_LTLIBRARIES=libosmo-asn1-sbcap.la
libosmo_asn1_sbcap_la_SOURCES=$(ASN_MODULE_SRC)
libosmo_asn1_sbcap_la_LIBADD=$(ASN1C_LDADD)

sbcap_LIBVERSION=2:0:0
lib_LTLIBRARIES = libosmo-sbcap.la
libosmo_sbcap_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(sbcap_LIBVERSION) -no-undefined
libosmo_sbcap_la_LIBADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) \
		                  $(ASN1C_LIBS) libosmo-asn1-sbcap.la
libosmo_sbcap_la_SOURCES = sbcap_common.c

regen: copy-skeleton-headers regenerate-from-asn1-source

# asn1c generator doesn't copy skeleton (support) header files, do that manually:
copy-skeleton-headers:
	if test -d $(top_srcdir)/src/sbcap/skel/; then \
		rm -rf $(top_srcdir)/src/sbcap/skel/; \
	fi
	mkdir -p $(top_srcdir)/src/sbcap/skel/
	cp $(ASN1C_SKELETON_PATH)/*.h $(top_srcdir)/src/sbcap/skel/
#	Set up ASN_DEBUG:
	sed -i -e '/#include "asn_application.h"/a\' -e '#include <osmocom/sbcap/sbcap_internal.h>' \
		$(top_srcdir)/src/sbcap/skel/asn_internal.h

# "-R" is not passed on purpose, in order to get C files from
# ASN1C_SKELETON_PATH (/usr/share/asn1c/) copied over:
regenerate-from-asn1-source:
	rm -f $(top_srcdir)/src/sbcap/gen/*.c
	ASN1C_PREFIX="SBcAP_" ${ASN1C_BIN_PATH} \
		-S $(ASN1C_SKELETON_PATH) \
		-fcompound-names \
		-gen-APER \
		-no-gen-BER \
		-no-gen-XER \
		-no-gen-JER \
		-no-gen-OER \
		-no-gen-UPER \
		-no-gen-example \
		$(top_srcdir)/src/sbcap/asn1/SBC_AP_CommonDataTypes.asn \
		$(top_srcdir)/src/sbcap/asn1/SBC_AP_Constants.asn \
		$(top_srcdir)/src/sbcap/asn1/SBC_AP_Containers.asn \
		$(top_srcdir)/src/sbcap/asn1/SBC_AP_IEs.asn \
		$(top_srcdir)/src/sbcap/asn1/SBC_AP_PDU_Contents.asn \
		$(top_srcdir)/src/sbcap/asn1/SBC_AP_PDU_Descriptions.asn

#	Fix dependency loops:
	sed -i '/#include "SBcAP_ProtocolExtensionContainer.h"/d' \
		SBcAP_Broadcast-Cancelled-Area-List-5GS.h \
		SBcAP_Broadcast-Scheduled-Area-List-5GS.h \
		SBcAP_EUTRAN-CGI.h \
		SBcAP_Global-GNB-ID.h \
		SBcAP_Global-NgENB-ID.h \
		SBcAP_NR-CGI.h \
		SBcAP_TAI-5GS.h \
		SBcAP_TAI-Broadcast-List-5GS.h
	sed -i -e '/#include/a\' -e '#include "SBcAP_ProtocolExtensionContainer.h"' \
		SBcAP_Broadcast-Cancelled-Area-List-5GS.c \
		SBcAP_EUTRAN-CGI.c \
		SBcAP_Global-GNB-ID.c \
		SBcAP_Global-NgENB-ID.c \
		SBcAP_NR-CGI.c \
		SBcAP_TAI-5GS.c

#	change include style to `#include <dir/foo.h>'
	$(top_srcdir)/move-asn1-header-files.sh osmocom/sbcap $(ASN_MODULE_INC)
#	Finally copy *.c from buildir to srcdir:
	if test "$(realpath $(CURDIR))" != "$(realpath $(top_srcdir)/src/sbcap/gen)"; then \
		mkdir -p $(top_srcdir)/src/sbcap/gen && \
		cp *.c $(top_srcdir)/src/sbcap/gen; \
	fi
	rm -f $(top_srcdir)/src/sbcap/gen/converter-example.c
