aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 0812c553d721bea5a58f6415707fe4cda6930f4d (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
BIN        := halk
PREFIX     := /usr/local/bin
CC         := gcc
REG_CFLAGS := -std=c99 -O3 -s
DBG_CFLAGS := -std=c99 -Og -ggdb -pedantic 
DBG_CFLAGS += -Wall -Wextra -Wformat -Wpedantic
DBG_CFLAGS += -fsanitize=address -fno-omit-frame-pointer -DDBG
CFLAGS     := none
SRCS       := $(wildcard src/*.c)
SRCS       := $(filter-out %stack.c,$(SRCS))	# Filter out unused stack code.
OBJS       := $(SRCS:.c=.o)
TEST_SRCS  := $(wildcard test/*.c)
TEST_OUTS  := $(TEST_SRCS:.c=.out)

.PHONY: all reg_options dbg_options halk dbg install uninstall clean test me a sandwich

all: halk

options:
	@echo "HALK build options:"
	@echo "CC:         $(CC)"
	@echo "CFLAGS:     $(CFLAGS)"
	@echo

halk: CFLAGS := $(REG_CFLAGS)
halk: options $(OBJS)
	$(CC) $(OBJS) $(REG_CFLAGS) -o $(BIN).out

dbg: CFLAGS := $(DBG_CFLAGS)
dbg: clean options $(OBJS)
	$(CC) $(OBJS) $(DBG_CFLAGS) -o $(BIN).out

test: CFLAGS := $(REG_CFLAGS)
test: $(TEST_OUTS)
	set -e
	for f in $(TEST_OUTS); do ./$$f; done

%.o: %.c
	$(CC) -c $< -o $@ $(CFLAGS)

%.out: %.c
	$(CC) $< $(filter-out %main.o,$(OBJS)) -o $@ $(CFLAGS)

install: all
	mkdir -p $(PREFIX)
	cp -f $(BIN).out $(PREFIX)/$(BIN)
	chmod 755 $(PREFIX)/$(BIN)

uninstall:
	rm -f $(PREFIX)/$(BIN)

clean:
	rm -f $(BIN).out src/*.o test/*.out

me a:
	@exit

sandwich:
	@[ "$(shell id -u)" = 0 ] && echo "Okay." || echo "What? Make it yourself."