gol/openmp/Makefile

58 lines
1.2 KiB
Makefile
Raw Permalink Normal View History

2021-12-04 15:34:49 -05:00
# This is some Makefile I've been using for projects for a while and can't find
# where I originally got it
CC ?= gcc
SRC_PATH = src
BUILD_PATH = build
BIN_PATH = $(BUILD_PATH)/bin
BIN_NAME = gol
SRC_EXT = c
SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-)
OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
DEPS = $(OBJECTS:.o=.d)
COMPILE_FLAGS = -Wall -g -fopenmp -lm -std=c99
INCLUDES = -I include/
LIBS = -fopenmp -lm
.PHONY: default_target
default_target: release
.PHONY: release
release: dirs
@$(MAKE) all
.PHONY: dirs
dirs:
@echo "Creating directories"
@mkdir -p $(dir $(OBJECTS))
@mkdir -p $(BIN_PATH)
.PHONY: clean
clean:
@echo "Deleting $(BIN_NAME) symlink"
@$(RM) $(BIN_NAME)
@echo "Deleting directories"
@$(RM) -r $(BUILD_PATH)
@$(RM) -r $(BIN_PATH)
.PHONY: all
all: $(BIN_PATH)/$(BIN_NAME)
@echo "Making symlink: $(BIN_NAME) -> $<"
@$(RM) $(BIN_NAME)
@ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME)
$(BIN_PATH)/$(BIN_NAME): $(OBJECTS)
@echo "Linking: $@"
$(CC) $(OBJECTS) -o $@ ${LIBS}
-include $(DEPS)
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
@echo "Compiling: $< -> $@"
$(CC) $(COMPILE_FLAGS) $(INCLUDES) -MP -MMD -c $< -o $@