-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
71 lines (56 loc) · 1.37 KB
/
Makefile
File metadata and controls
71 lines (56 loc) · 1.37 KB
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
# parameters
NO_LIBC ?= 0
ADD_CFLAGS ?=
ADD_LDFLAGS ?=
LIB_OPT ?= -O3
TEST_OPT ?= -O1
# C compiler
CFLAGS := -Wall -Werror -Wno-unused-result
ifneq ($(NO_LIBC), 0)
CFLAGS += -DNO_LIBC
ifneq ($(shell uname), Darwin)
CFLAGS += -nostdlib -nostdinc -static
endif
endif
CC := clang $(CFLAGS) $(ADD_CFLAGS)
# archiver
ARFLAGS := rc
AR := llvm-ar $(ARFLAGS)
# ranlib
RANLIBFLAGS :=
RANLIB := llvm-ranlib $(RANLIBFLAGS)
# directories
TOP_DIR := $(shell pwd)
SRC_DIR := $(TOP_DIR)/src
TEST_DIR := $(TOP_DIR)/test
BUILD_DIR := $(TOP_DIR)/build
OBJ_DIR := $(BUILD_DIR)/obj
BUILT_TEST_DIR := $(BUILD_DIR)/test
# files
SRCS := $(SRC_DIR)/sysy.c
ifneq ($(NO_LIBC), 0)
SRCS += $(shell find $(SRC_DIR)/nolibc -name "*.c")
endif
OBJS := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS))
TEST_SRCS := $(shell find $(TEST_DIR) -name "*.c")
# targets
LIBSYSY := $(BUILD_DIR)/libsysy.a
TESTS := $(patsubst $(TEST_DIR)/%.c, $(BUILT_TEST_DIR)/%, $(TEST_SRCS))
.PHONY: libsysy test clean
libsysy: $(LIBSYSY)
test: $(TESTS)
clean:
-rm -rf $(OBJ_DIR)
-rm -rf $(BUILT_TEST_DIR)
-rm $(LIBSYSY)
FORCE: ;
$(LIBSYSY): $(OBJS)
mkdir -p $(dir $@)
$(AR) $@ $^
$(RANLIB) $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
mkdir -p $(dir $@)
$(CC) $^ -o $@ -I$(SRC_DIR) -c $(LIB_OPT)
$(BUILT_TEST_DIR)/%: $(TEST_DIR)/%.c $(LIBSYSY)
mkdir -p $(dir $@)
$(CC) $(ADD_LDFLAGS) $< -o $@ -I$(SRC_DIR) -L$(BUILD_DIR) -lsysy $(TEST_OPT)