-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMakefile
69 lines (51 loc) · 1.49 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
default: all
SRC_DIRS := . src src/libmld src/libp src/libu src/libxmalloc src/uopt src/uopt/debug
AVOID_UB ?= 1
ARCH ?= x86
# Build uopt with ncurses debugging
DEBUG ?= 1
ifeq ($(ARCH),x86)
CC := gcc
ENDIANNESS := -DUOPT_LITTLE_ENDIAN
ARCH_FLAGS := -m32 -mfpmath=sse -msse2 -ffp-contract=off $(ENDIANNESS)
ifeq ($(DEBUG),1)
ARCH_FLAGS += -lncurses -DUOPT_DEBUG
OPTIMIZATION := -Og -flto=auto -ggdb3
#OPTIMIZATION := -O0 -ggdb3
else
OPTIMIZATION := -Og -flto=auto -ggdb3
#OPTIMIZATION := -O2 -march=native -mtune=native -flto=auto
endif
else ifeq ($(ARCH),mips)
CC := mips-linux-gnu-gcc
ARCH_FLAGS := -fPIC -mips2 -mfp32
OPTIMIZATION := -ggdb3
else
$(error unsupported arch "$(ARCH)")
endif
CFLAGS := -I src -I src/uopt -I src/uopt/debug -Wall $(ARCH_FLAGS) $(OPTIMIZATION)
LDFLAGS := $(ARCH_FLAGS) $(OPTIMIZATION) -lm
ifeq ($(AVOID_UB),1)
CFLAGS += -DAVOID_UB
endif
ifeq ($(ARCH),mips)
BUILD_DIR := build_mips
else
BUILD_DIR := build
endif
ALL_DIRS := $(addprefix $(BUILD_DIR)/,$(SRC_DIRS))
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
O_FILES := $(addprefix $(BUILD_DIR)/,$(C_FILES:.c=.o))
DEP_FILES := $(O_FILES:.o=.d)
# Ensure build directories exist before compiling anything
DUMMY != mkdir -p $(ALL_DIRS)
TARGET := $(BUILD_DIR)/uopt
all: $(TARGET)
$(TARGET): $(O_FILES)
$(CC) -o $@ $^ $(LDFLAGS)
$(BUILD_DIR)/%.o: %.c
$(CC) -MMD -c $(CFLAGS) -o $@ $<
clean:
$(RM) -r $(BUILD_DIR)
.PHONY: all clean default
-include $(DEP_FILES)