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 CSTD CXXSTD DPSRCS MAN \
26 NO_SHARED NO_WERROR 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})
37 .if defined(${v}.${PROG})
39 .elif defined(${v}_${PROG})
46 .if ${MK_DIRDEPS_BUILD} == "yes"
47 # Leave updating the Makefile.depend to the parent.
48 UPDATE_DEPENDFILE = NO
50 # Record our meta files for the parent to use.
51 CLEANFILES+= ${PROG}.meta_files
52 ${PROG}.meta_files: .NOMETA $${.MAKE.META.CREATED} ${_this}
53 @echo "Updating ${.TARGET}: ${.OODATE:T:[1..8]}"
54 @echo ${.MAKE.META.FILES} > ${.TARGET}
56 .if !defined(_SKIP_BUILD)
57 .END: ${PROG}.meta_files
59 .endif # ${MK_DIRDEPS_BUILD} == "yes"
61 # prog.mk will do the rest
62 .else # !defined(PROG)
63 .if !defined(_SKIP_BUILD)
67 META_XTRAS+= ${cat ${PROGS:S/$/*.meta_files/} 2>/dev/null || true:L:sh}
69 .if ${MK_STAGING} != "no" && !empty(PROGS)
70 # Stage from parent while respecting PROGNAME and BINDIR overrides.
71 .for _prog in ${PROGS}
72 STAGE_DIR.prog.${_prog}= ${STAGE_OBJTOP}${BINDIR.${_prog}:UBINDIR_${_prog}:U${BINDIR}}
73 STAGE_AS_SETS+= prog.${_prog}
74 STAGE_AS_prog.${_prog}= ${PROGNAME.${_prog}:UPROGNAME_${_prog}:U${_prog}}
75 stage_as.prog.${_prog}: ${_prog}
77 .endif # ${MK_STAGING} != "no" && !empty(PROGS)
79 .endif # PROGS || PROGS_CXX
81 # These are handled by the main make process.
82 .ifdef _RECURSING_PROGS
85 _PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS CONFGROUPS DIRS FILESGROUPS INCSGROUPS \
87 .for v in ${_PROGS_GLOBAL_VARS}
92 # handle being called [bsd.]progs.mk
93 .include <bsd.prog.mk>
95 .if !defined(_SKIP_BUILD)
96 # Find common sources among the PROGS to depend on them before building
97 # anything. This allows parallelization without them each fighting over
99 _PROGS_COMMON_SRCS= ${DPSRCS}
102 .for s in ${SRCS.${p}}
103 .if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}}
104 _PROGS_COMMON_SRCS+= ${s}
106 _PROGS_ALL_SRCS+= ${s}
110 .if !empty(_PROGS_COMMON_SRCS)
111 _PROGS_COMMON_OBJS= ${_PROGS_COMMON_SRCS:M*.[dhly]}
112 .if !empty(_PROGS_COMMON_SRCS:N*.[dhly])
113 _PROGS_COMMON_OBJS+= ${_PROGS_COMMON_SRCS:N*.[dhly]:${OBJS_SRCS_FILTER:ts:}:S/$/.o/g}
117 # When recursing, ensure common sources are not rebuilt in META_MODE.
118 .if defined(_RECURSING_PROGS) && !empty(_PROGS_COMMON_OBJS) && \
119 !empty(.MAKE.MODE:Mmeta)
120 ${_PROGS_COMMON_OBJS}: .NOMETA
124 .if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
125 # tell progs.mk we might want to install things
126 PROGS_TARGETS+= checkdpadd clean depend install
127 # Only handle removing depend files from the main process.
128 _PROG_MK.cleandir= CLEANDEPENDFILES= CLEANDEPENDDIRS=
129 _PROG_MK.cleanobj= CLEANDEPENDFILES= CLEANDEPENDDIRS=
130 # Only recurse on these if there is no objdir, meaning a normal
131 # 'clean' gets ran via the target defined in bsd.obj.mk.
132 # Same check from cleanobj: in bsd.obj.mk
133 .if ${CANONICALOBJDIR} == ${.CURDIR} || !exists(${CANONICALOBJDIR}/)
134 PROGS_TARGETS+= cleandir cleanobj
138 .if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
139 # bsd.prog.mk may need to know this
144 $p ${p}_p: .PHONY .MAKE ${_PROGS_COMMON_OBJS}
146 DEPENDFILE=.depend.$p \
147 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
150 # Pseudo targets for PROG, such as 'install'.
151 .for t in ${PROGS_TARGETS:O:u}
152 $p.$t: .PHONY .MAKE ${_PROGS_COMMON_OBJS}
154 DEPENDFILE=.depend.$p \
155 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
156 ${_PROG_MK.${t}} PROG=$p ${x.$p} ${@:E})
160 # Depend main pseudo targets on all PROG.pseudo targets too.
161 .for t in ${PROGS_TARGETS:O:u}
166 .endif # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)