2 # $Id: progs.mk,v 1.11 2012/11/06 17:18:54 sjg Exp $
4 # @(#) Copyright (c) 2006, Simon J. Gerraty
6 # This file is provided in the hope that it will
7 # be of use. There is absolutely NO WARRANTY.
8 # Permission to copy, redistribute or otherwise
9 # use this file is hereby granted provided that
10 # the above copyright notice and this notice are
13 # Please send copies of changes and bug-fixes to:
19 .if defined(PROGS) || defined(PROGS_CXX)
20 # we really only use PROGS below...
25 PROG_OVERRIDE_VARS += BINDIR BINGRP BINOWN BINMODE DPSRCS MAN NO_WERROR \
26 PROGNAME SRCS STRIP WARNS
27 PROG_VARS += CFLAGS CXXFLAGS DEBUG_FLAGS DPADD INTERNALPROG LDADD LIBADD \
28 LINKS LDFLAGS MLINKS ${PROG_OVERRIDE_VARS}
29 .for v in ${PROG_VARS:O:u}
30 .if empty(${PROG_OVERRIDE_VARS:M$v})
31 .if defined(${v}.${PROG})
33 .elif defined(${v}_${PROG})
41 .if ${MK_DIRDEPS_BUILD} == "yes"
42 # Leave updating the Makefile.depend to the parent.
43 UPDATE_DEPENDFILE = NO
45 # Record our meta files for the parent to use.
46 CLEANFILES+= ${PROG}.meta_files
47 ${PROG}.meta_files: .NOMETA $${.MAKE.META.CREATED} ${_this}
48 @echo "Updating ${.TARGET}: ${.OODATE:T:[1..8]}"
49 @echo ${.MAKE.META.FILES} > ${.TARGET}
51 .if !defined(_SKIP_BUILD)
52 .END: ${PROG}.meta_files
54 .endif # ${MK_DIRDEPS_BUILD} == "yes"
56 # prog.mk will do the rest
57 .else # !defined(PROG)
58 .if !defined(_SKIP_BUILD)
62 META_XTRAS+= ${cat ${PROGS:S/$/*.meta_files/} 2>/dev/null || true:L:sh}
64 .if ${MK_STAGING} != "no" && !empty(PROGS)
65 # Stage from parent while respecting PROGNAME and BINDIR overrides.
66 .for _prog in ${PROGS}
67 STAGE_DIR.prog.${_prog}= ${STAGE_OBJTOP}${BINDIR.${_prog}:UBINDIR_${_prog}:U${BINDIR}}
68 STAGE_AS_SETS+= prog.${_prog}
69 STAGE_AS_prog.${_prog}= ${PROGNAME.${_prog}:UPROGNAME_${_prog}:U${_prog}}
70 stage_as.prog.${_prog}: ${_prog}
72 .endif # ${MK_STAGING} != "no" && !empty(PROGS)
74 .endif # PROGS || PROGS_CXX
76 # These are handled by the main make process.
77 .ifdef _RECURSING_PROGS
80 _PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS CONFGROUPS FILESGROUPS INCSGROUPS \
82 .for v in ${_PROGS_GLOBAL_VARS}
87 # handle being called [bsd.]progs.mk
88 .include <bsd.prog.mk>
90 # Find common sources among the PROGS to depend on them before building
91 # anything. This allows parallelization without them each fighting over
96 .for s in ${SRCS.${p}}
97 .if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}}
98 _PROGS_COMMON_SRCS+= ${s}
100 _PROGS_ALL_SRCS+= ${s}
104 .if !empty(_PROGS_COMMON_SRCS)
105 _PROGS_COMMON_OBJS= ${_PROGS_COMMON_SRCS:M*.[dhly]}
106 .if !empty(_PROGS_COMMON_SRCS:N*.[dhly])
107 _PROGS_COMMON_OBJS+= ${_PROGS_COMMON_SRCS:N*.[dhly]:${OBJS_SRCS_FILTER:ts:}:S/$/.o/g}
111 # When recursing, ensure common sources are not rebuilt in META_MODE.
112 .if defined(_RECURSING_PROGS) && !empty(_PROGS_COMMON_OBJS) && \
113 !empty(.MAKE.MODE:Mmeta)
114 ${_PROGS_COMMON_OBJS}: .NOMETA
117 .if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
118 # tell progs.mk we might want to install things
119 PROGS_TARGETS+= checkdpadd clean depend install
120 # Only handle removing depend files from the main process.
121 _PROG_MK.cleandir= CLEANDEPENDFILES= CLEANDEPENDDIRS=
122 _PROG_MK.cleanobj= CLEANDEPENDFILES= CLEANDEPENDDIRS=
123 # Only recurse on these if there is no objdir, meaning a normal
124 # 'clean' gets ran via the target defined in bsd.obj.mk.
125 # Same check from cleanobj: in bsd.obj.mk
126 .if ${CANONICALOBJDIR} == ${.CURDIR} || !exists(${CANONICALOBJDIR}/)
127 PROGS_TARGETS+= cleandir cleanobj
130 # Ensure common objects are built before recursing.
131 .if !empty(_PROGS_COMMON_OBJS)
132 ${PROGS}: ${_PROGS_COMMON_OBJS}
136 .if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
137 # bsd.prog.mk may need to know this
142 $p ${p}_p: .PHONY .MAKE
144 DEPENDFILE=.depend.$p \
145 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
148 # Pseudo targets for PROG, such as 'install'.
149 .for t in ${PROGS_TARGETS:O:u}
152 DEPENDFILE=.depend.$p \
153 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
154 ${_PROG_MK.${t}} PROG=$p ${x.$p} ${@:E})
158 # Depend main pseudo targets on all PROG.pseudo targets too.
159 .for t in ${PROGS_TARGETS:O:u}
164 .endif # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)