aboutsummaryrefslogtreecommitdiff
path: root/reproduce/src/make/dependencies.mk
blob: fdc30a17d3721f009a50b956998d38042c3e8cc3 (plain)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# Build the reproduction pipeline dependencies (programs and libraries).
#
# ------------------------------------------------------------------------
#                      !!!!! IMPORTANT NOTES !!!!!
#
# This Makefile will be run by the initial `./configure' script. It is not
# included into the reproduction pipe after that.
#
# This Makefile also builds GNU Bash and GNU Make. Therefore this is the
# only Makefile in the reproduction pipeline where you MUST NOT assume that
# GNU Bash or GNU Make are to be used.
#
# ------------------------------------------------------------------------
#
# Original author:
#     Mohammad Akhlaghi <mohammad@akhlaghi.org>
# Contributing author(s):
#     Your name <your@email.address>
# Copyright (C) 2018, Your Name.
#
# This Makefile is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This Makefile is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.
#
# A copy of the GNU General Public License is available at
# <http://www.gnu.org/licenses/>.



# Top level environment
include reproduce/config/pipeline/LOCAL.mk
include reproduce/config/pipeline/dependency-versions.mk

ddir  = $(BDIR)/dependencies
tdir  = $(BDIR)/dependencies/tarballs
idir  = $(BDIR)/dependencies/installed
ibdir = $(BDIR)/dependencies/installed/bin
ildir = $(BDIR)/dependencies/installed/lib

# Define the top-level programs to build (installed in `.local/bin', so for
# Coreutils, only one of its executables is enough).
top-level-programs = ls gawk gs grep libtool sed git astnoisechisel
all: $(foreach p, $(top-level-programs), $(ibdir)/$(p))

# This Makefile will be called to also build Bash locally. So when we don't
# have it yet, we'll have to use the system's bash.
ifeq ($(USE_LOCAL_BASH),yes)
SHELL := $(ibdir)/bash
else
SHELL := /bin/sh
endif

# Other basic environment settings.
.ONESHELL:
.SHELLFLAGS      = -ec
PATH            := $(ibdir):$(PATH)
LDFLAGS         := -L$(ildir) $(LDFLAGS)
CPPFLAGS        := -I$(idir)/include $(CPPFLAGS)
LD_LIBRARY_PATH := $(ildir):$(LD_LIBRARY_PATH)





# Tarballs
# --------
#
# All the necessary tarballs are defined and prepared with this rule.
tarballs = $(foreach t, bash-$(bash-version).tar.gz                 \
	                cfitsio$(cfitsio-version).tar.gz            \
                        cmake-$(cmake-version).tar.gz               \
                        coreutils-$(coreutils-version).tar.xz       \
                        curl-$(curl-version).tar.gz                 \
	                gawk-$(gawk-version).tar.gz                 \
	                ghostscript-$(ghostscript-version).tar.gz   \
	                git-$(git-version).tar.xz                   \
	                gnuastro-$(gnuastro-version).tar.lz         \
	                grep-$(grep-version).tar.xz                 \
	                gsl-$(gsl-version).tar.gz                   \
	                jpegsrc.$(libjpeg-version).tar.gz           \
                        tiff-$(libtiff-version).tar.gz              \
	                libtool-$(libtool-version).tar.gz           \
                        libgit2-$(libgit2-version).tar.gz           \
	                sed-$(sed-version).tar.xz                   \
	                make-$(make-version).tar.gz                 \
	                wcslib-$(wcslib-version).tar.bz2            \
                        zlib-$(zlib-version).tar.gz                 \
                      , $(tdir)/$(t) )
$(tarballs): $(tdir)/%:
	if [ -f $(DEPENDENCIES-DIR)/$* ]; then
	  cp $(DEPENDENCIES-DIR)/$* $@
	else
          # Remove all numbers, `-' and `.' from the tarball name so we can
          # search more easily only with the program name.
	  n=$$(echo $* | sed -e's/[0-9\-]/ /g' -e's/\./ /g'         \
	               | awk '{print $$1}' )

          # Set the top download link of the requested tarball.
	  mergenames=1
	  if   [ $$n = bash        ]; then w=http://ftp.gnu.org/gnu/bash
	  elif [ $$n = cfitsio     ]; then w=https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c
	  elif [ $$n = cmake       ]; then w=https://cmake.org/files/v3.12
	  elif [ $$n = coreutils   ]; then w=http://ftp.gnu.org/gnu/coreutils
	  elif [ $$n = curl        ]; then w=https://curl.haxx.se/download
	  elif [ $$n = gawk        ]; then w=http://ftp.gnu.org/gnu/gawk
	  elif [ $$n = ghostscript ]; then w=https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs925
	  elif [ $$n = git         ]; then w=https://mirrors.edge.kernel.org/pub/software/scm/git
	  elif [ $$n = gnuastro    ]; then w=http://akhlaghi.org/src
	  elif [ $$n = grep        ]; then w=http://ftp.gnu.org/gnu/grep
	  elif [ $$n = gsl         ]; then w=http://ftp.gnu.org/gnu/gsl
	  elif [ $$n = jpegsrc     ]; then w=http://ijg.org/files
	  elif [ $$n = libtool     ]; then w=ftp://ftp.gnu.org/gnu/libtool
	  elif [ $$n = libgit      ]; then
	    mergenames=0
	    w=https://github.com/libgit2/libgit2/archive/v$(libgit2-version).tar.gz
	  elif [ $$n = make        ]; then w=http://akhlaghi.org/src
	  elif [ $$n = sed         ]; then w=http://ftp.gnu.org/gnu/sed
	  elif [ $$n = tiff        ]; then w=https://download.osgeo.org/libtiff
	  elif [ $$n = wcslib      ]; then w=ftp://ftp.atnf.csiro.au/pub/software/wcslib
	  elif [ $$n = zlib        ]; then w=https://www.zlib.net
	  else
	    echo; echo; echo;
	    echo "'$$n' not recognized as a dependency name to download."
	    echo; echo; echo;
	    exit 1
	  fi

          # Download the requested tarball. Note that some packages may not
          # follow our naming convention (where the package name is merged
          # with its version number). In such cases, `w' will be the full
          # address, not just the top directory address. But since we are
          # storing all the tarballs in one directory, we want it to have
          # the same naming convention, so we'll download it to a temporary
          # name, then rename that.
	  if [ $$mergenames = 1 ]; then  tarballurl=$$w/"$*"
	  else                           tarballurl=$$w
	  fi
	  echo "Downloading $$tarballurl"
	  if [ $$mergenames = 1 ]; then
	    $(DOWNLOADER) $@ $$tarballurl
	  else
	    $(DOWNLOADER) $@_tmp $$tarballurl
	    mv $@_tmp $@
	  fi
	fi





# Build system rules
# ------------------
gbuild = cd $(ddir); rm -rf $(2); tar xf $(tdir)/$(1); cd $(2);      \
         if [ $(3)x = staticx ]; then                                \
         opts="CFLAGS=--static --disable-shared";                    \
         fi;                                                         \
         ./configure $$opts $(4) --prefix=$(idir); make $(5);        \
         check="$(6)"; if [ x"$$check" != x ]; then $$check; fi;     \
         make install; cd ..; rm -rf $(2)


cbuild = cd $(ddir); rm -rf $(2); tar xf $(tdir)/$(1); cd $(2);      \
	 rm -rf my-build; mkdir my-build; cd my-build; opts="";      \
	 if [ $(3)x = staticx ]; then                                \
	   export CFLAGS="--static $$CFLAGS";                        \
	   opts="-DBUILD_SHARED_LIBS=OFF";                           \
	 fi;                                                         \
	 cmake .. $$opts $(4);                                       \
	 cmake --build .;                                            \
	 cmake .. -DCMAKE_INSTALL_PREFIX=$(idir);                    \
	 cmake --build . --target install; cd ../..; rm -rf $(2)





# Libraries
# ---------
$(ildir)/libcfitsio.a: $(tdir)/cfitsio$(cfitsio-version).tar.gz         \
                       $(ildir)/libcurl.a                               \
                       $(ibdir)/ls
	$(call gbuild,$(subst $(tdir),,$<), cfitsio, static,            \
                      --enable-sse2 --enable-reentrant)

$(ildir)/libcurl.a: $(tdir)/curl-$(curl-version).tar.gz \
                    $(ildir)/libz.a                     \
                    $(ibdir)/ls
	$(call gbuild,$(subst $(tdir),,$<), curl-$(curl-version), static, \
                      --without-brotli)

$(ildir)/libgit2.a: $(tdir)/libgit2-$(libgit2-version).tar.gz             \
                    $(ildir)/libcurl.a                                    \
                    $(ibdir)/cmake
	$(call cbuild,$(subst $(tdir),,$<), libgit2-$(libgit2-version),   \
	              static, -DUSE_SSH=OFF -DUSE_OPENSSL=OFF             \
                      -DBUILD_CLAR=OFF -DTHREADSAFE=ON, )

$(ildir)/libgsl.a: $(tdir)/gsl-$(gsl-version).tar.gz \
                   $(ibdir)/ls
	$(call gbuild,$(subst $(tdir),,$<), gsl-$(gsl-version), static)

$(ildir)/libjpeg.a: $(tdir)/jpegsrc.$(libjpeg-version).tar.gz
	$(call gbuild,$(subst $(tdir),,$<), jpeg-9b, static)

$(ildir)/libtiff.a: $(tdir)/tiff-$(libtiff-version).tar.gz \
                   $(ibdir)/ls
	$(call gbuild,$(subst $(tdir),,$<), tiff-$(libtiff-version), static)

$(ildir)/libwcs.a: $(tdir)/wcslib-$(wcslib-version).tar.bz2 \
	           $(ildir)/libcfitsio.a
	$(call gbuild,$(subst $(tdir),,$<), wcslib-$(wcslib-version),     \
                      static, LIBS="-pthread -lcurl -lm" --without-pgplot \
                         --disable-fortran)

# Zlib's `./configure' doesn't use Autoconf's configure script, it just
# accepts a direct `--static' option.
$(ildir)/libz.a: $(tdir)/zlib-$(zlib-version).tar.gz
	$(call gbuild,$(subst $(tdir),,$<), zlib-$(zlib-version), , \
                      --static)





# Programs
# --------
$(ibdir)/bash: $(tdir)/bash-$(bash-version).tar.gz
	$(call gbuild,$(subst $(tdir),,$<), bash-$(bash-version), static)

$(ibdir)/cmake: $(tdir)/cmake-$(cmake-version).tar.gz \
                $(ibdir)/ls
	$(call cbuild,$(subst $(tdir),,$<), cmake-$(cmake-version))

# Unfortunately GNU Make 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
# `--disable-load', but unfortunately I don't know any way to fix the
# second. So, we'll have to build it dynamically for now.
$(ibdir)/make: $(tdir)/make-$(make-version).tar.gz
	$(call gbuild,$(subst $(tdir),,$<), make-$(make-version))

$(ibdir)/ls: $(tdir)/coreutils-$(coreutils-version).tar.xz
	$(call gbuild,$(subst $(tdir),,$<), coreutils-$(coreutils-version), \
                      static)

$(ibdir)/gawk: $(tdir)/gawk-$(gawk-version).tar.gz \
               $(ibdir)/ls
	$(call gbuild,$(subst $(tdir),,$<), gawk-$(gawk-version), static)

$(ibdir)/sed: $(tdir)/sed-$(sed-version).tar.xz \
              $(ibdir)/ls
	$(call gbuild,$(subst $(tdir),,$<), sed-$(sed-version), static)

$(ibdir)/grep: $(tdir)/grep-$(grep-version).tar.xz \
               $(ibdir)/ls
	$(call gbuild,$(subst $(tdir),,$<), grep-$(grep-version), static)

$(ibdir)/libtool: $(tdir)/libtool-$(libtool-version).tar.gz \
                  $(ibdir)/ls
	$(call gbuild,$(subst $(tdir),,$<), libtool-$(libtool-version), static)

$(ibdir)/gs: $(tdir)/ghostscript-$(ghostscript-version).tar.gz \
             $(ibdir)/ls
	$(call gbuild,$(subst $(tdir),,$<), ghostscript-$(ghostscript-version))

$(ibdir)/git: $(tdir)/git-$(git-version).tar.xz \
             $(ibdir)/ls
	$(call gbuild,$(subst $(tdir),,$<), git-$(git-version), static)

$(ibdir)/astnoisechisel: $(tdir)/gnuastro-$(gnuastro-version).tar.lz \
                         $(ildir)/libgsl.a                           \
                         $(ildir)/libcfitsio.a                       \
                         $(ildir)/libwcs.a                           \
                         $(ibdir)/gs                                 \
                         $(ildir)/libjpeg.a                          \
                         $(ildir)/libtiff.a                          \
                         $(ildir)/libgit2.a                          \

	$(call gbuild,$(subst $(tdir),,$<), gnuastro-$(gnuastro-version), \
                      static, , -j8, make check -j8)