1 # $Id: jobs.mk,v 1.9 2023/04/27 18:10:27 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 defaults to 8 but should normally be derrived based on the
33 # number of cpus available. The wrapper script 'mk' makes that easy.
36 now_utc ?= ${%s:L:gmtime}
37 .if !defined(start_utc)
38 start_utc := ${now_utc}
42 .info ${.newline}${TIME_STAMP} Start ${.TARGETS}
44 JOB_LOGDIR ?= ${SRCTOP:H}
45 JOB_LOG = ${JOB_LOGDIR}/${.TARGET:S,-jobs,,:S,/,_,g}.log
47 # we like to rotate logs
49 .for d in ${.SYSPATH:U${.PARSEDIR}:@x@$x $x/scripts@}
50 .if exists($d/newlog.sh)
51 NEWLOG_SH := $d/newlog.sh
52 .if ${MAKE_VERSION} > 20220924
59 NEWLOG_SH := ${newlog.sh:L:${M_whence}}
61 NEWLOG_SH := ${(type newlog.sh) 2> /dev/null:L:sh:M/*}
65 .if !empty(NEWLOG_SH) && exists(${NEWLOG_SH})
66 NEWLOG := sh ${NEWLOG_SH}
67 JOB_NEWLOG_ARGS ?= -S -n ${JOB_LOG_GENS}
72 .if ${.MAKE.JOBS:U0} > 0
73 JOB_MAX= ${.MAKE.JOBS}
75 # This should be derrived from number of cpu's
77 JOB_ARGS+= -j${JOB_MAX}
80 # we need to reset .MAKE.LEVEL to 0 do that
81 # build orchestration works as expected (DIRDEPS_BUILD)
83 @${NEWLOG} ${JOB_NEWLOG_ARGS} ${JOB_LOG}
84 @echo "${TIME_STAMP} Start ${.TARGET:S,-jobs,,} ${JOB_ARGS} ${JOB_LOG_START} log=${JOB_LOG}" | tee ${JOB_LOG}
85 @cd ${.CURDIR} && env MAKELEVEL=0 \
86 ${.MAKE} ${JOB_ARGS} _TARGETS=${.TARGET:S,-jobs,,} ${.TARGET:S,-jobs,,} >> ${JOB_LOG} 2>&1
93 _build_finish: .NOMETA
94 @echo "${TIME_STAMP} Finished ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`"
96 _build_failed: .NOMETA
97 @echo "${TIME_STAMP} Failed ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`"