Joey Armstrong | fe2bf57 | 2024-04-29 12:20:35 -0400 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2023-2024 Open Networking Foundation Contributors |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # ----------------------------------------------------------------------- |
| 17 | # SPDX-FileCopyrightText: 2023-2024 Open Networking Foundation Contributors |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ----------------------------------------------------------------------- |
| 20 | |
| 21 | $(if $(DEBUG),$(warning ENTER)) |
| 22 | |
| 23 | ## ----------------------------------------------------------------------- |
| 24 | ## Infer path to cloned sandbox root |
| 25 | ## [TODO] Deprecate TOP= |
| 26 | ## ----------------------------------------------------------------------- |
| 27 | lf-sbx-root := $(abspath $(lastword $(MAKEFILE_LIST))) |
| 28 | lf-sbx-root := $(subst /lf/include.mk,$(null),$(lf-sbx-root)) |
| 29 | |
| 30 | ## ----------------------------------------------------------------------- |
| 31 | ## Define vars based on relative import (normalize symlinks) |
| 32 | ## Usage: include makefiles/onf/include.mk |
| 33 | ## ----------------------------------------------------------------------- |
| 34 | onf-mk-abs := $(abspath $(lastword $(MAKEFILE_LIST))) |
| 35 | onf-mk-top := $(subst /include.mk,$(null),$(onf-mk-abs)) |
| 36 | onf-mk-lib := $(onf-mk-top)/onf-make/makefiles |
| 37 | onf-mk-loc := $(onf-mk-top)/local |
| 38 | |
| 39 | TOP ?= $(patsubst %/makefiles/include.mk,%,$(onf-mk-abs)) |
| 40 | |
| 41 | ## ----------------------------------------------------------------------- |
| 42 | ## This variable is a bridge to help transition away from legacy makefiles. |
| 43 | ## ----------------------------------------------------------------------- |
| 44 | legacy-mk := $(lf-sbx-root)/makefiles |
| 45 | |
| 46 | ## ------------------------------------------------------ |
| 47 | ## Two distinct vars needed to access library or project |
| 48 | ## ------------------------------------------------------ |
| 49 | ONF_MAKEDIR ?= $(onf-mk-lib) |
| 50 | MAKEDIR ?= $(onf-mk-loc) |
| 51 | |
| 52 | # ----------------------------------------------------------------------- |
| 53 | # Load per-repository conditionals |
| 54 | # Load late else alter MAKEFILE_LIST |
| 55 | # NOTE: config.mk can be removed if dynamic feature detection by |
| 56 | # file extension is added. |
| 57 | # ----------------------------------------------------------------------- |
| 58 | include $(wildcard $(lf-sbx-root)/config.mk $(lf-sbx-root)/lf/config.mk) |
| 59 | |
| 60 | ## ----------------------------------------------------------------------- |
| 61 | ## Load makefiles in order: |
| 62 | ## 1) Library constants and logic loaded first |
| 63 | ## 2) Parameterize and augment targets from local (repo specific) |
| 64 | ## ----------------------------------------------------------------------- |
| 65 | include $(onf-mk-lib)/include.mk |
| 66 | include $(onf-mk-loc)/include.mk |
| 67 | |
| 68 | ## Define late so caller (?- env --ignore-environment -?) |
| 69 | GIT ?= /usr/bin/env git |
| 70 | |
| 71 | ## ----------------------------------------------------------------------- |
| 72 | ## Intent: This target will update dependent git-submodule to the latest |
| 73 | ## version available from the remote repository. Subsequently |
| 74 | ## a checkin will be needed to make the submodule update permanent. |
| 75 | ## ----------------------------------------------------------------------- |
| 76 | .PHONY: update-git-submodules |
| 77 | update-git-submodules: |
| 78 | $(GIT) submodule foreach git pull |
| 79 | |
| 80 | ## ----------------------------------------------------------------------- |
| 81 | ## Intent: On-demand cloning of git submodule(s). |
| 82 | ## ----------------------------------------------------------------------- |
| 83 | ## Trigger: include $(onf-mk-lib)/include.mk |
| 84 | ## - When the make command attempts to include a makefile from the |
| 85 | ## repo:onf-make submodule, this target/dependency will initialize |
| 86 | ## and checkout all submodules the current repository depends on. |
| 87 | ## ----------------------------------------------------------------------- |
| 88 | .PHONY: git-submodules |
| 89 | git-submodules : $(onf-mk-lib)/include.mk |
| 90 | |
| 91 | $(onf-mk-lib)/include.mk: |
| 92 | |
| 93 | $(call banner-enter,(Checkout git submodules)) |
| 94 | |
| 95 | $(GIT) submodule update --init --recursive |
| 96 | |
| 97 | $(call banner-leave,(Checkout git submodules)) |
| 98 | |
| 99 | ## ----------------------------------------------------------------------- |
| 100 | ## ----------------------------------------------------------------------- |
| 101 | help-git : |
| 102 | @printf ' %-33.33s %s\n' 'git-submodules' \ |
| 103 | 'Init and recursive checkout of git submodule(s)' |
| 104 | @printf ' %-33.33s %s\n' 'update-git-submodules' \ |
| 105 | 'Update git submodule(s) to the latest version' |
| 106 | |
| 107 | $(if $(DEBUG),$(warning LEAVE)) |
| 108 | |
| 109 | # [EOF] |