-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
126 lines (111 loc) · 2.95 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
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
## Makefile Method for making torch into a module for any lua
## Daniel D. Lee, Feb 2013.
## <[email protected]>
## Stephen McGill, Apr 2014
## <[email protected]>
TORCH_SOURCES=\
lib/TH/THBlas.c \
lib/TH/THDiskFile.c \
lib/TH/THFile.c \
lib/TH/THGeneral.c \
lib/TH/THLapack.c \
lib/TH/THLogAdd.c \
lib/TH/THMemoryFile.c \
lib/TH/THRandom.c \
lib/TH/THStorage.c \
lib/TH/THTensor.c \
lib/TH/THAllocator.c \
lib/luaT/luaT.c \
Generator.c \
DiskFile.c \
File.c \
MemoryFile.c \
PipeFile.c \
Storage.c \
Tensor.c \
TensorMath.c \
TensorOperator.c \
Timer.c \
init.c \
random.c \
utils.c
TORCH_OBJECTS=$(TORCH_SOURCES:.c=.o)
CFLAGS= \
-std=c99 -pedantic \
-c \
-I/usr/local/include \
-I/usr/include/lua \
-I/usr/include/lua5.1 \
-Ilib/luaT -Ilib/TH -I. \
-O3 -fpic\
-fno-stack-protector \
-fomit-frame-pointer \
-DTH_EXPORTS -DHAVE_MMAP=1 \
-DUSE_SSE3 -DUSE_SSE2 -DNDEBUG \
-DC_HAS_THREAD -DTH_HAVE_THREAD \
-march=native -mtune=native
#-Wall -Wno-unused-function -Wno-unknown-pragmas
ifndef OSTYPE
OSTYPE = $(shell uname -s|awk '{print tolower($$0)}')
endif
ifeq ($(OSTYPE),darwin)
CC=clang
LD=ld -macosx_version_min 10.8
SED=sed -i '' -e
LDFLAGS=-undefined dynamic_lookup \
-framework Accelerate \
-lm \
-L/usr/local/lib
CFLAGS+=-msse4.2 -DUSE_SSE4_2 \
-msse4.1 -DUSE_SSE4_1 \
-FAccelerate
else
LD=g++
#LDFLAGS=-shared -fpic -lm -lblas -llapack
LDFLAGS=-shared -fpic -lm -lopenblas
SED=sed -i -e
endif
all: $(TORCH_SOURCES) libtorch
prep:
cp lib/TH/THGeneral.h.in lib/TH/THGeneral.h
$(SED) 's/cmakedefine/define/g' lib/TH/THGeneral.h
$(SED) 's/@TH_INLINE@/inline/g' lib/TH/THGeneral.h
lua -e "package.path = package.path..';ext/?/init.lua;ext/?.lua'" TensorMath.lua TensorMath.c
lua -e "package.path = package.path..';ext/?/init.lua;ext/?.lua'" random.lua random.c
.c.o:
cc $(CFLAGS) $< -o $@
clean:
rm -f $(TORCH_OBJECTS)
rm -f *.so *.dylib
rm -f TensorMath.c
rm -f random.c
rm -f lib/TH/THGeneral.h
ifeq ($(OSTYPE),darwin)
# OSX linking and installation
# Mach-O means BUNDLE for lua loading, DYLIB for linking (2 diff files...)
# GCC is -dynamiclib, clang is -dylib for the DYLIB
# lua loads .so files, dylib files are linked
libtorch: $(TORCH_OBJECTS)
$(LD) -bundle $^ $(LDFLAGS) -o [email protected]
$(LD) -dylib $^ $(LDFLAGS) -o [email protected]
install: libtorch
mkdir -p /usr/local/include/torch/TH/generic
cp lib/luaT/luaT.h /usr/local/include/torch/
cp lib/TH/*.h /usr/local/include/torch/TH/
cp lib/TH/generic/* /usr/local/include/torch/TH/generic/
mkdir -p /usr/local/lib/lua/5.1
cp *.so /usr/local/lib/lua/5.1/
cp *.dylib /usr/local/lib/
else
# Linux linking and installation
libtorch: $(TORCH_OBJECTS)
$(LD) $^ $(LDFLAGS) -o [email protected]
install: libtorch
mkdir -p /usr/local/include/torch/TH/generic
cp lib/luaT/luaT.h /usr/local/include/torch/
cp lib/TH/*.h /usr/local/include/torch/TH/
cp lib/TH/generic/* /usr/local/include/torch/TH/generic/
mkdir -p /usr/local/lib/lua/5.1
cp *.so /usr/local/lib/lua/5.1/
cp *.so /usr/local/lib/
endif