diff --git a/makefile b/makefile index cc605799d8d11109096518a32c46382d1be68b26..a8b315dcbcc841c8088e9695fae559400d35ea48 100644 --- a/makefile +++ b/makefile @@ -6,21 +6,23 @@ LIBS = -lSDL2 -lm TARGET = main BIN = bin - -# Create the bin directory when the makefile is parsed -$(shell mkdir -p $(BIN)) +RUN = ./$(BIN)/$(TARGET) # Get source and object SOURCE = $(wildcard *.c) OBJECT = $(patsubst %,$(BIN)/%, $(notdir $(SOURCE:.c=.o))) -# Convert the source in object -$(BIN)/%.o: %.c +# Convert the source in object, but before all, run `$(BIN)` aka mkdir +$(BIN)/%.o: %.c | $(BIN) $(CC) $(CFLAGS) -c $< -o $@ # Create the target $(BIN)/$(TARGET): $(OBJECT) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) + $(RUN) + +$(BIN): + mkdir -p $(BIN) # Echo the source and object values help: @@ -29,7 +31,7 @@ help: # Run the program run: - ./$(BIN)/$(TARGET) + $(RUN) .PHONY: clean # Specify that the clean target is not a file clean: