Skip to content

Commit 484fc3b

Browse files
authored
Merge pull request #2286 from ucb-bar/portable-sed
Fix support for non-gnu SED
2 parents 01c50fb + 92b3661 commit 484fc3b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

common.mk

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
SED ?= sed
21

32
# Note: Individual rules that use RISCV or external tools perform local checks to avoid
43
# blocking unrelated targets. Use $(require_riscv) and $(call require_cmd,<tool>) inside recipes.
@@ -212,7 +211,7 @@ $(SFC_MFC_TARGETS) &: $(FIRRTL_FILE) $(FINAL_ANNO_FILE) $(MFC_LOWERING_OPTIONS)
212211
--split-verilog \
213212
-o $(GEN_COLLATERAL_DIR) \
214213
$(FIRRTL_FILE) |& tee $(FIRTOOL_LOG_FILE))
215-
$(SED) -i 's/.*/& /' $(MFC_SMEMS_CONF) # need trailing space for SFC macrocompiler
214+
$(SED) $(SED_INPLACE) 's/.*/& /' $(MFC_SMEMS_CONF) # need trailing space for SFC macrocompiler
216215
touch $(MFC_BB_MODS_FILELIST) # if there are no BB's then the file might not be generated, instead always generate it
217216
# DOC include end: FirrtlCompiler
218217

@@ -230,9 +229,9 @@ $(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(ALL_MODS_FILELIST) $(BB_MODS_FILEL
230229
--out-model-hier-json $(MFC_MODEL_HRCHY_JSON_UNIQUIFIED) \
231230
--gcpath $(GEN_COLLATERAL_DIR)
232231
$(SED) -e 's;^;$(GEN_COLLATERAL_DIR)/;' $(MFC_BB_MODS_FILELIST) > $(BB_MODS_FILELIST)
233-
$(SED) -i 's/\.\///' $(TOP_MODS_FILELIST)
234-
$(SED) -i 's/\.\///' $(MODEL_MODS_FILELIST)
235-
$(SED) -i 's/\.\///' $(BB_MODS_FILELIST)
232+
$(SED) $(SED_INPLACE) 's/\.\///' $(TOP_MODS_FILELIST)
233+
$(SED) $(SED_INPLACE) 's/\.\///' $(MODEL_MODS_FILELIST)
234+
$(SED) $(SED_INPLACE) 's/\.\///' $(BB_MODS_FILELIST)
236235
sort -u $(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(BB_MODS_FILELIST) > $(ALL_MODS_FILELIST)
237236

238237
$(TOP_SMEMS_CONF) $(MODEL_SMEMS_CONF) &: $(MFC_SMEMS_CONF) $(MFC_MODEL_HRCHY_JSON_UNIQUIFIED)

variables.mk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ SHELL := $(shell \
77
elif command -v bash >/dev/null 2>&1; then command -v bash; \
88
else printf /bin/bash; fi)
99

10+
# Portable sed in-place flag (GNU vs BSD/macOS)
11+
SED ?= sed
12+
SED_IS_GNU := $(shell sed --version >/dev/null 2>&1 && echo yes || echo no)
13+
ifeq ($(SED_IS_GNU),yes)
14+
SED_INPLACE := -i
15+
else
16+
SED_INPLACE := -i ''
17+
endif
18+
1019
#########################################################################################
1120
# makefile variables shared across multiple makefiles
1221
# - to use the help text, your Makefile should have a 'help' target that just

0 commit comments

Comments
 (0)