Makefile: Add install targets
[cuda-ada.git] / Makefile
1 PREFIX ?= $(HOME)/libraries
2 CUDASDK = /usr/local/cuda
3 OBJDIR  = obj
4 LIBDIR  = lib
5 SRCDIR  = src
6 THINDIR = thin
7 COVDIR  = $(OBJDIR)/cov
8 PERFDIR = perf
9
10 GPR_FILES = gnat/*.gpr
11
12 LIBRARY_PATH = $(CUDASDK)/lib:$(CUDASDK)/lib64
13
14 NUM_CPUS := $(shell getconf _NPROCESSORS_ONLN)
15 ARCH     ?= $(shell uname -m)
16
17 GMAKE_OPTS = -p -R -j$(NUM_CPUS)
18
19 MAJOR    = 0
20 MINOR    = 1
21 VERSION  = $(MAJOR).$(MINOR)
22 CUDA_ADA = libcudaada-$(VERSION)
23 TARBALL  = $(CUDA_ADA).tar.bz2
24
25 SO_LIBRARY   = libcudaada.so.$(VERSION)
26 LIBRARY_KIND = dynamic
27
28 SOURCES = \
29         $(SRCDIR)/*.ad[bs] \
30         $(THINDIR)/*.ad[bs] \
31         $(THINDIR)/$(ARCH)/*.ad[bs]
32 ALIFILES = \
33         $(LIBDIR)/*.ali \
34         $(OBJDIR)/$(THINDIR)/*.ali
35
36 all: build_lib
37
38 build_lib:
39         @LIBRARY_PATH=$(LIBRARY_PATH) gnatmake -p -Pcuda_lib \
40                 -XARCH=$(ARCH) -XVERSION="$(VERSION)" -XLIBRARY_KIND="$(LIBRARY_KIND)"
41
42 build_examples:
43         @LIBRARY_PATH=$(LIBRARY_PATH) gnatmake -p -Pcuda_examples -XARCH=$(ARCH)
44
45 build_tests:
46         @LIBRARY_PATH=$(LIBRARY_PATH) gnatmake $(GMAKE_OPTS) -Pcuda_tests.gpr \
47                 -XARCH=$(ARCH)
48
49 install: install_lib install_$(LIBRARY_KIND)
50
51 install_lib: build_lib
52         install -d $(PREFIX)/include/cuda-ada
53         install -d $(PREFIX)/lib/cuda-ada
54         install -d $(PREFIX)/lib/gnat
55         install -m 644 $(SOURCES) $(PREFIX)/include/cuda-ada
56         install -m 444 $(ALIFILES) $(PREFIX)/lib/cuda-ada
57         install -m 644 $(GPR_FILES) $(PREFIX)/lib/gnat
58
59 install_static:
60         install -m 444 $(LIBDIR)/libcudaada.a $(PREFIX)/lib/cuda-ada
61
62 install_dynamic:
63         install -m 444 $(LIBDIR)/$(SO_LIBRARY) $(PREFIX)/lib/cuda-ada
64         cd $(PREFIX)/lib/cuda-ada && \
65         ln -sf $(SO_LIBRARY) libcudaada.so && \
66         ln -sf $(SO_LIBRARY) libcudaada.so.$(MAJOR)
67
68 tests: build_tests
69         @LD_LIBRARY_PATH=$(LIBRARY_PATH) $(OBJDIR)/test_runner
70
71 doc:
72         $(MAKE) -C doc
73
74 cov:
75         @rm -f $(COVDIR)/*.gcda
76         @LIBRARY_PATH=$(LIBRARY_PATH) gnatmake $(GMAKE_OPTS) -Pcuda_tests.gpr \
77                 -XARCH=$(ARCH) -XBUILD="coverage"
78         @LD_LIBRARY_PATH=$(LIBRARY_PATH) $(COVDIR)/test_runner || true
79         @lcov -c -d $(COVDIR) -o $(COVDIR)/cov.info
80         @lcov -e $(COVDIR)/cov.info "$(PWD)/src/*.adb" -o $(COVDIR)/cov.info
81         @genhtml --no-branch-coverage $(COVDIR)/cov.info -o $(COVDIR)
82
83 perf: $(OBJDIR)/perf_c $(OBJDIR)/perf_c_drv
84         @LIBRARY_PATH=$(LIBRARY_PATH) gnatmake $(GMAKE_OPTS) -Pcuda_perf.gpr \
85                 -XARCH=$(ARCH)
86         @LD_LIBRARY_PATH=$(LIBRARY_PATH) $(OBJDIR)/perf_cudaada $(COUNT)
87         @LD_LIBRARY_PATH=$(LIBRARY_PATH) $(OBJDIR)/perf_c $(COUNT)
88         @LD_LIBRARY_PATH=$(LIBRARY_PATH) $(OBJDIR)/perf_c_drv $(COUNT)
89
90 $(OBJDIR)/perf_c: $(PERFDIR)/perf_c.cu
91         @mkdir -p $(OBJDIR)
92         LIBRARY_PATH=$(LIBRARY_PATH) $(CUDASDK)/bin/nvcc $< -o $@
93
94 $(OBJDIR)/perf_c_drv: $(PERFDIR)/perf_c_drv.c
95         @mkdir -p $(OBJDIR)
96         LIBRARY_PATH=$(LIBRARY_PATH) $(CC) $< -o $@ -I$(CUDASDK)/include -lcuda
97
98 clean:
99         @rm -rf cache
100         @rm -rf $(OBJDIR)
101         @rm -rf $(LIBDIR)
102         $(MAKE) -C doc clean
103
104 dist:
105         @echo "Creating release tarball $(TARBALL) ... "
106         @git archive --format=tar HEAD --prefix $(CUDA_ADA)/ | bzip2 > $(TARBALL)
107
108 .PHONY: all build_examples build_lib build_tests clean dist doc install \
109         install_dynamic install_lib install_static perf tests