-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
140 lines (123 loc) · 3.35 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
ifeq ($(DEBUG),true)
OPT_CFLAGS := -O0 -g3 -ftrapv -fstack-protector-all -D_FORTIFY_SOURCE=2
OPT_LDLIBS := -lssp
ifneq ($(shell echo $$OSTYPE),cygwin)
OPT_CFLAGS += -fsanitize=address -fno-omit-frame-pointer
OPT_LDLIBS += -fsanitize=address
endif
else
ifeq ($(OPT),true)
OPT_CFLAGS := -flto -Ofast -march=native -DNDEBUG
OPT_LDFLAGS := -flto -s
else
ifeq ($(LTO),true)
OPT_CFLAGS := -flto -DNDEBUG
OPT_LDFLAGS := -flto
else
OPT_CFLAGS := -O3 -DNDEBUG
OPT_LDFLAGS := -s
endif
endif
endif
WARNING_CFLAGS := \
-Wall \
-Wextra \
-Wabi \
-Wcast-align \
-Wcast-qual \
-Wconversion \
-Wdisabled-optimization \
-Wdouble-promotion \
-Wfloat-equal \
-Wformat=2 \
-Winit-self \
-Winline \
-Wlogical-op \
-Wmissing-declarations \
-Wpointer-arith \
-Wredundant-decls \
-Wstrict-aliasing=2 \
-Wsuggest-attribute=const \
-Wsuggest-attribute=noreturn \
-Wsuggest-attribute=pure \
-Wswitch-enum \
-Wundef \
-Wunsafe-loop-optimizations \
-Wunreachable-code \
-Wwrite-strings \
-Wc++-compat \
-Wbad-function-cast \
-Wjump-misses-init \
-Wmissing-prototypes \
-Wunsuffixed-float-constants \
-Wno-unused-result \
-pedantic
MAX_SOURCE_SIZE ?= 65536
MAX_BYTECODE_SIZE ?= 1048576
MAX_LABEL_LENGTH ?= 65536
MAX_N_LABEL ?= 1024
UNDEF_LIST_SIZE ?= 256
STACK_SIZE ?= 65536
HEAP_SIZE ?= 65536
CALL_STACK_SIZE ?= 65536
WS_INT ?= int
WS_ADDR_INT ?= 'unsigned int'
INDENT_STR ?= '" "'
MACROS ?= -DMAX_SOURCE_SIZE=$(MAX_SOURCE_SIZE) \
-DMAX_BYTECODE_SIZE=$(MAX_BYTECODE_SIZE) \
-DMAX_LABEL_LENGTH=$(MAX_LABEL_LENGTH) \
-DMAX_N_LABEL=$(MAX_N_LABEL) \
-DUNDEF_LIST_SIZE=$(UNDEF_LIST_SIZE) \
-DSTACK_SIZE=$(STACK_SIZE) \
-DHEAP_SIZE=$(HEAP_SIZE) \
-DCALL_STACK_SIZE=$(CALL_STACK_SIZE) \
-DWS_INT=$(WS_INT) \
-DWS_ADDR_INT=$(WS_ADDR_INT) \
-DINDENT_STR=$(INDENT_STR)
CC := gcc $(if $(STDC), $(addprefix -std=, $(STDC)),)
MAKE := make
MKDIR := mkdir -p
CP := cp
RM := rm -f
CTAGS := ctags
CFLAGS := -pipe $(WARNING_CFLAGS) $(OPT_CFLAGS)
CPPFLAGS := $(MACROS)
LDFLAGS := -pipe $(OPT_LDFLAGS)
CTAGSFLAGS := -R --languages=c
LDLIBS := $(OPT_LDLIBS)
TARGET := whitespace
OBJS := $(addsuffix .o, $(basename $(TARGET)))
SRCS := $(OBJS:.o=.c)
DEPENDS := depends.mk
ifeq ($(OS),Windows_NT)
TARGET := $(addsuffix .exe, $(TARGET))
else
TARGET := $(addsuffix .out, $(TARGET))
endif
INSTALLED_TARGET := $(if $(PREFIX), $(PREFIX),/usr/local)/bin/$(TARGET)
%.exe:
$(CC) $(LDFLAGS) $(filter %.c %.o, $^) $(LDLIBS) -o $@
%.out:
$(CC) $(LDFLAGS) $(filter %.c %.o, $^) $(LDLIBS) -o $@
.PHONY: all test depends syntax ctags install uninstall clean cleanobj
all: $(TARGET)
$(TARGET): $(OBJS)
$(foreach SRC,$(SRCS),$(eval $(filter-out \,$(shell $(CC) -MM $(SRC)))))
test: $(TARGET)
$(MAKE) -C t/
depends:
$(CC) -MM $(SRCS) > $(DEPENDS)
syntax:
$(CC) $(SRCS) $(STD_CFLAGS) -fsyntax-only $(WARNING_CFLAGS) $(INCS) $(MACROS)
ctags:
$(CTAGS) $(CTAGSFLAGS)
install: $(INSTALLED_TARGET)
$(INSTALLED_TARGET): $(TARGET)
@[ ! -d $(@D) ] && $(MKDIR) $(@D) || :
$(CP) $< $@
uninstall:
$(RM) $(INSTALLED_TARGET)
clean:
$(RM) $(TARGET) $(OBJS)
cleanobj:
$(RM) $(OBJS)