MFC:
[dragonfly.git] / share / mk / bsd.obj.mk
blob36d21aff6c0be677900e1ff47801413f0bb303dc
1 # $FreeBSD: src/share/mk/bsd.obj.mk,v 1.30.2.10 2003/02/15 05:36:25 kris Exp $
2 # $DragonFly: src/share/mk/bsd.obj.mk,v 1.5 2005/10/08 11:31:29 corecode Exp $
4 # The include file <bsd.obj.mk> handles creating the 'obj' directory
5 # and cleaning up object files, etc.
7 # +++ variables +++
9 # CLEANDIRS Additional directories to remove for the clean target.
11 # CLEANFILES Additional files to remove for the clean target.
13 # MAKEOBJDIR A pathname for the directory where the targets
14 # are built. Note: MAKEOBJDIR is an *environment* variable
15 # and works properly only if set as an environment variable,
16 # not as a global or command line variable!
18 # E.g. use `env MAKEOBJDIR=temp-obj make'
20 # MAKEOBJDIRPREFIX Specifies somewhere other than /usr/obj to root the object
21 # tree. Note: MAKEOBJDIRPREFIX is an *environment* variable
22 # and works properly only if set as an environment variable,
23 # not as a global or command line variable!
25 # E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
27 # NOOBJ Do not create object directories. This should not be set
28 # if anything is built.
30 # +++ targets +++
32 # clean:
33 # remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents.
35 # cleandir:
36 # remove the build directory (and all its contents) created by obj
38 # obj:
39 # create build directory.
42 .if !target(__<bsd.obj.mk>__)
43 __<bsd.obj.mk>__:
44 .include <bsd.own.mk>
46 .if defined(MAKEOBJDIRPREFIX)
47 CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
48 .else
49 CANONICALOBJDIR:=/usr/obj${.CURDIR}
50 .endif
53 # Warn of unorthodox object directory.
55 # The following directories are tried in order for ${.OBJDIR}:
57 # 1. ${MAKEOBJDIRPREFIX}/`pwd`
58 # 2. ${MAKEOBJDIR}
59 # 3. obj.${MACHINE}
60 # 4. obj
61 # 5. /usr/obj/`pwd`
62 # 6. ${.CURDIR}
64 # If ${.OBJDIR} is constructed using canonical cases 1 or 5, or
65 # case 2 (using MAKEOBJDIR), don't issue a warning. Otherwise,
66 # issue a warning differentiating between cases 6 and (3 or 4).
68 objwarn:
69 .if !defined(NOOBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} && \
70 !(defined(MAKEOBJDIRPREFIX) && exists(${CANONICALOBJDIR}/)) && \
71 !(defined(MAKEOBJDIR) && exists(${MAKEOBJDIR}/))
72 .if ${.OBJDIR} == ${.CURDIR}
73 @${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
74 .elif exists(${.CURDIR}/obj.${MACHINE}/) || exists(${.CURDIR}/obj/)
75 @${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
76 canonical ${CANONICALOBJDIR}"
77 .endif
78 .endif
80 .if !defined(NOOBJ)
81 .if !target(obj)
82 obj:
83 @if ! test -d ${CANONICALOBJDIR}/; then \
84 mkdir -p ${CANONICALOBJDIR}; \
85 if ! test -d ${CANONICALOBJDIR}/; then \
86 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
87 exit 1; \
88 fi; \
89 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
91 .endif
93 .if !target(objlink)
94 objlink:
95 @if test -d ${CANONICALOBJDIR}/; then \
96 rm -f ${.CURDIR}/obj; \
97 ${LN} -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
98 else \
99 echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
101 .endif
102 .endif # !defined(NOOBJ)
105 # where would that obj directory be?
107 .if !target(whereobj)
108 whereobj:
109 @echo ${.OBJDIR}
110 .endif
112 cleanobj:
113 .if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/)
114 rm -rf ${CANONICALOBJDIR}
115 .else
116 @cd ${.CURDIR} && ${MAKE} clean cleandepend
117 .endif
118 @if [ -L ${.CURDIR}/obj ]; then \
119 echo rm -f ${.CURDIR}/obj; \
120 rm -f ${.CURDIR}/obj; \
123 .if !target(clean)
124 clean:
125 .if defined(CLEANFILES) && !empty(CLEANFILES)
126 rm -f ${CLEANFILES}
127 .endif
128 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
129 rm -rf ${CLEANDIRS}
130 .endif
131 .endif
133 cleandir: cleanobj
135 .include <bsd.subdir.mk>
137 .endif # !target(__<bsd.obj.mk>__)