Skip to content

Instantly share code, notes, and snippets.

@hosackm
Created October 21, 2015 17:28
Show Gist options
  • Save hosackm/49a43ffb448786926028 to your computer and use it in GitHub Desktop.
Save hosackm/49a43ffb448786926028 to your computer and use it in GitHub Desktop.
Makefile for building objects for each source file. It takes too long too get it working when you start from scratch
CC=clang
LIB=
INCLUDES=-Iinclude/
FLAGS=-Wall -Werror -pedantic
SOURCES=$(wildcard src/*.c)
#OBJECTS=$(SOURCES:.c=.o) # This way works too
OBJECTS=$(patsubst %.c, %.o, $(SOURCES))
EXE=executable_name.out
all: $(EXE) clean
$(EXE): $(OBJECTS)
$(CC) $(INCLUDES) -o $@ $^
%.o: %.c
$(CC) -c $< $(FLAGS) $(LIB) $(INCLUDES) -o $@
clean:
rm -rf src/*.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment