aboutsummaryrefslogtreecommitdiff
path: root/reproduce/software/make/build-rules.mk
blob: 9f5b493ca4356366e6727e2a1de8b81bb13e5da6 (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
# Generic configurable recipes to build packages with GNU Build system or
# CMake. This is Makefile is not intended to be run directly, it will be
# imported into `basic.mk' and `high-level.mk'. They should be activated
# with Make's `Call' function.
#
# Copyright (C) 2018-2020 Mohammad Akhlaghi <mohammad@akhlaghi.org>
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this Makefile.  If not, see <http://www.gnu.org/licenses/>.





# IMPORTANT note
# --------------
#
# Without using `&&', if a step fails, the process will continue. However,
# in the `if' statements, we need `;' (particularly between `]' and
# `then'). So we need to put any necessary checks at the start, then when
# we start the process, every command will be separated by an `&&'.





# GNU Build system
# ----------------
#
# Arguments:
#  1: Directory name after unpacking.
#  2: Set to `static' for a static build.
#  3: Extra configuration options.
#  4: Extra options/arguments to pass to Make.
#  5: Step to run between `make' and `make install': usually `make check'.
#  6: The configuration script (`configure' by default).
#  7: Arguments for `make install'.
#
# NOTE: Unfortunately the configure script of `zlib' doesn't recognize
# `SHELL'. So we'll have to remove it from the call to the configure
# script.
#
# NOTE: A program might not contain any configure script. In this case,
# we'll just pass a non-relevant function like `pwd'. So SED should be used
# to modify `confscript' or to set `configop'.
gbuild = if [ x$(static_build) = xyes ] && [ "x$(2)" = xstatic ]; then \
	   export LDFLAGS="$$LDFLAGS -static"; \
	 fi; \
	 check="$(5)"; \
	 if [ x"$$check" = x ]; then check="echo Skipping-check"; fi; \
	 cd $(ddir); rm -rf $(1); \
	 if [ x"$$gbuild_tar" = x ]; then \
	   tarball=$(word 1,$(filter $(tdir)/%,$^)); \
	 else tarball=$$gbuild_tar; \
	 fi; \
	 if ! tar xf $$tarball; then \
	   echo; echo "Tar error"; exit 1; fi; \
	 cd $(1); \
	          \
	 if   [ x"$(strip $(6))" = x ]; then confscript=./configure; \
	 else confscript="$(strip $(6))"; \
	 fi; \
             \
	 if   [ -f $(ibdir)/bash ]; then \
	   if [ -f "$$confscript" ]; then \
	     sed -e's|\#\! /bin/sh|\#\! $(ibdir)/bash|' \
	         -e's|\#\!/bin/sh|\#\! $(ibdir)/bash|' \
	         $$confscript > $$confscript-tmp; \
	     mv $$confscript-tmp $$confscript; \
	     chmod +x $$confscript; \
	   fi; \
	   shellop="SHELL=$(ibdir)/bash"; \
	 elif [ -f /bin/bash ]; then shellop="SHELL=/bin/bash"; \
	 else shellop="SHELL=/bin/sh"; \
	 fi; \
             \
	 if [ -f "$$confscript" ]; then \
	   if [ x"$(strip $(1))" = x"zlib-$(zlib-version)" ]; then \
	     configop="--prefix=$(idir)"; \
	   else configop="$$shellop --prefix=$(idir)"; \
	   fi; \
	 fi; \
	     \
	 echo; echo "Using '$$confscript' to configure:"; echo; \
	 echo "$$confscript $(3) $$configop"; echo; \
	 $$confscript $(3) $$configop \
	 && make "$$shellop" $(4) \
	 && $$check \
	 && make "$$shellop" install $(7) \
	 && cd .. \
	 && rm -rf $(1)




# CMake
# -----
#
# According to the link below, in CMake `/bin/sh' is hardcoded, so there is
# no way to change it unfortunately!
#
# https://stackoverflow.com/questions/21167014/how-to-set-shell-variable-in-makefiles-generated-by-cmake
cbuild = if [ x$(static_build) = xyes ] && [ $(2)x = staticx ]; then \
	   export LDFLAGS="$$LDFLAGS -static"; \
	   opts="-DBUILD_SHARED_LIBS=OFF"; \
	 fi; \
	 cd $(ddir) \
	 && rm -rf $(1) \
	 && tar xf $(word 1,$(filter $(tdir)/%,$^)) \
	 && cd $(1) \
	 && rm -rf project-build \
	 && mkdir project-build \
	 && cd project-build \
	 && cmake .. -DCMAKE_LIBRARY_PATH=$(ildir) \
	             -DCMAKE_INSTALL_PREFIX=$(idir) \
	             -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON $$opts $(3) \
	 && make && make install \
	 && cd ../.. \
	 && rm -rf $(1)