-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
48 lines (36 loc) · 1.2 KB
/
Makefile
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
TARGET = refal
INSTALLDIR = /bin
SOURCES_ROOT = $(PROJECT_ROOT)src/
HEADERS := $(notdir $(wildcard $(SOURCES_ROOT)*.h))
SOURCES := main.c interpreter.c library.c message_print.c translator.c
CFLAGS := -std=c18 -Wall
ifeq ($(BUILD_MODE),debug)
CFLAGS := -DDEBUG -g $(CFLAGS) $(DEFINES)
else ifeq ($(BUILD_MODE),run)
CFLAGS := -O2 $(CFLAGS) $(DEFINES)
else ifeq ($(BUILD_MODE),)
CFLAGS := -DNDEBUG -O2 -flto $(CFLAGS) $(DEFINES)
LDFLAGS := -flto $(LDFLAGS)
else
$(error Build mode $(BUILD_MODE) not supported by this Makefile)
endif
OBJECTS = $(notdir $(SOURCES:.c=.o))
PROJECT_ROOT = $(dir $(lastword $(MAKEFILE_LIST)))
.PHONY: all clean install uninstall test
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) -o $@ $^ $(LDFLAGS)
$(OBJECTS):%.o: $(SOURCES_ROOT)%.c $(addprefix $(SOURCES_ROOT),$(HEADERS))
$(CC) -c $(CFLAGS) -o $@ $<
clean:
$(RM) $(TARGET) $(OBJECTS)
test: $(TARGET)
ls $(PROJECT_ROOT)tests/*.ref | while read filename ; do \
echo $${filename}; \
./$(TARGET) +n "$${filename}" | diff - "$${filename}.эталон"; \
done
echo "main (.1)(.2) = <Prout .1 .2>;" | ./$(TARGET) - Ok
install: $(TARGET)
install --strip $(TARGET) $(INSTALLDIR)
uninstall:
rm --force $(INSTALLDIR)/$(TARGET)