Skip to content

Instantly share code, notes, and snippets.

@jocke-l
Last active December 5, 2016 05:03
Show Gist options
  • Save jocke-l/8c0217c6257bd3a7b6a5 to your computer and use it in GitHub Desktop.
Save jocke-l/8c0217c6257bd3a7b6a5 to your computer and use it in GitHub Desktop.
Makefile
# This Makefile uses gcc's -MM-flag to scan your source tree for dependencies
# Other compilers may or may not have this feature. Adjust the DEPS
# definition accordingly.
CC := gcc
RM := rm
CFLAGS := -pedantic -Wall -Wextra -g
LIBS :=
BIN :=
SRCS := $(wildcard *.c)
OBJS := $(patsubst %.c, %.o, $(SRCS))
CLEAN_TARGETS := $(addprefix __clean__, $(OBJS) $(BIN))
# Haxx for making dynamic targets for dependencies
DEPS := $(shell $(CC) -MM $(SRCS))
.PHONY: all clean $(CLEAN_TARGETS)
.SILENT: all $(CLEAN_TARGETS) $(OBJS)
all: $(OBJS)
echo -e 'CC\t$(BIN)'
$(CC) $(OBJS) -o $(BIN) $(LIBS)
clean: $(CLEAN_TARGETS)
$(CLEAN_TARGETS): __clean__%:
echo -e 'RM\t$*'
$(RM) -f $*
%.o:
echo -e 'CC\t$@'
$(CC) -c $(CFLAGS) $*.c
# Dependencies
$(DEPS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment