home / fornax / fornax-v4-0 / makefile

makefile



###
### Attempt OS-detection.
###
ifeq ($(OS), Windows_NT)
OSNAME = WINDOWS
else ifeq ($(shell uname),Darwin)
OSNAME = MAC
else
OSNAME = LINUX
endif

###
### Files.
###
SRC_PATH = src
SOURCES := $(wildcard $(SRC_PATH)/*.cpp) $(wildcard $(SRC_PATH)/*/*.cpp)
OBJECT_PATH = objects
OBJECTS := $(patsubst $(SRC_PATH)/%.cpp, $(OBJECT_PATH)/%.o, $(SOURCES))

###
### Compiler.
###
CXX = g++

###
### Compiler flags.
###
CXXFLAGS = -std=c++14 -Ofast -march=native -flto
CXXFLAGS += -Wall -Wextra -Wpedantic -Wshadow
CXXFLAGS += -DNDEBUG

###
### Linked library flags.
###
ifeq ($(OSNAME), LINUX)
LDLIBS = -lpthread
else ifeq ($(OSNAME), WINDOWS)
LDLIBS = -static
endif

###
### Executable.
###
fornax: $(OBJECTS)
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDLIBS)

$(OBJECT_PATH)/%.o: $(SRC_PATH)/%.cpp
	$(CXX) $(CXXFLAGS) -I $(SRC_PATH) -c $< -o $@

all: fornax


###
### Cleaning build.
###
ifeq ($(OSNAME), WINDOWS)
CLEAN_COMMAND = del /s fornax.exe $(OBJECT_PATH)\*.o
else
CLEAN_COMMAND = rm fornax $(OBJECT_PATH)/*.o $(OBJECT_PATH)/*/*.o
endif

clean:
	$(CLEAN_COMMAND)

.PHONY: clean