Added template for GCC project
This commit is contained in:
commit
7cf28757b2
|
|
@ -0,0 +1 @@
|
||||||
|
build
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
puts("Hello, World !");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue