blob: cee210d9502919b43d7f4b1467daf5b018d16c1a [file] [log] [blame]
Joey Armstrongf548adc2023-09-08 15:59:42 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrongdb844cd2024-08-23 15:23:44 -04003# Copyright 2023-2024 Open Networking Foundation Contributors
Joey Armstrongf548adc2023-09-08 15:59:42 -04004#
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#
Joey Armstrongdb844cd2024-08-23 15:23:44 -040017# SPDX-FileCopyrightText: 2023 Open Networking Foundation Contributors
Joey Armstrongf548adc2023-09-08 15:59:42 -040018# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
Joey Armstrongf548adc2023-09-08 15:59:42 -040020# Setup:
21# 1) Makefile
22# include config.mk
23# include makefiles/include.mk
24# 2) cd makefiles
25# 23 copy makefiles_include_mk.ex into $repo/makefiles/include.mk
26# 4) make create-onf-lib
27# -----------------------------------------------------------------------
28
29$(if $(DEBUG),$(warning ENTER))
30
31## -----------------------------------------------------------------------
Joey Armstrongdb844cd2024-08-23 15:23:44 -040032## Infer path to cloned sandbox root
33## [TODO] Deprecate TOP=
34## -----------------------------------------------------------------------
35lf-sbx-root := $(abspath $(lastword $(MAKEFILE_LIST)))
36lf-sbx-root := $(subst /lf/include.mk,$(null),$(lf-sbx-root))
37
38## -----------------------------------------------------------------------
Joey Armstrongf548adc2023-09-08 15:59:42 -040039## Define vars based on relative import (normalize symlinks)
40## Usage: include makefiles/onf/include.mk
41## -----------------------------------------------------------------------
Joey Armstronga2db6cd2023-11-30 12:16:18 -050042onf-mk-abs := $(abspath $(lastword $(MAKEFILE_LIST)))
Joey Armstrongf548adc2023-09-08 15:59:42 -040043onf-mk-top := $(subst /include.mk,$(null),$(onf-mk-abs))
Joey Armstrongdb844cd2024-08-23 15:23:44 -040044onf-mk-lib := $(onf-mk-top)/onf-make/makefiles
Joey Armstrongf548adc2023-09-08 15:59:42 -040045onf-mk-loc := $(onf-mk-top)/local
46
47TOP ?= $(patsubst %/makefiles/include.mk,%,$(onf-mk-abs))
48
Joey Armstrongdb844cd2024-08-23 15:23:44 -040049## -----------------------------------------------------------------------
50## This variable is a bridge to help transition away from legacy makefiles.
51## -----------------------------------------------------------------------
52legacy-mk := $(lf-sbx-root)/makefiles
53
Joey Armstrongf548adc2023-09-08 15:59:42 -040054## ------------------------------------------------------
55## Two distinct vars needed to access library or project
56## ------------------------------------------------------
57ONF_MAKEDIR ?= $(onf-mk-lib)
58MAKEDIR ?= $(onf-mk-loc)
59
Joey Armstrongdb844cd2024-08-23 15:23:44 -040060# -----------------------------------------------------------------------
61# Load per-repository conditionals
62# Load late else alter MAKEFILE_LIST
63# NOTE: config.mk can be removed if dynamic feature detection by
64# file extension is added.
65# -----------------------------------------------------------------------
66include $(wildcard $(lf-sbx-root)/config.mk $(lf-sbx-root)/lf/config.mk)
67
Joey Armstrongf548adc2023-09-08 15:59:42 -040068## -----------------------------------------------------------------------
69## Load makefiles in order:
70## 1) Library constants and logic loaded first
71## 2) Parameterize and augment targets from local (repo specific)
72## -----------------------------------------------------------------------
73include $(onf-mk-lib)/include.mk
74include $(onf-mk-loc)/include.mk
75
Joey Armstrongdb844cd2024-08-23 15:23:44 -040076## Define late so caller (?- env --ignore-environment -?)
77GIT ?= /usr/bin/env git
78
Joey Armstronga2db6cd2023-11-30 12:16:18 -050079## -----------------------------------------------------------------------
80## Intent: Helper targets for maintaining git-submodules (repo:onf-make)
81## -----------------------------------------------------------------------
82
Joey Armstrongf548adc2023-09-08 15:59:42 -040083## -----------------------------------------
84## Submodue init target for new repositories
85## -----------------------------------------
86create-onf-lib : $(onf-mk-lib)
87$(onf-mk-lib):
88 mkdir -p $(dir $@)# makefiles
89 cd $(dir $@) \
90 && git submodule https://github.com/opencord/onf-make.git onf-lib
91
Joey Armstronga2db6cd2023-11-30 12:16:18 -050092## -----------------------------------------------------------------------
93## Intent: This target will update dependent git-submodule to the latest
94## version available from the remote repository. Subsequently
95## a checkin will be needed to make the submodule update permanent.
96## -----------------------------------------------------------------------
Joey Armstrongdb844cd2024-08-23 15:23:44 -040097.PHONY: update-git-submodules
98update-git-submodules:
99 $(GIT) submodule foreach git pull
Joey Armstrongf548adc2023-09-08 15:59:42 -0400100
Joey Armstronga2db6cd2023-11-30 12:16:18 -0500101## -----------------------------------------------------------------------
102## Intent: On-demand cloning of git submodule(s).
103## -----------------------------------------------------------------------
104## Trigger: include $(onf-mk-lib)/include.mk
105## - When the make command attempts to include a makefile from the
106## repo:onf-make submodule, this target/dependency will initialize
107## and checkout all submodules the current repository depends on.
108## -----------------------------------------------------------------------
Joey Armstrongdb844cd2024-08-23 15:23:44 -0400109.PHONY: git-submodules
110git-submodules : $(onf-mk-lib)/include.mk
111
Joey Armstronga2db6cd2023-11-30 12:16:18 -0500112$(onf-mk-lib)/include.mk:
Joey Armstrongdb844cd2024-08-23 15:23:44 -0400113
114 $(call banner-enter,(Checkout git submodules))
115
116 $(GIT) submodule update --init --recursive
117
118 $(call banner-leave,(Checkout git submodules))
119
120## -----------------------------------------------------------------------
121## -----------------------------------------------------------------------
122help-git :
123 @printf ' %-33.33s %s\n' 'git-submodules' \
124 'Init and recursive checkout of git submodule(s)'
125 @printf ' %-33.33s %s\n' 'update-git-submodules' \
126 'Update git submodule(s) to the latest version'
Joey Armstronga2db6cd2023-11-30 12:16:18 -0500127
Joey Armstrongf548adc2023-09-08 15:59:42 -0400128$(if $(DEBUG),$(warning LEAVE))
129
130# [EOF]