Skip to content

Instantly share code, notes, and snippets.

@dymk
Last active September 28, 2016 00:23
Show Gist options
  • Select an option

  • Save dymk/9f0ee3b56547ae31670bec1e65caf685 to your computer and use it in GitHub Desktop.

Select an option

Save dymk/9f0ee3b56547ae31670bec1e65caf685 to your computer and use it in GitHub Desktop.
CSE167 OSX Makefile

How to use:

Through brew (http://brew.sh/), install:
$ brew install glfw3 glm glew pkg-config

Verify that pkg-config finds glfw3 and friends' include dirs and libraries:
$ pkg-config --cflags --libs glfw3 glm glew

Should be something like: ... -I/usr/local/Cellar/glfw3/3.2.1/include -L/usr/local/Cellar/glfw3/3.2.1/lib -lglfw3 ... (more flags for glm/glew)

Also modify the includes in main.h and Window.h to be:

#include <GL/glew.h>
#include <OpenGL/gl3.h>
#include <OpenGL/glext.h>
#Makefile flags for OSX devices
CFLAGS = -g -DGL_GLEXT_PROTOTYPES -DGL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED -DOSX
GLCCFLAGS := `pkg-config --cflags glfw3 glm glew`
GLLDFLAGS := `pkg-config --libs glfw3 glm glew`
INCFLAGS = -I/usr/X11/include -I./include/ $(GLCCFLAGS)
LDFLAGS = -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo \
-L"/System/Library/Frameworks/OpenGL.framework/Libraries" \
-lstdc++ -lGL $(GLLDFLAGS)
RM = /bin/rm -f
.PHONY: all
all: glfwStarterProject
glfwStarterProject: main.o Window.o Cube.o
$(CC) $(CFLAGS) -o glfwStarterProject main.o Window.o Cube.o $(INCFLAGS) $(LDFLAGS)
main.o: Window.o main.cpp main.h
$(CC) $(CFLAGS) $(INCFLAGS) -c main.cpp
Window.o: Cube.o Window.cpp Window.h
$(CC) $(CFLAGS) $(INCFLAGS) -c Window.cpp
Cube.o: Cube.cpp Cube.h
$(CC) $(CFLAGS) $(INCFLAGS) -c Cube.cpp
clean:
$(RM) *.o glfwStarterProject
@alexhgian
Copy link

alexhgian commented Sep 28, 2016

You should name the output file something else since the starter code has a folder with the same name. Or just delete that folder since we don't have to use visual studio.

glfwStarterProject: main.o Window.o Cube.o
    $(CC) $(CFLAGS) -o myOutput main.o Window.o Cube.o $(INCFLAGS) $(LDFLAGS)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment