Compare commits

..

2 Commits

1 changed files with 54 additions and 14 deletions

View File

@ -1,25 +1,65 @@
# Compiler flags
CFLAGS = -std=c++17 -O3
# Build folder
BUILD_DIR = build
# Defaul target
all: build_dir json2bin_converter
# Source files
SOURCES = \
src/main.cpp \
src/bin.cpp
# Output file name
OUTPUT = 2D_Engine_Casio_Tool
# Compiler and flags
CXX = g++
CXXFLAGS = -std=c++17 -g
LDFLAGS =
# Deduce objects
OBJECTS = $(SOURCES:%.cpp=$(BUILD_DIR)/%.o)
# Verbose mode
ifeq ($(VERBOSE), 1)
Q :=
else
Q := @
endif
# Colors
GREEN := \033[0;32m
YELLOW := \033[1;33m
RESET := \033[0m
# Total number of files to process
TOTAL_FILES := $(shell echo $$(($(words $(SOURCES))+1)))
CURRENT_FILE = 0
# Default targets
all: $(BUILD_DIR) $(OUTPUT) end
# Create build directory
build_dir:
mkdir -p build
$(BUILD_DIR):
$(Q)mkdir -p $(dir $(OBJECTS))
# Link target
json2bin_converter: build/main.o build/bin.o
g++ -o json2bin_converter build/main.o build/bin.o
$(OUTPUT): $(OBJECTS)
@echo "[100%] $(YELLOW)Linking $(OUTPUT)$(RESET)"
$(Q)$(CXX) $(LDFLAGS) -o $@ $(OBJECTS)
# Compile objects
build/main.o: src/main.cpp src/bin.hpp src/json/json.hpp
g++ $(CFLAGS) -c src/main.cpp -o build/main.o
# Build .o files from .cpp
$(BUILD_DIR)/%.o: %.cpp
$(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE)+1))))
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE)*100/$(TOTAL_FILES)))))
@echo "[$(PERCENTAGE)%] $(GREEN)Building $@$(RESET)"
$(Q)mkdir -p $(dir $@)
$(Q)$(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
build/bin.o: src/bin.cpp src/bin.hpp src/json/json.hpp
g++ $(CFLAGS) -c src/bin.cpp -o build/bin.o
# Source files dependencies
-include $(OBJECTS:.o=.d)
end:
@echo "Built target $(OUTPUT)"
# Clean
.PHONY: clean
clean:
rm -rf build/* json2bin_converter
$(Q)rm -rf $(BUILD_DIR)