Skip to content

Instantly share code, notes, and snippets.

@je3f0o
Last active November 26, 2016 10:47
Show Gist options
  • Save je3f0o/b56e0b1f06d19aed23e5c54b49a1007b to your computer and use it in GitHub Desktop.
Save je3f0o/b56e0b1f06d19aed23e5c54b49a1007b to your computer and use it in GitHub Desktop.
Simple makefile for C++ program

Download using command line

$ wget https://git.io/v1TDX -O Makefile

SHELL = /bin/bash
TARGET = a.exe
SOURCES = $(shell find src -name "*.cpp")
HEADERS = include # current project's headers directory
OBJECTS = $(patsubst %.cpp, .objects/%.o, $(SOURCES))
CC = g++
FLAGS =
CFLAGS = -std=c++11 -W -Wall -Werror -O3
LIBS = `pkg-config --static --libs glfw3 glew` # example libs for reminder : glfw3 glew, you can change this
LDFLAGS = `pkg-config --cflags glfw3 glew` # example includes for reminder : glfw3 glew, you can change this
all : link
./$(TARGET)
$(OBJECTS) : .objects/%.o : %.cpp
@mkdir -p $(dir $@)
$(CC) $(FLAGS) $(CFLAGS) -I $(HEADERS) -c $< -o $@
assemble : $(OBJECTS)
link : assemble
$(CC) $(FLAGS) $(CFLAGS) $(LIBS) $(LDFLAGS) $(OBJECTS) -o $(TARGET)
# .PHONY : clean
clean :
rm -rf $(TARGET) .objects
# Only for debug purpose
print :
@echo $(HEADERS)
@echo $(SOURCES)
@echo $(OBJECTS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment