-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
80 lines (55 loc) · 1.86 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
# A basic build file to create executable targets for the various levels
# of optimization for each supported language.
## GLOBAL SETTINGS ##
S = @
CONFIG = debug
PLATFORM = macosx
ARCH = x86_64
MODULE_NAME = tool
MACH_O_TYPE = mh_execute
ROOT_DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BUILD_DIR = $(ROOT_DIR)/build
SRC_DIR = $(ROOT_DIR)/src
TOOLCHAIN = Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/$(PLATFORM)
TOOLCHAIN_PATH = $(shell xcode-select --print-path)/$(TOOLCHAIN)
SDK_PATH = $(shell xcrun --show-sdk-path -sdk $(PLATFORM))
CLANG = $(shell which clang)
SWIFT = $(shell xcrun -f swiftc)
LD = $(shell xcrun -f ld)
## LANGUAGE FLAGS ##
ANSIC_SOURCE = $(SRC_DIR)/main.c
ANSIC_LDFLAGS = -arch $(ARCH) -std=gnu99 -stdlib=libstdc++
SWIFT_SOURCE = $(wildcard $(SRC_DIR)/*.swift) $(wildcard $(SRC_DIR)/tests/*.swift)
SWIFT_LDFLAGS = -sdk $(SDK_PATH) -whole-module-optimization
.PHONY: test
test: clean ansic swift
$(S)echo
$(S) $(BUILD_DIR)/ansic_O0
$(S)echo
$(S) $(BUILD_DIR)/ansic_Os
$(S)echo
$(S) $(BUILD_DIR)/ansic_Ofast
$(S)echo
$(S) $(BUILD_DIR)/swift_Onone
$(S)echo
$(S) $(BUILD_DIR)/swift_O
$(S)echo
$(S) $(BUILD_DIR)/swift_Ounchecked
.PHONY: clean
clean:
$(S)rm -rf build
.PHONY: build_dir
build_dir:
$(S)mkdir -p $(BUILD_DIR)
## ANSIC LANGUAGE SETTINGS ##
.PHONY: ansic
ansic: build_dir ansic_O0 ansic_Os ansic_Ofast
ansic_%: build_dir
$(S)echo "> Building ANSI C -$*"
$(S)$(CLANG) -DOPT_$*=1 -$* $(ANSIC_LDFLAGS) -o $(BUILD_DIR)/ansic_$* $(ANSIC_SOURCE)
## SWIFT LANGUAGE SETTINGS ##
.PHONY: swift
swift: build_dir swift_Onone swift_O swift_Ounchecked
swift_%:
$(S)echo "> Building Swift -$*"
$(S)$(SWIFT) -D OPT_$* -$* $(SWIFT_LDFLAGS) -o $(BUILD_DIR)/swift_$* $(SWIFT_SOURCE)