aboutsummaryrefslogtreecommitdiff
path: root/pkgs/Makefile
blob: b605cae0ef393fab08a4e6a35ef74730ab312501 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# $FreeBSD$

# This is the top-level makefile - derrived from the Junos version
#
# If a subdir that matches the requested target exists, we assume
# a build target and initialize DIRDEPS, dirdeps.mk does the rest.
#
# Otherwise we include Makefile.xtras and hope it knows what to do.
#

# Copyright (c) 2010-2012, Juniper Networks, Inc.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions 
# are met: 
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer. 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.  
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

.if ${.MAKE.LEVEL} == 0

# this is our top-level makefile
.if make(pkg-*)
DIRDEPS_FILTER = Mpkgs/*
.endif

# in theory, this is what we want
target_dirs = pkgs pkgs/pseudo
# these tweak how we do it
target_prefix = pkg- build-
DIRDEPS := ${.TARGETS:Nall:${target_prefix:@p@S,^$p,,@:ts:}:@t@${target_dirs:@d@$d/$t@}@:@d@${exists(${SRCTOP}/$d):?$d:}@}

.if ${DIRDEPS:Mpkgs/pseudo/*} != ""
# all bets are off
PKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
.endif

.if make(check-commit)
# a special case
DIRDEPS = pkgs/pseudo/check-commit
.if defined(ALL_MACHINES)
CHECK_MACHINE_LIST = all
.undef ALL_MACHINES
.endif
SHIPDIR = no

.else

.if defined(ALL_MACHINES)
DIRDEPS := ${DIRDEPS:O:u:@d@${ALL_MACHINE_LIST:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T:R}.$m):?$d.$m:}@}@}
.undef ALL_MACHINES
PKG_MACHINE_LIST ?= ${DIRDEPS:E:O:u}
.elif defined(HOST_MACHINE) && ${MACHINE} == ${HOST_MACHINE}
# the above may be insufficient.
# some packages only support one machine which may not be ${MACHINE}
# some support multiple, in which case unless ALL_MACHINES is defined
# we only want ${MACHINE}
plain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T:R}):?$d:}@}
.if ${plain} != ${DIRDEPS}
all_machine_list = ${ALL_MACHINE_LIST} host
qual := ${DIRDEPS:${plain:${M_ListToSkip}}:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T:R}.$m):?$d.$m:}@}@}
DIRDEPS := ${plain} ${qual}
PKG_MACHINE_LIST ?= ${MACHINE} ${qual:E:O:u}
.endif
.else
# check that a .MAKE.DEPENDFILE exists
DIRDEPS := ${.MAKE.DEPENDFILE_PREFERENCE:T:@m@${DIRDEPS:@d@${exists(${SRCTOP}/$d/$m):?$d:}@}@:O:u}
.endif
.if !empty(PKG_MACHINE_LIST)
.if ${PKG_MACHINE_LIST:Mdepend} != ""
PKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
.endif
PKG_MACHINE_LIST := ${PKG_MACHINE_LIST}
.endif
.endif

.if !empty(build_options)
build_options := ${build_options:O:u}
.for v in ${build_options}
$v = yes
.endfor
.export ${build_options}
.endif

.if !empty(DIRDEPS)
# This is printed as we read the makefile
# so provides a useful clue as to when we really started.
# This allows us to work out how long reading 
# Makefile.depend* takes.
.if ${.MAKEFLAGS:M-V} == ""
.info ${TIME_STAMP} Start ${.TARGETS}
now_utc = ${%s:L:gmtime}
start_utc := ${now_utc}
.endif

_begin = count-makefiles

# by default, we clean pkgs/ which can otherwise accumulate a lot of cruft
.if ${NEED_CLEAN_PKGS:Uyes:tl} != "no"
_begin += clean-pkgs
.endif
.if defined(SHIPDIR) && ${NEED_CLEAN_SHIPDIR:Uno:tl} != "no" && exists(${SHIPDIR})
_begin += clean-shipdir
.endif
.if ${NEED_CLEAN_ERROR_LOGS:Uyes:tl} == "yes"
_begin += clean-error-logs
.endif
.if !empty(_begin) && !make(clean*)
dirdeps: ${_begin} .WAIT
.endif

.include "Makefile.inc"

.include <dirdeps.mk>

.for t in ${.TARGETS:Nall:Nclean*:${_begin:Uall:${M_ListToSkip}}}
$t: dirdeps
.endfor

elapsed_time= seconds=`expr ${now_utc} - ${start_utc}`

count-makefiles: .NOMETA
	@echo "${TIME_STAMP} Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} ${elapsed_time}"

.END: _build_finish
_build_finish:	.NOMETA
	@echo "${TIME_STAMP} Finished ${.TARGETS} ${elapsed_time}"

.ERROR: _build_failed
_build_failed: .NOMETA
	@echo "${TIME_STAMP} Failed ${.TARGETS} ${elapsed_time}"

.endif					# !empty(DIRDEPS)

clean-error-logs: .NOMETA
	@test ! -d ${meta_error_log:H} || rm -f ${meta_error_log:H}/*log

clean-pkgs:	.NOMETA
	@rm -rf ${ALL_MACHINE_LIST:N${MACHINE}:@m@${OBJROOT}$m/pkgs@} ${OBJROOT}${MACHINE}/pkgs/*

clean-shipdir:	.NOMETA
	${"${SHIPDIR:tl:Nno:N*\:*}":?rm -f ${SHIPDIR}/*:}

.if !target(_DIRDEP_USE)
# we did not read dirdeps.mk above, the target may be here
.include "Makefile.xtras"
.endif

.else
# dirdeps does it all
all:
.endif					# .MAKE.LEVEL == 0