make and the 'cd' command - Unix

This is a discussion on make and the 'cd' command - Unix ; In the below makefile I am trying to cd to a directory and run the g++ command: options = -Wall -pedantic -O3 -ansi dir=pic/ ..PHONY: test all: test test: test.cpp cd $(dir) g++ $(options) test.cpp -o test clean: rm $(dir)test ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: make and the 'cd' command

  1. make and the 'cd' command

    In the below makefile I am trying to cd to a directory and run the g++
    command:


    options = -Wall -pedantic -O3 -ansi
    dir=pic/

    ..PHONY: test

    all: test

    test: test.cpp
    cd $(dir) g++ $(options) test.cpp -o test

    clean:
    rm $(dir)test



    but when I run make I just get:

    cd pic/ g++ -Wall -pedantic -O3 -ansi test.cpp -o test

    but nothing gets created in the pic dir. What am I missing?

  2. Re: make and the 'cd' command

    On Mar 4, 1:48*pm, saneman wrote:
    > In the below makefile I am trying to cd to a directory and run the g++
    > command:
    >
    > options = -Wall -pedantic -O3 -ansi
    > dir=pic/
    >
    > .PHONY: test
    >
    > all: test
    >
    > test: test.cpp
    > * * * * cd $(dir) g++ $(options) test.cpp -o test
    >
    > clean:
    > * * * * rm $(dir)test
    >
    > but when I run make I just get:
    >
    > cd pic/ g++ -Wall -pedantic -O3 -ansi test.cpp -o test
    >
    > but nothing gets created in the pic dir. What am I missing?


    missing a semicolon after cd $(dir)

    --
    Fred Kleinschmidt

  3. Re: make and the 'cd' command

    fred.l.kleinschmidt@boeing.com wrote:
    > On Mar 4, 1:48 pm, saneman wrote:
    >> In the below makefile I am trying to cd to a directory and run the g++
    >> command:
    >>
    >> options = -Wall -pedantic -O3 -ansi
    >> dir=pic/
    >>
    >> .PHONY: test
    >>
    >> all: test
    >>
    >> test: test.cpp
    >> cd $(dir) g++ $(options) test.cpp -o test
    >>
    >> clean:
    >> rm $(dir)test
    >>
    >> but when I run make I just get:
    >>
    >> cd pic/ g++ -Wall -pedantic -O3 -ansi test.cpp -o test
    >>
    >> but nothing gets created in the pic dir. What am I missing?

    >
    > missing a semicolon after cd $(dir)


    No, he's missing a "&&". Consider "cd /tmp; rm -rf *". The semicolon is
    wildly overused by scripters relative to &&.

+ Reply to Thread