137 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			137 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
SHELL=/bin/bash
 | 
						|
 | 
						|
# configurable options
 | 
						|
 | 
						|
ifndef ($(SOURCES_DIR))
 | 
						|
	SOURCES_DIR := ./src
 | 
						|
endif
 | 
						|
 | 
						|
ifndef ($(TESTS_DIR))
 | 
						|
	TESTS_DIR := ./tests
 | 
						|
endif
 | 
						|
 | 
						|
ifndef ($(BUILD_DIR))
 | 
						|
	BUILD_DIR := ./build
 | 
						|
endif
 | 
						|
 | 
						|
 | 
						|
 | 
						|
CC := gcc
 | 
						|
CXX := g++
 | 
						|
 | 
						|
 | 
						|
# dependencies
 | 
						|
 | 
						|
PACKAGE_NAMES := fuse3 sqlite3
 | 
						|
 | 
						|
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 += -Og -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 := $(BUILD_DIR)/icfs
 | 
						|
 | 
						|
ifeq ($(TEST), 1)
 | 
						|
	TARGETS += icfs_test
 | 
						|
endif
 | 
						|
 | 
						|
ifneq ($(DIALOGUE), 0)
 | 
						|
	TARGETS += $(BUILD_DIR)/icfs_dialogue
 | 
						|
endif
 | 
						|
 | 
						|
# build!
 | 
						|
 | 
						|
default: $(TARGETS)
 | 
						|
 | 
						|
.PHONY: clean icfs_test clean-icfs clean-icfs_dialogue install uninstall
 | 
						|
 | 
						|
$(BUILD_DIR):
 | 
						|
	if [[ ! -d "FILE" ]]; then mkdir $(BUILD_DIR) fi
 | 
						|
 | 
						|
$(BUILD_DIR)/icfs_dialogue:
 | 
						|
	make -C $(SOURCES_DIR)/gui TEST=$(TEST) DEBUG=$(shell realpath $(DEBUG)) SOURCES_DIR=$(shell realpath $(SOURCES_DIR)/gui) BUILD_DIR=$(shell realpath $(BUILD_DIR)) TESTS_DIR=$(shell realpath $(TESTS_DIR)) $(BUILD_DIR)
 | 
						|
 | 
						|
$(BUILD_DIR)/icfs: $(BUILD_DIR)/main.o $(BUILD_DIR)/fuse_operations.o $(BUILD_DIR)/sourcefs.o $(BUILD_DIR)/ui-socket.o $(BUILD_DIR)/temp_permissions_table.o $(BUILD_DIR)/perm_permissions_table.o $(BUILD_DIR)/proc_operations.o
 | 
						|
	$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $(BUILD_DIR)/icfs
 | 
						|
 | 
						|
icfs_test: $(BUILD_DIR)/icfs
 | 
						|
	cd ./test && ./test.bash
 | 
						|
 | 
						|
$(BUILD_DIR)/test_access_control.o: $(TESTS_DIR)/test_access_control.c $(BUILD_DIR)
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
 | 
						|
 | 
						|
$(BUILD_DIR)/main.o: $(SOURCES_DIR)/main.c $(BUILD_DIR)
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $(BUILD_DIR)/main.o
 | 
						|
 | 
						|
$(BUILD_DIR)/fuse_operations.o: $(SOURCES_DIR)/fuse_operations.c $(SOURCES_DIR)/fuse_operations.h $(BUILD_DIR)
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
 | 
						|
 | 
						|
$(BUILD_DIR)/sourcefs.o: $(SOURCES_DIR)/sourcefs.c $(SOURCES_DIR)/sourcefs.h $(SOURCES_DIR)/real_filename.h $(BUILD_DIR)
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
 | 
						|
 | 
						|
$(BUILD_DIR)/ui-socket.o: $(SOURCES_DIR)/ui-socket.c $(SOURCES_DIR)/ui-socket.h $(BUILD_DIR)
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
 | 
						|
 | 
						|
$(BUILD_DIR)/temp_permissions_table.o: $(SOURCES_DIR)/temp_permissions_table.c $(SOURCES_DIR)/temp_permissions_table.h $(BUILD_DIR)
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
 | 
						|
 | 
						|
$(BUILD_DIR)/perm_permissions_table.o: $(SOURCES_DIR)/perm_permissions_table.c $(SOURCES_DIR)/perm_permissions_table.h $(BUILD_DIR)
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
 | 
						|
 | 
						|
$(BUILD_DIR)/proc_operations.o: $(SOURCES_DIR)/proc_operations.c $(SOURCES_DIR)/proc_operations.h $(BUILD_DIR)
 | 
						|
	$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
 | 
						|
 | 
						|
CLEAN_TARGETS=clean-icfs
 | 
						|
 | 
						|
ifneq ($(DIALOGUE), 0)
 | 
						|
	CLEAN_TARGETS += clean-icfs_dialogue
 | 
						|
endif
 | 
						|
 | 
						|
clean: $(CLEAN_TARGETS)
 | 
						|
 | 
						|
clean-icfs:
 | 
						|
	rm $(BUILD_DIR)/*.o $(BUILD_DIR)/icfs
 | 
						|
 | 
						|
clean-icfs_dialogue:
 | 
						|
		make -C $(SOURCES_DIR)/gui clean SOURCES_DIR=$(shell realpath $(SOURCES_DIR)/gui) BUILD_DIR=$(shell realpath $(BUILD_DIR)) TESTS_DIR=$(shell realpath $(TESTS_DIR))
 | 
						|
 | 
						|
install: $(BUILD_DIR)/icfs $(BUILD_DIR)/icfs_dialogue
 | 
						|
	@echo "Install script needs superuser permission to:"
 | 
						|
	@printf "\t1. Move executables to /usr/bin.\n"
 | 
						|
	@printf "\t2. Create \"icfs\" user.\n"
 | 
						|
	@printf "\t3. Set the setuid bit of icfs executable.\n"
 | 
						|
	sudo cp $(BUILD_DIR)/icfs /usr/bin/icfs && sudo cp $(BUILD_DIR)/icfs_dialogue /usr/bin/icfs_dialogue
 | 
						|
	id -u icfs &>/dev/null || sudo useradd --system --user-group icfs
 | 
						|
	sudo chown icfs: /usr/bin/icfs && sudo chmod 4777 /usr/bin/icfs
 | 
						|
	@read -p "Create /etc/icfs directory for permission databases [y/N]: " permd; if [[ $$permd == "y" ]]; then echo "sudo mkdir /etc/icfs && sudo chown :icfs /etc/icfs && sudo chmod g+rw,o= /etc/icfs;"; sudo mkdir /etc/icfs && sudo chown icfs:icfs /etc/icfs && sudo chmod g+rw,o= /etc/icfs; fi
 | 
						|
 | 
						|
uninstall:
 | 
						|
	@echo "Install script needs superuser permission to remove executables in /usr/bin"
 | 
						|
	sudo rm -f /usr/bin/icfs /usr/bin/icfs_dialogue
 | 
						|
	@read -p "Remove /etc/icfs directory [y/N]: " permd; if [[ $$permd == "y" ]]; then echo "sudo rm -rf /etc/icfs"; sudo rm -rf /etc/icfs; fi
 | 
						|
 |