-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
36 lines (27 loc) · 962 Bytes
/
Makefile
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
# Change this to `gcc` if you would prefer to use `gcc` for building.
CC = clang
# Enable all warnings and treat them as errors.
# NOTE: To enable AddressSanitizer, add `-fsanitize=address` | `-fsanitize=undefined`.
CFLAGS = -std=c23 -I./src -Wall -Wextra -Werror -g $(shell llvm-config --cflags)
# Link with libLLVM.
LDFLAGS = $(shell llvm-config --libs --ldflags)
# Compile all C files within the source directory.
SOURCES = $(shell find ./src -iname "*.c")
OBJECTS = $(SOURCES:./src/%.c=./build/%.o)
.PHONY: prepare
prepare:
mkdir -p build
.PHONY: clangd
setup-clangd: prepare
bear --output ./build/compile_commands.json -- make build
.PHONY: build
build: prepare $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -fsanitize=address -o ./build/petal
build/%.o: src/%.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
INSTALL_DIR = $(HOME)/.local/bin
.PHONY: install
install: build
mkdir -p $(INSTALL_DIR)
install -Dm755 ./build/petal $(INSTALL_DIR)/petal