xref: /freebsd/targets/Makefile (revision 61ad1ff58d4e7a8c21f05066d9a05aad2f84d291)
1b6209a9bSSimon J. Gerraty# $FreeBSD$
2b6209a9bSSimon J. Gerraty
3b6209a9bSSimon J. Gerraty# This is the top-level makefile - derrived 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-*)
38*61ad1ff5SSimon J. GerratyDIRDEPS_FILTER = Mtargets/*
39b6209a9bSSimon J. Gerraty.endif
40b6209a9bSSimon J. Gerraty
41b6209a9bSSimon J. Gerraty# in theory, this is what we want
42*61ad1ff5SSimon 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
47*61ad1ff5SSimon J. Gerraty.if ${DIRDEPS:Mtargets/pseudo/*} != ""
48b6209a9bSSimon J. Gerraty# all bets are off
49b6209a9bSSimon J. GerratyPKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
50b6209a9bSSimon J. Gerraty.endif
51b6209a9bSSimon J. Gerraty
52b6209a9bSSimon J. Gerraty.if make(check-commit)
53b6209a9bSSimon J. Gerraty# a special case
54*61ad1ff5SSimon J. GerratyDIRDEPS = targets/pseudo/check-commit
55b6209a9bSSimon J. Gerraty.if defined(ALL_MACHINES)
56b6209a9bSSimon J. GerratyCHECK_MACHINE_LIST = all
57b6209a9bSSimon J. Gerraty.undef ALL_MACHINES
58b6209a9bSSimon J. Gerraty.endif
59b6209a9bSSimon J. GerratySHIPDIR = no
60b6209a9bSSimon J. Gerraty
61b6209a9bSSimon J. Gerraty.else
62b6209a9bSSimon J. Gerraty
63b6209a9bSSimon J. Gerratyall_machine_list = ${ALL_MACHINE_LIST} host common
64b6209a9bSSimon J. Gerraty.if defined(ALL_MACHINES)
65b6209a9bSSimon J. GerratyDIRDEPS := ${DIRDEPS:O:u:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@}
66b6209a9bSSimon J. Gerraty.undef ALL_MACHINES
67b6209a9bSSimon J. GerratyPKG_MACHINE_LIST ?= ${DIRDEPS:E:O:u}
68b6209a9bSSimon J. Gerraty.elif defined(HOST_MACHINE) && ${MACHINE} == ${HOST_MACHINE}
69b6209a9bSSimon J. Gerraty# the above may be insufficient.
70b6209a9bSSimon J. Gerraty# some packages only support one machine which may not be ${MACHINE}
71b6209a9bSSimon J. Gerraty# some support multiple, in which case unless ALL_MACHINES is defined
72b6209a9bSSimon J. Gerraty# we only want ${MACHINE}
73b6209a9bSSimon J. Gerratyplain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@}
74b6209a9bSSimon J. Gerraty.if ${plain} != ${DIRDEPS}
75b6209a9bSSimon J. Gerratyqual := ${DIRDEPS:${plain:${M_ListToSkip}}:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@}
76b6209a9bSSimon J. GerratyDIRDEPS := ${plain} ${qual}
77b6209a9bSSimon J. GerratyPKG_MACHINE_LIST ?= ${MACHINE} ${qual:E:O:u}
78b6209a9bSSimon J. Gerraty.endif
79b6209a9bSSimon J. Gerraty.else
80b6209a9bSSimon J. Gerraty# check that a .MAKE.DEPENDFILE exists
81b6209a9bSSimon J. GerratyDIRDEPS := ${.MAKE.DEPENDFILE_PREFERENCE:T:@m@${DIRDEPS:@d@${exists(${SRCTOP}/$d/$m):?$d:}@}@:O:u}
82b6209a9bSSimon J. Gerraty.endif
83b6209a9bSSimon J. Gerraty.if !empty(PKG_MACHINE_LIST)
84b6209a9bSSimon J. Gerraty.if ${PKG_MACHINE_LIST:Mdepend} != ""
85b6209a9bSSimon J. GerratyPKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
86b6209a9bSSimon J. Gerraty.endif
87b6209a9bSSimon J. GerratyPKG_MACHINE_LIST := ${PKG_MACHINE_LIST}
88b6209a9bSSimon J. Gerraty.endif
89b6209a9bSSimon J. Gerraty.endif
90b6209a9bSSimon J. Gerraty
91b6209a9bSSimon J. Gerraty# we don't use DIRDEPS_FILTER, since we only want it to
92b6209a9bSSimon J. Gerraty# apply to this initial list
93b6209a9bSSimon J. Gerraty.if !empty(REQUESTED_MACHINE) && !empty(DIRDEPS)
94b6209a9bSSimon J. Gerraty# this is a variant of the logic above, we want plain
95b6209a9bSSimon J. Gerraty# but need to filter the qualified DIRDEPS to REQUESTED_MACHINE
96b6209a9bSSimon J. Gerratyplain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@}
97b6209a9bSSimon J. Gerraty.if ${plain} != ${DIRDEPS}
98b6209a9bSSimon J. Gerratyqual := ${DIRDEPS:${plain:${M_ListToSkip}}:M*.${REQUESTED_MACHINE}}
99b6209a9bSSimon J. Gerraty.if empty(qual)
100b6209a9bSSimon J. Gerratyqual := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T}):?$d.${.MAKE.DEPENDFILE:E}:}@}
101b6209a9bSSimon J. Gerraty.endif
102b6209a9bSSimon J. GerratyDIRDEPS := ${plain} ${qual}
103b6209a9bSSimon J. Gerraty.endif
104b6209a9bSSimon J. Gerraty.if empty(DIRDEPS)
105b6209a9bSSimon J. Gerraty.error ${REQUESTED_MACHINE} is not appropriate for ${DEP_RELDIR:T}
106b6209a9bSSimon J. Gerraty.endif
107b6209a9bSSimon J. Gerraty.endif
108b6209a9bSSimon J. Gerraty
109b6209a9bSSimon J. Gerraty.if !empty(build_options)
110b6209a9bSSimon J. Gerratybuild_options := ${build_options:O:u}
111b6209a9bSSimon J. Gerraty.for v in ${build_options}
112b6209a9bSSimon J. Gerraty$v = yes
113b6209a9bSSimon J. Gerraty.endfor
114b6209a9bSSimon J. Gerraty.export ${build_options}
115b6209a9bSSimon J. Gerraty.endif
116b6209a9bSSimon J. Gerraty
117b6209a9bSSimon J. Gerraty.if !empty(DIRDEPS)
118b6209a9bSSimon J. Gerraty# This is printed as we read the makefile
119b6209a9bSSimon J. Gerraty# so provides a useful clue as to when we really started.
120b6209a9bSSimon J. Gerraty# This allows us to work out how long reading
121b6209a9bSSimon J. Gerraty# Makefile.depend* takes.
122b6209a9bSSimon J. Gerraty.if ${.MAKEFLAGS:M-V} == ""
123b6209a9bSSimon J. Gerraty.info ${.newline}${TIME_STAMP} Start ${.TARGETS}
124b6209a9bSSimon J. Gerratynow_utc = ${%s:L:gmtime}
125b6209a9bSSimon J. Gerratystart_utc := ${now_utc}
126b6209a9bSSimon J. Gerraty.endif
127b6209a9bSSimon J. Gerraty
128b6209a9bSSimon J. Gerraty_begin = count-makefiles
129b6209a9bSSimon J. Gerraty
130*61ad1ff5SSimon J. Gerraty__DEFAULT_YES_OPTIONS+= \
131*61ad1ff5SSimon J. Gerraty	CLEAN_ERROR_LOGS
132*61ad1ff5SSimon J. Gerraty
133*61ad1ff5SSimon J. Gerraty.include <bsd.mkopt.mk>
134*61ad1ff5SSimon J. Gerraty
135*61ad1ff5SSimon J. Gerraty.if ${MK_CLEAN_ERROR_LOGS} == "yes"
136b6209a9bSSimon J. Gerraty_begin += clean-error-logs
137b6209a9bSSimon J. Gerraty.endif
138*61ad1ff5SSimon J. Gerraty
139b6209a9bSSimon J. Gerraty.if !empty(_begin) && !make(clean*)
140b6209a9bSSimon J. Gerratydirdeps: ${_begin} .WAIT
141b6209a9bSSimon J. Gerraty.endif
142b6209a9bSSimon J. Gerraty
143b6209a9bSSimon J. Gerraty.include "Makefile.inc"
144b6209a9bSSimon J. Gerraty
145b6209a9bSSimon J. Gerraty.include <dirdeps.mk>
146b6209a9bSSimon J. Gerraty
147b6209a9bSSimon J. Gerraty.for t in ${.TARGETS:Nall:Nclean*:${_begin:Uall:${M_ListToSkip}}}
148b6209a9bSSimon J. Gerraty$t: dirdeps
149b6209a9bSSimon J. Gerraty.endfor
150b6209a9bSSimon J. Gerraty
151b6209a9bSSimon J. Gerratyelapsed_time= seconds=`expr ${now_utc} - ${start_utc}`
152b6209a9bSSimon J. Gerraty
153b6209a9bSSimon J. Gerratycount-makefiles: .NOMETA
154b6209a9bSSimon J. Gerraty	@echo "${TIME_STAMP} Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${elapsed_time}"
155b6209a9bSSimon J. Gerraty
156b6209a9bSSimon J. Gerraty.END: _build_finish
157b6209a9bSSimon J. Gerraty_build_finish:	.NOMETA
158b6209a9bSSimon J. Gerraty	@echo "${TIME_STAMP} Finished ${.TARGETS} ${elapsed_time}"
159b6209a9bSSimon J. Gerraty
160b6209a9bSSimon J. Gerraty.ERROR: _build_failed
161b6209a9bSSimon J. Gerraty_build_failed: .NOMETA
162b6209a9bSSimon J. Gerraty	@echo "${TIME_STAMP} Failed ${.TARGETS} ${elapsed_time}"
163b6209a9bSSimon J. Gerraty
164b6209a9bSSimon J. Gerraty.endif					# !empty(DIRDEPS)
165b6209a9bSSimon J. Gerraty
166b6209a9bSSimon J. Gerratyclean-error-logs: .NOMETA
167b6209a9bSSimon J. Gerraty	@test ! -d ${meta_error_log:H} || rm -f ${meta_error_log:H}/*log
168b6209a9bSSimon J. Gerraty
169b6209a9bSSimon J. Gerraty.if !target(_DIRDEP_USE)
170b6209a9bSSimon J. Gerraty# we did not read dirdeps.mk above, the target may be here
171b6209a9bSSimon J. Gerraty.include "Makefile.xtras"
172b6209a9bSSimon J. Gerraty.endif
173b6209a9bSSimon J. Gerraty
174b6209a9bSSimon J. Gerraty.else
175b6209a9bSSimon J. Gerraty# dirdeps does it all
176b6209a9bSSimon J. Gerratyall:
177b6209a9bSSimon J. Gerraty.endif					# .MAKE.LEVEL == 0
178b6209a9bSSimon J. Gerraty
179