Andrei G has uploaded this change for review.
build: rewrite generated includes without sed -i
The gen_*.stamp rules in src/Makefile.am post-process the output of
asn1tostruct.py with "sed -i 'script' file...". The -i option is not
portable. GNU sed takes an optional suffix attached to the option; BSD
sed, on macOS and the other BSDs, takes the next argument as the backup
suffix, so it reads the script as a suffix and the first file name as
the script. The build stops in src/ before a single object is compiled:
sed: 1: "hnbap_encoder.c": unterminated substitute pattern
All eight rules are affected, for hnbap, rua, ranap and sabp.
Loop over the files instead and write each substitution through a
temporary file that then replaces the original. That uses only the
portable form of sed and gives the same result with either dialect.
Change-Id: I6f803fcfb5dd81f0a0b2998b00622f6a19afc5da
Signed-off-by: Andrei Gosman <andrei.gosman@gmail.com>
---
M src/Makefile.am
1 file changed, 27 insertions(+), 8 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-iuh refs/changes/88/43588/1
diff --git a/src/Makefile.am b/src/Makefile.am
index 343fa53..f668c7b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,9 @@
SUBDIRS = hnbap rua ranap sabp
# Build {hnbap,rua,ranap}_{encoder,decoder}.c using asn1tostruct
+# The generated files get their include lines rewritten below. BSD sed on
+# macOS takes the argument after -i as a backup suffix, so "sed -i 'script'
+# file" is not portable; write through a temporary file instead.
ASN1_ROOT = $(top_srcdir)/asn1
ASN1TOSTRUCT = $(ASN1_ROOT)/utils/asn1tostruct.py
BUILT_SOURCES = hnbap_decoder.c hnbap_encoder.c rua_decoder.c rua_encoder.c sabp_encoder.c sabp_decoder.c \
@@ -9,8 +12,12 @@
gen_hnbap.stamp: $(ASN1_ROOT)/hnbap/HNBAP-PDU-Contents.asn $(ASN1TOSTRUCT)
$(ASN1TOSTRUCT) -p HNBAP_ -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
+ for f in hnbap_encoder.c hnbap_decoder.c; do \
+ sed 's,^#include "hnbap_ies_defs.h",#include <osmocom/hnbap/hnbap_ies_defs.h>,' $$f > $$f.tmp && mv $$f.tmp $$f || exit 1; \
+ done
+ for f in hnbap_encoder.c hnbap_decoder.c hnbap_ies_defs.h; do \
+ sed 's,^#include "hnbap_common.h",#include <osmocom/hnbap/hnbap_common.h>,' $$f > $$f.tmp && mv $$f.tmp $$f || exit 1; \
+ done
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/.
@@ -21,8 +28,12 @@
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
+ for f in rua_encoder.c rua_decoder.c; do \
+ sed 's,^#include "rua_ies_defs.h",#include <osmocom/rua/rua_ies_defs.h>,' $$f > $$f.tmp && mv $$f.tmp $$f || exit 1; \
+ done
+ for f in rua_encoder.c rua_decoder.c rua_ies_defs.h; do \
+ sed 's,^#include "rua_common.h",#include <osmocom/rua/rua_common.h>,' $$f > $$f.tmp && mv $$f.tmp $$f || exit 1; \
+ done
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/.
@@ -33,8 +44,12 @@
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
+ for f in ranap_encoder.c ranap_decoder.c; do \
+ sed 's,^#include "ranap_ies_defs.h",#include <osmocom/ranap/ranap_ies_defs.h>,' $$f > $$f.tmp && mv $$f.tmp $$f || exit 1; \
+ done
+ for f in ranap_encoder.c ranap_decoder.c ranap_ies_defs.h; do \
+ sed 's,^#include "ranap_common.h",#include <osmocom/ranap/ranap_common.h>,' $$f > $$f.tmp && mv $$f.tmp $$f || exit 1; \
+ done
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/.
@@ -45,8 +60,12 @@
gen_sabp.stamp: $(ASN1_ROOT)/sabp/SABP-PDU-Contents.asn $(ASN1TOSTRUCT)
$(ASN1TOSTRUCT) -p SABP_ -f $<
# We also need to replace the include in the newly generated .c files:
- sed -i 's,^#include "sabp_ies_defs.h",#include <osmocom/sabp/sabp_ies_defs.h>,' sabp_encoder.c sabp_decoder.c
- sed -i 's,^#include "sabp_common.h",#include <osmocom/sabp/sabp_common.h>,' sabp_encoder.c sabp_decoder.c sabp_ies_defs.h
+ for f in sabp_encoder.c sabp_decoder.c; do \
+ sed 's,^#include "sabp_ies_defs.h",#include <osmocom/sabp/sabp_ies_defs.h>,' $$f > $$f.tmp && mv $$f.tmp $$f || exit 1; \
+ done
+ for f in sabp_encoder.c sabp_decoder.c sabp_ies_defs.h; do \
+ sed 's,^#include "sabp_common.h",#include <osmocom/sabp/sabp_common.h>,' $$f > $$f.tmp && mv $$f.tmp $$f || exit 1; \
+ done
mv sabp_ies_defs.h $(top_builddir)/include/osmocom/sabp/
# this is ugly ^. sabp_ies_defs.h is generated from asn1tostruct.py here, but
# it should live in include/osmocom/sabp/.
To view, visit change 43588. To unsubscribe, or for help writing mail filters, visit settings.