diff --git a/.clang-tidy b/.clang-tidy index b1eeb03..b31f16d 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,13 @@ --- -ExtraArgs: ["-std=gnu17", "-D _GNU_SOURCE 1", "-I./include", "-I./lib/log", "-I./lib/argtable"] +ExtraArgs: + [ + "-std=gnu17", + "-D _GNU_SOURCE 1", + "-D __STDC_WANT_LIB_EXT1__", + "-I./include", + "-I./lib/log", + "-I./lib/argtable", + ] HeaderFileExtensions: - h HeaderFilterRegex: "./include/*" diff --git a/Makefile b/Makefile index e11fea4..5360fb8 100644 --- a/Makefile +++ b/Makefile @@ -28,38 +28,52 @@ LIB_LOG_FLAGS := -DLOG_USE_COLOR OBJS := $(BARCO).o cgroups.o container.o mount.o sec.o user.o $(LIB_ARGTABLE_NAME).o $(LIB_LOG_NAME).o # Compiler settings -CC_INCLUDE_FLAGS := -I$(INCLUDE_DIR) -I$(LIB_ARGTABLE_DIR) -I$(LIB_LOG_DIR) -CC := clang-18 --config ./clang.cfg $(CC_INCLUDE_FLAGS) +CC := clang-18 LINTER := clang-tidy-18 FORMATTER := clang-format-18 DEBUGGER := lldb-18 DISASSEMBLER := llvm-objdump-18 -# Debug Settings +# Compiler and Linker flags Settings: +# -std=gnu17: Use the GNU17 standard +# -D _GNU_SOURCE: Use GNU extensions +# -D __STDC_WANT_LIB_EXT1__: Use C11 extensions +# -Wall: Enable all warnings +# -Wextra: Enable extra warnings +# -pedantic: Enable pedantic warnings +# -I$(INCLUDE_DIR): Include the include directory +# -I$(LIB_ARGTABLE_DIR): Include the argtable library directory +# -I$(LIB_LOG_DIR): Include the log library directory +# -lcap: Link to libcap +# -lseccomp: Link to libseccomp +# -lm: Link to libm +CFLAGS := -std=gnu17 -D _GNU_SOURCE -D __STDC_WANT_LIB_EXT1__ -Wall -Wextra -pedantic -I$(INCLUDE_DIR) -I$(LIB_ARGTABLE_DIR) -I$(LIB_LOG_DIR) +LFLAGS := -lcap -lseccomp -lm + ifeq ($(debug), 1) - CC := $(CC) -g -O0 + CFLAGS := $(CFLAGS) -g -O0 else - CC := $(CC) -Oz + CFLAGS := $(CFLAGS) -Oz endif # Targets # Build barco executable $(BARCO): format lint dir $(OBJS) - $(CC) -o $(BIN_DIR)/$(BARCO) $(foreach file,$(OBJS),$(BUILD_DIR)/$(file)) + $(CC) $(CFLAGS) $(LFLAGS) -o $(BIN_DIR)/$(BARCO) $(foreach file,$(OBJS),$(BUILD_DIR)/$(file)) # Build object files %.o: dir $(SRC_DIR)/%.c - @$(CC) -o $(BUILD_DIR)/$*.o -c $(SRC_DIR)/$*.c + @$(CC) $(CFLAGS) -o $(BUILD_DIR)/$*.o -c $(SRC_DIR)/$*.c # Build third-party libraries $(LIB_ARGTABLE_NAME).o: dir $(LIB_ARGTABLE_SRC) - @$(CC) -o $(BUILD_DIR)/$(LIB_ARGTABLE_NAME).o -c $(LIB_ARGTABLE_SRC) + @$(CC) $(CFLAGS) -o $(BUILD_DIR)/$(LIB_ARGTABLE_NAME).o -c $(LIB_ARGTABLE_SRC) $(LIB_LOG_NAME).o: dir $(LIB_ARGTABLE_SRC) - @$(CC) -o $(BUILD_DIR)/$(LIB_LOG_NAME).o -c $(LIB_LOG_SRC) $(LIB_LOG_FLAGS) + @$(CC) $(CFLAGS) -o $(BUILD_DIR)/$(LIB_LOG_NAME).o -c $(LIB_LOG_SRC) $(LIB_LOG_FLAGS) # Run CUnit tests test: dir - @$(CC) -lcunit -o $(BIN_DIR)/$(BARCO)_test $(TESTS_DIR)/$(BARCO)_test.c + @$(CC) $(CFLAGS) -lcunit -o $(BIN_DIR)/$(BARCO)_test $(TESTS_DIR)/$(BARCO)_test.c @$(BIN_DIR)/$(BARCO)_test # Run linter on source directories diff --git a/README.md b/README.md index 3f21eb2..ded120c 100644 --- a/README.md +++ b/README.md @@ -118,13 +118,12 @@ The project is structured as follows: ├── lib third-party libraries ├── scripts scripts for setup and other tasks ├── src C source files -│ ├── barco.c (main) +│ ├── barco.c (main) Entry point for the CLI │ └── *.c ├── tests contains tests -├── .clang-format configuration for clang-format -├── .cang-tidy configuration for clang-tidy +├── .clang-format configuration for the formatter +├── .clang-tidy configuration for the linter ├── .gitignore -├── .clang.cfg configuration for the compiler ├── LICENSE ├── Makefile └── README.md @@ -152,7 +151,7 @@ In the future, suitable tools for automated testing and documentation might be a ## Improvements - Investigate further, document and refactor: user and mount and cgroup namespaces, syscalls and capabilities -- The functions in `cgroups.c`, `mount.c`, `sec.c`, `userns.c` are specific to `barco` and should be made more generic +- The functions in `cgroups.c`, `mount.c`, `sec.c`, `user.c` are specific to `barco` and should be made more generic - CMake and Conan are industry standards, so they should be used eventually instead of Make and the current build system. Unfortunately, CMake and Conan also add a lot of complexity which is not needed at this time. ## Credits diff --git a/clang.cfg b/clang.cfg deleted file mode 100644 index e97cf48..0000000 --- a/clang.cfg +++ /dev/null @@ -1,10 +0,0 @@ -# C configuration --std=gnu17 --D _GNU_SOURCE --D __STDC_WANT_LIB_EXT1__ - -# Warnings and errors --Wall -Wextra -pedantic - -# Libraries --lcap -lseccomp -lm