-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
52 lines (36 loc) · 1.28 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
COMPILER = $(shell xcrun -f swiftc)
LIBTOOL = $(shell xcrun -f libtool)
LIBS = $(shell xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
SRC_DIR = src
INC_DIR = include
OBJ_DIR = obj
BIN_DIR = bin
SAMPLE_DIR = sample
SRCS = $(shell find $(SRC_DIR) -name '*.swift')
OBJS = $(subst $(SRC_DIR),$(OBJ_DIR),$(SRCS:.swift=.o))
MODULE = PureSwiftUnit
MODFLAGS = -module-name $(MODULE) -emit-module
OBJFLAGS = -module-name $(MODULE) -emit-library -emit-object
BINFLAGS = -lc -L$(LIBS) -dynamic
INCLUDE_FILE = $(INC_DIR)/$(MODULE).swiftmodule
DYLIB_FILE = $(CURDIR)/$(BIN_DIR)/lib$(MODULE).dylib
.PHONY: default all includes libs sample clean
default: $(INCLUDE_FILE) $(DYLIB_FILE)
$(INCLUDE_FILE): $(SRCS)
@[ -d $(INC_DIR) ] || mkdir -p $(INC_DIR)
cd $(INC_DIR); $(COMPILER) $(MODFLAGS) $(addprefix ../,$^)
$(DYLIB_FILE): $(OBJS)
@[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
$(LIBTOOL) $(BINFLAGS) -o $@ $^
$(OBJS): $(SRCS)
@[ -d $(OBJ_DIR) ] || mkdir -p $(OBJ_DIR)
cd $(OBJ_DIR); $(COMPILER) $(OBJFLAGS) $(addprefix ../,$^)
all: clean default
includes: $(INCLUDE_FILE)
@echo "-I$(CURDIR)/$(INC_DIR)"
libs: $(DYLIB_FILE)
@echo "-L$(CURDIR)/$(BIN_DIR) -l$(MODULE)"
sample: $(INCLUDE_FILE) $(DYLIB_FILE)
@cd $(SAMPLE_DIR); make
clean:
rm -rf $(INC_DIR) $(OBJ_DIR) $(BIN_DIR)