Skip to content

Instantly share code, notes, and snippets.

@romsalva
Last active August 29, 2015 14:13
Show Gist options
  • Save romsalva/83615b6a8a4c753dab7e to your computer and use it in GitHub Desktop.
Save romsalva/83615b6a8a4c753dab7e to your computer and use it in GitHub Desktop.
GLFW MinGW makefile
LIBNAME=libglfw3.a
SRCDIR=./src/
TESTSDIR=./tests/
EXAMPLESDIR=./examples/
DEPSDIR=./deps/
OBJDIR=./obj/
BUILDDIR=./build/
TESTSBUILDDIR=$(BUILDDIR)tests/
EXAMPLESBUILDDIR=$(BUILDDIR)examples/
LIBTARGET=$(BUILDDIR)$(LIBNAME)
SOURCES=context.c wgl_context.c\
clipboard.c gamma.c init.c input.c joystick.c monitor.c time.c window.c\
win32_clipboard.c win32_gamma.c win32_init.c win32_joystick.c win32_monitor.c\
win32_time.c win32_window.c
TESTS= accuracy.c clipboard.c defaults.c events.c fsaa.c gamma.c glfwinfo.c \
iconify.c joysticks.c modes.c peter.c reopen.c sharing.c tearing.c threads.c\
title.c windows.c
EXAMPLES= boing.c gears.c heightmap.c simple.c splitview.c wave.c
DEPS=getopt.c tinycthread.c
SOURCESWITHDIR=$(SOURCES:%=$(SRCDIR)%)
OBJECTS=$(SOURCES:%.c=$(OBJDIR)%.o)
TESTSEXES=$(TESTS:%.c=$(TESTSBUILDDIR)%.exe)
EXAMLPESEXES=$(EXAMPLES:%.c=$(EXAMPLESBUILDDIR)%.exe)
DEPSOBJS=$(DEPS:%.c=$(OBJDIR)%.o)
CC=gcc
AR=ar
CFLAGS=-c -O2 -Wall
TECFLAGS=-O2 -Wall -Iinclude -Ideps
CDEFS=-D_GLFW_WIN32 -D_GLFW_WGL -D_GLFW_USE_OPENGL
ARFLAGS=rcs
all: lib tests examples
lib: $(LIBTARGET)
tests: $(TESTSEXES)
examples: $(EXAMLPESEXES)
deps: $(DEPSOBJS)
clean:
@rm -f $(TESTSEXES)
@rm -f $(EXAMLPESEXES)
@rm -f $(LIBTARGET)
@rm -f $(OBJECTS)
@rm -rf $(BUILDDIR)
@rm -rf $(OBJDIR)
clean-tests:
@rm -f $(TESTSEXES)
clean-examples:
@rm -f $(EXAMLPESEXES)
$(LIBTARGET): $(OBJECTS) | $(BUILDDIR)
@ECHO Building static library $@
@$(AR) $(ARFLAGS) $@ $^
$(OBJDIR):
@ECHO Creating directory $@
@mkdir -p $@
$(BUILDDIR):
@ECHO Creating directory $@
@mkdir -p $@
$(TESTSBUILDDIR): | $(BUILDDIR)
@ECHO Creating directory $@
@mkdir -p $@
$(EXAMPLESBUILDDIR): | $(BUILDDIR)
@ECHO Creating directory $@
@mkdir -p $@
$(OBJDIR)%.o: $(SRCDIR)%.c | $(OBJDIR)
@ECHO Compiling $@
@$(CC) $(CFLAGS) $(CDEFS) $< -o $@
$(OBJDIR)%.o: $(DEPSDIR)%.c | $(OBJDIR)
@ECHO Compiling $@
@$(CC) $(CFLAGS) $< -o $@
$(TESTSBUILDDIR)%.exe: $(TESTSDIR)%.c $(LIBTARGET) $(DEPSOBJS) | $(TESTSBUILDDIR)
@ECHO Building $@
@$(CC) $(TECFLAGS) $^ -o $@ -lopengl32 -lglu32 -lgdi32
$(EXAMPLESBUILDDIR)%.exe: $(EXAMPLESDIR)%.c $(LIBTARGET) $(DEPSOBJS) | $(EXAMPLESBUILDDIR)
@ECHO Building $@
@$(CC) $(TECFLAGS) $^ -o $@ -lopengl32 -lglu32 -lgdi32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment