mail(1): Invert calloc(3) argument order.
[freebsd-src.git] / targets / Makefile
blob8040953c6d1a6956ccc8761264f9956fcbed75be
1 # $FreeBSD$
3 # This is the top-level makefile - derived 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
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.
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
37 .if make(pkg-*)
38 DIRDEPS_FILTER = Mtargets/*
39 .endif
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 all_machine_list = ${ALL_MACHINE_LIST} host common
49 .if ${DIRDEPS:Mtargets/pseudo/*} != ""
50 # all bets are off
51 PKG_MACHINE_LIST = ${all_machine_list}
52 .endif
54 .if make(check-commit)
55 # a special case
56 DIRDEPS = targets/pseudo/check-commit
57 .if defined(ALL_MACHINES)
58 CHECK_MACHINE_LIST = all
59 .undef ALL_MACHINES
60 .endif
61 SHIPDIR = no
63 .else
65 .if defined(ALL_MACHINES)
66 DIRDEPS := ${DIRDEPS:O:u:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@}
67 .undef ALL_MACHINES
68 PKG_MACHINE_LIST ?= ${DIRDEPS:E:O:u}
69 .elif empty(REQUESTED_MACHINE)
70 # the above may be insufficient.
71 # some packages only support one machine which may not be ${MACHINE}
72 # some support multiple, in which case unless ALL_MACHINES is defined
73 # we only want ${MACHINE}
74 plain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@}
75 .if ${plain} != ${DIRDEPS}
76 qual := ${DIRDEPS:${plain:${M_ListToSkip}}:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@}
77 DIRDEPS := ${plain} ${qual}
78 PKG_MACHINE_LIST ?= ${MACHINE} ${qual:E:O:u}
79 .endif
80 .else
81 # check that a .MAKE.DEPENDFILE exists
82 DIRDEPS := ${.MAKE.DEPENDFILE_PREFERENCE:T:@m@${DIRDEPS:@d@${exists(${SRCTOP}/$d/$m):?$d:}@}@:O:u}
83 .endif
84 .if !empty(PKG_MACHINE_LIST)
85 .if ${PKG_MACHINE_LIST:Mdepend} != ""
86 PKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
87 .endif
88 PKG_MACHINE_LIST := ${PKG_MACHINE_LIST}
89 .endif
90 .endif
92 # we don't use DIRDEPS_FILTER, since we only want it to
93 # apply to this initial list
94 .if !empty(REQUESTED_MACHINE) && !empty(DIRDEPS)
95 # this is a variant of the logic above, we want plain
96 # but need to filter the qualified DIRDEPS to REQUESTED_MACHINE
97 plain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@}
98 .if !empty(plain) && ${plain} != ${DIRDEPS}
99 qual := ${DIRDEPS:${plain:${M_ListToSkip}}:M*.${REQUESTED_MACHINE}}
100 .if empty(qual)
101 qual := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T}):?$d.${.MAKE.DEPENDFILE:E}:}@}
102 .endif
103 DIRDEPS := ${plain} ${qual}
104 .endif
105 .if empty(DIRDEPS)
106 .error ${REQUESTED_MACHINE} is not appropriate for ${.TARGETS}
107 .endif
108 .endif
110 .if !empty(build_options)
111 build_options := ${build_options:O:u}
112 .for v in ${build_options}
113 $v = yes
114 .endfor
115 .export ${build_options}
116 .endif
118 .if !empty(DIRDEPS)
119 # This is printed as we read the makefile
120 # so provides a useful clue as to when we really started.
121 # This allows us to work out how long reading
122 # Makefile.depend* takes.
123 .if ${.MAKEFLAGS:M-V} == ""
124 .if ${BUILD_DIRDEPS_CACHE:Uno} == "no"
125 .info ${.newline}${TIME_STAMP} Start ${.TARGETS}
126 .endif
127 now_utc = ${%s:L:gmtime}
128 start_utc := ${now_utc}
129 .endif
131 _begin =
132 .if ${BUILD_DIRDEPS_CACHE:Uno} == "no"
133 __DEFAULT_YES_OPTIONS+= \
134 CLEAN_ERROR_LOGS
136 .include <bsd.mkopt.mk>
138 .if ${MK_CLEAN_ERROR_LOGS} == "yes"
139 _begin += clean-error-logs
140 .endif
142 .if !empty(_begin) && !make(clean*)
143 dirdeps: ${_begin} .WAIT
144 .endif
145 .endif
147 .include "Makefile.inc"
149 .include <dirdeps.mk>
151 .for t in ${.TARGETS:Nall:Nclean*:${_begin:Uall:${M_ListToSkip}}}
152 $t: dirdeps
153 .endfor
155 elapsed_time= seconds=`expr ${now_utc} - ${start_utc}`
157 .if ${BUILD_DIRDEPS_CACHE:Uno} == "no"
158 .END: _build_finish
159 _build_finish: .NOMETA
160 @echo "${TIME_STAMP} Finished ${.TARGETS} ${elapsed_time}"
161 .endif
163 .ERROR: _build_failed
164 _build_failed: .NOMETA
165 @echo "${TIME_STAMP} Failed ${.TARGETS} ${elapsed_time}"
167 .endif # !empty(DIRDEPS)
169 clean-error-logs: .NOMETA
170 @test ! -d ${meta_error_log:H} || rm -f ${meta_error_log:H}/*log
172 .if !target(_DIRDEP_USE)
173 # we did not read dirdeps.mk above, the target may be here
174 .include "Makefile.xtras"
175 .endif
177 .else
178 # dirdeps does it all
179 all:
180 .endif # .MAKE.LEVEL == 0