diff options
Diffstat (limited to 'userspace/Makefile')
-rw-r--r-- | userspace/Makefile | 95 |
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. |
29 | OUT=$(TWD)/build | 33 | OUT=$(TWD)/build |
30 | 34 | ||
35 | # Core unit test framework. | ||
36 | CORE_SRC=$(TWD)/src | ||
37 | CORE_OUT=$(OUT)/nvgpu_unit_core | ||
38 | |||
31 | # Nvgpu driver code. | 39 | # Nvgpu driver code. |
32 | NVGPU_SRC=$(TWD)/../drivers/gpu/nvgpu | 40 | NVGPU_SRC=$(TWD)/../drivers/gpu/nvgpu |
33 | NVGPU_OUT=$(OUT)/libnvgpu | 41 | NVGPU_OUT=$(OUT)/libnvgpu |
34 | 42 | ||
35 | INCLUDES= \ | 43 | # Unit tests themselves. |
36 | -I$(NVGPU_SRC) \ | 44 | UNIT_SRC=$(TWD)/units |
37 | -I$(NVGPU_SRC)/include \ | 45 | UNIT_OUT=$(OUT)/units |
38 | -I../include \ | ||
39 | -I../include/uapi | ||
40 | 46 | ||
41 | CONFIGS= \ | 47 | INCLUDES= \ |
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 | |||
54 | CONFIGS=-D__NVGPU_POSIX__ | ||
43 | 55 | ||
44 | # Compiler, c-flags, etc. | 56 | # Compiler, c-flags, etc. |
45 | 57 | ||
46 | # CC = clang | 58 | # CC = clang |
47 | CC = gcc | 59 | CC = gcc |
48 | CFLAGS = -Wall -ggdb -Werror -fPIC $(INCLUDES) $(CONFIGS) | 60 | CFLAGS = -Wall -ggdb -Werror -fPIC $(INCLUDES) $(CONFIGS) |
49 | LIBS = -lpthread -pthread | 61 | LIB_PATHS = -L$(OUT) |
62 | LIBS = -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. |
52 | include Makefile.sources | 66 | include Makefile.sources |
@@ -55,19 +69,68 @@ include Makefile.sources | |||
55 | # Linux kernel. | 69 | # Linux kernel. |
56 | include Makefile.configs | 70 | include Makefile.configs |
57 | 71 | ||
58 | all: $(OUT)/libnvgpu-drv.so | 72 | all: $(OUT)/nvgpu_unit $(UNITS) |
73 | |||
74 | # Convenience targets. | ||
75 | .PHONY: libnvgpu core units | ||
76 | libnvgpu: $(OUT)/libnvgpu-drv.so | ||
77 | core: $(OUT)/nvgpu_unit | ||
78 | units: $(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. | ||
112 | export TWD INCLUDES CONFIGS UNIT_SRC UNIT_OUT | ||
113 | export 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 | ||
72 | clean: | 120 | .PHONY: clean nvgpu_clean core_clean unit_clean |
121 | |||
122 | clean: nvgpu_clean core_clean unit_clean | ||
73 | rm -rf $(OUT) | 123 | rm -rf $(OUT) |
124 | |||
125 | nvgpu_clean: | ||
126 | rm -rf $(OUT)/libnvgpu* | ||
127 | |||
128 | core_clean: | ||
129 | rm -rf $(OUT)/nvgpu_unit* | ||
130 | |||
131 | unit_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 | ||