| 1 |
no_target_specified: runcore |
| 2 |
@echo |
| 3 |
@echo The default make rule is equivalent to \'make runcore\' which runs only the most basic tests. |
| 4 |
@echo The following \'meta-targets\' are available: |
| 5 |
@echo " " $(meta_targets) |
| 6 |
@echo Here is the complete list of individual program targets: |
| 7 |
@echo " " $(all_primary_targets) |
| 8 |
@echo Prepend \'run\' to any of the program targets or metatargets |
| 9 |
@echo to run the binary and check for a zero exit status. |
| 10 |
@echo Adding force=1 on the command line causes all targets to be considered out-of-date. |
| 11 |
.PHONY: no_target_specified |
| 12 |
|
| 13 |
# metatargets are variables which get mapped by METATARGET_template |
| 14 |
meta_targets:=kat core aesni timing c cpp gsl thread cuda opencl metal ut |
| 15 |
|
| 16 |
# Platform metatargets: each one typically has specific requirements in the build environment. |
| 17 |
# c is C99 (will work in MSVC), cpp is C++98, gsl requires the GNU Scientific Library |
| 18 |
# (specifically, the gsl-config program in the PATH), thread requires POSIX threads, |
| 19 |
# CUDA requires NVIDIA CUDA 3.x or newer, OpenCL requires OpenCL includes & libraries |
| 20 |
# (e.g. AMD APP SDK, NVIDIA SDK) |
| 21 |
c:=kat_c ut_ars time_serial |
| 22 |
cpp:=kat_cpp ut_carray ut_M128 ut_features ut_ReinterpretCtr ut_Engine ut_aes timers time_boxmuller ut_ua ut_uniform |
| 23 |
gsl:=ut_gsl |
| 24 |
thread:=time_thread |
| 25 |
cuda:=time_cuda kat_cuda time_boxmuller_cuda |
| 26 |
opencl:=time_opencl kat_opencl |
| 27 |
metal:=kat_metal |
| 28 |
|
| 29 |
# Convenience metatargets: these are to help developers test functional subsets across platforms |
| 30 |
kat:=kat_c kat_cpp |
| 31 |
core:=$(c) $(cpp) |
| 32 |
aesni:=ut_aes ut_ars |
| 33 |
timing:=timers time_serial time_thread |
| 34 |
# N.B. ut doesn't include ut_gsl, ut_ars or ut_aes |
| 35 |
ut:=ut_carray ut_Engine ut_features ut_M128 ut_ReinterpretCtr ut_ua ut_uniform ut_uniform_IEEEkat |
| 36 |
|
| 37 |
$(gsl) : override LDLIBS += `gsl-config --libs` |
| 38 |
$(gsl) : override CFLAGS += `gsl-config --cflags` |
| 39 |
|
| 40 |
$(opencl) : % : %_kernel.i |
| 41 |
# Or try this if we USE_GENCL in kat_opencl.c |
| 42 |
#$(opencl) : override CPPFLAGS += -DSRCDIR=\"$(dir $(abspath $<)).\" |
| 43 |
|
| 44 |
ifeq ($(shell uname),Darwin) |
| 45 |
$(opencl) : override LDLIBS+=-framework OpenCL |
| 46 |
else |
| 47 |
$(opencl) : override LDLIBS+=-lOpenCL |
| 48 |
endif |
| 49 |
$(opencl) : override CFLAGS+=-I. |
| 50 |
# Note, the Intel OpenCL SDK (1.5) has unresolved C++ symbols in its |
| 51 |
# libOpenCL.so Even though 'main' is a C program, you may need to link |
| 52 |
# it with a C++ compiler-driver, e.g., g++. Since this Makefile does |
| 53 |
# compile-and-link in one step, use something like: |
| 54 |
# $(opencl) : CC=g++ -xc |
| 55 |
# which will invoke the g++ compiler-driver, but will treat the |
| 56 |
# program as C rather than C++. |
| 57 |
|
| 58 |
# N.B. gcc -pthread (without the -l) on linux at compile time also |
| 59 |
# adds -D_REENTRANT. Unfortunately -pthread is unrecognized by |
| 60 |
# SunPRO. Posix says that -lpthread is portable (as if anyone cares |
| 61 |
# what Posix says), and it seems to work in all the environments we've |
| 62 |
# tested. Gcc's features.h says that _THREAD_SAFE is "often used by |
| 63 |
# other systems" as a synonym for _REENTRANT. Cross your fingers... |
| 64 |
$(thread) : override LDLIBS+=-lpthread |
| 65 |
$(thread) : override CPPFLAGS+=-D_REENTRANT=1 -D_THREAD_SAFE=1 |
| 66 |
|
| 67 |
$(metal) : % : %_kernel.metallib |
| 68 |
$(metal) : override LDLIBS+=-framework Metal -framework Foundation -framework CoreGraphics |
| 69 |
|
| 70 |
all_primary_targets += $(addsuffix _kernel.i, $(opencl)) |
| 71 |
all_primary_targets += $(addsuffix _kernel.metallib, $(metal)) |
| 72 |
all_primary_targets += $(addsuffix _kernel.air, $(metal)) |
| 73 |
|
| 74 |
################################################ |
| 75 |
# Generic boilerplate from here down: |
| 76 |
vpath %.c $(srcdir/) |
| 77 |
vpath %.cpp $(srcdir/) |
| 78 |
vpath %.cu $(srcdir/) |
| 79 |
vpath %.ocl $(srcdir/) |
| 80 |
vpath %.metal $(srcdir/) |
| 81 |
|
| 82 |
define METATARGET_template |
| 83 |
.PHONY: $(1) |
| 84 |
$(1) : $(filter-out $(SKIP_TARGETS), $($(1))) |
| 85 |
.PHONY: run$(1) |
| 86 |
run$(1) : $(addprefix run, $(filter-out $(SKIP_TARGETS), $($(1)))) |
| 87 |
all_primary_targets += $($(1)) |
| 88 |
endef |
| 89 |
|
| 90 |
$(foreach T,$(meta_targets), $(eval $(call METATARGET_template,$(T)))) |
| 91 |
|
| 92 |
# sort also does 'uniq' |
| 93 |
all_primary_targets:=$(sort $(all_primary_targets)) |
| 94 |
|
| 95 |
INC=$(srcdir/)../include |
| 96 |
override CPPFLAGS += -I$(INC) |
| 97 |
|
| 98 |
ifndef NVCC |
| 99 |
NVCC:=nvcc |
| 100 |
endif |
| 101 |
# The rngs are *very* slow without optimization. In the simplest case, |
| 102 |
# where the user just calls 'make', we don't want them to see terrible |
| 103 |
# performance. Unfortunately, this might surprise someone |
| 104 |
# who says, e.g., make CPPFLAGS=-O0. Oh well... |
| 105 |
ifndef CFLAGS |
| 106 |
CFLAGS:=-O |
| 107 |
endif |
| 108 |
ifndef CXXFLAGS |
| 109 |
CXXFLAGS:=-O |
| 110 |
endif |
| 111 |
|
| 112 |
%.i : %.ocl |
| 113 |
CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" $(srcdir/)./gencl.sh $< > $@ |
| 114 |
|
| 115 |
% : %.cu |
| 116 |
$(NVCC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LOADLIBES) $(LDLIBS) -o $@ |
| 117 |
|
| 118 |
% : %.c |
| 119 |
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LOADLIBES) $(LDLIBS) -o $@ |
| 120 |
|
| 121 |
% : %.cpp |
| 122 |
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LOADLIBES) $(LDLIBS) -o $@ |
| 123 |
|
| 124 |
% : %.m |
| 125 |
$(CC) $(OBJCFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LOADLIBES) $(LDLIBS) -o $@ |
| 126 |
|
| 127 |
%.air : %.metal |
| 128 |
xcrun --sdk macosx metal $(CPPFLAGS) -c $< -o $@ |
| 129 |
|
| 130 |
%.metallib : %.air |
| 131 |
xcrun --sdk macosx metallib $< -o $@ |
| 132 |
|
| 133 |
run% : % |
| 134 |
./$^ $(RUN_ARGS) |
| 135 |
|
| 136 |
# In lieu of autodepends, just say that all the compilation targets depend on all the headers. |
| 137 |
hdrs:=$(wildcard $(srcdir/)*.h $(srcdir/)gsl/*.c $(INC)/Random123/*.h $(INC)/Random123/*.hpp $(INC)/Random123/*/*.h $(INC)/Random123/*/*.hpp) |
| 138 |
misc:=$(wildcard $(srcdir/)*.cu $(srcdir/)*.ocl) |
| 139 |
$(all_primary_targets) : $(hdrs) |
| 140 |
$(misc) : $(hdrs) |
| 141 |
|
| 142 |
# If you put force=y on the command line, then $(all_primary_targets) will be |
| 143 |
# depend on FORCE, and hence will not be up-to-date. |
| 144 |
ifdef force |
| 145 |
$(all_primary_targets) : FORCE |
| 146 |
FORCE: |
| 147 |
endif |
| 148 |
|
| 149 |
.PHONY : echo_build_commands |
| 150 |
echo_build_commands: |
| 151 |
make -n force=1 $(all_primary_targets) | grep -v 'is up to date' |
| 152 |
|
| 153 |
.PHONY : clean veryclean |
| 154 |
clean: |
| 155 |
rm -f $(all_primary_targets) |
| 156 |
|
| 157 |
veryclean: |
| 158 |
rm -f $(all_primary_targets) *.o \#* *~ *.pdb *.exe *.obj *.ilk *.suo |
| 159 |
|
| 160 |
.PHONY : install |
| 161 |
|
| 162 |
# N.B. normally these are exported by ../GNUmakefile |
| 163 |
prefix?=/usr/local |
| 164 |
datarootdir?=$(prefix)/share |
| 165 |
docdir?=$(datarootdir)/doc/Random123 |
| 166 |
|
| 167 |
# Are 'tests/' "documentation" or "architecture independent data files"? |
| 168 |
# If the former, then they belong in $(docdir)/tests (aka /usr/local/share/doc/Random123/tests) |
| 169 |
# If the latter, then they belong in $(datarootdir)/Random123/tests (aka /usr/local/share/Random123/tests) |
| 170 |
install: |
| 171 |
mkdir -p $(DESTDIR)$(docdir)/tests |
| 172 |
cp README GNUmakefile BUILDVC* *kat_vectors* *.sh *.c *.h *.cpp *.cu *.metal *.m *.ocl $(DESTDIR)$(docdir)/tests |