Better architecture

pull/1/head^2
Mathéo Hersan 2 years ago
parent fe4dd67414
commit 66f90ea81c

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

BIN
app

Binary file not shown.

@ -2,10 +2,11 @@
SCRIPT_NAME=$(basename "$0") SCRIPT_NAME=$(basename "$0")
BUILD_DIR="build" BUILD_DIR="build"
OBJ_DIR="obj"
SRC_DIR="src" SRC_DIR="src"
APP_NAME="APP" APP_NAME="app"
GCC_OPTIONS="-c -O3" GCC_OPTIONS="-Wall -Wextra -I $SRC_DIR -Wno-unused-parameter -Wno-unused-but-set-variable"
GREEN='\033[0;32m'
RESET='\033[0m'
# Display functions # Display functions
function show_success { function show_success {
@ -41,7 +42,7 @@ fi
# Clean generated files # Clean generated files
function clean { function clean {
local command="rm -rf $OBJ_DIR $BUILD_DIR" local command="rm -r $BUILD_DIR $APP_NAME"
echo -e "➔ Cleaning..." echo -e "➔ Cleaning..."
show_command "$command" show_command "$command"
make clean > /dev/null || show_error "Error during cleaning." make clean > /dev/null || show_error "Error during cleaning."
@ -50,7 +51,7 @@ function clean {
# Build # Build
function build { function build {
local command="gcc $GCC_OPTIONS -o $OBJ_DIR/main.o $SRC_DIR/main.c" local command="make"
echo -e "➔ Building..." echo -e "➔ Building..."
show_command "$command" show_command "$command"
make > /dev/null || show_error "Error during compilation." make > /dev/null || show_error "Error during compilation."
@ -59,7 +60,7 @@ function build {
# Execute the executable # Execute the executable
function execute { function execute {
local executable="$BUILD_DIR/$APP_NAME" local executable="$APP_NAME"
local command="./$executable" local command="./$executable"
echo -e "➔ Executing the executable..." echo -e "➔ Executing the executable..."
show_command "$command" show_command "$command"

Binary file not shown.

@ -1,43 +1,21 @@
CC = gcc GCCFLAGS = -Wall -Wextra -I src -Wno-unused-parameter -Wno-unused-but-set-variable
SRC_DIR = src
OBJ_DIR = obj
SOURCES = $(wildcard $(SRC_DIR)/*.c)
OBJECTS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SOURCES))
EXECUTABLE = APP
BUILD_DIR = build BUILD_DIR = build
LDFLAGS = SOURCES = $(shell find src -name '*.c')
CFLAGS_RELEASE = -O3 TARGETS = $(patsubst %.c, %.o, $(SOURCES))
CFLAGS_DEBUG = -g -O0 TARGETS := $(addprefix $(BUILD_DIR)/, $(TARGETS))
APP_NAME = app
# Generate dependency files all: $(APP_NAME)
DEPS = $(OBJECTS:.o=.d)
-include $(DEPS)
# Commands $(APP_NAME): $(TARGETS)
all: build @gcc $(GCCFLAGS) -o $(APP_NAME) $(TARGETS)
@echo -e $(GREEN)build done.$(RESET)
build: $(BUILD_DIR)/$(EXECUTABLE) $(TARGETS): $(SOURCES)
@mkdir -p $(@D)
@gcc $(GCCFLAGS) -c $(patsubst %.o, %.c, $(@:$(BUILD_DIR)/%=%)) -o $@
$(BUILD_DIR)/$(EXECUTABLE): $(OBJECTS)
@mkdir -p $(BUILD_DIR)
$(CC) $(LDFLAGS) -o $@ $^
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) -c $(CFLAGS_RELEASE) -MMD -MP -o $@ $<
debug:
$(MAKE) CFLAGS_RELEASE="$(CFLAGS_DEBUG)" build
clean: clean:
rm -rf $(OBJ_DIR) $(BUILD_DIR) @rm -r $(BUILD_DIR) $(APP_NAME)
@echo -e $(GREEN)clean done.$(RESET)
run: build
$<
doc_doxygen:
@echo "Doxygen build started"
@$(MAKE) -C docs
.PHONY: all build debug clean run doc_doxygen

Loading…
Cancel
Save