1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
19 $1_tarball_strip_dirs ?= 0
20 $1_src_dir ?= $(B)/src-$1
21 $1_patch_dir ?= $(CURDIR)/patches/$1_$($1_version)
22 $1_build_dir ?= $(B)/build-$1
23 $1_install_dir ?= $(I)
24 $1_config_log ?= $(B)/$1.config.log
25 $1_build_log ?= $(B)/$1.build.log
26 $1_install_log ?= $(B)/$1.install.log
28 ##############################################################################
30 ##############################################################################
31 downloads/$($1_tarball):
33 @if [ -e $(DL_CACHE_DIR)/$($1_tarball) ] ; \
34 then cp $(DL_CACHE_DIR)/$($1_tarball) downloads/ ; \
36 echo "Downloading $($1_url)" ; \
37 curl -o downloads/$($1_tarball) -LO $($1_url) ; \
39 @rm -f $(B)/.download.ok
41 $(B)/.$1.download.ok: downloads/$($1_tarball)
43 $$(call h1,"validating $1 $($1_version) checksum")
44 @SUM=$$(shell openssl md5 $$< | cut -f 2 -d " " -) ; \
45 ([ "$$$${SUM}" = "$($1_tarball_md5sum)" ] || \
46 ( echo "==========================================================" && \
47 echo "Bad Checksum!" && \
48 echo "Expected: $($1_tarball_md5sum)" && \
49 echo "Calculated: $$$${SUM}" && \
50 echo "Please remove $$< and retry" && \
51 echo "==========================================================" && \
56 $1-download: $(B)/.$1.download.ok
58 ##############################################################################
60 ##############################################################################
61 $(B)/.$1.extract.ok: $(B)/.$1.download.ok
62 $$(call h1,"extracting $1 $($1_version)")
63 @mkdir -p $$($1_src_dir)
65 --directory $$($1_src_dir) \
67 --strip-components=$$($1_tarball_strip_dirs) \
68 --file downloads/$($1_tarball)
72 $1-extract: $(B)/.$1.extract.ok
74 ##############################################################################
76 ##############################################################################
77 $(B)/.$1.patch.ok: $(B)/.$1.extract.ok
78 $$(call h1,"patching $1 $($1_version)")
79 ifneq ($$(wildcard $$($1_patch_dir)/*.patch),)
80 @for f in $$($1_patch_dir)/*.patch ; do \
81 echo "Applying patch: $$$$(basename $$$$f)" ; \
82 patch -p1 -d $$($1_src_dir) < $$$$f ; \
88 $1-patch: $(B)/.$1.patch.ok
90 ##############################################################################
92 ##############################################################################
94 ifeq ($$(call $1_config_cmds),)
96 @cd $$($1_build_dir) && \
97 CFLAGS="$$($1_cflags)" \
98 $$($1_src_dir)/configure \
99 --prefix=$$($1_install_dir) \
100 $$($1_configure_args) > $$($1_config_log)
104 $(B)/.$1.config.ok: $(B)/.$1.patch.ok $(addsuffix -install,$($1_depends))
105 $$(call h1,"configuring $1 $($1_version) - log: $$($1_config_log)")
106 @mkdir -p $$($1_build_dir)
107 $$(call $1_config_cmds)
111 $1-config: $(B)/.$1.config.ok
113 ##############################################################################
115 ##############################################################################
117 ifeq ($$(call $1_build_cmds),)
119 @$(MAKE) $(MAKE_ARGS) -C $$($1_build_dir) > $$($1_build_log)
123 $(B)/.$1.build.ok: $(B)/.$1.config.ok
124 $$(call h1,"building $1 $($1_version) - log: $$($1_build_log)")
125 $$(call $1_build_cmds)
129 $1-build: $(B)/.$1.build.ok
131 ##############################################################################
133 ##############################################################################
135 ifeq ($$(call $1_install_cmds),)
136 define $1_install_cmds
137 @$(MAKE) $(MAKE_ARGS) -C $$($1_build_dir) install > $$($1_install_log)
141 $(B)/.$1.install.ok: $(B)/.$1.build.ok
142 $$(call h1,"installing $1 $($1_version) - log: $$($1_install_log)")
143 $$(call $1_install_cmds)
147 $1-install: $(B)/.$1.install.ok
149 ALL_TARGETS += $1-install