xref: /freebsd/targets/Makefile (revision b6209a9b5861cbf265a23afeac999cb27bfc7eae)
1*b6209a9bSSimon J. Gerraty# $FreeBSD$
2*b6209a9bSSimon J. Gerraty
3*b6209a9bSSimon J. Gerraty# This is the top-level makefile - derrived from the Junos version
4*b6209a9bSSimon J. Gerraty#
5*b6209a9bSSimon J. Gerraty# If a subdir that matches the requested target exists, we assume
6*b6209a9bSSimon J. Gerraty# a build target and initialize DIRDEPS, dirdeps.mk does the rest.
7*b6209a9bSSimon J. Gerraty#
8*b6209a9bSSimon J. Gerraty# Otherwise we include Makefile.xtras and hope it knows what to do.
9*b6209a9bSSimon J. Gerraty#
10*b6209a9bSSimon J. Gerraty
11*b6209a9bSSimon J. Gerraty# Copyright (c) 2010-2012, Juniper Networks, Inc.
12*b6209a9bSSimon J. Gerraty#
13*b6209a9bSSimon J. Gerraty# Redistribution and use in source and binary forms, with or without
14*b6209a9bSSimon J. Gerraty# modification, are permitted provided that the following conditions
15*b6209a9bSSimon J. Gerraty# are met:
16*b6209a9bSSimon J. Gerraty# 1. Redistributions of source code must retain the above copyright
17*b6209a9bSSimon J. Gerraty#    notice, this list of conditions and the following disclaimer.
18*b6209a9bSSimon J. Gerraty# 2. Redistributions in binary form must reproduce the above copyright
19*b6209a9bSSimon J. Gerraty#    notice, this list of conditions and the following disclaimer in the
20*b6209a9bSSimon J. Gerraty#    documentation and/or other materials provided with the distribution.
21*b6209a9bSSimon J. Gerraty#
22*b6209a9bSSimon J. Gerraty# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23*b6209a9bSSimon J. Gerraty# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24*b6209a9bSSimon J. Gerraty# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25*b6209a9bSSimon J. Gerraty# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26*b6209a9bSSimon J. Gerraty# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27*b6209a9bSSimon J. Gerraty# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28*b6209a9bSSimon J. Gerraty# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29*b6209a9bSSimon J. Gerraty# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30*b6209a9bSSimon J. Gerraty# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31*b6209a9bSSimon J. Gerraty# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32*b6209a9bSSimon J. Gerraty# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*b6209a9bSSimon J. Gerraty
34*b6209a9bSSimon J. Gerraty.if ${.MAKE.LEVEL} == 0
35*b6209a9bSSimon J. Gerraty
36*b6209a9bSSimon J. Gerraty# this is our top-level makefile
37*b6209a9bSSimon J. Gerraty.if make(pkg-*)
38*b6209a9bSSimon J. GerratyDIRDEPS_FILTER = Mpkgs/*
39*b6209a9bSSimon J. Gerraty.endif
40*b6209a9bSSimon J. Gerraty
41*b6209a9bSSimon J. Gerraty# in theory, this is what we want
42*b6209a9bSSimon J. Gerratytarget_dirs = pkgs pkgs/pseudo
43*b6209a9bSSimon J. Gerraty# these tweak how we do it
44*b6209a9bSSimon J. Gerratytarget_prefix = pkg- build-
45*b6209a9bSSimon J. GerratyDIRDEPS := ${.TARGETS:Nall:${target_prefix:@p@S,^$p,,@:ts:}:@t@${target_dirs:@d@$d/$t@}@:@d@${exists(${SRCTOP}/$d):?$d:}@}
46*b6209a9bSSimon J. Gerraty
47*b6209a9bSSimon J. Gerraty.if ${DIRDEPS:Mpkgs/pseudo/*} != ""
48*b6209a9bSSimon J. Gerraty# all bets are off
49*b6209a9bSSimon J. GerratyPKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
50*b6209a9bSSimon J. Gerraty.endif
51*b6209a9bSSimon J. Gerraty
52*b6209a9bSSimon J. Gerraty.if make(check-commit)
53*b6209a9bSSimon J. Gerraty# a special case
54*b6209a9bSSimon J. GerratyDIRDEPS = pkgs/pseudo/check-commit
55*b6209a9bSSimon J. Gerraty.if defined(ALL_MACHINES)
56*b6209a9bSSimon J. GerratyCHECK_MACHINE_LIST = all
57*b6209a9bSSimon J. Gerraty.undef ALL_MACHINES
58*b6209a9bSSimon J. Gerraty.endif
59*b6209a9bSSimon J. GerratySHIPDIR = no
60*b6209a9bSSimon J. Gerraty
61*b6209a9bSSimon J. Gerraty.else
62*b6209a9bSSimon J. Gerraty
63*b6209a9bSSimon J. Gerratyall_machine_list = ${ALL_MACHINE_LIST} host common
64*b6209a9bSSimon J. Gerraty.if defined(ALL_MACHINES)
65*b6209a9bSSimon J. GerratyDIRDEPS := ${DIRDEPS:O:u:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@}
66*b6209a9bSSimon J. Gerraty.undef ALL_MACHINES
67*b6209a9bSSimon J. GerratyPKG_MACHINE_LIST ?= ${DIRDEPS:E:O:u}
68*b6209a9bSSimon J. Gerraty.elif defined(HOST_MACHINE) && ${MACHINE} == ${HOST_MACHINE}
69*b6209a9bSSimon J. Gerraty# the above may be insufficient.
70*b6209a9bSSimon J. Gerraty# some packages only support one machine which may not be ${MACHINE}
71*b6209a9bSSimon J. Gerraty# some support multiple, in which case unless ALL_MACHINES is defined
72*b6209a9bSSimon J. Gerraty# we only want ${MACHINE}
73*b6209a9bSSimon J. Gerratyplain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@}
74*b6209a9bSSimon J. Gerraty.if ${plain} != ${DIRDEPS}
75*b6209a9bSSimon J. Gerratyqual := ${DIRDEPS:${plain:${M_ListToSkip}}:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}.$m):?$d.$m:}@}@}
76*b6209a9bSSimon J. GerratyDIRDEPS := ${plain} ${qual}
77*b6209a9bSSimon J. GerratyPKG_MACHINE_LIST ?= ${MACHINE} ${qual:E:O:u}
78*b6209a9bSSimon J. Gerraty.endif
79*b6209a9bSSimon J. Gerraty.else
80*b6209a9bSSimon J. Gerraty# check that a .MAKE.DEPENDFILE exists
81*b6209a9bSSimon J. GerratyDIRDEPS := ${.MAKE.DEPENDFILE_PREFERENCE:T:@m@${DIRDEPS:@d@${exists(${SRCTOP}/$d/$m):?$d:}@}@:O:u}
82*b6209a9bSSimon J. Gerraty.endif
83*b6209a9bSSimon J. Gerraty.if !empty(PKG_MACHINE_LIST)
84*b6209a9bSSimon J. Gerraty.if ${PKG_MACHINE_LIST:Mdepend} != ""
85*b6209a9bSSimon J. GerratyPKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
86*b6209a9bSSimon J. Gerraty.endif
87*b6209a9bSSimon J. GerratyPKG_MACHINE_LIST := ${PKG_MACHINE_LIST}
88*b6209a9bSSimon J. Gerraty.endif
89*b6209a9bSSimon J. Gerraty.endif
90*b6209a9bSSimon J. Gerraty
91*b6209a9bSSimon J. Gerraty# we don't use DIRDEPS_FILTER, since we only want it to
92*b6209a9bSSimon J. Gerraty# apply to this initial list
93*b6209a9bSSimon J. Gerraty.if !empty(REQUESTED_MACHINE) && !empty(DIRDEPS)
94*b6209a9bSSimon J. Gerraty# this is a variant of the logic above, we want plain
95*b6209a9bSSimon J. Gerraty# but need to filter the qualified DIRDEPS to REQUESTED_MACHINE
96*b6209a9bSSimon J. Gerratyplain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE_PREFIX:T}):?$d:}@}
97*b6209a9bSSimon J. Gerraty.if ${plain} != ${DIRDEPS}
98*b6209a9bSSimon J. Gerratyqual := ${DIRDEPS:${plain:${M_ListToSkip}}:M*.${REQUESTED_MACHINE}}
99*b6209a9bSSimon J. Gerraty.if empty(qual)
100*b6209a9bSSimon J. Gerratyqual := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T}):?$d.${.MAKE.DEPENDFILE:E}:}@}
101*b6209a9bSSimon J. Gerraty.endif
102*b6209a9bSSimon J. GerratyDIRDEPS := ${plain} ${qual}
103*b6209a9bSSimon J. Gerraty.endif
104*b6209a9bSSimon J. Gerraty.if empty(DIRDEPS)
105*b6209a9bSSimon J. Gerraty.error ${REQUESTED_MACHINE} is not appropriate for ${DEP_RELDIR:T}
106*b6209a9bSSimon J. Gerraty.endif
107*b6209a9bSSimon J. Gerraty.endif
108*b6209a9bSSimon J. Gerraty
109*b6209a9bSSimon J. Gerraty.if !empty(build_options)
110*b6209a9bSSimon J. Gerratybuild_options := ${build_options:O:u}
111*b6209a9bSSimon J. Gerraty.for v in ${build_options}
112*b6209a9bSSimon J. Gerraty$v = yes
113*b6209a9bSSimon J. Gerraty.endfor
114*b6209a9bSSimon J. Gerraty.export ${build_options}
115*b6209a9bSSimon J. Gerraty.endif
116*b6209a9bSSimon J. Gerraty
117*b6209a9bSSimon J. Gerraty.if !empty(DIRDEPS)
118*b6209a9bSSimon J. Gerraty# This is printed as we read the makefile
119*b6209a9bSSimon J. Gerraty# so provides a useful clue as to when we really started.
120*b6209a9bSSimon J. Gerraty# This allows us to work out how long reading
121*b6209a9bSSimon J. Gerraty# Makefile.depend* takes.
122*b6209a9bSSimon J. Gerraty.if ${.MAKEFLAGS:M-V} == ""
123*b6209a9bSSimon J. Gerraty.info ${.newline}${TIME_STAMP} Start ${.TARGETS}
124*b6209a9bSSimon J. Gerratynow_utc = ${%s:L:gmtime}
125*b6209a9bSSimon J. Gerratystart_utc := ${now_utc}
126*b6209a9bSSimon J. Gerraty.endif
127*b6209a9bSSimon J. Gerraty
128*b6209a9bSSimon J. Gerraty_begin = count-makefiles
129*b6209a9bSSimon J. Gerraty
130*b6209a9bSSimon J. Gerraty# by default, we clean pkgs/ which can otherwise accumulate a lot of cruft
131*b6209a9bSSimon J. Gerraty.if ${NEED_CLEAN_PKGS:Uyes:tl} != "no"
132*b6209a9bSSimon J. Gerraty_begin += clean-pkgs
133*b6209a9bSSimon J. Gerraty.endif
134*b6209a9bSSimon J. Gerraty.if defined(SHIPDIR) && ${NEED_CLEAN_SHIPDIR:Uno:tl} != "no" && exists(${SHIPDIR})
135*b6209a9bSSimon J. Gerraty_begin += clean-shipdir
136*b6209a9bSSimon J. Gerraty.endif
137*b6209a9bSSimon J. Gerraty.if ${NEED_CLEAN_ERROR_LOGS:Uyes:tl} == "yes"
138*b6209a9bSSimon J. Gerraty_begin += clean-error-logs
139*b6209a9bSSimon J. Gerraty.endif
140*b6209a9bSSimon J. Gerraty.if !empty(_begin) && !make(clean*)
141*b6209a9bSSimon J. Gerratydirdeps: ${_begin} .WAIT
142*b6209a9bSSimon J. Gerraty.endif
143*b6209a9bSSimon J. Gerraty
144*b6209a9bSSimon J. Gerraty.include "Makefile.inc"
145*b6209a9bSSimon J. Gerraty
146*b6209a9bSSimon J. Gerraty.include <dirdeps.mk>
147*b6209a9bSSimon J. Gerraty
148*b6209a9bSSimon J. Gerraty.for t in ${.TARGETS:Nall:Nclean*:${_begin:Uall:${M_ListToSkip}}}
149*b6209a9bSSimon J. Gerraty$t: dirdeps
150*b6209a9bSSimon J. Gerraty.endfor
151*b6209a9bSSimon J. Gerraty
152*b6209a9bSSimon J. Gerratyelapsed_time= seconds=`expr ${now_utc} - ${start_utc}`
153*b6209a9bSSimon J. Gerraty
154*b6209a9bSSimon J. Gerratycount-makefiles: .NOMETA
155*b6209a9bSSimon J. Gerraty	@echo "${TIME_STAMP} Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${elapsed_time}"
156*b6209a9bSSimon J. Gerraty
157*b6209a9bSSimon J. Gerraty.END: _build_finish
158*b6209a9bSSimon J. Gerraty_build_finish:	.NOMETA
159*b6209a9bSSimon J. Gerraty	@echo "${TIME_STAMP} Finished ${.TARGETS} ${elapsed_time}"
160*b6209a9bSSimon J. Gerraty
161*b6209a9bSSimon J. Gerraty.ERROR: _build_failed
162*b6209a9bSSimon J. Gerraty_build_failed: .NOMETA
163*b6209a9bSSimon J. Gerraty	@echo "${TIME_STAMP} Failed ${.TARGETS} ${elapsed_time}"
164*b6209a9bSSimon J. Gerraty
165*b6209a9bSSimon J. Gerraty.endif					# !empty(DIRDEPS)
166*b6209a9bSSimon J. Gerraty
167*b6209a9bSSimon J. Gerratyclean-error-logs: .NOMETA
168*b6209a9bSSimon J. Gerraty	@test ! -d ${meta_error_log:H} || rm -f ${meta_error_log:H}/*log
169*b6209a9bSSimon J. Gerraty
170*b6209a9bSSimon J. Gerratyclean-pkgs:	.NOMETA
171*b6209a9bSSimon J. Gerraty	@rm -rf ${ALL_MACHINE_LIST:N${MACHINE}:@m@${OBJROOT}$m/pkgs@} ${OBJROOT}${MACHINE}/pkgs/*
172*b6209a9bSSimon J. Gerraty
173*b6209a9bSSimon J. Gerratyclean-shipdir:	.NOMETA
174*b6209a9bSSimon J. Gerraty	${"${SHIPDIR:tl:Nno:N*\:*}":?rm -f ${SHIPDIR}/*:}
175*b6209a9bSSimon J. Gerraty
176*b6209a9bSSimon J. Gerraty.if !target(_DIRDEP_USE)
177*b6209a9bSSimon J. Gerraty# we did not read dirdeps.mk above, the target may be here
178*b6209a9bSSimon J. Gerraty.include "Makefile.xtras"
179*b6209a9bSSimon J. Gerraty.endif
180*b6209a9bSSimon J. Gerraty
181*b6209a9bSSimon J. Gerraty.else
182*b6209a9bSSimon J. Gerraty# dirdeps does it all
183*b6209a9bSSimon J. Gerratyall:
184*b6209a9bSSimon J. Gerraty.endif					# .MAKE.LEVEL == 0
185*b6209a9bSSimon J. Gerraty
186