From d44e99ade5d197fbc52d16fe6f57155b451474a4 Mon Sep 17 00:00:00 2001 From: Quinn Date: Sat, 22 Mar 2025 11:15:53 +0100 Subject: [PATCH] sync config files with template --- .clang-format | 197 ++++++++++++++++++++++++++++++++++++++++++++ .editorconfig | 23 ++++++ .gitignore | 28 +++++-- .vscode/launch.json | 21 ----- .vscode/tasks.json | 15 ---- makefile | 70 ++++++++++------ 6 files changed, 284 insertions(+), 70 deletions(-) create mode 100644 .clang-format create mode 100644 .editorconfig delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/tasks.json diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..5c1061b --- /dev/null +++ b/.clang-format @@ -0,0 +1,197 @@ +--- +# --------------------------- +# general style settings +# --------------------------- +BasedOnStyle: '' # (LLVM,Google,Chromium,Mozilla,WebKit,Microsoft,GNU,InheritParentConfig) +Standard: Auto # automatically detect the language version +ColumnLimit: 0 # 0: disable column limit +LineEnding: LF # use LF line endings +UseTab: Never # (Never,ForIndentation,ForContinuationAndIndentation,Always) +TabWidth: 4 # recommended to set this equal to IndentWidth +IndentWidth: 4 # how wide each indent is +ContinuationIndentWidth: 4 # width for a line continuation + +# --------------------------- +# alignment options +# --------------------------- +AlignAfterOpenBracket: Align # (Align,DontAlign,AlwaysBreak,BlockIndent) +AlignArrayOfStructures: Left # (Left,Right,None) +AlignConsecutiveMacros: AcrossEmptyLines # (None,Consecutive,AcrossEmptyLines,AcrossComments,AcrossEmptyLinesAndComments) +AlignConsecutiveAssignments: None # (None,Consecutive,AcrossEmptyLines,AcrossComments,AcrossEmptyLinesAndComments) +AlignConsecutiveBitFields: AcrossEmptyLines # (None,Consecutive,AcrossEmptyLines,AcrossComments,AcrossEmptyLinesAndComments) +AlignConsecutiveDeclarations: None # (None,Consecutive,AcrossEmptyLines,AcrossComments,AcrossEmptyLinesAndComments) +AlignEscapedNewlines: Left # (DontAlign,Left,LeftWithLastLine,Right) +AlignOperands: Align # (DontAlign,Align,AlignAfterOperator) +AlignTrailingComments: Always # (Leave,Always,Never) + +# --------------------------- +# short constructs on a single line +# --------------------------- +AllowShortBlocksOnASingleLine: Always # (Never,Empty,Always) +AllowShortFunctionsOnASingleLine: All # (None,InlineOnly,Empty,All) +AllowShortLambdasOnASingleLine: All # (None,Empty,Inline,All) +AllowShortIfStatementsOnASingleLine: AllIfsAndElse # (Never,WithoutElse,OnlyFirstIf,AllIfsAndElse) +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortLoopsOnASingleLine: true + +# --------------------------- +# break and wrapping options +# --------------------------- +AlwaysBreakBeforeMultilineStrings: true # when defining multi-line strings, linebreak should be inserted +BreakAfterReturnType: Automatic # is decided by PenaltyReturnTypeOnItsOwnLine +BreakTemplateDeclarations: MultiLine # (Leave,No,MultiLine,Yes) +BreakBeforeBinaryOperators: None # (None,NonAssignment,All) +BreakBeforeConceptDeclarations: Never # (Never,Allowed,Always) +BreakBeforeBraces: Attach # (Attach,Linux,Mozilla,Stroustrup,Allman,Whitesmiths,GNU,WebKit,Custom) +BreakInheritanceList: BeforeColon # (BeforeColon,BeforeComma,AfterColon) +BreakConstructorInitializers: BeforeColon # (BeforeColon,BeforeComma,AfterColon) +BreakBeforeTernaryOperators: true +BreakStringLiterals: true + +# --------------------------- +# brace wrapping configuration +# --------------------------- +BraceWrapping: + AfterControlStatement: Never # (Never,MultiLine,Always) + AfterCaseLabel: false + AfterClass: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false + +# --------------------------- +# constructor initializer and parameter packing options +# --------------------------- +ConstructorInitializerIndentWidth: 4 +PackConstructorInitializers: BinPack # (Never,BinPack,CurrentLine,NextLine,NextLineOnly) +BinPackParameters: true # use bin-packing for paramter lists +BinPackArguments: false # false: function calls either on one line or one per line + +# --------------------------- +# pointer alignment +# --------------------------- +DerivePointerAlignment: false # automatically detect pointer alignment +PointerAlignment: Left # (Left,Right,Middle) +ReferenceAlignment: Pointer # (Pointer,Left,Right,Middle) + +# --------------------------- +# include settings and sorting +# --------------------------- +IncludeIsMainSourceRegex: '' # only [*.{c,cc,cpp,c++,cxx,m,mm}] are considered to be "main" +IncludeIsMainRegex: '([-_](test|unittest))?$' # regex used for identifying an include as "main", to assign catagory 0 +IncludeBlocks: Regroup # (Preserve,Merge,Regroup) +IncludeCategories: + - Regex: '^<.*\.h>' # system headers + Priority: 1 + SortPriority: 0 + CaseSensitive: true + - Regex: '^".*' # custom headers + Priority: 2 + SortPriority: 0 + CaseSensitive: true + +# --------------------------- +# macro and language-specific settings +# --------------------------- +AttributeMacros: + - __capability +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME + +# --------------------------- +# additional formatting and sorting details +# --------------------------- +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +EmptyLineAfterAccessModifier: Never # (Never,Leave,Always) +EmptyLineBeforeAccessModifier: LogicalBlock # (Never,Leave,LogicalBlock,Always) +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true # adds comments at namespace delimiters +MaxEmptyLinesToKeep: 4 # what the maximum amount of empty lines that we're allowed to keep +ReflowComments: true # reflow comment text to match column limits +RemoveBracesLLVM: false # don't automatically remove braces +SeparateDefinitionBlocks: Leave # (Leave,Always.Never) +ShortNamespaceLines: 1 # how many lines a namespaces can be to be regarded "short" +SortIncludes: CaseSensitive # (Never,CaseSensitive,CaseInsensitive) +SortUsingDeclarations: LexicographicNumeric # (Never,Lexicographic,LexicographicNumeric) + +# --------------------------- +# spacing options +# --------------------------- +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements # (ControlStatements,ControlStatementsExceptControlMacros,NonEmptyParentheses,Always,Custom) +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default # (Default,Before,After,Both) recommend to use Default and let PointerAlignment decide +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: true +SpacesInParens: Custom +SpacesInParensOptions: + ExceptDoubleParentheses: false + InConditionalStatements: false + InCStyleCasts: false + Other: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never # (Never,Always,Leave) +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: 1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both # (Both,None,Before,After) + +# --------------------------- +# indentation details +# --------------------------- +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentExternBlock: AfterExternBlock # (AfterExternBlock,NoIndent,Indent) +IndentRequiresClause: false +IndentPPDirectives: AfterHash # preprocessor indent style (None,AfterHash,BeforeHash) +PPIndentWidth: 1 +... diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9957977 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,23 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{rs}] +indent_style = space +indent_size = 4 + +[*.{c,h,cpp,hpp}] +indent_style = space +indent_size = 4 + +[makefile] +indent_style = tab +indent_size = 2 + +[*.{yaml,json}] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore index aa4e436..9e34ec3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,21 @@ -.cache -.vscode/* -!.vscode/tasks.json -!.vscode/launch.json -bin -obj -compile_commands.json +# ignore all dotfiles by default +.* + +# rubbish we don't want to track +~* +*~ +*.bak + +# ignore output files +*.o +*.d +*.log +/bin/ +/obj/ +/compile_commands.json + +# unignore dotfiles that we'd like to keep +!.gitignore +!.editorconfig +!/.clang-format +!/.github/ diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index ea127f6..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "version": "2.0.0", - "configurations": [ - { - "name": "(lldb) debug project", - "type": "lldb", - "request": "launch", - "program": "", - "linux": { - "preLaunchTask": "(dbg) compile linux-x86_64", - "program": "bin/linux-x86_64/${workspaceFolderBasename}", - "cwd": "bin/linux-x86_64/" - }, - "windows": { - "preLaunchTask": "(dbg) compile win-x86_64", - "program": "bin/win-x86_64/${workspaceFolderBasename}.exe", - "cwd": "bin/win-x86_64/" - }, - } - ] -} diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 21aff10..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "(dbg) compile linux-x86_64", - "type": "shell", - "command": "DEBUG=1 make linux-x86_64", - }, - { - "label": "(dbg) compile win-x86_64", - "type": "shell", - "command": "DEBUG=1 make win-x86_64", - } - ] -} diff --git a/makefile b/makefile index 8926cb4..aa9b514 100644 --- a/makefile +++ b/makefile @@ -1,30 +1,41 @@ +# dependencies: +# - make +# - clang +# - bear (debug) +# - sdl2 +# - git bash (windows) +# +# project name = the workspace directory name NAME := $(shell basename $(PWD)) # compiler settings CC := clang STD := c17 LANG = c -CFLAGS := $(shell pkg-config --cflags sdl2 SDL2_ttf) -Wall -Wextra -Wpedantic -Wno-pointer-arith -LDFLAGS := $(shell pkg-config --libs sdl2 SDL2_ttf) -lm +CFLAGS := $(shell pkg-config --cflags sdl2) -Wall -Wextra -Wpedantic -Wno-pointer-arith +LDFLAGS := $(shell pkg-config --libs sdl2) -lm +DEBUG ?= 0 ifeq ($(DEBUG),1) -CFLAGS += -DDEBUG -Og -g +CFLAGS += -DDEBUG -fsanitize=address,undefined -g -Og +PROF := dbg else -REL_FLAGS += -O3 +REL_FLAGS += -O2 +PROF := rel endif # dirs DIR_BIN := bin DIR_OBJ := obj -DIR_BUILD := $(DIR_BIN)/$(ARCH) -DIR := $(DIR_BIN)/$(ARCH) $(DIR_OBJ)/$(ARCH) +DIR_BUILD := $(DIR_BIN)/$(ARCH)/$(PROF) +DIR := $(DIR_BIN)/$(ARCH)/$(PROF) $(DIR_OBJ)/$(ARCH)/$(PROF) # source files SRC := $(wildcard src/*.c) $(wildcard src/**/*.c) $(wildcard src/**/**/*.c) $(wildcard src/**/**/**/*.c) $(wildcard src/**/**/**/**/*.c) SRC_ASSETS := $(wildcard assets/*) # output locations -OBJ := $(patsubst src/%,$(DIR_OBJ)/$(ARCH)/%,$(SRC:.c=.o)) +OBJ := $(patsubst src/%,$(DIR_OBJ)/$(ARCH)/$(PROF)/%,$(SRC:.c=.o)) DEP := $(OBJ:.o=.d) ASSETS := $(patsubst assets/%,$(DIR_BUILD)/%,$(SRC_ASSETS)) TARGET := $(DIR_BUILD)/$(NAME)$(EXT) @@ -33,50 +44,55 @@ define wr_colour @echo -e "\033[$(2)m$(1)\033[0m" endef -# sets the variables for the different targets -linux-x86_64: - @$(MAKE) _build ARCH=linux-x86_64 CFLAGS="$(CFLAGS) -target x86_64-pc-linux-gnu" -win-x86_64: - @$(MAKE) _build ARCH=win-x86-64 CFLAGS="$(CFLAGS) -target x86_64-pc-windows-gnu" EXT=".exe" -web: - @$(MAKE) _build ARCH=web CC=emcc EXT=".html" +# set the correct environment variables depending on the platform +ifeq ($(ARCH),linux-x86_64) +CFLAGS += -target x86_64-pc-linux-gnu +else ifeq ($(ARCH),win-x86_64) +CFLAGS += -target x86_64-pc-windows-gnu +EXT=.exe +else +$(error you must set the ARCH environment variable to one of these: 'linux-x86_64' 'win-x86_64') +endif -all: linux-x86_64 win-x86_64 web -_build: compile_commands.json $(DIR) $(TARGET) $(ASSETS) +# compiles and execute the binary +run: compile + ./$(TARGET) +compile: compile_commands.json $(DIR) $(TARGET) $(ASSETS) clean: rm -rf $(DIR_BIN) $(DIR_OBJ) compile_commands.json -# create the binary +# create the binary (linking step) $(TARGET): $(OBJ) - @$(call wr_colour,"using arguments: $(CFLAGS) $(LDFLAGS)",94) + @$(call wr_colour,"CC: '$(CC)'",94) + @$(call wr_colour,"CFLAGS: '$(CFLAGS)'",94) + @$(call wr_colour,"LDFLAGS: '$(LDFLAGS)'",94) + @$(call wr_colour,"linking to: '$@'",92) @$(CC) -o $(TARGET) $^ $(CFLAGS) $(LDFLAGS) + @$(call wr_colour,"current profile: '$(PROF)'",93) # create .o and .d files -$(DIR_OBJ)/$(ARCH)/%.o: src/%.c +$(DIR_OBJ)/$(ARCH)/$(PROF)/%.o: src/%.c + @$(call wr_colour,"compiling $(notdir $@) from $(notdir $<)",92) @mkdir -p $(dir $@) @$(CC) -o $@ -MD -MP -c $< $(CFLAGS) -std=$(STD) -x $(LANG) -Wno-unused-command-line-argument # copy assets $(DIR_BUILD)/%: assets/% @mkdir -p $(dir $@) - cp $< $@ + cp -v $< $@ # create directories $(DIR): - @mkdir -p $@ + mkdir -p $@ # update compile commands if the makefile has been updated (for linting) ifeq ($(DEBUG),1) compile_commands.json: makefile - @$(call wr_colour,"compiling in debug mode",93) $(MAKE) clean @touch compile_commands.json - bear -- make + bear -- make compile else -compile_commands.json: makefile - @$(call wr_colour,"compiling in non-debug mode",93) - $(MAKE) clean - @touch compile_commands.json +compile_commands.json: endif # include the dependencies