summaryrefslogtreecommitdiffstats
path: root/userspace/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'userspace/Makefile')
-rw-r--r--userspace/Makefile95
1 files changed, 79 insertions, 16 deletions
diff --git a/userspace/Makefile b/userspace/Makefile
index 70e93bad..56709ec4 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -18,6 +18,10 @@
18# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19# DEALINGS IN THE SOFTWARE. 19# DEALINGS IN THE SOFTWARE.
20 20
21# TODO:
22# - Separate rule for nvgpu_unit shared library
23# - Proper header dependency checking.
24
21# Turn off suffix rules. They are deprecated. 25# Turn off suffix rules. They are deprecated.
22.SUFFIXES: 26.SUFFIXES:
23 27
@@ -28,25 +32,35 @@ TWD=$(CURDIR)
28# Top level out dir. 32# Top level out dir.
29OUT=$(TWD)/build 33OUT=$(TWD)/build
30 34
35# Core unit test framework.
36CORE_SRC=$(TWD)/src
37CORE_OUT=$(OUT)/nvgpu_unit_core
38
31# Nvgpu driver code. 39# Nvgpu driver code.
32NVGPU_SRC=$(TWD)/../drivers/gpu/nvgpu 40NVGPU_SRC=$(TWD)/../drivers/gpu/nvgpu
33NVGPU_OUT=$(OUT)/libnvgpu 41NVGPU_OUT=$(OUT)/libnvgpu
34 42
35INCLUDES= \ 43# Unit tests themselves.
36 -I$(NVGPU_SRC) \ 44UNIT_SRC=$(TWD)/units
37 -I$(NVGPU_SRC)/include \ 45UNIT_OUT=$(OUT)/units
38 -I../include \
39 -I../include/uapi
40 46
41CONFIGS= \ 47INCLUDES= \
42 -D__NVGPU_POSIX__ 48 -I$(NVGPU_SRC) \
49 -I$(NVGPU_SRC)/include \
50 -I$(TWD)/../include \
51 -I$(TWD)/../include/uapi \
52 -I$(TWD)/include
53
54CONFIGS=-D__NVGPU_POSIX__
43 55
44# Compiler, c-flags, etc. 56# Compiler, c-flags, etc.
45 57
46# CC = clang 58# CC = clang
47CC = gcc 59CC = gcc
48CFLAGS = -Wall -ggdb -Werror -fPIC $(INCLUDES) $(CONFIGS) 60CFLAGS = -Wall -ggdb -Werror -fPIC $(INCLUDES) $(CONFIGS)
49LIBS = -lpthread -pthread 61LIB_PATHS = -L$(OUT)
62LIBS = -lpthread -pthread -lgcov -ldl
63
50 64
51# Source files. We expect $(OBJS) and $(HEADERS) to get filled in here. 65# Source files. We expect $(OBJS) and $(HEADERS) to get filled in here.
52include Makefile.sources 66include Makefile.sources
@@ -55,19 +69,68 @@ include Makefile.sources
55# Linux kernel. 69# Linux kernel.
56include Makefile.configs 70include Makefile.configs
57 71
58all: $(OUT)/libnvgpu-drv.so 72all: $(OUT)/nvgpu_unit $(UNITS)
73
74# Convenience targets.
75.PHONY: libnvgpu core units
76libnvgpu: $(OUT)/libnvgpu-drv.so
77core: $(OUT)/nvgpu_unit
78units: $(UNITS)
79
80# Note the weird libnvgpu_unit.so file: this is a bit of a hack. It lets the
81# unit tests link back against the nvgpu_unit executable so that they can call
82# functions (like unit_info()) directly. This shared library isn't actually
83# used for anything beyond that.
84#
85# Also it really should have its own rule...
86$(OUT)/nvgpu_unit: $(OUT)/libnvgpu-drv.so $(CORE_OBJS)
87 $(CC) -shared -o $(OUT)/libnvgpu_unit.so \
88 $(CORE_OBJS) $(LIB_PATHS) $(LIBS)
89 $(CC) --coverage \
90 -o $(OUT)/nvgpu_unit $(CORE_OBJS) $(LIB_PATHS) $(LIBS)
59 91
60$(OUT)/libnvgpu-drv.so: $(OBJS) 92$(OUT)/libnvgpu-drv.so: $(OBJS)
61 $(CC) -shared -o $(OUT)/libnvgpu-drv.so $(OBJS) -lgcov 93 $(CC) -shared -o $(OUT)/libnvgpu-drv.so $(OBJS) -lgcov
62 94
63# Default build target for all the object files we want to build in userspace. 95# Default build target for all the nvgpu driver object files we want to build in
96# userspace. These get bundled into libnvgpu-drv.so.
64$(NVGPU_OUT)/%.o : $(NVGPU_SRC)/%.c $(HEADERS) 97$(NVGPU_OUT)/%.o : $(NVGPU_SRC)/%.c $(HEADERS)
65 @if [ ! -d $(dir $@) ] ; then \ 98 @if [ ! -d $(dir $@) ] ; then \
66 mkdir -p $(dir $@) ; \ 99 mkdir -p $(dir $@) ; \
67 fi 100 fi
68 $(CC) $(CFLAGS) $(configs) -c -o $@ $< 101 $(CC) --coverage $(CFLAGS) $(configs) -c -o $@ $<
102
103# Build target for unit test files. These are not part of the libnvgpu-drv.so.
104# These comprise the unit test framework.
105$(CORE_OUT)/%.o : $(CORE_SRC)/%.c $(CORE_HEADERS)
106 @if [ ! -d $(dir $@) ] ; then \
107 mkdir -p $(dir $@) ; \
108 fi
109 $(CC) --coverage $(CFLAGS) $(configs) -c -o $@ $<
110
111# Certain variables should be exported to the unit test module builds.
112export TWD INCLUDES CONFIGS UNIT_SRC UNIT_OUT
113export CC CFLAGS LIB_PATHS LIBS
69 114
70.PHONY: clean 115.PHONY: $(UNITS)
116$(UNITS): $(OUT)/libnvgpu-drv.so
117 @echo "Building unit module: $@"
118 @+$(MAKE) --no-print-directory -C $@
71 119
72clean: 120.PHONY: clean nvgpu_clean core_clean unit_clean
121
122clean: nvgpu_clean core_clean unit_clean
73 rm -rf $(OUT) 123 rm -rf $(OUT)
124
125nvgpu_clean:
126 rm -rf $(OUT)/libnvgpu*
127
128core_clean:
129 rm -rf $(OUT)/nvgpu_unit*
130
131unit_clean:
132 @for d in $(UNITS); do \
133 echo Cleaning $$d; \
134 $(MAKE) --no-print-directory -C $$d clean; \
135 done
136 rm -rf $(OUT)/units