Last active
January 28, 2021 20:23
-
-
Save correaswebert/1603308d601b4be8a20034b3b79895db to your computer and use it in GitHub Desktop.
A simple Makefile for C
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
TARGET := main | |
SRC := src | |
INC := include | |
BIN := bin | |
TEST := test | |
BUILD := build | |
# group the files | |
HEADER = $(wildcard $(INC)/*.h) | |
OBJECT = $(patsubst %, $(BUILD)/%, $(notdir $(SOURCE:.c=.o))) | |
CC = gcc | |
CFLAGS = -I$(INC) -std=c11 | |
# $@ : target | |
# $^ : dependency list | |
# $< : first name in dependency list | |
# compile target if any object file or header file changes | |
$(BIN)/$(TARGET): $(OBJECT) $(HEADER) | |
$(CC) $(CFLAGS) -o $@ $(OBJECT) | |
# compile object files but do not link them | |
$(BUILD)/%.o: $(SRC)/%.c | |
$(CC) $(CFLAGS) -o $@ -c $< | |
# avoid doing something to file named clean | |
.PHONY: clean | |
clean: | |
rm -f build/* bin/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment