1 # $Id: jobs.mk,v 1.14 2023/09/11 16:52:44 sjg Exp $
3 # @(#) Copyright (c) 2012-2023, Simon J. Gerraty
5 # This file is provided in the hope that it will
6 # be of use. There is absolutely NO WARRANTY.
7 # Permission to copy, redistribute or otherwise
8 # use this file is hereby granted provided that
9 # the above copyright notice and this notice are
12 # Please send copies of changes and bug-fixes to:
16 # This makefile is used by top-level makefile.
30 # ${MAKE} -j${JOB_MAX} target > ${JOB_LOGDIR}/target.log 2>&1
32 # JOB_MAX should be something like 1.2 - 1.5 times the number of
34 # If bmake sets .MAKE.JOBS.C=yes we can use -jC and
35 # JOB_MAX defaults to JOB_MAX_C (default 1.33C).
39 now_utc ?= ${%s:L:localtime}
40 .if !defined(start_utc)
41 start_utc := ${now_utc}
45 .info ${.newline}${TIME_STAMP} Start ${.TARGETS}
47 JOB_LOGDIR ?= ${SRCTOP:H}
48 JOB_LOG = ${JOB_LOGDIR}/${.TARGET:S,-jobs,,:S,/,_,g}.log
50 # we like to rotate logs
52 .for d in ${.SYSPATH:U${.PARSEDIR}:@x@$x $x/scripts@}
53 .if exists($d/newlog.sh)
54 NEWLOG_SH := $d/newlog.sh
55 .if ${MAKE_VERSION} > 20220924
62 NEWLOG_SH := ${newlog.sh:L:${M_whence}}
64 NEWLOG_SH := ${(type newlog.sh) 2> /dev/null:L:sh:M/*}
68 .if !empty(NEWLOG_SH) && exists(${NEWLOG_SH})
69 NEWLOG := sh ${NEWLOG_SH}
70 JOB_NEWLOG_ARGS ?= -S -n ${JOB_LOG_GENS}
75 .if ${.MAKE.JOBS:U0} > 0
76 JOB_MAX = ${.MAKE.JOBS}
78 # This should be derrived from number of cpu's
79 .if ${.MAKE.JOBS.C:Uno} == "yes"
80 # 1.2 - 1.5 times nCPU works well on most machines that support -jC
82 JOB_MAX ?= ${JOB_MAX_C}
85 JOB_ARGS += -j${JOB_MAX}
88 # we need to reset .MAKE.LEVEL to 0 so that
89 # build orchestration works as expected (DIRDEPS_BUILD)
91 @${NEWLOG} ${JOB_NEWLOG_ARGS} ${JOB_LOG}
92 @echo "${TIME_STAMP} Start ${.TARGET:S,-jobs,,} ${JOB_ARGS} ${JOB_LOG_START} log=${JOB_LOG}" | tee ${JOB_LOG}
93 @cd ${.CURDIR} && env MAKELEVEL=0 \
94 ${.MAKE} ${JOB_ARGS} _TARGETS=${.TARGET:S,-jobs,,} ${.TARGET:S,-jobs,,} >> ${JOB_LOG} 2>&1
101 _build_finish: .NOMETA
102 @echo "${TIME_STAMP} Finished ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`"
104 _build_failed: .NOMETA
105 @echo "${TIME_STAMP} Failed ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`"