I have a makefile for compiling Arduino programs.
I need to add some text at the beginning of some files based on some logic. I am using echo command for that.
ECHO = echo
and later in the file, I have lot of places like
$(OBJDIR)/%.cpp: %.pde
$(ECHO) '#if ARDUINO >= 100\n #include "Arduino.h"\n#else\n #include "WProgram.h"\n#endif' > $@
which works fine.
Recently, some users complained that echo command doesn’t work properly in some linux distros and I had to add the ‘-e’ option to the echo command.
So I changed the first line where I declare the command to
ECHO = echo -e
This is not working, because makefile considers -e as part of the text and not as part of the option.
Edit:
I am not getting any error, but the text -e is also appended to the file that I am creating.
Is there a way to declare the -e as an option and not as part of the text?
Most likely you’re seeing behavior differences because
echois a shell built-in command in some versions of some shells. Then that’s being compounded because make only sometimes uses the shell to invoke commands — it will prefer to invoke commands directly if possible. So, sometimes, on some systems, you are not invoking theechocommand that you think you are.You would probably have better luck by setting
which will explicitly invoke the external
echocommand, even if the shell has a built-in version. That way you should get consistent results.