I'm trying to create a Makefile that causes all .c files to be compiled without the need to add filenames line per line inside the Makefile. I think this is fairly similar to makefiles - compile all c files at once. Here's what I want to do:
1 - Verify if all .c files from /src have their respective .o files from /obj. If the .o file does not exist, build it from the .c file;
2 - Compile main.exe from all .o and put it on /bin.
My Makefile:
BIN = ./bin
OBJ = ./obj
INCLUDE = ./include
SRC = ./src
all:
gcc -c "$(SRC)/Distances.c" -o "$(OBJ)/Distances.o"
gcc -c "$(SRC)/HandleArrays.c" -o "$(OBJ)/HandleArrays.o"
gcc -c "$(SRC)/HandleFiles.c" -o "$(OBJ)/HandleFiles.o"
gcc -c "$(SRC)/Classifier.c" -o "$(OBJ)/Classifier.o"
gcc -c main.c -o "$(OBJ)/main.o"
gcc -o $(BIN)/main.exe $(OBJ)/*.o -lm
run:
$(BIN)/main.exe
clean:
del /F /Q "$(OBJ)" ".o"
del /F /Q "$(BIN)" ".exe"
I guess I need to use something like $(SRC)/*.c, but I couldn't make it.
Now, about make clean, I don't know how to make it work cross-platform. I'm using del as I'm on Windows.