Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # credits:
- # https://www.youtube.com/watch?v=noBh17uxQ1E
- # compiler and linker flags
- CC := g++
- SRC_DIR := src
- BIN_DIR := bin
- BIN_EXE := $(BIN_DIR)/main
- OUTPUT := $(if $(findstring Windows_NT, $(OS)), $(BIN_EXE).exe, $(BIN_EXE).out)
- OBJ_DIR := $(BIN_DIR)/obj
- INC_DIRS := -I$(SRC_DIR)
- LIB_DIRS :=
- SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp)
- H_FILES := $(wildcard $(SRC_DIR)/*.h)
- OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRC_FILES))
- CPP_FLAGS := -std=c++17
- LD_FLAGS :=
- MAKEFLAGS += -j8
- # compile the object files and place them in their own directory
- $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(H_FILES)
- $(CC) $(CPP_FLAGS) $(INC_DIRS) -c -o $@ $<
- # link the object files together to create the final executable
- $(OUTPUT): $(OBJ_FILES) Makefile
- $(CC) $(LIB_DIRS) $(LD_FLAGS) $(OBJ_FILES) -o $(OUTPUT)
- # when we type make, compile and link the executable
- all: $(OUTPUT)
- # if we type 'make run' it will build and run the executable
- run: $(OUTPUT)
- $(if $(findstring Windows_NT, $(OS)), cd bin && main.exe && cd .., cd bin && ./main.out && cd ..)
- # if we type 'make clean' it will clean up all the object files and the executable
- clean:
- $(if $(findstring Windows_NT, $(OS)), del bin\obj\*.o && del bin\main.exe, rm $(OBJ_DIR)/*.o && rm $(OUTPUT))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement