You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
5.5KB

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