All: rename stepA_interop to stepA_mal
[jackhill/mal.git] / c / Makefile
1 USE_READLINE ?=
2 CFLAGS += -g
3 LDFLAGS += -g
4
5 #####################
6
7 TESTS =
8
9 SOURCES_BASE = readline.h readline.c types.h types.c \
10 reader.h reader.c printer.h printer.c \
11 interop.h interop.c
12 SOURCES_LISP = env.c core.h core.c stepA_mal.c
13 SOURCES = $(SOURCES_BASE) $(SOURCES_LISP)
14
15
16 #####################
17
18 SRCS = step0_repl.c step1_read_print.c step2_eval.c step3_env.c \
19 step4_if_fn_do.c step5_tco.c step6_file.c step7_quote.c \
20 step8_macros.c step9_try.c stepA_mal.c
21 OBJS = $(SRCS:%.c=%.o)
22 BINS = $(OBJS:%.o=%)
23 OTHER_OBJS = types.o readline.o reader.o printer.o env.o core.o interop.o
24 OTHER_HDRS = types.h readline.h reader.h printer.h core.h interop.h
25
26 GLIB_CFLAGS ?= $(shell pkg-config --cflags glib-2.0)
27 GLIB_LDFLAGS ?= $(shell pkg-config --libs glib-2.0)
28
29 ifeq (,$(USE_READLINE))
30 RL_LIBRARY ?= edit
31 else
32 RL_LIBRARY ?= readline
33 CFLAGS += -DUSE_READLINE=1
34 endif
35
36 CFLAGS += $(GLIB_CFLAGS)
37 LDFLAGS += -l$(RL_LIBRARY) $(GLIB_LDFLAGS) -ldl -lffi
38
39 #####################
40
41 all: $(BINS) mal
42
43 mal: $(word $(words $(BINS)),$(BINS))
44 cp $< $@
45
46 $(OBJS) $(OTHER_OBJS): %.o: %.c $(OTHER_HDRS)
47 gcc $(CFLAGS) -c $(@:%.o=%.c) -o $@
48
49 $(patsubst %.o,%,$(filter step%,$(OBJS))): $(OTHER_OBJS)
50 $(BINS): %: %.o
51 gcc $+ -o $@ $(LDFLAGS)
52
53 clean:
54 rm -f $(OBJS) $(BINS) $(OTHER_OBJS) mal
55
56 .PHONY: stats stats-lisp tests $(TESTS)
57
58 stats: $(SOURCES)
59 @wc $^
60 stats-lisp: $(SOURCES_LISP)
61 @wc $^
62
63 tests: $(TESTS)
64
65 $(TESTS):
66 @echo "Running $@"; \
67 ./$@ || exit 1; \