diff options
author | Mohammad Akhlaghi <mohammad@akhlaghi.org> | 2018-11-16 19:07:03 +0000 |
---|---|---|
committer | Mohammad Akhlaghi <mohammad@akhlaghi.org> | 2018-11-16 19:10:41 +0000 |
commit | 035e44f3bfdd814c4b7d8240011672ed625aed8d (patch) | |
tree | 612f3604fee775869462d3bc888ad88ce4a0eba1 | |
parent | a0ac5af0b21c79a65d8657f762ff5324bd2419ae (diff) |
Configure script checks if static libraries will be built
The default Mac compiler has problems building static libraries. Since we
are not yet building the GNU C Compiler as part of the pipeline, we'll have
to rely on the host system's compiler. Therefore, a check is now added a
the start of the configure script that will build a minimal program with
the `-static' flag and if it fails, it will print a warning. Afterwards,
none of the dependencies will be built with the `-static' flag.
-rwxr-xr-x | configure | 61 | ||||
-rw-r--r-- | reproduce/src/make/dependencies-basic.mk | 51 | ||||
-rw-r--r-- | reproduce/src/make/dependencies-build-rules.mk | 6 |
3 files changed, 110 insertions, 8 deletions
@@ -406,8 +406,52 @@ ln -s $(pwd)/reproduce/config/gnuastro .gnuastro -# Build basic dependencies -# ------------------------ +# See if the C compiler can build static libraries +# ------------------------------------------------ +oprog=$ddir/static-test +cprog=$ddir/static-test.c +echo "#include <stdio.h>" > $cprog +echo "int main(void) {return 0;}" >> $cprog +if [ x$CC = x ]; then CC=gcc; fi; +if $CC $cprog -o$oprog -static -ljunk &> /dev/null; then + export static_build="yes" +else + export static_build="no" +fi +rm -f $oprog $cprog +if [ $static_build = "no" ]; then + cat <<EOF +_________________________________________________________________________ +!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!! + +Your system's C compiler ('$CC') doesn't support building static +libraries. Therefore the dependencies will be built dynamically. This means +that they will depend more strongly on changes/updates in the host +system. For high-level applications (like most research projects in natural +sciences), this shouldn't be a significant problem. + +But generally, for reproducibility, its better to build static libraries +and programs. For more on their difference (and generally an introduction +on linking), please see the link below: + +https://www.gnu.org/software/gnuastro/manual/html_node/Linking.html + +If you have other compilers on your system, you can select a different +compiler by setting the 'CC' environment variable before running +'./configure'. + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +EOF + sleep 5 +fi + + + + + +# Inform the user that the build process is starting +# ------------------------------------------------- tsec=10 cat <<EOF @@ -425,7 +469,15 @@ pipeline. They will be installed in: EOF sleep $tsec -make -f reproduce/src/make/dependencies-basic.mk #-j2 + + + + + +# Build Basic dependencies +# ------------------------ +make -f reproduce/src/make/dependencies-basic.mk \ + static_build=$static_build #-j2 @@ -438,7 +490,8 @@ make -f reproduce/src/make/dependencies-basic.mk #-j2 # Makefile. To make the job easier, we'll do it in a Makefile, not a # script. Bash and Make were the tools we need to run Makefiles, so we had # to build them in this script. But after this, we can rely on Makefiles. -.local/bin/make -f reproduce/src/make/dependencies.mk #-j8 +./.local/bin/make -f reproduce/src/make/dependencies.mk \ + static_build=$static_build #-j8 diff --git a/reproduce/src/make/dependencies-basic.mk b/reproduce/src/make/dependencies-basic.mk index 4c57e30..45a4192 100644 --- a/reproduce/src/make/dependencies-basic.mk +++ b/reproduce/src/make/dependencies-basic.mk @@ -134,8 +134,16 @@ $(tarballs): $(tdir)/%: # GNU Lzip: For a static build, the `-static' flag should be given to # LDFLAGS on the command-line (not from the environment). $(ibdir)/lzip: $(tdir)/lzip-$(lzip-version).tar.gz + echo; echo $(static_build); echo; +ifeq ($(static_build),yes) $(call gbuild,$(subst $(tdir)/,,$<), lzip-$(lzip-version), , \ - LDFLAGS="-static") + LDFLAGS="-static") +else + $(call gbuild,$(subst $(tdir)/,,$<), lzip-$(lzip-version)) +endif + + + # GNU Gzip. @@ -144,24 +152,47 @@ $(ibdir)/gzip: $(tdir)/gzip-$(gzip-version).tar.lz \ $(call gbuild,$(subst $(tdir)/,,$<), gzip-$(gzip-version), static) + + + # Zlib: its `./configure' doesn't use Autoconf's configure script, it just # accepts a direct `--static' option. $(ildir)/libz.a: $(tdir)/zlib-$(zlib-version).tar.gz +ifeq ($(static_build),yes) $(call gbuild,$(subst $(tdir)/,,$<), zlib-$(zlib-version), , \ --static) +else + $(call gbuild,$(subst $(tdir)/,,$<), zlib-$(zlib-version)) +endif + + + + # XZ Utils $(ibdir)/xz: $(tdir)/xz-$(xz-version).tar.gz $(call gbuild,$(subst $(tdir)/,,$<), xz-$(xz-version), static) + + + + # Bzip2: Bzip2 doesn't have a configure script. $(ibdir)/bzip2: $(tdir)/bzip2-$(bzip2-version).tar.gz tdir=bzip2-$(bzip2-version); \ + if [ $(static_build) = yes ]; then \ + makecommand="make LDFLAGS=-static"; \ + else \ + makecommand="make"; \ + fi; \ cd $(ddir) && rm -rf $$tdir && tar xf $< && cd $$tdir && \ - make LDFLAGS=-static && make install PREFIX=$(idir) && \ + $$makecommand && make install PREFIX=$(idir) && \ cd .. && rm -rf $$tdir + + + # GNU Binutils: $(ibdir)/nm: $(tdir)/binutils-$(binutils-version).tar.lz \ $(ibdir)/lzip \ @@ -169,6 +200,10 @@ $(ibdir)/nm: $(tdir)/binutils-$(binutils-version).tar.lz \ $(call gbuild,$(subst $(tdir)/,,$<), binutils-$(binutils-version), \ static) + + + + # GNU Tar: When built statically, tar gives a segmentation fault on # unpacking Bash. So we'll build it dynamically. $(ibdir)/tar: $(tdir)/tar-$(tar-version).tar.gz \ @@ -179,6 +214,10 @@ $(ibdir)/tar: $(tdir)/tar-$(tar-version).tar.gz \ $(ibdir)/nm $(call gbuild,$(subst $(tdir)/,,$<), tar-$(tar-version)) + + + + # GNU Make: Unfortunately it needs dynamic linking in two instances: when # loading objects (dynamically linked libraries), or when using the # `getpwnam' function (for tilde expansion). The first can be disabled with @@ -188,8 +227,16 @@ $(ibdir)/make: $(tdir)/make-$(make-version).tar.lz \ $(ibdir)/tar $(call gbuild,$(subst $(tdir)/,,$<), make-$(make-version)) + + + + # GNU Bash $(ibdir)/bash: $(tdir)/bash-$(bash-version).tar.gz \ $(ibdir)/make +ifeq ($(static_build),yes) $(call gbuild,$(subst $(tdir)/,,$<), bash-$(bash-version), , \ --enable-static-link) +else + $(call gbuild,$(subst $(tdir)/,,$<), bash-$(bash-version)) +endif diff --git a/reproduce/src/make/dependencies-build-rules.mk b/reproduce/src/make/dependencies-build-rules.mk index 31e7759..49838f3 100644 --- a/reproduce/src/make/dependencies-build-rules.mk +++ b/reproduce/src/make/dependencies-build-rules.mk @@ -48,7 +48,9 @@ # 4: Extra configuration options. # 5: Extra options/arguments to pass to Make. # 6: Step to run between `make' and `make install': usually `make check'. -gbuild = if [ $(3)x = staticx ]; then export LDFLAGS="$$LDFLAGS -static"; fi; \ +gbuild = if [ $(static_build) = yes ] && $(3)x = staticx ]; then \ + export LDFLAGS="$$LDFLAGS -static"; \ + fi; \ check="$(6)"; \ if [ x"$$check" = x ]; then check="echo Skipping-check"; fi; \ cd $(ddir) && rm -rf $(2) && tar xf $(tdir)/$(1) && cd $(2) && \ @@ -64,7 +66,7 @@ gbuild = if [ $(3)x = staticx ]; then export LDFLAGS="$$LDFLAGS -static"; fi; \ # CMake # ----- -cbuild = if [ $(3)x = staticx ]; then \ +cbuild = if [ $(static_build) = yes ] && [ $(3)x = staticx ]; then \ export LDFLAGS="$$LDFLAGS -static"; \ opts="-DBUILD_SHARED_LIBS=OFF"; \ fi; \ |