make: move mk files to share/mk and clean them up
[unleashed.git] / share / mk / obj.mk
blobb936379d4f6b5321af0d24bbac5c0baa74fb0bef
1 # $Id: obj.mk,v 1.15 2012/11/11 22:37:02 sjg Exp $
3 # @(#) Copyright (c) 1999-2010, 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
10 # left intact.
12 # Please send copies of changes and bug-fixes to:
13 # sjg@crufty.net
16 .if !target(__${.PARSEFILE:S,bsd.,,}__)
17 __${.PARSEFILE:S,bsd.,,}__:
19 .include <init.mk>
21 ECHO_TRACE ?= echo
23 .if ${MK_OBJDIRS} == "no"
24 obj:
25 objlink:
26 objwarn:
27 .else
29 # this has to match how make behaves
30 .if defined(MAKEOBJDIRPREFIX) || defined(MAKEOBJDIR)
31 .if defined(MAKEOBJDIRPREFIX)
32 __objdir:= ${MAKEOBJDIRPREFIX}${.CURDIR}
33 .else
34 __objdir:= ${MAKEOBJDIR}
35 .endif
36 .else
37 __objdir= ${__objlink}
38 .endif
40 .if defined(OBJMACHINE)
41 __objlink= obj.${MACHINE}
42 .else
43 __objlink= obj
44 .endif
46 .if ${MK_AUTO_OBJ} == "yes"
47 .-include "auto.obj.mk"
48 .endif
50 .NOPATH: ${__objdir}
51 .PHONY: obj
53 obj: _SUBDIRUSE
54 @if test ! -d ${__objdir}/.; then \
55 mkdir -p ${__objdir}; \
56 if test ! -d ${__objdir}; then \
57 mkdir ${__objdir}; exit 1; \
58 fi; \
59 ${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \
62 .if !target(_SUBDIRUSE)
63 # this just allows us to be included by ourselves
64 _SUBDIRUSE:
65 .endif
67 # so we can interact with freebsd makefiles
68 .if !target(objwarn)
69 objwarn:
70 .if ${.OBJDIR} == ${.CURDIR}
71 @echo "Warning Object directory is ${.CURDIR}"
72 .elif ${.OBJDIR} != ${__objdir}
73 @echo "Warning Object directory is ${.OBJDIR} vs. ${__objdir}"
74 .endif
75 .endif
77 .if !target(objlink)
78 objlink:
79 .if ${__objdir:T} != ${__objlink}
80 @if test -d ${__objdir}/.; then \
81 ${RM} -f ${.CURDIR}/${__objlink}; \
82 ${LN} -s ${__objdir} ${.CURDIR}/${__objlink}; \
83 echo "${__objlink} -> ${__objdir}"; \
84 else \
85 echo "No ${__objdir} to link to - do a 'make obj'"; \
87 .endif
88 .endif
89 .endif
91 _CURDIR?= ${.CURDIR}
92 _OBJDIR?= ${.OBJDIR}
94 .if !target(print-objdir)
95 print-objdir:
96 @echo ${_OBJDIR}
97 .endif
99 .if !target(whereobj)
100 whereobj:
101 @echo ${_OBJDIR}
102 .endif
104 .if !target(destroy)
105 .if ${.CURDIR} != ${.OBJDIR}
106 destroy:
107 (cd ${_CURDIR} && rm -rf ${_OBJDIR})
108 .else
109 destroy: clean
110 .endif
111 .endif
113 .endif