Re: sh and Makefile

From: Bill Seivert (seivert_at_pcisys.net)
Date: 02/26/05


Date: Fri, 25 Feb 2005 20:44:41 -0700


Mark wrote:
> Hello,
>
> I have an unusual scenario for you. I am attempting to automate the
> generation of some dependancies in make. I have written the following
> code inside my makefile but am getting errors. I'm afraid I'm a newbie
> to all this.
>
> Could someone please help!
>
> -------------------------------Makefile---------------------------------------
> SHELL = /bin/sh
> CXX = g++
> CXXFLAGS = -g -Wall
> DEFS = -D_MOSIX
>
> # Automatically generate dependencies and include them in Makefile
> depend: $(SOURCES) $(HEADERS)
> for file in `find . -name *.cpp`; do \
> filewosuffix=`echo "$$file" | sed 's/.cpp//g'` \
> g++ $$file -MT '${OBJDIR}/"$$filewosuffix".o' >> depend \
> echo '$${CXX} -c $${CXXFLAGS} $${DEFS} -o $$@ $$<' >> depend \
> done
> -------------------------------/Makefile---------------------------------------
>
> I am getting the following errors:
> /bin/sh: -c: line 2: syntax error: unexpected end of file
>
> Thanks for your help.
>

You probably want to erase depend since you are only
appending to it. You need more semicolons and use double
quotes around the *.cpp in the find command and on the final
echo. One semicolon after each statement:

depend: $(SOURCES) $(HEADERS)
     cat </dev/null >depend ; \
     for file in `find . -name "*.cpp"`; do \
         filewosuffix=`echo "$$file" | sed 's/.cpp//g'` ; \
         g++ $$file -MT '${OBJDIR}/"$$filewosuffix".o' >> depend ; \
         echo "$${CXX} -c $${CXXFLAGS} $${DEFS} -o $$@ $$<" >> depend ; \
     done

(untested)

Bill Seivert



Relevant Pages

  • sh and Makefile
    ... I have an unusual scenario for you. ... I am attempting to automate the ... generation of some dependancies in make. ... code inside my makefile but am getting errors. ...
    (comp.unix.shell)
  • Re: sh and Makefile
    ... > generation of some dependancies in make. ... > code inside my makefile but am getting errors. ... SRC = $/file1.cpp $/file2.cpp ... separate source tree from object tree, g++, compilation). ...
    (comp.unix.shell)
  • makedepend
    ... for 2 platforms and copies perl ans shell scripts to an output directory. ... THis adds MUCHOOOO stuff to my makefile. ... I think I may be wasting my time to try and get dependancies for 233 ...
    (comp.unix.programmer)
  • Re: Windows and Linux
    ... Pierre Asselin wrote: ... or somethink can help me to automate my build process. ... can I use ONE makefile under both os - how can I detect the os ...
    (comp.lang.c)
  • Re: Compiling Tcl apps redux
    ... >> Starkits/starpacks are very complex and seemingly impossible to ... >> automate in a Makefile or something similar. ... Prev by Date: ...
    (comp.lang.tcl)