commit 7cf28757b2731e343e4269ba96e61856d56b00b6 Author: Ulysse Cura Date: Sun Dec 21 19:43:49 2025 +0100 Added template for GCC project diff --git a/GCC_Project/.gitignore b/GCC_Project/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/GCC_Project/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/GCC_Project/.vscode/tasks.json b/GCC_Project/.vscode/tasks.json new file mode 100644 index 0000000..8021ddb --- /dev/null +++ b/GCC_Project/.vscode/tasks.json @@ -0,0 +1,77 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build", + "detail": "Build project", + "type": "shell", + "command": "make", + //"args": [ + // "-j$(nproc)" + //], + "group": "build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, + { + "label": "Clean", + "detail": "Clean build directory and executable", + "type": "shell", + "command": "make", + "args": [ + "clean" + ], + "group": "build", + "presentation": { + "echo": false, + "reveal": "never", + "focus": false, + "panel": "shared", + "showReuseMessage": false, + "clear": true + } + }, + { + "label": "Build Verbose", + "detail": "Build project with verbosity on", + "type": "shell", + "command": "make", + "args": [ + "VERBOSE=1" + ], + "group": "build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, + { + "label": "Run", + "detail": "Run executable", + "type": "shell", + "command": "make", + "args": [ + "run" + ], + "group": "build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + } + ] +} \ No newline at end of file diff --git a/GCC_Project/Makefile b/GCC_Project/Makefile new file mode 100644 index 0000000..2219a95 --- /dev/null +++ b/GCC_Project/Makefile @@ -0,0 +1,76 @@ +# Build folder +BUILD_DIR = build + +# Source files +SOURCES := \ + src/main.c + +# Output target name +OUTPUT := GCC_Project + +# Compiler and flags +CXX = ccache gcc +CXXFLAGS = -Wall -Wextra -std=c17 -g +INCLUDE_DIRS = +LDFLAGS = + +# Change output location +OUTPUT := $(BUILD_DIR)/$(OUTPUT) + +# Deduce objects +OBJECTS = $(SOURCES:%.c=$(BUILD_DIR)/%.o) + +# Verbose mode +ifeq ($(VERBOSE), 1) +Q := +else +Q := @ +endif + +# Colors +GREEN := \033[0;32m +YELLOW := \033[1;33m +RESET := \033[0m + +# Current file nb to process +CURRENT_FILE := 0 + +# Default targets +all: count_build build_dir end + +# Create build directory +build_dir: + $(Q)mkdir -p $(dir $(OBJECTS)) + +# Link target +$(OUTPUT): $(OBJECTS) + @echo "[100%] $(YELLOW)Linking $(OUTPUT)$(RESET)" + $(Q)$(CXX) $(LDFLAGS) -o $@ $(OBJECTS) + +# Build .o files from .c +$(BUILD_DIR)/%.o: %.c + $(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE)+1)))) + $(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE)*100/$(TOTAL_FILES))))) + @echo "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)" + $(Q)$(CXX) $(CXXFLAGS) $(INCLUDE_DIRS:%=-I%) -MMD -MP -c $< -o $@ + +# Source files dependencies +-include $(OBJECTS:.o=.d) + +count_build: + $(eval export TOTAL_FILES := $(shell echo $$(($$(make -n $(OBJECTS) 2>/dev/null | grep -c "Building") + 1)))) + +# Print ending message +end: $(OUTPUT) + @echo "Built target $(OUTPUT)" + +# Clean +.PHONY: clean +clean: + $(Q)rm -rf $(BUILD_DIR) + $(Q)rm -rf $(dir $(FXCONV_CONVERTERS))/__pycache__ + +# Run executable +.PHONY: run +run: + $(Q)./$(OUTPUT) diff --git a/GCC_Project/src/main.c b/GCC_Project/src/main.c new file mode 100644 index 0000000..e99279a --- /dev/null +++ b/GCC_Project/src/main.c @@ -0,0 +1,8 @@ +#include + +int main(void) +{ + puts("Hello, World !"); + + return 0; +}