Updated Makefile with pkg-config
and a test target.
Makefile now gets the necessary `cflags` and `libs` compiler arguments from `pkg-config` which increases portability and makes adding new dependencies easier. Also added `TEST` flag, to have automated testing in the future.
This commit is contained in:
parent
0cc9140aa3
commit
d292abbba5
57
Makefile
57
Makefile
@ -1,13 +1,34 @@
|
|||||||
SHELL=/bin/bash
|
SHELL=/bin/bash
|
||||||
|
|
||||||
|
# configurable options
|
||||||
|
|
||||||
|
SOURCES_DIR := ./src
|
||||||
|
TESTS_DIR := ./tests
|
||||||
|
BUILD_DIR := ./build
|
||||||
|
|
||||||
CC := gcc
|
CC := gcc
|
||||||
CXX := g++
|
CXX := g++
|
||||||
|
|
||||||
CFLAGS := -I/usr/include/fuse -D_FILE_OFFSET_BITS=64
|
|
||||||
LDFLAGS := -lfuse3 -pthread
|
|
||||||
|
|
||||||
ifdef DEBUG
|
# dependencies
|
||||||
CFLAGS += -O0 -pedantic -Wall -Wextra -Wcast-align \
|
|
||||||
|
PACKAGE_NAMES := fuse3
|
||||||
|
|
||||||
|
ifeq ($(TEST), 1)
|
||||||
|
# PACKAGE_NAMES += check # TODO: use check?
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
# set up cflags and libs
|
||||||
|
|
||||||
|
CFLAGS := -D_FILE_OFFSET_BITS=64
|
||||||
|
LDFLAGS :=
|
||||||
|
|
||||||
|
CFLAGS += $(shell pkg-config --cflags $(PACKAGE_NAMES))
|
||||||
|
LDFLAGS += $(shell pkg-config --libs $(PACKAGE_NAMES))
|
||||||
|
|
||||||
|
ifeq ($(DEBUG),1)
|
||||||
|
CFLAGS += -O0 -pedantic -g -Wall -Wextra -Wcast-align \
|
||||||
-Wcast-qual -Wdisabled-optimization -Wformat=2 \
|
-Wcast-qual -Wdisabled-optimization -Wformat=2 \
|
||||||
-Winit-self -Wlogical-op -Wmissing-declarations \
|
-Winit-self -Wlogical-op -Wmissing-declarations \
|
||||||
-Wmissing-include-dirs -Wredundant-decls -Wshadow \
|
-Wmissing-include-dirs -Wredundant-decls -Wshadow \
|
||||||
@ -19,12 +40,32 @@ else
|
|||||||
LDFLAGS +=
|
LDFLAGS +=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SOURCES_DIR := ./src
|
|
||||||
BUILD_DIR := ./build
|
|
||||||
|
|
||||||
build: $(BUILD_DIR)/main.o $(BUILD_DIR)/fuse_operations.o $(BUILD_DIR)/sourcefs.o $(BUILD_DIR)/ui-socket.o
|
# set up targets
|
||||||
|
|
||||||
|
TARGETS := icfs
|
||||||
|
|
||||||
|
ifeq ($(TEST), 1)
|
||||||
|
TARGETS += icfs_test
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
# build!
|
||||||
|
|
||||||
|
default: $(TARGETS)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
icfs: $(BUILD_DIR)/main.o $(BUILD_DIR)/fuse_operations.o $(BUILD_DIR)/sourcefs.o $(BUILD_DIR)/ui-socket.o
|
||||||
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $(BUILD_DIR)/icfs
|
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $(BUILD_DIR)/icfs
|
||||||
|
|
||||||
|
icfs_test: $(BUILD_DIR)/main.o $(BUILD_DIR)/fuse_operations.o $(BUILD_DIR)/sourcefs.o $(BUILD_DIR)/ui-socket.o
|
||||||
|
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $(BUILD_DIR)/icfs_test
|
||||||
|
# $(BUILD_DIR)/icfs_test # TODO: implement testing
|
||||||
|
|
||||||
|
$(BUILD_DIR)/test_access_control.o: $(TESTS_DIR)/test_access_control.c
|
||||||
|
$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
|
||||||
|
|
||||||
$(BUILD_DIR)/main.o: $(SOURCES_DIR)/main.c
|
$(BUILD_DIR)/main.o: $(SOURCES_DIR)/main.c
|
||||||
$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $(BUILD_DIR)/main.o
|
$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $(BUILD_DIR)/main.o
|
||||||
|
|
||||||
@ -38,4 +79,4 @@ $(BUILD_DIR)/ui-socket.o: $(SOURCES_DIR)/ui-socket.c $(SOURCES_DIR)/ui-socket.h
|
|||||||
$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
|
$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(BUILD_DIR)/*
|
rm $(BUILD_DIR)/*.o $(BUILD_DIR)/icfs*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user