Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 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: |
| 5 | # |
| 6 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | # |
| 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. |
| 13 | |
| 14 | define h1 |
| 15 | @echo "--- $(1)" |
| 16 | endef |
| 17 | |
| 18 | define package |
| 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 |
| 27 | |
| 28 | ############################################################################## |
| 29 | # Download |
| 30 | ############################################################################## |
| 31 | downloads/$($1_tarball): |
| 32 | mkdir -p downloads |
| 33 | @if [ -e $(DL_CACHE_DIR)/$($1_tarball) ] ; \ |
Benoît Ganne | fe750c2 | 2019-03-25 11:41:34 +0100 | [diff] [blame] | 34 | then cp $(DL_CACHE_DIR)/$($1_tarball) $$@ ; \ |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 35 | else \ |
| 36 | echo "Downloading $($1_url)" ; \ |
Benoît Ganne | fe750c2 | 2019-03-25 11:41:34 +0100 | [diff] [blame] | 37 | curl -o $$@ -LO $($1_url) ; \ |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 38 | fi |
Benoît Ganne | fe750c2 | 2019-03-25 11:41:34 +0100 | [diff] [blame] | 39 | @rm -f $(B)/.$1.download.ok |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 40 | |
| 41 | $(B)/.$1.download.ok: downloads/$($1_tarball) |
| 42 | @mkdir -p $(B) |
| 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 "==========================================================" && \ |
| 52 | false )) |
| 53 | @touch $$@ |
| 54 | |
| 55 | .PHONY: $1-download |
| 56 | $1-download: $(B)/.$1.download.ok |
| 57 | |
| 58 | ############################################################################## |
| 59 | # Extract |
| 60 | ############################################################################## |
| 61 | $(B)/.$1.extract.ok: $(B)/.$1.download.ok |
| 62 | $$(call h1,"extracting $1 $($1_version)") |
| 63 | @mkdir -p $$($1_src_dir) |
| 64 | @tar \ |
| 65 | --directory $$($1_src_dir) \ |
| 66 | --extract \ |
| 67 | --strip-components=$$($1_tarball_strip_dirs) \ |
| 68 | --file downloads/$($1_tarball) |
| 69 | @touch $$@ |
| 70 | |
| 71 | .PHONY: $1-extract |
| 72 | $1-extract: $(B)/.$1.extract.ok |
| 73 | |
| 74 | ############################################################################## |
| 75 | # Patch |
| 76 | ############################################################################## |
Damjan Marion | d93638e | 2019-03-29 21:22:09 +0100 | [diff] [blame] | 77 | $(B)/.$1.patch.ok: $(B)/.$1.extract.ok |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 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 ; \ |
| 83 | done |
| 84 | endif |
| 85 | @touch $$@ |
| 86 | |
| 87 | .PHONY: $1-patch |
| 88 | $1-patch: $(B)/.$1.patch.ok |
| 89 | |
| 90 | ############################################################################## |
| 91 | # Config |
| 92 | ############################################################################## |
| 93 | |
| 94 | ifeq ($$(call $1_config_cmds),) |
| 95 | define $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) |
| 101 | endef |
| 102 | endif |
| 103 | |
Mohammed Hawari | 9db6db0 | 2023-02-02 13:29:28 +0100 | [diff] [blame] | 104 | ifneq ($(filter $1,$(VPP_SKIP_EXTERNAL)), $1) |
Jieqiang Wang | d69233f | 2023-02-24 16:40:58 +0800 | [diff] [blame^] | 105 | $(B)/.$1.config.ok: $(B)/.$1.patch.ok $(addprefix $(B)/.,$(addsuffix .install.ok,$($1_depends))) |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 106 | $$(call h1,"configuring $1 $($1_version) - log: $$($1_config_log)") |
| 107 | @mkdir -p $$($1_build_dir) |
| 108 | $$(call $1_config_cmds) |
| 109 | @touch $$@ |
Mohammed Hawari | 9db6db0 | 2023-02-02 13:29:28 +0100 | [diff] [blame] | 110 | else |
| 111 | $(B)/.$1.config.ok: |
| 112 | $$(call h1,"Skipping $1 $($1_version)") |
| 113 | @mkdir -p $(B) |
| 114 | @touch $$@ |
| 115 | endif |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 116 | |
| 117 | .PHONY: $1-config |
| 118 | $1-config: $(B)/.$1.config.ok |
| 119 | |
| 120 | ############################################################################## |
| 121 | # Build |
| 122 | ############################################################################## |
| 123 | |
| 124 | ifeq ($$(call $1_build_cmds),) |
| 125 | define $1_build_cmds |
| 126 | @$(MAKE) $(MAKE_ARGS) -C $$($1_build_dir) > $$($1_build_log) |
| 127 | endef |
| 128 | endif |
| 129 | |
Mohammed Hawari | 9db6db0 | 2023-02-02 13:29:28 +0100 | [diff] [blame] | 130 | ifneq ($(filter $1,$(VPP_SKIP_EXTERNAL)), $1) |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 131 | $(B)/.$1.build.ok: $(B)/.$1.config.ok |
| 132 | $$(call h1,"building $1 $($1_version) - log: $$($1_build_log)") |
| 133 | $$(call $1_build_cmds) |
| 134 | @touch $$@ |
Mohammed Hawari | 9db6db0 | 2023-02-02 13:29:28 +0100 | [diff] [blame] | 135 | else |
| 136 | $(B)/.$1.build.ok: |
| 137 | $$(call h1,"Skipping $1 $($1_version)") |
| 138 | @mkdir -p $(B) |
| 139 | @touch $$@ |
| 140 | endif |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 141 | |
| 142 | .PHONY: $1-build |
| 143 | $1-build: $(B)/.$1.build.ok |
| 144 | |
| 145 | ############################################################################## |
| 146 | # Install |
| 147 | ############################################################################## |
| 148 | |
| 149 | ifeq ($$(call $1_install_cmds),) |
| 150 | define $1_install_cmds |
| 151 | @$(MAKE) $(MAKE_ARGS) -C $$($1_build_dir) install > $$($1_install_log) |
| 152 | endef |
| 153 | endif |
| 154 | |
Mohammed Hawari | 9db6db0 | 2023-02-02 13:29:28 +0100 | [diff] [blame] | 155 | ifneq ($(filter $1,$(VPP_SKIP_EXTERNAL)), $1) |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 156 | $(B)/.$1.install.ok: $(B)/.$1.build.ok |
| 157 | $$(call h1,"installing $1 $($1_version) - log: $$($1_install_log)") |
| 158 | $$(call $1_install_cmds) |
| 159 | @touch $$@ |
Mohammed Hawari | 9db6db0 | 2023-02-02 13:29:28 +0100 | [diff] [blame] | 160 | else |
| 161 | $(B)/.$1.install.ok: |
| 162 | $$(call h1,"Skipping $1 $($1_version)") |
| 163 | @mkdir -p $(B) |
| 164 | @touch $$@ |
| 165 | endif |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 166 | |
| 167 | .PHONY: $1-install |
| 168 | $1-install: $(B)/.$1.install.ok |
| 169 | |
Mohammed Hawari | 4e939ce | 2022-09-19 16:26:25 +0200 | [diff] [blame] | 170 | .PHONY: $1-show-% |
| 171 | $1-show-%: |
| 172 | @echo $$($$*) |
| 173 | |
Damjan Marion | 561f273 | 2018-09-21 12:27:45 +0200 | [diff] [blame] | 174 | ALL_TARGETS += $1-install |
| 175 | endef |