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.
		
			
				
	
	
		
			83 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
SHELL=/bin/bash
 | 
						|
 | 
						|
# configurable options
 | 
						|
 | 
						|
SOURCES_DIR := ./src
 | 
						|
TESTS_DIR := ./tests
 | 
						|
BUILD_DIR := ./build
 | 
						|
 | 
						|
CC := gcc
 | 
						|
CXX := g++
 | 
						|
 | 
						|
 | 
						|
# dependencies
 | 
						|
 | 
						|
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 \
 | 
						|
						-Winit-self -Wlogical-op -Wmissing-declarations \
 | 
						|
						-Wmissing-include-dirs -Wredundant-decls -Wshadow \
 | 
						|
						-Wsign-conversion -Wstrict-overflow=5 \
 | 
						|
						-Wswitch-default -Wundef -Wno-unused
 | 
						|
	LDFLAGS += 
 | 
						|
else
 | 
						|
	CFLAGS += -O3
 | 
						|
	LDFLAGS +=
 | 
						|
endif
 | 
						|
 | 
						|
 | 
						|
# 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
 | 
						|
 | 
						|
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
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $(BUILD_DIR)/main.o
 | 
						|
 | 
						|
$(BUILD_DIR)/fuse_operations.o: $(SOURCES_DIR)/fuse_operations.c $(SOURCES_DIR)/fuse_operations.h
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
 | 
						|
 | 
						|
$(BUILD_DIR)/sourcefs.o: $(SOURCES_DIR)/sourcefs.c $(SOURCES_DIR)/sourcefs.h
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
 | 
						|
 | 
						|
$(BUILD_DIR)/ui-socket.o: $(SOURCES_DIR)/ui-socket.c $(SOURCES_DIR)/ui-socket.h
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
 | 
						|
 | 
						|
clean:
 | 
						|
	rm $(BUILD_DIR)/*.o $(BUILD_DIR)/icfs*
 |