Deleted Added
full compact
bsd.obj.mk (225736) bsd.obj.mk (252048)
1# $FreeBSD: stable/9/share/mk/bsd.obj.mk 144893 2005-04-11 07:13:29Z harti $
1# $FreeBSD: stable/9/share/mk/bsd.obj.mk 252048 2013-06-20 22:50:08Z sjg $
2#
3# The include file <bsd.obj.mk> handles creating the 'obj' directory
4# and cleaning up object files, etc.
5#
6# +++ variables +++
7#
8# CLEANDIRS Additional directories to remove for the clean target.
9#
10# CLEANFILES Additional files to remove for the clean target.
11#
12# MAKEOBJDIR A pathname for the directory where the targets
13# are built. Note: MAKEOBJDIR is an *environment* variable
14# and works properly only if set as an environment variable,
15# not as a global or command line variable!
16#
17# E.g. use `env MAKEOBJDIR=temp-obj make'
18#
19# MAKEOBJDIRPREFIX Specifies somewhere other than /usr/obj to root the object
20# tree. Note: MAKEOBJDIRPREFIX is an *environment* variable
21# and works properly only if set as an environment variable,
22# not as a global or command line variable!
23#
24# E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
25#
26# NO_OBJ Do not create object directories. This should not be set
27# if anything is built.
28#
29# +++ targets +++
30#
31# clean:
32# remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents.
33#
34# cleandir:
35# remove the build directory (and all its contents) created by obj
36#
37# obj:
38# create build directory.
39#
40
41.if !target(__<bsd.obj.mk>__)
42__<bsd.obj.mk>__:
43.include <bsd.own.mk>
44
45.if defined(MAKEOBJDIRPREFIX)
46CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
2#
3# The include file <bsd.obj.mk> handles creating the 'obj' directory
4# and cleaning up object files, etc.
5#
6# +++ variables +++
7#
8# CLEANDIRS Additional directories to remove for the clean target.
9#
10# CLEANFILES Additional files to remove for the clean target.
11#
12# MAKEOBJDIR A pathname for the directory where the targets
13# are built. Note: MAKEOBJDIR is an *environment* variable
14# and works properly only if set as an environment variable,
15# not as a global or command line variable!
16#
17# E.g. use `env MAKEOBJDIR=temp-obj make'
18#
19# MAKEOBJDIRPREFIX Specifies somewhere other than /usr/obj to root the object
20# tree. Note: MAKEOBJDIRPREFIX is an *environment* variable
21# and works properly only if set as an environment variable,
22# not as a global or command line variable!
23#
24# E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
25#
26# NO_OBJ Do not create object directories. This should not be set
27# if anything is built.
28#
29# +++ targets +++
30#
31# clean:
32# remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents.
33#
34# cleandir:
35# remove the build directory (and all its contents) created by obj
36#
37# obj:
38# create build directory.
39#
40
41.if !target(__<bsd.obj.mk>__)
42__<bsd.obj.mk>__:
43.include <bsd.own.mk>
44
45.if defined(MAKEOBJDIRPREFIX)
46CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
47.elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != ""
48CANONICALOBJDIR:=${MAKEOBJDIR}
47.else
48CANONICALOBJDIR:=/usr/obj${.CURDIR}
49.endif
50
51#
52# Warn of unorthodox object directory.
53#
54# The following directories are tried in order for ${.OBJDIR}:
55#
56# 1. ${MAKEOBJDIRPREFIX}/`pwd`
57# 2. ${MAKEOBJDIR}
58# 3. obj.${MACHINE}
59# 4. obj
60# 5. /usr/obj/`pwd`
61# 6. ${.CURDIR}
62#
63# If ${.OBJDIR} is constructed using canonical cases 1 or 5, or
64# case 2 (using MAKEOBJDIR), don't issue a warning. Otherwise,
65# issue a warning differentiating between cases 6 and (3 or 4).
66#
67objwarn:
68.if !defined(NO_OBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} && \
69 !(defined(MAKEOBJDIRPREFIX) && exists(${CANONICALOBJDIR}/)) && \
70 !(defined(MAKEOBJDIR) && exists(${MAKEOBJDIR}/))
71.if ${.OBJDIR} == ${.CURDIR}
72 @${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
73.elif exists(${.CURDIR}/obj.${MACHINE}/) || exists(${.CURDIR}/obj/)
74 @${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
75 canonical ${CANONICALOBJDIR}"
76.endif
77.endif
78
79.if !defined(NO_OBJ)
80.if !target(obj)
81obj: .PHONY
82 @if ! test -d ${CANONICALOBJDIR}/; then \
83 mkdir -p ${CANONICALOBJDIR}; \
84 if ! test -d ${CANONICALOBJDIR}/; then \
85 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
86 exit 1; \
87 fi; \
88 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
89 fi
90.endif
91
92.if !target(objlink)
93objlink:
94 @if test -d ${CANONICALOBJDIR}/; then \
95 rm -f ${.CURDIR}/obj; \
96 ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
97 else \
98 echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
99 fi
100.endif
101.endif # !defined(NO_OBJ)
102
103#
104# where would that obj directory be?
105#
106.if !target(whereobj)
107whereobj:
108 @echo ${.OBJDIR}
109.endif
110
111.if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/)
112cleanobj:
113 @rm -rf ${CANONICALOBJDIR}
114.else
115cleanobj: clean cleandepend
116.endif
117 @if [ -L ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
118
49.else
50CANONICALOBJDIR:=/usr/obj${.CURDIR}
51.endif
52
53#
54# Warn of unorthodox object directory.
55#
56# The following directories are tried in order for ${.OBJDIR}:
57#
58# 1. ${MAKEOBJDIRPREFIX}/`pwd`
59# 2. ${MAKEOBJDIR}
60# 3. obj.${MACHINE}
61# 4. obj
62# 5. /usr/obj/`pwd`
63# 6. ${.CURDIR}
64#
65# If ${.OBJDIR} is constructed using canonical cases 1 or 5, or
66# case 2 (using MAKEOBJDIR), don't issue a warning. Otherwise,
67# issue a warning differentiating between cases 6 and (3 or 4).
68#
69objwarn:
70.if !defined(NO_OBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} && \
71 !(defined(MAKEOBJDIRPREFIX) && exists(${CANONICALOBJDIR}/)) && \
72 !(defined(MAKEOBJDIR) && exists(${MAKEOBJDIR}/))
73.if ${.OBJDIR} == ${.CURDIR}
74 @${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
75.elif exists(${.CURDIR}/obj.${MACHINE}/) || exists(${.CURDIR}/obj/)
76 @${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
77 canonical ${CANONICALOBJDIR}"
78.endif
79.endif
80
81.if !defined(NO_OBJ)
82.if !target(obj)
83obj: .PHONY
84 @if ! test -d ${CANONICALOBJDIR}/; then \
85 mkdir -p ${CANONICALOBJDIR}; \
86 if ! test -d ${CANONICALOBJDIR}/; then \
87 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
88 exit 1; \
89 fi; \
90 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
91 fi
92.endif
93
94.if !target(objlink)
95objlink:
96 @if test -d ${CANONICALOBJDIR}/; then \
97 rm -f ${.CURDIR}/obj; \
98 ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
99 else \
100 echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
101 fi
102.endif
103.endif # !defined(NO_OBJ)
104
105#
106# where would that obj directory be?
107#
108.if !target(whereobj)
109whereobj:
110 @echo ${.OBJDIR}
111.endif
112
113.if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/)
114cleanobj:
115 @rm -rf ${CANONICALOBJDIR}
116.else
117cleanobj: clean cleandepend
118.endif
119 @if [ -L ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
120
121# Tell bmake not to look for generated files via .PATH
122.if !empty(CLEANFILES)
123.NOPATH: ${CLEANFILES}
124.endif
125
119.if !target(clean)
120clean:
121.if defined(CLEANFILES) && !empty(CLEANFILES)
122 rm -f ${CLEANFILES}
123.endif
124.if defined(CLEANDIRS) && !empty(CLEANDIRS)
125 rm -rf ${CLEANDIRS}
126.endif
127.endif
128
129cleandir: cleanobj
130
131.include <bsd.subdir.mk>
132
133.endif # !target(__<bsd.obj.mk>__)
126.if !target(clean)
127clean:
128.if defined(CLEANFILES) && !empty(CLEANFILES)
129 rm -f ${CLEANFILES}
130.endif
131.if defined(CLEANDIRS) && !empty(CLEANDIRS)
132 rm -rf ${CLEANDIRS}
133.endif
134.endif
135
136cleandir: cleanobj
137
138.include <bsd.subdir.mk>
139
140.endif # !target(__<bsd.obj.mk>__)