Skip to content

Instantly share code, notes, and snippets.

@wvovaw
Created May 7, 2021 15:58
Show Gist options
  • Save wvovaw/17080c9cc9f5ce859416410f4ec63984 to your computer and use it in GitHub Desktop.
Save wvovaw/17080c9cc9f5ce859416410f4ec63984 to your computer and use it in GitHub Desktop.
Makefile for small C projects
# 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