nike wrote: > Hi I am trying to use the following code in a Makfile to change into a > directory and to execute Make all after testing the existence of a > file. However, Make does not seem to like the idea and report an > unexpected token. > all : > @echo "in the main directory" > @cd dir1 && if [-s toto]; then echo "toto existe"; else echo > "no > toto"; fi; && $(MAKE) all
You have multiple syntax problems with the shell command on that makefile line. Whitespace is important! Do not compress it around the test [ ... ] operator. Second you cannot simply put in newlines wherever. Each newline will terminate the command. Where you have echo on a line by itself this will simply echo an empty line. Then you have "no" and "toto" on separate lines which is definitely wrong. Don't do that. Put all of that one one line. > could someone help me understanding how to execute multiple commands > on the same line? Each logical line of a makefile is executed in its own shell. This means that variables cannot be set across lines and directory changes cannot be changed across lines. This means that everything must occur on one logical line. In order to use multiple commands you must separate them on the same line using the shell such as ';' to separate commands or '|' to pipe commands or '&&' and '||' to create conditional execution of lists of commands. all : @echo "in the main directory" @cd dir1 ; if [ -s toto ]; then echo "toto existe"; else echo; "no toto"; fi ; $(MAKE) all The whitespace at the beginning of the line must start with a TAB character. It cannot begin with spaces. It is possible to break up long lines across multiple makefile lines. In order to do this the newline character at the end of the line must be escaped with a backslash. This causes it to "disappear" from the input. This means that the ';' and other shell separators must still exist. all : @echo "in the main directory" @cd dir1 && \ if [ -s toto ]; \ then echo "toto existe"; \ else echo; "no toto"; \ fi; $(MAKE) all Bob