1# 2# This could be more DRY using some Makefile magic, but for the example 3# app will try to maximize clarity by making most rules explicit 4# 5 6# Where to find Halide. 7# 8# If you are building this demo using Halide installed systemwide (e.g. on 9# OS X installed via homebrew), you can set: 10# 11# HALIDE_TOOLS_DIR = /usr/local/share/halide/tools 12# HALIDE_LIB_PATH = 13# HALIDE_INC_PATH = 14# 15# These settings are for building within the Halide source tree: 16HALIDE_TOOLS_DIR = ../../tools 17HALIDE_LIB_PATH = -L ../../bin 18HALIDE_INC_PATH = -I ../../include 19HL_TARGET ?= host 20 21# Platform-specific settings. 22# 23UNAME = $(shell uname) 24 25ifeq ($(UNAME),Darwin) 26 27 # These are for OS X: 28 DTX_FONT = /Library/Fonts/Arial.ttf 29 OPENGL_LIBS = -lglfw -framework OpenGL -framework GLUT 30 GENERATOR_LIBS = -lHalide -lz -lcurses 31 32else 33 34 # These are for Ubuntu Linux 35 DTX_FONT = /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf 36 OPENGL_LIBS = `pkg-config glfw3 --libs` -lGL -lglut -lX11 -lpthread -ldl -lXxf86vm -lXinerama -lXcursor -lXrandr 37 GENERATOR_LIBS = -lHalide -lz -lcurses -Wl,--rpath=$(HALIDE_LIB_PATH) 38 39endif 40 41# 42# General build settings. Should be good cross-platform. 43# 44MAIN_LIBS = -lpng -ldrawtext $(OPENGL_LIBS) 45GENERATOR_LIBS = -lHalide -lz -lcurses 46CXXFLAGS = -std=c++11 -g -DDTX_FONT=\"$(DTX_FONT)\" $(HALIDE_INC_PATH) 47 48# Output directory. 49BIN ?= bin 50 51.PHONY: run clean 52 53default: run 54 55run: $(BIN)/opengl_demo 56 $(BIN)/opengl_demo image.png 57 58clean: 59 rm -rf $(BIN) 60 61$(BIN)/opengl_demo: \ 62 $(BIN)/main.o \ 63 $(BIN)/layout.o \ 64 $(BIN)/timer.o \ 65 $(BIN)/glfw_helpers.o \ 66 $(BIN)/opengl_helpers.o \ 67 $(BIN)/png_helpers.o \ 68 $(BIN)/sample_filter_cpu.o \ 69 $(BIN)/sample_filter_opengl.o 70 $(CXX) $(CXXFLAGS) -o $@ $^ $(MAIN_LIBS) 71 72# 73# Explicitly list the dependency on the generated filter header files, 74# to ensure that they are created first. 75# 76$(BIN)/main.o: \ 77 $(BIN)/sample_filter_cpu.h \ 78 $(BIN)/sample_filter_opengl.h 79 80# 81# Rules to AOT-compile the halide filter for both CPU and OpenGL; the 82# compiled filters depend on $(BIN)/sample_filter.generator, which in turn 83# depends on the halide filter source in sample_filter.cpp 84# 85$(BIN)/sample_filter_cpu.o $(BIN)/sample_filter_cpu.h: $(BIN)/sample_filter.generator 86 LD_LIBRARY_PATH=../../bin $(BIN)/sample_filter.generator -g sample_filter -e object,c_header,stmt -o $(BIN) -f sample_filter_cpu target=$(HL_TARGET) 87 88$(BIN)/sample_filter_opengl.o $(BIN)/sample_filter_opengl.h: $(BIN)/sample_filter.generator 89 LD_LIBRARY_PATH=../../bin $(BIN)/sample_filter.generator -g sample_filter -e object,c_header,stmt -o $(BIN) -f sample_filter_opengl target=host-opengl-debug 90 91$(BIN)/sample_filter.generator: sample_filter_generator.cpp 92 @mkdir -p $(@D) 93 $(CXX) $(CXXFLAGS) -o $@ $^ $(HALIDE_TOOLS_DIR)/GenGen.cpp $(HALIDE_LIB_PATH) $(GENERATOR_LIBS) $(HALIDE_SYSTEM_LIBS) 94 95# 96# Build in subdir using auto-dependency mechanism 97# 98$(BIN)/%.o: %.cpp 99 @mkdir -p $(@D) 100 $(CXX) -c $(CXXFLAGS) -I$(BIN) -MMD -MF $(patsubst %.o,%.d,$@) -o $@ $< 101 102-include $(wildcard $(BIN)/*.d) 103