Skip to content

Instantly share code, notes, and snippets.

@dradtke
Created September 25, 2012 21:38
Show Gist options
  • Save dradtke/3784616 to your computer and use it in GitHub Desktop.
Save dradtke/3784616 to your computer and use it in GitHub Desktop.
Example Makefile for building and running a self-contained game
CC := clang
TARGET := game
AL_CFLAGS := -Ilib/allegro/include
AL_LDFLAGS := -Llib/allegro/lib
GLIB_CFLAGS := -Ilib/glib -Ilib/glib/glib
GLIB_LDFLAGS := -Llib/glib/glib/.libs
CFLAGS := -g -Wall $(AL_CFLAGS) $(GLIB_CFLAGS)
LDFLAGS := $(AL_LDFLAGS) $(GLIB_LDFLAGS)
SOURCES := $(shell find src -type f -name *.c)
OBJECTS := $(patsubst src/%,build/%,$(SOURCES:.c=.o))
DEPS := $(OBJECTS:.o=.deps)
LIBS := -lglib-2.0 -lallegro
LIB_PATH := lib/allegro/lib:lib/glib/glib/.libs
all: $(TARGET)
$(TARGET): $(OBJECTS)
@echo " Linking..."; $(CC) $(LDFLAGS) $^ -o $(TARGET) $(LIBS)
build/%.o: src/%.c | init
@echo " CC $<"; $(CC) $(CFLAGS) -MD -MF $(@:.o=.deps) -c -o $@ $<
init:
@mkdir -p build
clean:
@echo " Cleaning..."; $(RM) -r build $(TARGET)
run: $(TARGET)
@LD_LIBRARY_PATH=$(LIB_PATH) ./$(TARGET)
-include $(DEPS)
.PHONY: all init clean run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment