1b6209a9bSSimon J. Gerraty# $FreeBSD$ 2b6209a9bSSimon J. Gerraty 3*4938741aSAndriy Voskoboinyk# This is the top-level makefile - derived from the Junos version 4b6209a9bSSimon J. Gerraty# 5b6209a9bSSimon J. Gerraty# If a subdir that matches the requested target exists, we assume 6b6209a9bSSimon J. Gerraty# a build target and initialize DIRDEPS, dirdeps.mk does the rest. 7b6209a9bSSimon J. Gerraty# 8b6209a9bSSimon J. Gerraty# Otherwise we include Makefile.xtras and hope it knows what to do. 9b6209a9bSSimon J. Gerraty# 10b6209a9bSSimon J. Gerraty 11b6209a9bSSimon J. Gerraty# Copyright (c) 2010-2012, Juniper Networks, Inc. 12b6209a9bSSimon J. Gerraty# 13b6209a9bSSimon J. Gerraty# Redistribution and use in source and binary forms, with or without 14b6209a9bSSimon J. Gerraty# modification, are permitted provided that the following conditions 15b6209a9bSSimon J. Gerraty# are met: 16b6209a9bSSimon J. Gerraty# 1. Redistributions of source code must retain the above copyright 17b6209a9bSSimon J. Gerraty# notice, this list of conditions and the following disclaimer. 18b6209a9bSSimon J. Gerraty# 2. Redistributions in binary form must reproduce the above copyright 19b6209a9bSSimon J. Gerraty# notice, this list of conditions and the following disclaimer in the 20b6209a9bSSimon J. Gerraty# documentation and/or other materials provided with the distribution. 21b6209a9bSSimon J. Gerraty# 22b6209a9bSSimon J. Gerraty# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23b6209a9bSSimon J. Gerraty# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24b6209a9bSSimon J. Gerraty# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25b6209a9bSSimon J. Gerraty# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26b6209a9bSSimon J. Gerraty# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27b6209a9bSSimon J. Gerraty# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28b6209a9bSSimon J. Gerraty# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29b6209a9bSSimon J. Gerraty# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30b6209a9bSSimon J. Gerraty# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31b6209a9bSSimon J. Gerraty# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32b6209a9bSSimon J. Gerraty# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33b6209a9bSSimon J. Gerraty 34b6209a9bSSimon J. Gerraty.if ${.MAKE.LEVEL} == 0 35b6209a9bSSimon J. Gerraty 36b6209a9bSSimon J. Gerraty# this is our top-level makefile 37b6209a9bSSimon J. Gerraty.if make(pkg-*) 3861ad1ff5SSimon J. GerratyDIRDEPS_FILTER = Mtargets/* 39b6209a9bSSimon J. Gerraty.endif 40b6209a9bSSimon J. Gerraty 41b6209a9bSSimon J. Gerraty# in theory, this is what we want 4261ad1ff5SSimon J. Gerratytarget_dirs = targets targets/pseudo 43b6209a9bSSimon J. Gerraty# these tweak how we do it 44b6209a9bSSimon J. Gerratytarget_prefix = pkg- build- 45b6209a9bSSimon J. GerratyDIRDEPS := ${.TARGETS:Nall:${target_prefix:@p@S,^$p,,@:ts:}:@t@${target_dirs:@d@$d/$t@}@:@d@${exists(${SRCTOP}/$d):?$d:}@} 46b6209a9bSSimon J. Gerraty 4798e0ffaeSSimon J. Gerratyall_machine_list = ${ALL_MACHINE_LIST} host common 4898e0ffaeSSimon J. Gerraty 4961ad1ff5SSimon J. Gerraty.if ${DIRDEPS:Mtargets/pseudo/*} != "" 50b6209a9bSSimon J. Gerraty# all bets are off 5198e0ffaeSSimon J. GerratyPKG_MACHINE_LIST = ${all_machine_list} 52b6209a9bSSimon J. Gerraty.endif 53b6209a9bSSimon J. Gerraty 54b6209a9bSSimon J. Gerraty.if make(check-commit) 55b6209a9bSSimon J. Gerraty# a special case 5661ad1ff5SSimon J. GerratyDIRDEPS = targets/pseudo/check-commit 57b6209a9bSSimon J. Gerraty.if defined(ALL_MACHINES) 58b6209a9bSSimon J. GerratyCHECK_MACHINE_LIST = all 59b6209a9bSSimon J. Gerraty.undef ALL_MACHINES 60b6209a9bSSimon J. Gerraty.endif 61b6209a9bSSimon J. GerratySHIPDIR = no 62b6209a9bSSimon J. Gerraty 63b6209a9bSSimon J. Gerraty.else 64b6209a9bSSimon J. Gerraty 65b6209a9bSSimon J. Gerraty.if defined(ALL_MACHINES) 66b6209a9bSSimon J. GerratyDIRDEPS := ${DIRDEPS:O:u:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@} 67b6209a9bSSimon J. Gerraty.undef ALL_MACHINES 68b6209a9bSSimon J. GerratyPKG_MACHINE_LIST ?= ${DIRDEPS:E:O:u} 6998e0ffaeSSimon J. Gerraty.elif empty(REQUESTED_MACHINE) 70b6209a9bSSimon J. Gerraty# the above may be insufficient. 71b6209a9bSSimon J. Gerraty# some packages only support one machine which may not be ${MACHINE} 72b6209a9bSSimon J. Gerraty# some support multiple, in which case unless ALL_MACHINES is defined 73b6209a9bSSimon J. Gerraty# we only want ${MACHINE} 74b6209a9bSSimon J. Gerratyplain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@} 75b6209a9bSSimon J. Gerraty.if ${plain} != ${DIRDEPS} 76b6209a9bSSimon J. Gerratyqual := ${DIRDEPS:${plain:${M_ListToSkip}}:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@} 77b6209a9bSSimon J. GerratyDIRDEPS := ${plain} ${qual} 78b6209a9bSSimon J. GerratyPKG_MACHINE_LIST ?= ${MACHINE} ${qual:E:O:u} 79b6209a9bSSimon J. Gerraty.endif 80b6209a9bSSimon J. Gerraty.else 81b6209a9bSSimon J. Gerraty# check that a .MAKE.DEPENDFILE exists 82b6209a9bSSimon J. GerratyDIRDEPS := ${.MAKE.DEPENDFILE_PREFERENCE:T:@m@${DIRDEPS:@d@${exists(${SRCTOP}/$d/$m):?$d:}@}@:O:u} 83b6209a9bSSimon J. Gerraty.endif 84b6209a9bSSimon J. Gerraty.if !empty(PKG_MACHINE_LIST) 85b6209a9bSSimon J. Gerraty.if ${PKG_MACHINE_LIST:Mdepend} != "" 86b6209a9bSSimon J. GerratyPKG_MACHINE_LIST = ${ALL_MACHINE_LIST} 87b6209a9bSSimon J. Gerraty.endif 88b6209a9bSSimon J. GerratyPKG_MACHINE_LIST := ${PKG_MACHINE_LIST} 89b6209a9bSSimon J. Gerraty.endif 90b6209a9bSSimon J. Gerraty.endif 91b6209a9bSSimon J. Gerraty 92b6209a9bSSimon J. Gerraty# we don't use DIRDEPS_FILTER, since we only want it to 93b6209a9bSSimon J. Gerraty# apply to this initial list 94b6209a9bSSimon J. Gerraty.if !empty(REQUESTED_MACHINE) && !empty(DIRDEPS) 95b6209a9bSSimon J. Gerraty# this is a variant of the logic above, we want plain 96b6209a9bSSimon J. Gerraty# but need to filter the qualified DIRDEPS to REQUESTED_MACHINE 97b6209a9bSSimon J. Gerratyplain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@} 9898e0ffaeSSimon J. Gerraty.if !empty(plain) && ${plain} != ${DIRDEPS} 99b6209a9bSSimon J. Gerratyqual := ${DIRDEPS:${plain:${M_ListToSkip}}:M*.${REQUESTED_MACHINE}} 100b6209a9bSSimon J. Gerraty.if empty(qual) 101b6209a9bSSimon J. Gerratyqual := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T}):?$d.${.MAKE.DEPENDFILE:E}:}@} 102b6209a9bSSimon J. Gerraty.endif 103b6209a9bSSimon J. GerratyDIRDEPS := ${plain} ${qual} 104b6209a9bSSimon J. Gerraty.endif 105b6209a9bSSimon J. Gerraty.if empty(DIRDEPS) 10698e0ffaeSSimon J. Gerraty.error ${REQUESTED_MACHINE} is not appropriate for ${.TARGETS} 107b6209a9bSSimon J. Gerraty.endif 108b6209a9bSSimon J. Gerraty.endif 109b6209a9bSSimon J. Gerraty 110b6209a9bSSimon J. Gerraty.if !empty(build_options) 111b6209a9bSSimon J. Gerratybuild_options := ${build_options:O:u} 112b6209a9bSSimon J. Gerraty.for v in ${build_options} 113b6209a9bSSimon J. Gerraty$v = yes 114b6209a9bSSimon J. Gerraty.endfor 115b6209a9bSSimon J. Gerraty.export ${build_options} 116b6209a9bSSimon J. Gerraty.endif 117b6209a9bSSimon J. Gerraty 118b6209a9bSSimon J. Gerraty.if !empty(DIRDEPS) 119b6209a9bSSimon J. Gerraty# This is printed as we read the makefile 120b6209a9bSSimon J. Gerraty# so provides a useful clue as to when we really started. 121b6209a9bSSimon J. Gerraty# This allows us to work out how long reading 122b6209a9bSSimon J. Gerraty# Makefile.depend* takes. 123b6209a9bSSimon J. Gerraty.if ${.MAKEFLAGS:M-V} == "" 12498e0ffaeSSimon J. Gerraty.if ${BUILD_DIRDEPS_CACHE:Uno} == "no" 125b6209a9bSSimon J. Gerraty.info ${.newline}${TIME_STAMP} Start ${.TARGETS} 12698e0ffaeSSimon J. Gerraty.endif 127b6209a9bSSimon J. Gerratynow_utc = ${%s:L:gmtime} 128b6209a9bSSimon J. Gerratystart_utc := ${now_utc} 129b6209a9bSSimon J. Gerraty.endif 130b6209a9bSSimon J. Gerraty 13198e0ffaeSSimon J. Gerraty_begin = 13298e0ffaeSSimon J. Gerraty.if ${BUILD_DIRDEPS_CACHE:Uno} == "no" 13361ad1ff5SSimon J. Gerraty__DEFAULT_YES_OPTIONS+= \ 13461ad1ff5SSimon J. Gerraty CLEAN_ERROR_LOGS 13561ad1ff5SSimon J. Gerraty 13661ad1ff5SSimon J. Gerraty.include <bsd.mkopt.mk> 13761ad1ff5SSimon J. Gerraty 13861ad1ff5SSimon J. Gerraty.if ${MK_CLEAN_ERROR_LOGS} == "yes" 139b6209a9bSSimon J. Gerraty_begin += clean-error-logs 140b6209a9bSSimon J. Gerraty.endif 14161ad1ff5SSimon J. Gerraty 142b6209a9bSSimon J. Gerraty.if !empty(_begin) && !make(clean*) 143b6209a9bSSimon J. Gerratydirdeps: ${_begin} .WAIT 144b6209a9bSSimon J. Gerraty.endif 14598e0ffaeSSimon J. Gerraty.endif 146b6209a9bSSimon J. Gerraty 147b6209a9bSSimon J. Gerraty.include "Makefile.inc" 148b6209a9bSSimon J. Gerraty 149b6209a9bSSimon J. Gerraty.include <dirdeps.mk> 150b6209a9bSSimon J. Gerraty 151b6209a9bSSimon J. Gerraty.for t in ${.TARGETS:Nall:Nclean*:${_begin:Uall:${M_ListToSkip}}} 152b6209a9bSSimon J. Gerraty$t: dirdeps 153b6209a9bSSimon J. Gerraty.endfor 154b6209a9bSSimon J. Gerraty 155b6209a9bSSimon J. Gerratyelapsed_time= seconds=`expr ${now_utc} - ${start_utc}` 156b6209a9bSSimon J. Gerraty 15798e0ffaeSSimon J. Gerraty.if ${BUILD_DIRDEPS_CACHE:Uno} == "no" 158b6209a9bSSimon J. Gerraty.END: _build_finish 159b6209a9bSSimon J. Gerraty_build_finish: .NOMETA 160b6209a9bSSimon J. Gerraty @echo "${TIME_STAMP} Finished ${.TARGETS} ${elapsed_time}" 16198e0ffaeSSimon J. Gerraty.endif 162b6209a9bSSimon J. Gerraty 163b6209a9bSSimon J. Gerraty.ERROR: _build_failed 164b6209a9bSSimon J. Gerraty_build_failed: .NOMETA 165b6209a9bSSimon J. Gerraty @echo "${TIME_STAMP} Failed ${.TARGETS} ${elapsed_time}" 166b6209a9bSSimon J. Gerraty 167b6209a9bSSimon J. Gerraty.endif # !empty(DIRDEPS) 168b6209a9bSSimon J. Gerraty 169b6209a9bSSimon J. Gerratyclean-error-logs: .NOMETA 170b6209a9bSSimon J. Gerraty @test ! -d ${meta_error_log:H} || rm -f ${meta_error_log:H}/*log 171b6209a9bSSimon J. Gerraty 172b6209a9bSSimon J. Gerraty.if !target(_DIRDEP_USE) 173b6209a9bSSimon J. Gerraty# we did not read dirdeps.mk above, the target may be here 174b6209a9bSSimon J. Gerraty.include "Makefile.xtras" 175b6209a9bSSimon J. Gerraty.endif 176b6209a9bSSimon J. Gerraty 177b6209a9bSSimon J. Gerraty.else 178b6209a9bSSimon J. Gerraty# dirdeps does it all 179b6209a9bSSimon J. Gerratyall: 180b6209a9bSSimon J. Gerraty.endif # .MAKE.LEVEL == 0 181b6209a9bSSimon J. Gerraty 182