Created
May 7, 2021 15:58
-
-
Save wvovaw/17080c9cc9f5ce859416410f4ec63984 to your computer and use it in GitHub Desktop.
Makefile for small C projects
This file contains hidden or 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
# Add name of the program as target | |
TARGET = out | |
CC = cc | |
# Add libs | |
LIBS = -lm | |
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os | |
OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) | |
INCS = $(wildcard *.h) | |
all : options ${TARGET} | |
debug: CFLAGS += -g -DDEBUG | |
debug: options ${TARGET} | |
%.o: %.c $(INCS) | |
$(CC) $(CFLAGS) -c $< -o $@ | |
.PRECIOUS: $(TARGET) $(OBJS) | |
$(TARGET) : $(OBJS) | |
$(CC) $(OBJS) -Wall $(LIBS) -o $@ | |
options: | |
@echo Build options | |
@echo "CFLAGS = ${CFLAGS}" | |
@echo "CC = ${CC}" | |
@echo "INCS = ${INCS}" | |
@echo "LIBS = ${LIBS}" | |
@echo "OBJS = ${OBJS}" | |
clean: | |
-rm -f *.o | |
-rm -f $(TARGET) | |
.PHONY: all clean% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment