aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: dfa9bf002273d3c17b7703b795d523fe7a933e2c (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
50
51
52
53
54
CFLAGS+= -Isrc/ -L. -std=c99 -pedantic
CC?=gcc
LIBNAME = libctemplates.a
BIN_POSTFIX = .exe

ifeq ($(DEBUG),true)
	CFLAGS += -g -O0 -Wall -Wextra -Werror
else
	CFLAGS += -O3
endif

objs = ctemplates fbuf hashmap kmp lexer
objfiles = $(objs:%=build/%.o)


test_srcs = $(wildcard t/*.c)
test_objs = $(test_srcs:%.c=%.o)
test_bins = $(test_srcs:%.c=%)


$(LIBNAME): $(objfiles)
	ar rc $@ $^
	ranlib $@

$(objfiles) : build/%.o : src/%.c src/%.h
	$(CC) $(CFLAGS) -c -o $@ $<

clean:
	$(RM) build/*.o *.a $(LIBNAME)

test: $(test_bins)
	./test_1.exe
	./test_2.exe
	./test_3.ext

$(test_bins) : % : %.o
	$(CC) -Iinclude/ -o $@ $< libctemplates.a

$(test_objs) : %.o : %.c $(LIBNAME)
	$(CC) -Iinclude/ -o $@ -c $<

examples: $(example_bins)
	$(example_bins)

$(example_bins): %$(BIN_POSTFIX) : %.o
	$(CC) $(CFLAGS) -o $@ $< -lctemplates

$(example_objs): %.o : %.c
	$(CC) -I./include -L. -c -o $@ $< -lctemplates

install: $(LIBNAME)
	cp $(LIBNAME) /usr/local/lib
	mkdir -p /usr/local/include/ctemplates
	cp include/ctemplates.h /usr/local/include/ctemplates/