Skip to content

Instantly share code, notes, and snippets.

@RcColes
Last active March 6, 2019 23:27
Show Gist options
  • Save RcColes/8972a2b00967b54ad9b248829cf4c567 to your computer and use it in GitHub Desktop.
Save RcColes/8972a2b00967b54ad9b248829cf4c567 to your computer and use it in GitHub Desktop.
# Copyright 2019 Raef Coles
#===============================================================================
# You can touch this bit
EXE=swarm_control
SRC_DIR =./src
BIN_DIR =./bin
BLD_DIR =./build
SDL_CFLAGS = $(shell sdl2-config --cflags)
SDL_LDFLAGS = $(shell sdl2-config --libs)
CFLAGS = -c -O3 -g -fopenmp $(SDL_CFLAGS)
LDFLAGS = -lm -g -no-pie $(SDL_LDFLAGS)
CC = g++
#===============================================================================
# Here there be dragons
MK_DIR =./.makefiles
DIRS = $(BIN_DIR) $(BLD_DIR) $(MK_DIR)
VPATH = $(shell find $(SRC_DIR) -type d)
SRC = $(notdir $(shell find $(SRC_DIR) -type f -name *.cpp -o -name *.c))
OBJ = $(addprefix $(BLD_DIR)/, $(filter %.o, $(SRC:.cpp=.o) $(SRC:.c=.o)))
MKF = $(addprefix $(MK_DIR)/, $(filter %.mk, $(SRC:.cpp=.mk) $(SRC:.c=.mk)))
.PHONY: clean
$(BIN_DIR)/$(EXE): $(OBJ) | $(MKF) $(BIN_DIR)
$(CC) $(LDFLAGS) $^ -o $@
include $(MKF)
$(MK_DIR)/%.mk : %.cpp | $(MK_DIR) $(BLD_DIR)
$(CC) -MT $(BLD_DIR)/$(*F).o -MM $(CFLAGS) $< -MF $@
@echo " $(CC) $(CFLAGS) $< -o $(BLD_DIR)/$(*F).o" >> $@
$(MK_DIR)/%.mk : %.c | $(MK_DIR) $(BLD_DIR)
$(CC) -MT $(BLD_DIR)/$(*F).o -MM $(CFLAGS) $< -MF $@
@echo " $(CC) $(CFLAGS) $< -o $(BLD_DIR)/$(*F).o" >> $@
$(DIRS):
mkdir -p $@
clean:
rm -rf $(DIRS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment