Skip to content

Commit

Permalink
update CFLAGS and remove clang.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
lucavallin committed Aug 9, 2023
1 parent 0bed9e2 commit 4a9e579
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
10 changes: 9 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -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",
]

This comment has been minimized.

Copy link
@N-R-K

N-R-K Aug 9, 2023

Contributor

@lucavallin One small tip: you can provide compiler arguments to clang-tidy by putting them after --. So instead of duplicating them here, you can append -- $(CFLAGS) at the end of the LINTER command in the Makefile.

One caveat is that this will also include the warning flags from CFLAGS, but in my experience, that's a usually a non-issue.

This comment has been minimized.

Copy link
@lucavallin

lucavallin Aug 10, 2023

Author Owner

Hey @N-R-K! Thanks for the tip: I was very annoyed by the duplicated args, this makes it much easier!

HeaderFileExtensions:
- h
HeaderFilterRegex: "./include/*"
Expand Down
34 changes: 24 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions clang.cfg

This file was deleted.

0 comments on commit 4a9e579

Please sign in to comment.