55 lines
1.1 KiB
Makefile
55 lines
1.1 KiB
Makefile
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 -std=c99
|
|
INCLUDES = -I include/
|
|
LIBS =
|
|
|
|
.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 $@
|