]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - pkgs/Makefile
Merge head
[FreeBSD/FreeBSD.git] / pkgs / Makefile
1 # $FreeBSD$
2
3 # This is the top-level makefile - derrived 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-*)
38 DIRDEPS_FILTER = Mpkgs/*
39 .endif
40
41 # in theory, this is what we want
42 target_dirs = pkgs pkgs/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:}@}
46
47 .if ${DIRDEPS:Mpkgs/pseudo/*} != ""
48 # all bets are off
49 PKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
50 .endif
51
52 .if make(check-commit)
53 # a special case
54 DIRDEPS = pkgs/pseudo/check-commit
55 .if defined(ALL_MACHINES)
56 CHECK_MACHINE_LIST = all
57 .undef ALL_MACHINES
58 .endif
59 SHIPDIR = no
60
61 .else
62
63 .if defined(ALL_MACHINES)
64 DIRDEPS := ${DIRDEPS:O:u:@d@${ALL_MACHINE_LIST:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T:R}.$m):?$d.$m:}@}@}
65 .undef ALL_MACHINES
66 PKG_MACHINE_LIST ?= ${DIRDEPS:E:O:u}
67 .elif defined(HOST_MACHINE) && ${MACHINE} == ${HOST_MACHINE}
68 # the above may be insufficient.
69 # some packages only support one machine which may not be ${MACHINE}
70 # some support multiple, in which case unless ALL_MACHINES is defined
71 # we only want ${MACHINE}
72 plain := ${DIRDEPS:@d@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T:R}):?$d:}@}
73 .if ${plain} != ${DIRDEPS}
74 all_machine_list = ${ALL_MACHINE_LIST} host
75 qual := ${DIRDEPS:${plain:${M_ListToSkip}}:@d@${all_machine_list:O:u:@m@${exists(${SRCTOP}/$d/${.MAKE.DEPENDFILE:T:R}.$m):?$d.$m:}@}@}
76 DIRDEPS := ${plain} ${qual}
77 PKG_MACHINE_LIST ?= ${MACHINE} ${qual:E:O:u}
78 .endif
79 .else
80 # check that a .MAKE.DEPENDFILE exists
81 DIRDEPS := ${.MAKE.DEPENDFILE_PREFERENCE:T:@m@${DIRDEPS:@d@${exists(${SRCTOP}/$d/$m):?$d:}@}@:O:u}
82 .endif
83 .if !empty(PKG_MACHINE_LIST)
84 .if ${PKG_MACHINE_LIST:Mdepend} != ""
85 PKG_MACHINE_LIST = ${ALL_MACHINE_LIST}
86 .endif
87 PKG_MACHINE_LIST := ${PKG_MACHINE_LIST}
88 .endif
89 .endif
90
91 .if !empty(build_options)
92 build_options := ${build_options:O:u}
93 .for v in ${build_options}
94 $v = yes
95 .endfor
96 .export ${build_options}
97 .endif
98
99 .if !empty(DIRDEPS)
100 # This is printed as we read the makefile
101 # so provides a useful clue as to when we really started.
102 # This allows us to work out how long reading 
103 # Makefile.depend* takes.
104 .if ${.MAKEFLAGS:M-V} == ""
105 .info ${.newline}${TIME_STAMP} Start ${.TARGETS}
106 now_utc = ${%s:L:gmtime}
107 start_utc := ${now_utc}
108 .endif
109
110 _begin = count-makefiles
111
112 # by default, we clean pkgs/ which can otherwise accumulate a lot of cruft
113 .if ${NEED_CLEAN_PKGS:Uyes:tl} != "no"
114 _begin += clean-pkgs
115 .endif
116 .if defined(SHIPDIR) && ${NEED_CLEAN_SHIPDIR:Uno:tl} != "no" && exists(${SHIPDIR})
117 _begin += clean-shipdir
118 .endif
119 .if ${NEED_CLEAN_ERROR_LOGS:Uyes:tl} == "yes"
120 _begin += clean-error-logs
121 .endif
122 .if !empty(_begin) && !make(clean*)
123 dirdeps: ${_begin} .WAIT
124 .endif
125
126 .include "Makefile.inc"
127
128 .include <dirdeps.mk>
129
130 .for t in ${.TARGETS:Nall:Nclean*:${_begin:Uall:${M_ListToSkip}}}
131 $t: dirdeps
132 .endfor
133
134 elapsed_time= seconds=`expr ${now_utc} - ${start_utc}`
135
136 count-makefiles: .NOMETA
137         @echo "${TIME_STAMP} Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${elapsed_time}"
138
139 .END: _build_finish
140 _build_finish:  .NOMETA
141         @echo "${TIME_STAMP} Finished ${.TARGETS} ${elapsed_time}"
142
143 .ERROR: _build_failed
144 _build_failed: .NOMETA
145         @echo "${TIME_STAMP} Failed ${.TARGETS} ${elapsed_time}"
146
147 .endif                                  # !empty(DIRDEPS)
148
149 clean-error-logs: .NOMETA
150         @test ! -d ${meta_error_log:H} || rm -f ${meta_error_log:H}/*log
151
152 clean-pkgs:     .NOMETA
153         @rm -rf ${ALL_MACHINE_LIST:N${MACHINE}:@m@${OBJROOT}$m/pkgs@} ${OBJROOT}${MACHINE}/pkgs/*
154
155 clean-shipdir:  .NOMETA
156         ${"${SHIPDIR:tl:Nno:N*\:*}":?rm -f ${SHIPDIR}/*:}
157
158 .if !target(_DIRDEP_USE)
159 # we did not read dirdeps.mk above, the target may be here
160 .include "Makefile.xtras"
161 .endif
162
163 .else
164 # dirdeps does it all
165 all:
166 .endif                                  # .MAKE.LEVEL == 0
167