blob: 9deaf5891dab7f9db5e8dcde0c86265c02c9beb8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# Copyright (c) 2021, Marvin Borner <melvix@marvinborner.de>
# SPDX-License-Identifier: MIT
CC = gcc
LD = ld
SU = sudo
TG = ctags
BUILD = $(PWD)/build
MNT = $(PWD)/mnt
SRC = ./src
INC = ./inc
SRCS = $(shell find $(SRC) -type f -name '*.c')
OBJS = $(SRCS:%=$(BUILD)/%.o)
CFLAGS_DEBUG = -Wno-error -Wno-unused -fsanitize=address -fsanitize=undefined -fstack-protector-all
CFLAGS_WARNINGS = -Wall -Wextra -Werror -Wshadow -Wpointer-arith -Wwrite-strings -Wredundant-decls -Wnested-externs -Wformat=2 -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wswitch-default -Wswitch-enum -Wunreachable-code -Wundef -Wold-style-definition -Wvla -pedantic-errors
CFLAGS = $(CFLAGS_WARNINGS) -std=c11 -fno-profile-generate -fno-omit-frame-pointer -fno-common -fno-asynchronous-unwind-tables -mno-red-zone -Ofast -D_DEFAULT_SOURCE -I$(INC) $(shell pkg-config fuse3 --cflags --libs) $(CFLAGS_DEBUG)
all: $(BUILD) $(OBJS)
compile: all sync
clean:
@rm -rf $(BUILD)/*
clean_disk:
@rm -rf $(BUILD)/*.img
run: mount
sync: # Ugly hack
@$(MAKE) --always-make --dry-run | grep -wE 'gcc' | jq -nR '[inputs|{directory: ".", command: ., file: match(" [^ ]+$$").string[1:]}]' >compile_commands.json &
@$(TG) -R --exclude=.git --exclude=build . &
$(BUILD)/%.c.o: %.c
@$(CC) $(CFLAGS) $< -o $(patsubst $(BUILD)/$(SRC)/%.c.o,$(BUILD)/marfs_%,$@)
.PHONY: all run compile clean clean_disk sync mount umount
$(BUILD):
@mkdir -p $@
$(MNT):
@mkdir -p $@
mount: disk $(MNT)
@DEV=$$($(SU) losetup -a | grep $(BUILD)/disk.img | grep -m 1 -o '/dev/loop[[:digit:]]*') && \
PART="p1" && \
($(SU) $(BUILD)/marfs_fuse "$$DEV$$PART" -f $(MNT) -o allow_other &) && \
echo "Mounted $$DEV$$PART"
umount:
@DEV=$$($(SU) losetup -a | grep $(BUILD)/disk.img | grep -m 1 -o '/dev/loop[[:digit:]]*') && \
$(SU) losetup -d "$$DEV" && \
$(SU) umount $(MNT) && \
echo "Unmounted $$DEV$$PART" || \
echo "No disk to unmount"
disk: $(BUILD)/disk.img
%.img: compile clean_disk $(BUILD)
@dd if=/dev/zero of=$@ bs=1k count=32k status=none
@DEV=$$($(SU) losetup --find --partscan --show $@) && \
PART="p1" && \
$(SU) parted -s "$$DEV" mklabel msdos mkpart primary 32k 100% -a minimal set 1 boot on && \
$(SU) ./build/marfs_mkfs "$$DEV$$PART" && \
echo "Created $$DEV$$PART. Please run '$(MAKE) umount' afterwards"
|