Created
August 26, 2023 15:15
-
-
Save jkin0/197d1de9e095fa885a6a8933628e92b3 to your computer and use it in GitHub Desktop.
The perfect C Makefile script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = gcc | |
CFLAGS = -Wall -Wextra -std=c18 -g | |
SRC_DIR = src | |
BUILD_DIR = build | |
EXE = exe | |
SRCS = $(wildcard $(SRC_DIR)/*.c) | |
OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS)) | |
all: $(EXE) | |
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | |
@mkdir -p $(BUILD_DIR) | |
$(CC) $(CFLAGS) -c $< -o $@ | |
$(EXE): $(OBJS) | |
$(CC) $(CFLAGS) $^ -o $@ | |
clean: | |
rm -rf $(BUILD_DIR) | |
rebuild: clean all | |
.PHONY: all clean rebuild |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment