-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
126 lines (111 loc) · 3.43 KB
/
Makefile
File metadata and controls
126 lines (111 loc) · 3.43 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
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
OS ?= ubuntu
PLATFORM ?= x86_64
CONFIG ?= debug
D_COMPILER ?= dmd
DC ?= dmd
SRCDIR := src
TARGET_SUBDIR := $(PLATFORM)_$(CONFIG)
OBJDIR := obj/$(TARGET_SUBDIR)
TARGETDIR := bin/$(TARGET_SUBDIR)
TARGETNAME := urt
# unittest config adjustments
ifeq ($(CONFIG),unittest)
TARGETNAME := $(TARGETNAME)_test
BUILD_TYPE := exe
else
BUILD_TYPE := lib
endif
DEPFILE := $(OBJDIR)/$(TARGETNAME).d
DFLAGS := $(DFLAGS) -preview=bitfields -preview=rvaluerefparam -preview=nosharedaccess -preview=in
ifeq ($(OS),windows)
SOURCES := $(shell dir /s /b $(SRCDIR)\\*.d)
else
SOURCES := $(shell find "$(SRCDIR)" -type f -name '*.d')
endif
# Set target file based on build type and OS
ifeq ($(BUILD_TYPE),exe)
BUILD_CMD_FLAGS :=
ifeq ($(OS),windows)
TARGET = $(TARGETDIR)/$(TARGETNAME).exe
else
TARGET = $(TARGETDIR)/$(TARGETNAME)
endif
else # lib
BUILD_CMD_FLAGS := -lib
ifeq ($(OS),windows)
TARGET = $(TARGETDIR)/$(TARGETNAME).lib
else
TARGET = $(TARGETDIR)/lib$(TARGETNAME).a
endif
endif
ifeq ($(D_COMPILER),ldc)
DFLAGS := $(DFLAGS) -I $(SRCDIR)
ifeq ($(PLATFORM),x86_64)
# DFLAGS := $(DFLAGS) -mtriple=x86_64-linux-gnu
else ifeq ($(PLATFORM),x86)
ifeq ($(OS),windows)
DFLAGS := $(DFLAGS) -mtriple=i686-windows-msvc
else
DFLAGS := $(DFLAGS) -mtriple=i686-linux-gnu
endif
else ifeq ($(PLATFORM),arm64)
DFLAGS := $(DFLAGS) -mtriple=aarch64-linux-gnu
else ifeq ($(PLATFORM),arm)
DFLAGS := $(DFLAGS) -mtriple=arm-linux-eabihf -mcpu=cortex-a7
else ifeq ($(PLATFORM),riscv64)
# we are building the Sipeed M1s device... which is BL808 as I understand
DFLAGS := $(DFLAGS) -mtriple=riscv64-unknown-elf -mcpu=c906 -mattr=+m,+a,+f,+c,+v
else
$(error "Unsupported platform: $(PLATFORM)")
endif
ifeq ($(CONFIG),release)
DFLAGS := $(DFLAGS) -release -O3 -enable-inlining
else
DFLAGS := $(DFLAGS) -g -d-debug
endif
else ifeq ($(D_COMPILER),dmd)
DFLAGS := $(DFLAGS) -I=$(SRCDIR)
ifeq ($(PLATFORM),x86_64)
# DFLAGS := $(DFLAGS) -m64
else ifeq ($(PLATFORM),x86)
DFLAGS := $(DFLAGS) -m32
else
$(error "Unsupported platform: $(PLATFORM)")
endif
ifeq ($(CONFIG),release)
DFLAGS := $(DFLAGS) -release -O -inline
else
DFLAGS := $(DFLAGS) -g -debug
endif
else
$(error "Unknown D compiler: $(D_COMPILER)")
endif
ifeq ($(CONFIG),unittest)
DFLAGS := $(DFLAGS) -unittest
endif
-include $(DEPFILE)
$(TARGET):
ifeq ($(OS),windows)
@if not exist "obj" mkdir "obj" > nul 2>&1
@if not exist "$(subst /,\,$(OBJDIR))" mkdir "$(subst /,\,$(OBJDIR))" > nul 2>&1
@if not exist "bin" mkdir "bin" > nul 2>&1
@if not exist "$(subst /,\,$(TARGETDIR))" mkdir "$(subst /,\,$(TARGETDIR))" > nul 2>&1
else
mkdir -p $(OBJDIR) $(TARGETDIR)
endif
ifeq ($(D_COMPILER),ldc)
"$(DC)" $(DFLAGS) $(BUILD_CMD_FLAGS) -of$(TARGET) -od$(OBJDIR) -deps=$(DEPFILE) $(SOURCES)
else ifeq ($(D_COMPILER),dmd)
ifeq ($(BUILD_TYPE),lib)
"$(DC)" $(DFLAGS) $(BUILD_CMD_FLAGS) -of$(notdir $(TARGET)) -od$(OBJDIR) -makedeps $(SOURCES) > $(DEPFILE)
ifeq ($(OS),windows)
move "$(subst /,\,$(OBJDIR))\\$(notdir $(TARGET))" "$(subst /,\,$(TARGETDIR))" > nul
else
mv "$(OBJDIR)/$(notdir $(TARGET))" "$(TARGETDIR)"
endif
else # exe
"$(DC)" $(DFLAGS) $(BUILD_CMD_FLAGS) -of$(TARGET) -od$(OBJDIR) -makedeps $(SOURCES) > $(DEPFILE)
endif
endif
clean:
rm -rf $(OBJDIR) $(TARGETDIR)