I am trying to make a make file function that cleans everything instead of 4 specific files:
all: clean compile run
compile: main.c util.c util.h
@echo "-------------------------------------------"
@echo "Compiling..."
@gcc -o test main.c util.c
run:
@echo "-------------------------------------------"
@echo "Running the tests...."
@echo "================================================================>
@./test
@echo "================================================================>
@echo "Completed tests...."
clean:
@echo "-------------------------------------------"
@echo "Cleaning..."
@rm -v !("main.c"||"makefile"||"util.c"||"util.h")
other functions do work but I get this error for $make clean:
-------------------------------------------
Cleaning...
/bin/sh: 1: Syntax error: "(" unexpected
make: *** [makefile:19: clean] Error 2
The line "rm -v !("main.c"||"makefile"||"util.c"||"util.h")" works normally when I type in on the console.What am I doing wrong?
ps: I am on ubuntu vm
I have tried to clean every file except 4 specific files with a makefile, but I got an error instead. The line works normally on the console.
2
Answers
make
runs each line of the Makefile in/bin/sh
. If you want a different shell, you have to set theSHELL
variable. In your case, start the Makefile withBut it’s not enough, you also need to enable the
extglob
shell option. In GNU make, you can add the options directly to the variable:As @choroba mentioned, you’re using a special bash syntax, and make defaults to using
sh
. You can use the following syntax which is compatible withsh
: