aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 42176f070c6ba74e3fd816035e1de6b275214b71 (plain)
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
CC=gcc
CFLAGS=-std=c17 -Wall -Werror -g
test_framework=criterion

# Directories
bin_dir=bin
obj_dir=obj
src_dir=src
test_dir=tests

# Files
src_files=$(wildcard $(src_dir)/*.c)
obj_files=$(patsubst $(src_dir)/%.c, $(obj_dir)/%.o, $(src_files))
test_files=$(wildcard $(test_dir)/*.c)
test_bins=$(patsubst $(test_dir)/%.c, $(bin_dir)/%, $(test_files))

# Actions
.PHONY: all
all: test

.PHONY: test
test: $(test_bins)
	for test in $(test_bins); do ./$$test --verbose; done

.PHONY: clean
clean:
	rm -r $(bin_dir) $(obj_dir)

.PHONY: info
info:
	@printf "src_files: %s\n" $(src_files)
	@printf "obj_files: %s\n" $(obj_files)
	@printf "test_files: %s\n" $(test_files)
	@printf "test_bins: %s\n" $(test_bins)

# Make Directories
$(obj_dir):
	mkdir $@

$(bin_dir):
	mkdir $@

# Make object files
$(obj_dir)/%.o: $(src_dir)/%.c $(obj_dir)
	$(CC) $(CFLAGS) -o $@ -c $<

# Make test binaries
$(bin_dir)/%: $(bin_dir) $(test_files) $(obj_files)
	$(CC) $(CFLAGS) -o $@ -l $(test_framework) $(filter-out $<,$^)