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 = Mpkgs/*
41 # in theory, this is what we want
42 target_dirs = pkgs pkgs/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:Mpkgs/pseudo/*} != ""
49 PKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
52 .if make(check-commit)
54 DIRDEPS = pkgs/pseudo/check-commit
55 .if defined(ALL_MACHINES)
56 CHECK_MACHINE_LIST = all
63 .if defined(ALL_MACHINES)
64 DIRDEPS := ${DIRDEPS:O:u:@d@${ALL_MACHINE_LIST:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T:R}.$m):?$d.$m:}@}@}
66 PKG_MACHINE_LIST ?= ${DIRDEPS:E:O:u}
67 .elif defined(HOST_MACHINE) && ${MACHINE} == ${HOST_MACHINE}
68 # the above may be insufficient.
69 # some packages only support one machine which may not be ${MACHINE}
70 # some support multiple, in which case unless ALL_MACHINES is defined
71 # we only want ${MACHINE}
72 plain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T:R}):?$d:}@}
73 .if ${plain} != ${DIRDEPS}
74 all_machine_list = ${ALL_MACHINE_LIST} host
75 qual := ${DIRDEPS:${plain:${M_ListToSkip}}:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T:R}.$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 .if !empty(build_options)
92 build_options := ${build_options:O:u}
93 .for v in ${build_options}
96 .export ${build_options}
100 # This is printed as we read the makefile
101 # so provides a useful clue as to when we really started.
102 # This allows us to work out how long reading
103 # Makefile.depend* takes.
104 .if ${.MAKEFLAGS:M-V} == ""
105 .info ${.newline}${TIME_STAMP} Start ${.TARGETS}
106 now_utc = ${%s:L:gmtime}
107 start_utc := ${now_utc}
110 _begin = count-makefiles
112 # by default, we clean pkgs/ which can otherwise accumulate a lot of cruft
113 .if ${NEED_CLEAN_PKGS:Uyes:tl} != "no"
116 .if defined(SHIPDIR) && ${NEED_CLEAN_SHIPDIR:Uno:tl} != "no" && exists(${SHIPDIR})
117 _begin += clean-shipdir
119 .if ${NEED_CLEAN_ERROR_LOGS:Uyes:tl} == "yes"
120 _begin += clean-error-logs
122 .if !empty(_begin) && !make(clean*)
123 dirdeps: ${_begin} .WAIT
126 .include "Makefile.inc"
128 .include <dirdeps.mk>
130 .for t in ${.TARGETS:Nall:Nclean*:${_begin:Uall:${M_ListToSkip}}}
134 elapsed_time= seconds=`expr ${now_utc} - ${start_utc}`
136 count-makefiles: .NOMETA
137 @echo "${TIME_STAMP} Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${elapsed_time}"
140 _build_finish: .NOMETA
141 @echo "${TIME_STAMP} Finished ${.TARGETS} ${elapsed_time}"
143 .ERROR: _build_failed
144 _build_failed: .NOMETA
145 @echo "${TIME_STAMP} Failed ${.TARGETS} ${elapsed_time}"
147 .endif # !empty(DIRDEPS)
149 clean-error-logs: .NOMETA
150 @test ! -d ${meta_error_log:H} || rm -f ${meta_error_log:H}/*log
153 @rm -rf ${ALL_MACHINE_LIST:N${MACHINE}:@m@${OBJROOT}$m/pkgs@} ${OBJROOT}${MACHINE}/pkgs/*
155 clean-shipdir: .NOMETA
156 ${"${SHIPDIR:tl:Nno:N*\:*}":?rm -f ${SHIPDIR}/*:}
158 .if !target(_DIRDEP_USE)
159 # we did not read dirdeps.mk above, the target may be here
160 .include "Makefile.xtras"
164 # dirdeps does it all
166 .endif # .MAKE.LEVEL == 0