Search code examples
c++makefilewxwidgetsheader-files

<image>.h - Where is this -e coming from?


I'm getting the following issue when I try to build this project:

drazisil@Lightning:~/comical$ make -C src
make: Entering directory '/home/drazisil/comical/src'
Converting firstpage.png
...

make[1]: Entering directory `/home/travis/build/drazisil/comical/src'

`wx-config --cxx` `wx-config --cxxflags` -O2 -Wall -pipe -D_UNIX -I../unrar -I../unzip -c -o ComicalApp.o ComicalApp.cpp

In file included from ComicalFrame.h:43:0,

                 from ComicalManager.h:32,

                 from ComicalApp.h:32,

                 from ComicalApp.cpp:28:

firstpage.h:2:1: error: stray ‘#’ in program

The reason appears to be because there is an -e being inserted in both the beginning and end of of the generated .h files:

#ifndef _firstpage_png_h
-e #define _firstpage_png_h
static const unsigned char firstpage_png[] = {
...
...
...
-e };

#endif

Since I'm not sure what step of the process is causing this, I'm not sure how to remove it, or what it even means. Searching -e doesn't work all that well.

ETA: Makefile: https://github.com/drazisil/comical/blob/dev/Makefile

How can I fix it?


Solution

  • The problem is this target in the src/Makefile file.

    %.h : %.png
        @echo "Converting" $<
        @echo "#ifndef _"$*"_png_h" > $@
        @echo -e "#define _"$*"_png_h\n" >> $@
        @echo "static const unsigned char "$*"_png[] = {" >> $@
        @hexdump -e "13/1 \"0x%02X, \" \"\n\"" $< | sed 's/0x  ,//g' >> $@
        @echo -e "};\n\n#endif" >> $@
    

    Specifically, the two lines that use echo -e in an attempt to put an extra newline at the end of the echoed output.

    echo -e, however, is non-standard and your shell/version of echo clearly doesn't understand it.

    That target would be better with those lines rewritten as:

    @printf '#define _$*_png_h\n\n' >> $@
    @printf '};\n\n#endif\n' >> $@
    

    Additional improvements to that target are also possible but out-of-scope for this problem (mainly to use a single shell command and single redirection instead of five).