nbos

nbos

https://git.tonybtw.com/nbos.git git://git.tonybtw.com/nbos.git
1,410 bytes raw
1
CC      ?= cc
2
CFLAGS  ?= -std=c23 -O2 -g \
3
           -Wall -Wextra -Wpedantic -Wshadow -Wconversion \
4
           -Wstrict-prototypes -Wmissing-prototypes \
5
           -Wno-unused-parameter \
6
           -fno-strict-aliasing
7
LDFLAGS ?=
8
9
PROFILE ?= release
10
ifdef SANITIZE
11
    PROFILE := sanitize
12
    CFLAGS  += -fsanitize=address,undefined -fno-omit-frame-pointer
13
    LDFLAGS += -fsanitize=address,undefined
14
endif
15
16
BUILD_DIR := .build/$(PROFILE)
17
18
INCLUDES = -Iinclude -Isrc
19
20
SRC_FILES = \
21
    src/main.c \
22
    src/arena.c \
23
    src/error.c \
24
    src/hash.c \
25
    src/store.c \
26
    src/resolve.c \
27
    src/validate.c \
28
    src/fetch.c \
29
    src/sandbox.c \
30
    src/build.c \
31
    src/run.c \
32
    src/realize.c \
33
    src/activate.c
34
35
PKG_FILES = $(shell find pkgs -name '*.c')
36
CONFIG_FILE ?= etc-example/config.c
37
38
ALL_SRCS  = $(SRC_FILES) $(PKG_FILES) $(CONFIG_FILE)
39
OBJ_FILES = $(patsubst %.c,$(BUILD_DIR)/%.o,$(ALL_SRCS))
40
DEP_FILES = $(OBJ_FILES:.o=.d)
41
42
.PHONY: all clean registry switch
43
44
all: nb
45
46
nb: $(BUILD_DIR)/nb
47
	@ln -sf $< $@
48
49
$(BUILD_DIR)/nb: $(OBJ_FILES)
50
	$(CC) $(LDFLAGS) -o $@ $^
51
52
$(BUILD_DIR)/%.o: %.c
53
	@mkdir -p $(@D)
54
	$(CC) $(CFLAGS) $(INCLUDES) -MMD -MP -c -o $@ $<
55
56
-include $(DEP_FILES)
57
58
registry:
59
	./tools/gen-registry.sh > pkgs/all.h.tmp
60
	mv pkgs/all.h.tmp pkgs/all.h
61
	./tools/gen-registry.sh --c > pkgs/all.c.tmp
62
	mv pkgs/all.c.tmp pkgs/all.c
63
64
clean:
65
	rm -rf .build nb
66
67
switch: nb
68
	./nb switch