aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: f772350d12fa83067ddd40c8bf4d3e62b4341610 (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 -Werror
else
	CFLAGS += -O3
endif

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


TEST_1_NAME = t/test_1$(BIN_POSTFIX)
TEST_2_NAME = t/test_2$(BIN_POSTFIX)

examples=hello variable
example_bins=$(examples:%=examples/%$(BIN_POSTFIX))
example_objs=$(examples:%=examples/%.o)

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

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

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

$(TEST_1_NAME): t/test_1.c $(LIBNAME)
	$(CC) $(CFLAGS) -o $@ $< -lctemplates

$(TEST_2_NAME): t/test_2.c $(LIBNAME)
	$(CC) $(CFLAGS) -o $@ $< -lctemplates

test: $(TEST_1_NAME) $(TEST_2_NAME)
	#$(TEST_1_NAME)
	$(TEST_2_NAME)

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/