Deleted Added
full compact
bsd.obj.mk (95254) bsd.obj.mk (95306)
1# $FreeBSD: head/share/mk/bsd.obj.mk 95254 2002-04-22 09:12:18Z ru $
1# $FreeBSD: head/share/mk/bsd.obj.mk 95306 2002-04-23 09:03:56Z ru $
2#
3# The include file <bsd.obj.mk> handles creating the 'obj' directory
4# and cleaning up object files, etc.
5#
2#
3# The include file <bsd.obj.mk> handles creating the 'obj' directory
4# and cleaning up object files, etc.
5#
6# Under construction: it also contains the _SUBDIR target (which is used
7# by most `mk' files to recurse into subdirectories) and defaults for the
8# cleandepend, depend and tags targets. It may eventually be merged with
9# with bsd.subdir.mk.
10#
11# +++ variables +++
12#
13# CLEANDIRS Additional directories to remove for the clean target.
14#
15# CLEANFILES Additional files to remove for the clean target.
16#
17# MAKEOBJDIR A pathname for the directory where the targets
18# are built. Note: MAKEOBJDIR is an *enviroment* variable
19# and works properly only if set as an enviroment variable,
20# not as a global or command line variable!
21#
22# E.g. use `env MAKEOBJDIR=temp-obj make'
23#
24# MAKEOBJDIRPREFIX Specifies somewhere other than /usr/obj to root the object
25# tree. Note: MAKEOBJDIRPREFIX is an *enviroment* variable
26# and works properly only if set as an enviroment variable,
27# not as a global or command line variable!
28#
29# E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
30#
31# NOOBJ Do not create object directories. This should not be set
32# if anything is built.
33#
34# +++ targets +++
35#
36# clean:
37# remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents.
38#
39# cleandir:
40# remove the build directory (and all its contents) created by obj
41#
42# obj:
43# create build directory.
44#
45
46.if !target(__<bsd.obj.mk>__)
47__<bsd.obj.mk>__:
48.include <bsd.own.mk>
49
50.if defined(MAKEOBJDIRPREFIX)
51CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
52.else
53CANONICALOBJDIR:=/usr/obj${.CURDIR}
54.endif
55
56#
57# Warn of unorthodox object directory.
58#
59# The following directories are tried in order for ${.OBJDIR}:
60#
61# 1. ${MAKEOBJDIRPREFIX}/`pwd`
62# 2. ${MAKEOBJDIR}
63# 3. obj.${MACHINE}
64# 4. obj
65# 5. /usr/obj/`pwd`
66# 6. ${.CURDIR}
67#
68# If ${.OBJDIR} is constructed using canonical cases 1 or 5, or
69# case 2 (using MAKEOBJDIR), don't issue a warning. Otherwise,
70# issue a warning differentiating between cases 6 and (3 or 4).
71#
72objwarn:
73.if !defined(NOOBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} && \
74 !(defined(MAKEOBJDIRPREFIX) && exists(${CANONICALOBJDIR}/)) && \
75 !(defined(MAKEOBJDIR) && exists(${MAKEOBJDIR}/))
76.if ${.OBJDIR} == ${.CURDIR}
77 @${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
78.elif exists(${.CURDIR}/obj.${MACHINE}/) || exists(${.CURDIR}/obj/)
79 @${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
80 canonical ${CANONICALOBJDIR}"
81.endif
82.endif
83
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 *enviroment* variable
14# and works properly only if set as an enviroment 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 *enviroment* variable
21# and works properly only if set as an enviroment variable,
22# not as a global or command line variable!
23#
24# E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
25#
26# NOOBJ 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.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(NOOBJ) && ${.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
84.if !target(obj)
85.if defined(NOOBJ)
79.if !target(obj) && !defined(NOOBJ)
86obj:
80obj:
87.else
88obj: _SUBDIR
89 @if ! test -d ${CANONICALOBJDIR}/; then \
90 mkdir -p ${CANONICALOBJDIR}; \
91 if ! test -d ${CANONICALOBJDIR}/; then \
92 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
93 exit 1; \
94 fi; \
95 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
96 fi
97.endif
81 @if ! test -d ${CANONICALOBJDIR}/; then \
82 mkdir -p ${CANONICALOBJDIR}; \
83 if ! test -d ${CANONICALOBJDIR}/; then \
84 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
85 exit 1; \
86 fi; \
87 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
88 fi
89.endif
98.endif
99
100.if !target(objlink)
90
91.if !target(objlink)
101objlink: _SUBDIR
92objlink:
102 @if test -d ${CANONICALOBJDIR}/; then \
103 rm -f ${.CURDIR}/obj; \
104 ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
105 else \
106 echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
107 fi
108.endif
109
110#
111# where would that obj directory be?
112#
113.if !target(whereobj)
114whereobj:
115 @echo ${.OBJDIR}
116.endif
117
118cleanobj:
119.if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/)
120 @rm -rf ${CANONICALOBJDIR}
121.else
122 @cd ${.CURDIR} && ${MAKE} clean cleandepend
123.endif
124 @if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
125
126.if !target(clean)
93 @if test -d ${CANONICALOBJDIR}/; then \
94 rm -f ${.CURDIR}/obj; \
95 ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
96 else \
97 echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
98 fi
99.endif
100
101#
102# where would that obj directory be?
103#
104.if !target(whereobj)
105whereobj:
106 @echo ${.OBJDIR}
107.endif
108
109cleanobj:
110.if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/)
111 @rm -rf ${CANONICALOBJDIR}
112.else
113 @cd ${.CURDIR} && ${MAKE} clean cleandepend
114.endif
115 @if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
116
117.if !target(clean)
127clean: _SUBDIR
118clean:
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
136.if !target(checkdpadd)
119.if defined(CLEANFILES) && !empty(CLEANFILES)
120 rm -f ${CLEANFILES}
121.endif
122.if defined(CLEANDIRS) && !empty(CLEANDIRS)
123 rm -rf ${CLEANDIRS}
124.endif
125.endif
126
127.if !target(checkdpadd)
137checkdpadd: _SUBDIR
128checkdpadd:
138.if (defined(DPADD) || defined(LDADD))
139checkdpadd:
140.if ${OBJFORMAT} != aout
141 @ldadd=`echo \`for lib in ${DPADD} ; do \
142 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
143 done \`` ; \
144 ldadd1=`echo ${LDADD}` ; \
145 if [ "$$ldadd" != "$$ldadd1" ] ; then \
146 echo ${.CURDIR} ; \
147 echo "DPADD -> $$ldadd" ; \
148 echo "LDADD -> $$ldadd1" ; \
149 fi
150.else
151 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \
152 if [ "$$dpadd" != "${DPADD}" ] ; then \
153 echo ${.CURDIR} ; \
154 echo "LDADD -> $$dpadd" ; \
155 echo "DPADD = ${DPADD}" ; \
156 fi
157.endif
158.endif
159.endif
160
129.if (defined(DPADD) || defined(LDADD))
130checkdpadd:
131.if ${OBJFORMAT} != aout
132 @ldadd=`echo \`for lib in ${DPADD} ; do \
133 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
134 done \`` ; \
135 ldadd1=`echo ${LDADD}` ; \
136 if [ "$$ldadd" != "$$ldadd1" ] ; then \
137 echo ${.CURDIR} ; \
138 echo "DPADD -> $$ldadd" ; \
139 echo "LDADD -> $$ldadd1" ; \
140 fi
141.else
142 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \
143 if [ "$$dpadd" != "${DPADD}" ] ; then \
144 echo ${.CURDIR} ; \
145 echo "LDADD -> $$dpadd" ; \
146 echo "DPADD = ${DPADD}" ; \
147 fi
148.endif
149.endif
150.endif
151
161cleandir: cleanobj _SUBDIR
152cleandir: cleanobj
162
153
163.for __target in cleandepend depend tags
164.if !target(${__target})
165${__target}: _SUBDIR
166.endif
167.endfor
154.include <bsd.subdir.mk>
168
155
169_SUBDIR: .USE
170.if defined(SUBDIR) && !empty(SUBDIR)
171 @for entry in ${SUBDIR}; do \
172 if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
173 ${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH}"; \
174 edir=$${entry}.${MACHINE_ARCH}; \
175 cd ${.CURDIR}/$${edir}; \
176 else \
177 ${ECHODIR} "===> ${DIRPRFX}$$entry"; \
178 edir=$${entry}; \
179 cd ${.CURDIR}/$${edir}; \
180 fi; \
181 ${MAKE} ${.TARGET:realinstall=install} \
182 DIRPRFX=${DIRPRFX}$$edir/; \
183 done
184.endif
185
186.endif !target(__<bsd.obj.mk>__)
156.endif !target(__<bsd.obj.mk>__)