Skip to content

Instantly share code, notes, and snippets.

@averne
Created April 19, 2019 08:15
Show Gist options
  • Save averne/2d048694f066c3d8022e27636f73550b to your computer and use it in GitHub Desktop.
Save averne/2d048694f066c3d8022e27636f73550b to your computer and use it in GitHub Desktop.
VSCode Linux project
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang"
}
],
"version": 4
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug (gdb)",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "debug",
"externalConsole": false,
"program": "${workspaceRoot}/out/${workspaceFolderBasename}-debug.elf",
"args": [],
"cwd": "${workspaceRoot}/src",
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "Python",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
TARGET = $(notdir $(CURDIR))
EXTENSION = elf
OUT = out
RELEASE = release
DEBUG = debug
SOURCES = src
INCLUDES =
LIBS =
ARCH = -march=native -fpie
FLAGS = -Wall -pipe
CFLAGS = -std=gnu11
CXXFLAGS = -std=gnu++17
ASFLAGS =
LDFLAGS = -Wl,-pie
LINKS =
RELEASE_FLAGS = $(FLAGS) -O2 -ffunction-sections -fdata-sections
RELEASE_CFLAGS = $(CFLAGS)
RELEASE_CXXFLAGS = $(CXXFLAGS)
RELEASE_ASFLAGS = $(ASFLAGS)
RELEASE_LDFLAGS = $(LDFLAGS) -Wl,--gc-sections -flto
DEBUG_FLAGS = $(FLAGS) -g -Og -DDEBUG=1
DEBUG_CFLAGS = $(CFLAGS)
DEBUG_CXXFLAGS = $(CXXFLAGS)
DEBUG_ASFLAGS = $(ASFLAGS) -g
DEBUG_LDFLAGS = $(LDFLAGS) -g -Wl,-Map,$(DEBUG)/$(TARGET).map
PREFIX =
CC = $(PREFIX)gcc
CXX = $(PREFIX)g++
AS = $(PREFIX)as
LD = $(PREFIX)g++
# -----------------------------------------------
CFILES = $(shell find $(SOURCES) -name *.c)
CPPFILES = $(shell find $(SOURCES) -name *.cpp)
SFILES = $(shell find $(SOURCES) -name *.s -or -name *.S)
OFILES = $(CFILES:%=$(BUILD)/%.o) $(CPPFILES:%=$(BUILD)/%.o) $(SFILES:%=$(BUILD)/%.o)
DFILES = $(OFILES:.o=.d)
RELEASE_TARGET = $(if $(OUT:=), $(OUT)/$(TARGET).$(EXTENSION), .$(OUT)/$(TARGET).$(EXTENSION))
DEBUG_TARGET = $(if $(OUT:=), $(OUT)/$(TARGET)-debug.$(EXTENSION), .$(OUT)/$(TARGET)-debug.$(EXTENSION))
INCLUDE_FLAGS = $(addprefix -I,$(INCLUDES)) $(foreach dir,$(LIBS),-I$(dir)/include)
LIB_FLAGS = $(foreach dir,$(LIBS),-L$(dir)/lib)
# -----------------------------------------------
.SUFFIXES:
.PHONY: all release debug clean
all: release debug
release: $(RELEASE_TARGET)
debug: $(DEBUG_TARGET)
$(RELEASE_TARGET): $(addprefix $(RELEASE),$(OFILES))
@echo " LD " $@
@mkdir -p $(dir $@)
@$(LD) $(ARCH) $(RELEASE_LDFLAGS) $(LIB_FLAGS) $(LINKS) $^ -o $@
$(DEBUG_TARGET): $(addprefix $(DEBUG),$(OFILES))
@echo " LD " $@
@mkdir -p $(dir $@)
@$(LD) $(ARCH) $(DEBUG_LDFLAGS) $(LIB_FLAGS) $(LINKS) $^ -o $@
$(RELEASE)/%.c.o: %.c
@echo " CC " $@
@mkdir -p $(dir $@)
@$(CC) -MMD -MP $(ARCH) $(RELEASE_FLAGS) $(RELEASE_CFLAGS) $(DEFINES) $(INCLUDE_FLAGS) -I$(CURDIR)/$(RELEASE) -c $< -o $@
$(DEBUG)/%.c.o: %.c
@echo " CC " $@
@mkdir -p $(dir $@)
@$(CC) -MMD -MP $(ARCH) $(DEBUG_FLAGS) $(DEBUG_CFLAGS) $(DEFINES) $(INCLUDE_FLAGS) -I$(CURDIR)/$(DEBUG) -c $< -o $@
$(RELEASE)/%.cpp.o: %.cpp
@echo " CXX " $@
@mkdir -p $(dir $@)
@$(CXX) -MMD -MP $(ARCH) $(RELEASE_FLAGS) $(RELEASE_CXXFLAGS) $(DEFINES) $(INCLUDE_FLAGS) -I$(CURDIR)/$(RELEASE) -c $< -o $@
$(DEBUG)/%.cpp.o: %.cpp
@echo " CXX " $@
@mkdir -p $(dir $@)
@$(CXX) -MMD -MP $(ARCH) $(DEBUG_FLAGS) $(DEBUG_CXXFLAGS) $(DEFINES) $(INCLUDE_FLAGS) -I$(CURDIR)/$(DEBUG) -c $< -o $@
$(RELEASE)/%.s.o: %.s
@echo " AS " $@
@mkdir -p $(dir $@)
@$(AS) -MMD -MP -x assembler-with-cpp $(ARCH) $(RELEASE_FLAGS) $(RELEASE_ASFLAGS) $(INCLUDE_FLAGS) -c $< -o $@
$(DEBUG)/%.s.o: %.s
@echo " AS " $@
@mkdir -p $(dir $@)
@$(AS) -MMD -MP -x assembler-with-cpp $(ARCH) $(DEBUG_FLAGS) $(DEBUG_ASFLAGS) $(INCLUDE_FLAGS) -c $< -o $@
clean:
@echo Cleaning...
@rm -rf $(DEBUG) $(RELEASE) $(RELEASE_TARGET) $(DEBUG_TARGET) $(OUT)
-include $(DFILES)
{
"version": "2.0.0",
"tasks": [
{
"label": "release",
"type": "shell",
"command": "make",
"args": [
"release"
],
"presentation": {
"panel": "shared"
},
"problemMatcher": {
"base": "$gcc",
"fileLocation": [
"relative",
"${workspaceFolder}"
]
}
},
{
"label": "debug",
"type": "shell",
"command": "make",
"args": [
"debug"
],
"presentation": {
"panel": "shared"
},
"problemMatcher": {
"base": "$gcc",
"fileLocation": [
"relative",
"${workspaceFolder}"
]
}
},
{
"label": "all",
"type": "shell",
"command": "make",
"args": [
"all"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "shared"
},
"problemMatcher": []
},
{
"label": "clean",
"type": "shell",
"command": "make",
"args": [
"clean"
],
"presentation": {
"panel": "shared",
"reveal": "never"
},
"problemMatcher": []
},
{
"label": "clean all",
"dependsOn": [
"clean",
"all"
],
"problemMatcher": []
},
{
"label": "run",
"dependsOn": [
"release"
],
"type": "shell",
"command": "${workspaceFolder}/out/${workspaceFolderBasename}.elf",
"options": {
"cwd": "${workspaceFolder}/out"
},
"presentation": {
"reveal": "always",
"panel": "dedicated",
"clear": true
},
"problemMatcher": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment