1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
# Arguments:
# MODOBJFILES
# UserLDFLAGS
# UserINCFLAGS
# LinkCoreNEURON
# Rules to build MODOBJFILES from mod files are found in makemod2c_inc
# Mechanisms version are by default 0.0, but should be overriden
MECH_NAME =
MECH_VERSION = 0.0
MODS_PATH = .
# in the @CMAKE_HOST_SYSTEM_PROCESSOR@ folder
OUTPUT = .
DESTDIR =
UserINCFLAGS =
UserLDFLAGS =
# install dirs
bindir := ${ROOT}/@CMAKE_INSTALL_BINDIR@
libdir := ${ROOT}/@CMAKE_INSTALL_LIBDIR@
incdir := ${ROOT}/@CMAKE_INSTALL_INCLUDEDIR@
datadir:= ${ROOT}/@CMAKE_INSTALL_DATADIR@
datadir_lib := ${ROOT}/@CMAKE_INSTALL_DATADIR@/lib
# Additional variables set in CMAKE usable here
# - @NRN_COMPILE_DEFS
# - @NRN_LINK_DEFS
LDFLAGS = $(LINKFLAGS) $(UserLDFLAGS) @NRN_LINK_DEFS@
# In GPU wheel distributions then the shipped libnrniv.so is linked against
# some NVIDIA runtime libraries that are shipped with the wheel. If we use
# nrnivmodl on the user machine then the NVIDIA compilers will link the local
# versions of these libraries too, causing duplication.
libnrniv_without_nvidia: $(libdir)/libnrniv.so
cp -v $(libdir)/libnrniv.so $(OUTPUT)/libnrniv-without-nvidia.so
patchelf $(OUTPUT)/libnrniv-without-nvidia.so --print-needed | grep '^libnv\(hpcatm\|omp\|cpumath\|cpumath-avx2\|c\)-[a-f0-9]\{8\}\.so' | xargs -t -r -n 1 patchelf $(OUTPUT)/libnrniv-without-nvidia.so --remove-needed
patchelf $(OUTPUT)/libnrniv-without-nvidia.so --set-soname libnrniv-without-nvidia.so
patchelf $(OUTPUT)/libnrniv-without-nvidia.so --print-rpath
ldd $(OUTPUT)/libnrniv-without-nvidia.so
# In a GPU wheel build then we need to fudge libnrniv.so before linking to it.
# NEURONDEMO should be set when we run this as part of the wheel build, in
# which case we do *not* want this hack.
ifeq (@NRN_ENABLE_CORENEURON@@NRN_WHEEL_BUILD@@CORENRN_ENABLE_GPU@$(if $(NRNDEMO),OFF,ON), ONONONON)
NRNLIB_FLAGS = -L$(OUTPUT) -lnrniv-without-nvidia
NRNLIB_RPATH_FLAGS = -Wl,-rpath,\$$ORIGIN -Wl,-rpath,\$$ORIGIN/..
nrn_lib = libnrniv_without_nvidia
else
NRNLIB_FLAGS = -L$(libdir) -lnrniv
NRNLIB_RPATH_FLAGS = -Wl,-rpath,$(libdir)
nrn_lib =
endif
OS_NAME := $(shell uname)
_cm =,
# We rebuild the include dirs since a lot of stuff changes place
INCLUDES = -I. $(INCFLAGS) $(UserINCFLAGS) -I$(incdir)
ifeq (@NRN_INCLUDE_MPI_HEADERS@, ON)
INCLUDES += $(if @MPI_C_INCLUDE_PATH@, -I$(subst ;, -I,@MPI_C_INCLUDE_PATH@),)
endif
# CC/CXX are always defined. If the definition comes from default change it
ifeq ($(origin CC), default)
CC = @CMAKE_C_COMPILER@
CXX = @CMAKE_CXX_COMPILER@
endif
CFLAGS = @BUILD_TYPE_C_FLAGS@ @CMAKE_C_FLAGS@ @C11_STANDARD_COMPILE_OPTION@
CXXFLAGS = @BUILD_TYPE_CXX_FLAGS@ @CMAKE_CXX_FLAGS@ @CXX11_STANDARD_COMPILE_OPTION@
COMPILE = $(CC) $(CFLAGS) @NRN_COMPILE_DEFS_STRING@ @NRN_COMPILE_FLAGS_STRING@
CXXCOMPILE = $(CXX) $(CXXFLAGS) @NRN_COMPILE_DEFS_STRING@ @NRN_COMPILE_FLAGS_STRING@
CXX_LINK_EXE = $(CXX) $(CXXFLAGS) @CMAKE_EXE_LINKER_FLAGS@ @NRN_LINK_FLAGS_STRING@
CXX_LINK_SHARED = $(CXX) $(CXXFLAGS) @CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS@ @CMAKE_SHARED_LIBRARY_CXX_FLAGS@ @CMAKE_SHARED_LINKER_FLAGS@
NOCMODL = $(bindir)/nocmodl
NRNUNITS = $(datadir_lib)/nrnunits.lib
# File path config (internal)
MODC_DIR = .
OBJS_DIR = .
mod_objs = $(MODOBJFILES)
mod_func_o = $(OBJS_DIR)/mod_func.o
mod_func_cpp = $(MODC_DIR)/mod_func.cpp
special = $(OUTPUT)/special
LIB_SUFFIX_ = $(if $(MECH_NAME),_$(MECH_NAME),)
mech_libname = nrnmech
# In case of static library we need to link NRNLIB_FLAGS twice to avoid undefined
# symbols from circular dependencies. But for shared library we don't do it to avoid
# pthread linking with wheels.
ifeq (@NRN_ENABLE_SHARED@, ON)
mech_lib = $(OUTPUT)/lib$(mech_libname)@CMAKE_SHARED_LIBRARY_SUFFIX@
mech_lib_type = mech_lib_shared
extra_lib_link =
else
mech_lib = $(OUTPUT)/lib$(mech_libname)@CMAKE_STATIC_LIBRARY_SUFFIX@
mech_lib_type = mech_lib_static
extra_lib_link = $(NRNLIB_FLAGS)
endif
# add coreneuron flags
ifeq ($(LinkCoreNEURON), true)
EXTRA_LDFLAGS = @CORENEURON_LIB_LINK_FLAGS@
endif
# If no DESTDIR (we are probably just building) we use $ORIGIN (@loader_path in OSX)
_ORIGIN := $(if $(filter Darwin,$(OS_NAME)),@loader_path,$$ORIGIN)
_SONAME := -Wl,$(if $(filter Darwin,$(OS_NAME)),-install_name${_cm}@rpath/,-soname${_cm})$(notdir ${mech_lib})
DESTDIR_RPATH = $(if $(DESTDIR),$(DESTDIR)/lib,$(_ORIGIN))
C_RESET := \033[0m
C_GREEN := \033[32m
# ======== MAIN BUILD RULES ============
# Take the main and link with nrnmech.
# RPATH is set for DESTDIR_RPATH and coreneuron lib
special: $(mech_lib)
@printf " => $(C_GREEN)LINKING$(C_RESET) executable $(special) LDFLAGS are: $(LDFLAGS)\n"
$(CXX_LINK_EXE) -I $(incdir) -I $(incdir)/nrncvode -DAUTO_DLOPEN_NRNMECH=0 $(datadir)/nrnmain.cpp -o $(special) \
-L $(OBJS_DIR) -l$(mech_libname) $(NRNLIB_FLAGS) -l$(mech_libname) $(extra_lib_link) -Wl,-rpath,'$(DESTDIR_RPATH)' -Wl,-rpath,$(libdir) $(LDFLAGS) $(EXTRA_LDFLAGS)
$(mech_lib): $(mech_lib_type)
mech_lib_shared: mod_func.o $(mod_objs) $(nrn_lib) build_always
@printf " => $(C_GREEN)LINKING$(C_RESET) shared library $(mech_lib)\n"
$(CXX_LINK_SHARED) -I $(incdir) -o ${mech_lib} ${_SONAME} \
$(mod_func_o) $(mod_objs) $(NRNLIB_FLAGS) $(NRNLIB_RPATH_FLAGS) $(LDFLAGS)
rm -f $(OBJS_DIR)/.libs/libnrnmech.so ; mkdir -p $(OBJS_DIR)/.libs ; cp $(mech_lib) $(OBJS_DIR)/.libs/libnrnmech.so
mech_lib_static: mod_func.o $(mod_objs) $(nrn_lib) build_always
@printf " => $(C_GREEN)LINKING$(C_RESET) static library $(mech_lib)\n"
ar cq ${mech_lib} $(mod_func_o) $(mod_objs) $(cobjs);
mod_func.o: mod_func.cpp
@printf " -> $(C_GREEN)Compiling$(C_RESET) $<\n"
$(CXXCOMPILE) $(INCLUDES) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ -c $< -o $@
# Generic build c->o. Need PIC for shared lib
$(OBJS_DIR)/%.o: $(MODC_DIR)/%.c | $(OBJS_DIR)
@printf " -> $(C_GREEN)Compiling$(C_RESET) $<\n"
$(COMPILE) $(INCLUDES) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ -c $< -o $@
include makemod2c_inc
# If .mod doesnt exist attempt from previously built opt mods in shared/
$(MODC_DIR)/%.cpp: $(datadir_lib)/%.cpp | $(MODC_DIR)
ln -s $< $@
install: special $(mech_lib)
install -d $(DESTDIR)/bin $(DESTDIR)/lib
install $(mech_lib) $(DESTDIR)/lib
install $(special) $(DESTDIR)/bin
libnrnmech.la: $(mech_lib)
# == INIT ==
$(MODC_DIR):
(cd .. ; mkdir -p $(MODC_DIR))
#$(OBJS_DIR):
# mkdir -p $(OBJS_DIR)
.PHONY: build_always
$(VERBOSE).SILENT:
|