From 39c57bca3cbb42b1939a28377d8ef6cfab872450 Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Thu, 20 Mar 2025 16:28:52 -0400 Subject: Makefile improvements - Add an "all" build target - Fix build if libcuda.so is not on linker search path - Do not assume that nvcc is available on $PATH - Allow specifying CFLAGS and LDFLAGS when running make - Allow passing non-standard CUDA build locations to make Suggested usage if CUDA is installed in a non-standard location, say, /playpen/jbakita/CUDA/cuda-archive/cuda-12.2: make CUDA=/playpen/jbakita/CUDA/cuda-archive/cuda-12.2 --- Makefile | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 5af440e..5256634 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,28 @@ +# Set this if CUDA is installed in a different location +CUDA ?= /usr/local/cuda # Note that CXX and CC are predefined as g++ and cc (respectively) by Make -NVCC ?= nvcc -# -fPIC is needed in all cases, as we may be linked into another shared library -CFLAGS = -fPIC -LDFLAGS = -lcuda -I/usr/local/cuda/include +NVCC ?= $(CUDA)/bin/nvcc +# Everything has to have -lcuda, as it's needed for libsmctrl +LDFLAGS := -lcuda -I$(CUDA)/include -L$(CUDA)/lib64 -.PHONY: clean tests +.PHONY: clean tests all +# ----- Main Library ----- libsmctrl.so: libsmctrl.c libsmctrl.h - $(CC) $< -shared -o $@ $(CFLAGS) $(LDFLAGS) + $(CC) $< -shared -o $@ -fPIC $(CFLAGS) $(LDFLAGS) +# -fPIC is needed even if built as a static library, in case we are linked into +# another shared library libsmctrl.a: libsmctrl.c libsmctrl.h - $(CC) $< -c -o libsmctrl.o $(CFLAGS) $(LDFLAGS) + $(CC) $< -c -o libsmctrl.o -fPIC $(CFLAGS) $(LDFLAGS) ar rcs $@ libsmctrl.o +# ----- Utilities ----- # Use static linking with tests to avoid LD_LIBRARY_PATH issues libsmctrl_test_gpc_info: libsmctrl_test_gpc_info.c libsmctrl.a testbench.h - $(CC) $< -o $@ -g -L. -l:libsmctrl.a $(LDFLAGS) + $(CC) $< -o $@ -g -L. -l:libsmctrl.a $(CFLAGS) $(LDFLAGS) +# ----- Tests ----- libsmctrl_test_mask_shared.o: libsmctrl_test_mask_shared.cu testbench.h $(NVCC) -ccbin $(CXX) $< -c -g @@ -37,6 +43,8 @@ libsmctrl_test_next_mask_override: libsmctrl_test_next_mask_override.c libsmctrl tests: libsmctrl_test_gpc_info libsmctrl_test_global_mask libsmctrl_test_stream_mask libsmctrl_test_stream_mask_override libsmctrl_test_next_mask libsmctrl_test_next_mask_override +all: libsmctrl.so tests + clean: rm -f libsmctrl.so libsmctrl.a libsmctrl_test_gpu_info \ libsmctrl_test_mask_shared.o libmsctrl_test_global_mask \ -- cgit v1.2.2