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