Skip to content

Commit

Permalink
Toolchain: Towards static linking
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Jun 8, 2021
1 parent 6dcb27d commit e2bdc4a
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 15 deletions.
7 changes: 6 additions & 1 deletion tools/toolchain/scripts/generate_arch_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ FCFLAGS="$G_CFLAGS \$(FCDEBFLAGS) \$(WFLAGS) \$(DFLAGS)"
CFLAGS="$G_CFLAGS -std=c11 -Wall -Wextra -Werror \$(DFLAGS)"

# Linker flags
LDFLAGS="\$(FCFLAGS) ${CP_LDFLAGS}"
# About --whole-archive see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52590
STATIC_FLAGS="-static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive"
# Get unfortunately ignored: -static-libgcc -static-libstdc++ -static-libgfortran
LDFLAGS="IF_STATIC(${STATIC_FLAGS}|) \$(FCFLAGS) ${CP_LDFLAGS}"

# Library flags
# add standard libs
Expand Down Expand Up @@ -194,12 +197,14 @@ EOF
rm -f ${INSTALLDIR}/arch/local*
# normal production arch files
gen_arch_file "local.ssmp"
gen_arch_file "local_static.ssmp" STATIC
gen_arch_file "local.sdbg" DEBUG
arch_vers="ssmp sdbg"

if [ "$MPI_MODE" != no ]; then
gen_arch_file "local.psmp" MPI
gen_arch_file "local.pdbg" MPI DEBUG
gen_arch_file "local_static.psmp" MPI STATIC
gen_arch_file "local_warn.psmp" MPI WARNALL
gen_arch_file "local_coverage.pdbg" MPI COVERAGE
arch_vers="${arch_vers} psmp pdbg"
Expand Down
1 change: 1 addition & 0 deletions tools/toolchain/scripts/parse_if.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def ParseDocument(self, input_file, output_file):
"CUDA": False,
"WARNALL": False,
"DEBUG": False,
"STATIC": False,
"VALGRIND": False,
"COVERAGE": False,
}
Expand Down
9 changes: 9 additions & 0 deletions tools/toolchain/scripts/stage0/install_gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ case "$with_gcc" in
GCCROOT=${PWD}
mkdir obj
cd obj
# TODO: Maybe use --disable-libquadmath-support to improve static linking:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539
#
# TODO: Maybe use --disable-gnu-unique-object to improve static linking:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60348#c13
# https://stackoverflow.com/questions/11931420
#
# TODO: Unfortunately, we can not simply use --disable-shared, because
# it would break OpenBLAS build and probably others too.
${GCCROOT}/configure --prefix="${pkg_install_dir}" \
--libdir="${pkg_install_dir}/lib" \
--enable-languages=c,c++,fortran \
Expand Down
11 changes: 10 additions & 1 deletion tools/toolchain/scripts/stage1/install_mpich.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ case "$with_mpich" in
# workaround for compilation with GCC-10, until properly fixed:
# https://github.com/pmodels/mpich/issues/4300
("${FC}" --version | grep -Eq 'GNU.+\s10\.') && compat_flag="-fallow-argument-mismatch" || compat_flag=""
./configure --prefix="${pkg_install_dir}" --libdir="${pkg_install_dir}/lib" MPICC="" FFLAGS="${FCFLAGS} ${compat_flag}" FCFLAGS="${FCFLAGS} ${compat_flag}" --without-x --enable-gl=no > configure.log 2>&1
./configure \
--prefix="${pkg_install_dir}" \
--libdir="${pkg_install_dir}/lib" \
MPICC="" \
FFLAGS="${FCFLAGS} ${compat_flag}" \
FCFLAGS="${FCFLAGS} ${compat_flag}" \
--without-x \
--enable-gl=no \
--disable-shared \
> configure.log 2>&1
make -j $(get_nprocs) > make.log 2>&1
make install > install.log 2>&1
cd ..
Expand Down
2 changes: 2 additions & 0 deletions tools/toolchain/scripts/stage2/install_openblas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ case "$with_openblas" in
#
# wrt NUM_THREADS=64: this is what the most common Linux distros seem to choose atm
# for a good compromise between memory usage and scalability
#
# Unfortunately, NO_SHARED=1 breaks ScaLAPACK build.
(
make -j $(get_nprocs) \
MAKE_NB_JOBS=0 \
Expand Down
2 changes: 1 addition & 1 deletion tools/toolchain/scripts/stage3/install_fftw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ case "$with_fftw" in
[ -d fftw-${fftw_ver} ] && rm -rf fftw-${fftw_ver}
tar -xzf ${fftw_pkg}
cd fftw-${fftw_ver}
FFTW_FLAGS="--enable-openmp --enable-shared --enable-static"
FFTW_FLAGS="--enable-openmp --disable-shared --enable-static"
# fftw has mpi support but not compiled by default. so compile it if we build with mpi.
# it will create a second library to link with if needed
[ "$MPI_MODE" != "no" ] && FFTW_FLAGS="--enable-mpi ${FFTW_FLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion tools/toolchain/scripts/stage6/install_gsl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ case "$with_gsl" in
cd gsl-${gsl_ver}
./configure --prefix="${pkg_install_dir}" \
--libdir="${pkg_install_dir}/lib" \
--enable-shared \
--disable-shared \
--enable-static > configure.log 2>&1
make -j $(get_nprocs) > make.log 2>&1
make -j $(get_nprocs) install > install.log 2>&1
Expand Down
7 changes: 4 additions & 3 deletions tools/toolchain/scripts/stage6/install_plumed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ case "$with_plumed" in
CXXFLAGS="${CXXFLAGS//-g/-g0} ${GSL_CFLAGS}" \
LDFLAGS="${LDFLAGS} ${GSL_LDFLAGS}" \
LIBS="${libs}" \
--disable-shared \
--prefix=${pkg_install_dir} \
--libdir="${pkg_install_dir}/lib" > configure.log 2>&1
make VERBOSE=1 -j $(get_nprocs) > make.log 2>&1
Expand Down Expand Up @@ -96,9 +97,9 @@ EOF
cat << EOF >> "${BUILDDIR}/setup_plumed"
export PLUMED_LDFLAGS="${PLUMED_LDFLAGS}"
export PLUMED_LIBS="${PLUMED_LIBS}"
export CP_DFLAGS="\${CP_DFLAGS} -D__PLUMED2"
export CP_LDFLAGS="\${CP_LDFLAGS} ${PLUMED_LDFLAGS}"
export CP_LIBS="${PLUMED_LIBS} \${CP_LIBS}"
export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__PLUMED2|)"
export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${PLUMED_LDFLAGS}|)"
export CP_LIBS="IF_MPI(${PLUMED_LIBS}|) \${CP_LIBS}"
EOF
fi

Expand Down
2 changes: 1 addition & 1 deletion tools/toolchain/scripts/stage7/install_hdf5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ case "$with_hdf5" in
./configure \
--prefix="${pkg_install_dir}" \
--libdir="${pkg_install_dir}/lib" \
--enable-shared \
--disable-shared \
> configure.log 2>&1
make -j $(get_nprocs) > make.log 2>&1
make -j $(get_nprocs) install > install.log 2>&1
Expand Down
9 changes: 4 additions & 5 deletions tools/toolchain/scripts/stage7/install_spglib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ case "$with_spglib" in
cmake \
-DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_SHARED_LIBS=NO \
.. > configure.log 2>&1
make -j $(get_nprocs) > make.log 2>&1
make -j $(get_nprocs) symspg > make.log 2>&1
make install >> make.log 2>&1
mkdir ${pkg_install_dir}/include/spglib
cp ${pkg_install_dir}/include/{,spglib/}spglib.h
cd ..
# Despite -DBUILD_SHARED_LIBS=NO the shared library gets build and installed.
rm "${pkg_install_dir}"/lib/*.so*
write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage7/$(basename ${SCRIPT_NAME})"
fi

Expand Down
6 changes: 4 additions & 2 deletions tools/toolchain/scripts/stage8/install_spfft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ case "$with_spfft" in
cmake \
-DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \
-DCMAKE_INSTALL_LIBDIR=lib \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_CXX_COMPILER="${MPICXX}" \
-DSPFFT_OMP=ON \
-DSPFFT_MPI=ON \
-DSPFFT_STATIC=ON \
-DSPFFT_INSTALL=ON \
.. > cmake.log 2>&1
make -j $(get_nprocs) > make.log 2>&1
Expand All @@ -63,9 +64,10 @@ case "$with_spfft" in
cmake \
-DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \
-DCMAKE_INSTALL_LIBDIR=lib \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_CXX_COMPILER="${MPICXX}" \
-DSPFFT_OMP=ON \
-DSPFFT_MPI=ON \
-DSPFFT_STATIC=ON \
-DSPFFT_INSTALL=ON \
-DSPFFT_GPU_BACKEND=CUDA \
.. > cmake.log 2>&1
Expand Down

0 comments on commit e2bdc4a

Please sign in to comment.