Skip to content

Instantly share code, notes, and snippets.

@mwilliammyers
Created January 20, 2016 22:53
Show Gist options
  • Save mwilliammyers/1dfb20ad63b3aae3c24f to your computer and use it in GitHub Desktop.
Save mwilliammyers/1dfb20ad63b3aae3c24f to your computer and use it in GitHub Desktop.
Simple Makefile template
TARGET ?= target
LIBS = -lm
CC = gcc
CFLAGS = -g -Wall
.PHONY: default all test clean
default: $(TARGET)
all: default test
OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
HEADERS = $(wildcard *.h)
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@
.PRECIOUS: $(TARGET) $(OBJECTS)
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -Wall $(LIBS) -o $@
test:
./$(TARGET)
clean:
rm -f *.o
rm -f $(TARGET)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment