-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
90 lines (81 loc) · 2.27 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
# configuration settings - specifying OS
OSNAME:=$(shell uname -s)
ARCH:=$(shell uname -m)
include makefile.def
# project variables
NAME=gpuvm
MAJOR_VERSION=0
MINOR_VERSION=0.1
VERSION=$(MAJOR_VERSION).$(MINOR_VERSION)
SRCH=src/*.h
SRCC=src/*.c
SRC=$(SRCH) $(SRCC)
DL_SUFFIX=so
ifeq ($(OSNAME), Darwin)
DL_SUFFIX=dylib
endif
TGT_DL=lib$(NAME).$(DL_SUFFIX)
TGT_WITH_VERSION=$(TGT_DL).$(VERSION)
TGT_WITH_MAJOR_VERSION=$(TGT_DL).$(MAJOR_VERSION)
ifeq ($(OSNAME), Darwin)
TGT_WITH_VERSION=lib$(NAME).$(VERSION).$(DL_SUFFIX)
TGT_WITH_MAJOR_VERSION=lib$(NAME).$(MAJOR_VERSION).$(DL_SUFFIX)
endif
TGT=bin/$(TGT_WITH_VERSION)
HEADER=$(NAME).h
TGT_HEADER=src/$(HEADER)
TMP=$(TGT) *~ src/*~ $(TGT) bin/$(TGT_WITH_MAJOR_VERSION) bin/*.$(DL_SUFFIX) \
doc/*/* samples/bin/* samples/*/*~ samples/*/src/*~
# compilation settings, also handle configuration and OS-dependent settings
INCLUDE_DIRS=
CC=gcc
CFLAGS=-O2 -pthread
DEFS=
DL_FLAGS=-fPIC -fvisibility=hidden -shared -Wl,-soname,$(TGT_DL).$(MAJOR_VERSION)
LIBS=-lpthread
LIB_DIRS=
LIBDIR_STD=lib
ifeq ($(ARCH), x86_64)
LIBDIR_STD=lib64
endif
ifeq ($(ARCH), amd64)
LIBDIR_STD=lib64
endif
ifeq ($(ENABLE_OPENCL), y)
DEFS+= -DOPENCL_ENABLED
LIBS+= -lOpenCL
endif
ifeq ($(ENABLE_CUDA), y)
DEFS+= -DCUDA_ENABLED
LIBS+= -lcudart
INCLUDE_DIRS+= -I$(CUDA_INSTALL_PATH)/include
LIB_DIRS+= -L$(CUDA_INSTALL_PATH)/$(LIBDIR_STD)
endif
ifeq ($(OSNAME), Darwin)
INCLUDE_DIRS+= -I/system/library/frameworks/opencl.framework/headers
DL_FLAGS=-fvisibility=hidden -dynamiclib
CFLAGS+= -arch i386 -arch x86_64
else
LIBS+= -lrt
endif
build : $(TGT)
$(TGT) : $(SRC) makefile.def
$(CC) $(CFLAGS) $(DL_FLAGS) $(DEFS) $(INCLUDE_DIRS) $(LIB_DIRS) $(LIBS) \
$(SRCC) -o $(TGT)
ln -sf $(TGT_WITH_VERSION) bin/$(TGT_DL)
ln -sf $(TGT_WITH_VERSION) bin/$(TGT_WITH_MAJOR_VERSION)
# todo: handle setting symbolic links in a more accurate way
install: $(TGT)
cp $(TGT_HEADER) $(HEADER_PREFIX)
cp $(TGT) $(LIB_PREFIX)
ln -sf $(LIB_PREFIX)/$(TGT_WITH_VERSION) $(LIB_PREFIX)/$(TGT_WITH_MAJOR_VERSION)
ln -sf $(LIB_PREFIX)/$(TGT_WITH_MAJOR_VERSION) $(LIB_PREFIX)/$(TGT_DL)
uninstall:
rm -f $(HEADER_PREFIX)/$(HEADER)
rm -f $(LIB_PREFIX)/$(TGT_DL)
rm -f $(LIB_PREFIX)/$(TGT_WITH_MAJOR_VERSION)
rm -f $(LIB_PREFIX)/$(TGT_WITH_VERSION)
doxy: $(SRC)
doxygen doxygen
clean:
rm -rf $(TMP)