xref: /freebsd/targets/Makefile (revision 1456f0f9681bbd7fdae7b683553f6c7491508c4e)
1# $FreeBSD$
2
3# This is the top-level makefile - derived 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
47all_machine_list = ${ALL_MACHINE_LIST} host common
48
49.if ${DIRDEPS:Mtargets/pseudo/*} != ""
50# all bets are off
51PKG_MACHINE_LIST = ${all_machine_list}
52.endif
53
54.if make(check-commit)
55# a special case
56DIRDEPS = targets/pseudo/check-commit
57.if defined(ALL_MACHINES)
58CHECK_MACHINE_LIST = all
59.undef ALL_MACHINES
60.endif
61SHIPDIR = no
62
63.else
64
65.if defined(ALL_MACHINES)
66DIRDEPS := ${DIRDEPS:O:u:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@}
67.undef ALL_MACHINES
68PKG_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}
74plain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@}
75.if ${plain} != ${DIRDEPS}
76qual := ${DIRDEPS:${plain:${M_ListToSkip}}:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@}
77DIRDEPS := ${plain} ${qual}
78PKG_MACHINE_LIST ?= ${MACHINE} ${qual:E:O:u}
79.endif
80.else
81# check that a .MAKE.DEPENDFILE exists
82DIRDEPS := ${.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} != ""
86PKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
87.endif
88PKG_MACHINE_LIST := ${PKG_MACHINE_LIST}
89.endif
90.endif
91
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
97plain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@}
98.if !empty(plain) && ${plain} != ${DIRDEPS}
99qual := ${DIRDEPS:${plain:${M_ListToSkip}}:M*.${REQUESTED_MACHINE}}
100.if empty(qual)
101qual := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T}):?$d.${.MAKE.DEPENDFILE:E}:}@}
102.endif
103DIRDEPS := ${plain} ${qual}
104.endif
105.if empty(DIRDEPS)
106.error ${REQUESTED_MACHINE} is not appropriate for ${.TARGETS}
107.endif
108.endif
109
110.if !empty(build_options)
111build_options := ${build_options:O:u}
112.for v in ${build_options}
113$v = yes
114.endfor
115.export ${build_options}
116.endif
117
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
127now_utc = ${%s:L:gmtime}
128start_utc := ${now_utc}
129.endif
130
131_begin =
132.if ${BUILD_DIRDEPS_CACHE:Uno} == "no"
133__DEFAULT_YES_OPTIONS+= \
134	CLEAN_ERROR_LOGS
135
136.include <bsd.mkopt.mk>
137
138.if ${MK_CLEAN_ERROR_LOGS} == "yes"
139_begin += clean-error-logs
140.endif
141
142.if !empty(_begin) && !make(clean*)
143dirdeps: ${_begin} .WAIT
144.endif
145.endif
146
147.include "Makefile.inc"
148
149.include <dirdeps.mk>
150
151.for t in ${.TARGETS:Nall:Nclean*:${_begin:Uall:${M_ListToSkip}}}
152$t: dirdeps
153.endfor
154
155elapsed_time= seconds=`expr ${now_utc} - ${start_utc}`
156
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
162
163.ERROR: _build_failed
164_build_failed: .NOMETA
165	@echo "${TIME_STAMP} Failed ${.TARGETS} ${elapsed_time}"
166
167.endif					# !empty(DIRDEPS)
168
169clean-error-logs: .NOMETA
170	@test ! -d ${meta_error_log:H} || rm -f ${meta_error_log:H}/*log
171
172.if !target(_DIRDEP_USE)
173# we did not read dirdeps.mk above, the target may be here
174.include "Makefile.xtras"
175.endif
176
177.else
178# dirdeps does it all
179all:
180.endif					# .MAKE.LEVEL == 0
181
182