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