Last active
November 2, 2017 09:11
-
-
Save milesrout/6d1dae191ecea88b2ae5e9ebb3bfc66c to your computer and use it in GitHub Desktop.
partially based on https://spin.atomicobject.com/2016/08/26/makefile-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
TARGET := a.out | |
PC_DEPS := gl glfw3 | |
PC_CFLAGS := $(shell pkg-config --cflags $(PC_DEPS)) | |
PC_LIBS := $(shell pkg-config --libs $(PC_DEPS)) | |
SRCS := $(shell find src -name *.c) | |
OBJS := $(SRCS:%=build/%.o) | |
DEPS := $(OBJS:.o=.d) | |
INCS := $(addprefix -I,$(shell find ./include -type d)) | |
CFLAGS += $(PC_CFLAGS) $(INCS) -MMD -MP | |
LDLIBS += $(PC_LIBS) | |
build/$(TARGET): $(OBJS) | |
$(CC) $(OBJS) -o $@ $(LDFLAGS) $(LDLIBS) | |
build/%.c.o: %.c | |
mkdir -p $(dir $@) | |
$(CC) -c $(CFLAGS) $< -o $@ | |
.PHONY: clean syntastic | |
clean: | |
rm build/$(TARGET) $(OBJS) $(DEPS) | |
syntastic: | |
echo $(CFLAGS) | tr ' ' '\n' > .syntastic_c_config | |
-include $(DEPS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment