]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/bmake/mk/obj.mk
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / bmake / mk / obj.mk
1 # $Id: obj.mk,v 1.15 2012/11/11 22:37:02 sjg Exp $
2 #
3 #       @(#) Copyright (c) 1999-2010, Simon J. Gerraty
4 #
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. 
11 #      
12 #       Please send copies of changes and bug-fixes to:
13 #       sjg@crufty.net
14 #
15
16 .if !target(__${.PARSEFILE:S,bsd.,,}__)
17 __${.PARSEFILE:S,bsd.,,}__:
18
19 .include <init.mk>
20
21 ECHO_TRACE ?= echo
22
23 .if ${MK_OBJDIRS} == "no"
24 obj:
25 objlink:
26 objwarn:
27 .else
28
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
39
40 .if defined(OBJMACHINE)
41 __objlink=      obj.${MACHINE}
42 .else
43 __objlink=      obj
44 .endif
45
46 .if ${MK_AUTO_OBJ} == "yes"
47 .-include "auto.obj.mk"
48 .endif
49
50 .NOPATH:        ${__objdir}
51 .PHONY:         obj
52
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; \
60         fi
61
62 .if !target(_SUBDIRUSE)
63 # this just allows us to be included by ourselves
64 _SUBDIRUSE:
65 .endif
66
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
76
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'"; \
86         fi
87 .endif
88 .endif
89 .endif
90
91 _CURDIR?= ${.CURDIR}
92 _OBJDIR?= ${.OBJDIR}
93
94 .if !target(print-objdir)
95 print-objdir:
96         @echo ${_OBJDIR}
97 .endif
98
99 .if !target(whereobj)
100 whereobj:
101         @echo ${_OBJDIR}
102 .endif
103
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
112
113 .endif