Commit cc781f40 authored by Kevin Höllring's avatar Kevin Höllring
Browse files

Add Makefile to build binaries

parent ce185270
# Relevant directories
BUILD_DIR = ./build
TARGET_DIR = ./bin
SOURCE_DIR = ./src
INCLUDE_DIR = ./include
TMP_DIR = ./tmp
INP_DIR = ./inputs
OUT_DIR = ./outputs
# Build parameters
LDFLAGS=
CFLAGS=-Wall -Werror -I$(INCLUDE_DIR) -I/usr/local/include -fsanitize=address
SAMPLE_CFLAGS=-Wall -I$(INCLUDE_DIR) -I/usr/local/include -fsanitize=address
CPPFLAGS=-std=c++14
CC=g++
CPP_SRC_SAMPLES = $(wildcard $(SOURCE_DIR)/sample_*.cpp)
CPP_OBJ_SAMPLES = $(patsubst $(SOURCE_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(CPP_SRC_SAMPLES))
BINARIES_SAMPLES = $(patsubst $(SOURCE_DIR)/%.cpp, $(TARGET_DIR)/%, $(CPP_SRC_SAMPLES))
CPP_SRC = $(wildcard $(SOURCE_DIR)/task_*.cpp)
CPP_OBJ = $(patsubst $(SOURCE_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(CPP_SRC))
BINARIES = $(patsubst $(SOURCE_DIR)/%.cpp, $(TARGET_DIR)/%, $(CPP_SRC))
.PHONY: all
all: init build_samples build
@echo "done"
# Generating object files from source
$(CPP_OBJ_SAMPLES): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.cpp
$(CC) -O3 -g -c $< -o $@ $(SAMPLE_CFLAGS) $(CPPFLAGS)
# Generating object files from source
$(CPP_OBJ): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.cpp
$(CC) -O3 -g -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
# Dependency creation
$(CPP_DEP): $(BUILD_DIR)/%.d : $(SOURCE_DIR)/%.cpp
$(CC) -MM $< > $@ $(CFLAGS) $(CPPFLAGS)
.PHONY: init
init:
mkdir -p $(BUILD_DIR)
mkdir -p $(TARGET_DIR)
.PHONY: init_test
init_test: init
mkdir -p $(TMP_DIR)
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)/* $(TARGET_DIR)/*
.PHONY: test
test: init_test test_task1 test_task2 test_task3 test_task4 test_task5
build: init $(BINARIES)
build_samples: init $(BINARIES_SAMPLES)
$(TARGET_DIR)/%: $(BUILD_DIR)/%.o
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ $(LDFLAGS)
TASK1_EXE = $(TARGET_DIR)/task_1
test_task1: build
$(TASK1_EXE) < $(INP_DIR)/task_1_sample.in > $(TMP_DIR)/task_1_sample.out
diff -us $(TMP_DIR)/task_1_sample.out $(OUT_DIR)/task_1_sample.out
TASK2_EXE = $(TARGET_DIR)/task_2
test_task2: build
$(TASK2_EXE) < $(INP_DIR)/task_2_sample.in > $(TMP_DIR)/task_2_sample.out
diff -us $(TMP_DIR)/task_2_sample.out $(OUT_DIR)/task_2_sample.out
TASK3_EXE = $(TARGET_DIR)/task_3
test_task3: build
$(TASK3_EXE) < $(INP_DIR)/task_3_sample.in > $(TMP_DIR)/task_3_sample.out
diff -us $(TMP_DIR)/task_3_sample.out $(OUT_DIR)/task_3_sample.out
TASK4_EXE = $(TARGET_DIR)/task_4
test_task4: build
$(TASK4_EXE) < $(INP_DIR)/task_4_sample.in > $(TMP_DIR)/task_4_sample.out
diff -us $(TMP_DIR)/task_4_sample.out $(OUT_DIR)/task_4_sample.out
TASK5_EXE = $(TARGET_DIR)/task_5
test_task5: build
$(TASK5_EXE) < $(INP_DIR)/task_5_sample.in > $(TMP_DIR)/task_5_sample.out
diff -us $(TMP_DIR)/task_5_sample.out $(OUT_DIR)/task_5_sample.out
.DEFAULT_GOAL:= all
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment