1*0df4d8adSSimon J. Gerraty# $Id: jobs.mk,v 1.7 2023/04/18 23:32:28 sjg Exp $ 2*0df4d8adSSimon J. Gerraty# 3*0df4d8adSSimon J. Gerraty# @(#) Copyright (c) 2012-2023, Simon J. Gerraty 4*0df4d8adSSimon J. Gerraty# 5*0df4d8adSSimon J. Gerraty# This file is provided in the hope that it will 6*0df4d8adSSimon J. Gerraty# be of use. There is absolutely NO WARRANTY. 7*0df4d8adSSimon J. Gerraty# Permission to copy, redistribute or otherwise 8*0df4d8adSSimon J. Gerraty# use this file is hereby granted provided that 9*0df4d8adSSimon J. Gerraty# the above copyright notice and this notice are 10*0df4d8adSSimon J. Gerraty# left intact. 11*0df4d8adSSimon J. Gerraty# 12*0df4d8adSSimon J. Gerraty# Please send copies of changes and bug-fixes to: 13*0df4d8adSSimon J. Gerraty# sjg@crufty.net 14*0df4d8adSSimon J. Gerraty# 15*0df4d8adSSimon J. Gerraty 16*0df4d8adSSimon J. Gerraty# This makefile is used by top-level makefile. 17*0df4d8adSSimon J. Gerraty# With the following: 18*0df4d8adSSimon J. Gerraty# 19*0df4d8adSSimon J. Gerraty# .if make(*-jobs) 20*0df4d8adSSimon J. Gerraty# .include <jobs.mk> 21*0df4d8adSSimon J. Gerraty# .endif 22*0df4d8adSSimon J. Gerraty# 23*0df4d8adSSimon J. Gerraty# 24*0df4d8adSSimon J. Gerraty# Then if you do: 25*0df4d8adSSimon J. Gerraty# 26*0df4d8adSSimon J. Gerraty# mk target-jobs 27*0df4d8adSSimon J. Gerraty# 28*0df4d8adSSimon J. Gerraty# We will run: 29*0df4d8adSSimon J. Gerraty# 30*0df4d8adSSimon J. Gerraty# ${MAKE} -j${JOB_MAX} target > ${JOB_LOGDIR}/target.log 2>&1 31*0df4d8adSSimon J. Gerraty# 32*0df4d8adSSimon J. Gerraty# JOB_MAX defaults to 8 but should normally be derrived based on the 33*0df4d8adSSimon J. Gerraty# number of cpus available. The wrapper script 'mk' makes that easy. 34*0df4d8adSSimon J. Gerraty# 35*0df4d8adSSimon J. Gerraty 36*0df4d8adSSimon J. Gerratynow_utc ?= ${%s:L:gmtime} 37*0df4d8adSSimon J. Gerraty.if !defined(start_utc) 38*0df4d8adSSimon J. Gerratystart_utc := ${now_utc} 39*0df4d8adSSimon J. Gerraty.endif 40*0df4d8adSSimon J. Gerraty 41*0df4d8adSSimon J. Gerraty.info ${.newline}${TIME_STAMP} Start ${.TARGETS} 42*0df4d8adSSimon J. Gerraty 43*0df4d8adSSimon J. Gerraty.if make(*-jobs) 44*0df4d8adSSimon J. Gerraty 45*0df4d8adSSimon J. GerratyJOB_LOGDIR ?= ${SRCTOP:H} 46*0df4d8adSSimon J. GerratyJOB_LOG = ${JOB_LOGDIR}/${.TARGET:S,-jobs,,:S,/,_,g}.log 47*0df4d8adSSimon J. GerratyJOB_LOG_GENS ?= 4 48*0df4d8adSSimon J. Gerraty# we like to rotate logs 49*0df4d8adSSimon J. Gerraty.if empty(NEWLOG_SH) 50*0df4d8adSSimon J. Gerraty.ifdef M_whence 51*0df4d8adSSimon J. GerratyNEWLOG_SH := ${newlog.sh:L:${M_whence}} 52*0df4d8adSSimon J. Gerraty.else 53*0df4d8adSSimon J. GerratyNEWLOG_SH := ${(type newlog.sh) 2> /dev/null:L:sh:M/*} 54*0df4d8adSSimon J. Gerraty.endif 55*0df4d8adSSimon J. Gerraty.endif 56*0df4d8adSSimon J. Gerraty.if !empty(NEWLOG_SH) && exists(${NEWLOG_SH}) 57*0df4d8adSSimon J. GerratyNEWLOG := sh ${NEWLOG_SH} 58*0df4d8adSSimon J. GerratyJOB_NEWLOG_ARGS ?= -S -n ${JOB_LOG_GENS} 59*0df4d8adSSimon J. Gerraty.else 60*0df4d8adSSimon J. GerratyNEWLOG = : 61*0df4d8adSSimon J. Gerraty.endif 62*0df4d8adSSimon J. Gerraty 63*0df4d8adSSimon J. Gerraty.if ${.MAKE.JOBS:U0} > 0 64*0df4d8adSSimon J. GerratyJOB_MAX= ${.MAKE.JOBS} 65*0df4d8adSSimon J. Gerraty.else 66*0df4d8adSSimon J. Gerraty# This should be derrived from number of cpu's 67*0df4d8adSSimon J. GerratyJOB_MAX?= 8 68*0df4d8adSSimon J. GerratyJOB_ARGS+= -j${JOB_MAX} 69*0df4d8adSSimon J. Gerraty.endif 70*0df4d8adSSimon J. Gerraty 71*0df4d8adSSimon J. Gerraty# we need to reset .MAKE.LEVEL to 0 do that 72*0df4d8adSSimon J. Gerraty# build orchestration works as expected (DIRDEPS_BUILD) 73*0df4d8adSSimon J. Gerraty${.TARGETS:M*-jobs}: 74*0df4d8adSSimon J. Gerraty @${NEWLOG} ${JOB_NEWLOG_ARGS} ${JOB_LOG} 75*0df4d8adSSimon J. Gerraty @echo Logging to ${JOB_LOG} 76*0df4d8adSSimon J. Gerraty @cd ${.CURDIR} && env MAKELEVEL=0 \ 77*0df4d8adSSimon J. Gerraty ${.MAKE} ${JOB_ARGS} _TARGETS=${.TARGET:S,-jobs,,} ${.TARGET:S,-jobs,,} >> ${JOB_LOG} 2>&1 78*0df4d8adSSimon J. Gerraty 79*0df4d8adSSimon J. Gerraty.endif 80*0df4d8adSSimon J. Gerraty 81*0df4d8adSSimon J. Gerraty.END: _build_finish 82*0df4d8adSSimon J. Gerraty.ERROR: _build_failed 83*0df4d8adSSimon J. Gerraty 84*0df4d8adSSimon J. Gerraty_build_finish: .NOMETA 85*0df4d8adSSimon J. Gerraty @echo "${TIME_STAMP} Finished ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`" 86*0df4d8adSSimon J. Gerraty 87*0df4d8adSSimon J. Gerraty_build_failed: .NOMETA 88*0df4d8adSSimon J. Gerraty @echo "${TIME_STAMP} Failed ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`" 89