3 # This is the top-level makefile - derrived from the Junos version
5 # If a subdir that matches the requested target exists, we assume
6 # a build target and initialize DIRDEPS, dirdeps.mk does the rest.
8 # Otherwise we include Makefile.xtras and hope it knows what to do.
11 # Copyright (c) 2010-2012, Juniper Networks, Inc.
13 # Redistribution and use in source and binary forms, with or without
14 # modification, are permitted provided that the following conditions
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.
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.
34 .if ${.MAKE.LEVEL} == 0
36 # this is our top-level makefile
38 DIRDEPS_FILTER = Mtargets/*
41 # in theory, this is what we want
42 target_dirs = targets targets/pseudo
43 # these tweak how we do it
44 target_prefix = pkg- build-
45 DIRDEPS := ${.TARGETS:Nall:${target_prefix:@p@S,^$p,,@:ts:}:@t@${target_dirs:@d@$d/$t@}@:@d@${exists(${SRCTOP}/$d):?$d:}@}
47 .if ${DIRDEPS:Mtargets/pseudo/*} != ""
49 PKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
52 .if make(check-commit)
54 DIRDEPS = targets/pseudo/check-commit
55 .if defined(ALL_MACHINES)
56 CHECK_MACHINE_LIST = all
63 all_machine_list = ${ALL_MACHINE_LIST} host common
64 .if defined(ALL_MACHINES)
65 DIRDEPS := ${DIRDEPS:O:u:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@}
67 PKG_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}
73 plain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@}
74 .if ${plain} != ${DIRDEPS}
75 qual := ${DIRDEPS:${plain:${M_ListToSkip}}:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@}
76 DIRDEPS := ${plain} ${qual}
77 PKG_MACHINE_LIST ?= ${MACHINE} ${qual:E:O:u}
80 # check that a .MAKE.DEPENDFILE exists
81 DIRDEPS := ${.MAKE.DEPENDFILE_PREFERENCE:T:@m@${DIRDEPS:@d@${exists(${SRCTOP}/$d/$m):?$d:}@}@:O:u}
83 .if !empty(PKG_MACHINE_LIST)
84 .if ${PKG_MACHINE_LIST:Mdepend} != ""
85 PKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
87 PKG_MACHINE_LIST := ${PKG_MACHINE_LIST}
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
96 plain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@}
97 .if ${plain} != ${DIRDEPS}
98 qual := ${DIRDEPS:${plain:${M_ListToSkip}}:M*.${REQUESTED_MACHINE}}
100 qual := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T}):?$d.${.MAKE.DEPENDFILE:E}:}@}
102 DIRDEPS := ${plain} ${qual}
105 .error ${REQUESTED_MACHINE} is not appropriate for ${DEP_RELDIR:T}
109 .if !empty(build_options)
110 build_options := ${build_options:O:u}
111 .for v in ${build_options}
114 .export ${build_options}
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}
124 now_utc = ${%s:L:gmtime}
125 start_utc := ${now_utc}
128 _begin = count-makefiles
130 __DEFAULT_YES_OPTIONS+= \
133 .include <bsd.mkopt.mk>
135 .if ${MK_CLEAN_ERROR_LOGS} == "yes"
136 _begin += clean-error-logs
139 .if !empty(_begin) && !make(clean*)
140 dirdeps: ${_begin} .WAIT
143 .include "Makefile.inc"
145 .include <dirdeps.mk>
147 .for t in ${.TARGETS:Nall:Nclean*:${_begin:Uall:${M_ListToSkip}}}
151 elapsed_time= seconds=`expr ${now_utc} - ${start_utc}`
153 count-makefiles: .NOMETA
154 @echo "${TIME_STAMP} Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${elapsed_time}"
157 _build_finish: .NOMETA
158 @echo "${TIME_STAMP} Finished ${.TARGETS} ${elapsed_time}"
160 .ERROR: _build_failed
161 _build_failed: .NOMETA
162 @echo "${TIME_STAMP} Failed ${.TARGETS} ${elapsed_time}"
164 .endif # !empty(DIRDEPS)
166 clean-error-logs: .NOMETA
167 @test ! -d ${meta_error_log:H} || rm -f ${meta_error_log:H}/*log
169 .if !target(_DIRDEP_USE)
170 # we did not read dirdeps.mk above, the target may be here
171 .include "Makefile.xtras"
175 # dirdeps does it all
177 .endif # .MAKE.LEVEL == 0