In a makefile, I have
@echo "$(IGNORE_DIRS) $(CLEAN_FILES) $(CLEAN_DIRS) $(REALCLEAN_FILES)" | tr ' ' '\n' >> $@
The problem is that $(CLEAN_FILES)
is quite large, so when I run make, I get
make: execvp: /bin/sh: Argument list too long
I'm on Xubuntu 18.10.
Edit: I should provide a little more context. What I am working on is a make rule (I'm using GNU make) to automatically generate the .hgignore
file. Here is the make rule in its entirety:
.hgignore : .hgignore_extra
@echo "Making $@"
@rm -f $@
@echo "# Automatically generated by Make. Edit .hgignore_extra instead." > $@
@tail -n +2 $< >> $@
@echo "" >> $@
@echo "# The following files come from the Makefile." >> $@
@echo "syntax: glob" >> $@
@echo "$(IGNORE_DIRS) $(CLEAN_FILES) $(CLEAN_DIRS) $(REALCLEAN_FILES)" | tr ' ' '\n' >> $@
@chmod a-w $@
.PHONY : .hgignore
Edit 2: At @mosvy 's suggestion, I have also tried
.hgignore : .hgignore_extra
@echo "Making $@"
@rm -f $@
@echo "# Automatically generated by Make. Edit .hgignore_extra instead." > $@
@tail -n +2 $< >> $@
@echo "" >> $@
@echo "# The following files come from the Makefile." >> $@
@echo "syntax: glob" >> $@
$(file >$@) $(foreach V,$(IGNORE_DIRS) $(CLEAN_FILES) $(CLEAN_DIRS) $(REALCLEAN_FILES),$(file >>$@,$V))
@true
@chmod a-w $@
.PHONY : .hgignore
Running make .hgignore
with this, I no longer get the "Argument list too long" error, but the generated .hgignore file only contains output up to the syntax: glob
line, and then nothing after that.
$(file >$@)
part, that's only there to truncate the file if it already existed, but you already have contents there, so you don't want it... Is that line indented with space or with a TAB character? It needs to be a TAB for it to work... You also don't need the @true, since you have another rule following that one... – filbranden Nov 09 '18 at 21:26$(file >$@)
and@true
, but it still doesn't work. – teerav42 Nov 09 '18 at 21:47.hgignore
is at least questionable... Particularly since it supports wildcards such as*.o
,*.pyc
, etc. – filbranden Nov 09 '18 at 23:41$(file)
) before it runs the shell commands. Try using Make commands only, you can do most of that using$(file)
, and$(shell)
will be useful too, e.g.$(shell chmod a-x $@)
or$(file >>$@,$(shell tail -n +2 $<))
– filbranden Nov 10 '18 at 06:02