Skip to content

Instantly share code, notes, and snippets.

@r8d8
Created May 23, 2019 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r8d8/bed93452ea339ba1fd7496ffd17fb182 to your computer and use it in GitHub Desktop.
Save r8d8/bed93452ea339ba1fd7496ffd17fb182 to your computer and use it in GitHub Desktop.
# Determine the platform
UNAME_S := $(shell uname -s)
CC := clang++
# Folders
SRCDIR := ./
BUILDDIR := build
TARGETDIR := bin
# Targets
EXECUTABLE := BulletManager
TARGET := $(TARGETDIR)/$(EXECUTABLE)
# Final Paths
INSTALLBINDIR := /usr/local/bin
# Code Lists
SRCEXT := cpp
SOURCES := $(shell find $(SRCDIR) -type f -name '*.$(SRCEXT)')
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
# Folder Lists
# Note: Intentionally excludes the root of the include folder so the lists are clean
INCDIRS := $(shell find $(SRCDIR) -name '*.h' -exec dirname {} \; | sort | uniq)
INCLIST := $(patsubst $(SRCDIR)%,-I $(SRCDIR)%,$(INCDIRS))
BUILDLIST := $(patsubst $(SRCDIR)%,$(BUILDDIR)/%,$(INCDIRS))
# Shared Compiler Flags
CFLAGS := -Wall
INC := -I include $(INCLIST) -I /usr/local/include -I /usr/include/SDL2
LIB := -L /usr/local/lib
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(BUILDLIST)
@echo "Compiling $<..."; $(CC) $(CFLAGS) $(INC) -c -o $@ $<
$(TARGET): $(OBJECTS)
@mkdir -p $(TARGETDIR)
@echo "Linking..."
@echo " Linking $(TARGET)"; $(CC) $^ -o $(TARGET) $(LIB)
clean:
@echo "Cleaning $(TARGET)..."; $(RM) -r $(BUILDDIR) $(TARGET)
install:
@echo "Installing $(EXECUTABLE)..."; cp $(TARGET) $(INSTALLBINDIR)
distclean:
@echo "Removing $(EXECUTABLE)"; rm $(INSTALLBINDIR)/$(EXECUTABLE)
.PHONY: clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment