Move /var/svc/log to /var/log/svc
[unleashed/lotheac.git] / share / mk / lib.mk
blobedb785338cbfb4cf4a89a028456ff697bcf05f3f
1 # $Id: lib.mk,v 1.61 2017/05/06 17:30:09 sjg Exp $
3 .if !target(__${.PARSEFILE}__)
4 __${.PARSEFILE}__:
6 .include <init.mk>
8 .if ${OBJECT_FMT} == "ELF"
9 NEED_SOLINKS?= yes
10 .endif
12 SHLIB_VERSION_FILE?= ${.CURDIR}/shlib_version
13 .if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE})
14 .include "${SHLIB_VERSION_FILE}"
15 SHLIB_MAJOR:=${major}
16 SHLIB_MINOR:=${minor}
17 .endif
19 .for x in major minor teeny
20 print-shlib-$x:
21 .if defined(SHLIB_${x:tu}) && ${MK_PIC} != "no"
22 @echo ${SHLIB_${x:tu}}
23 .else
24 @false
25 .endif
26 .endfor
28 .ifndef SHLIB_FULLVERSION
29 SHLIB_FULLVERSION= ${SHLIB_MAJOR}
30 .if !empty(SHLIB_MINOR)
31 SHLIB_FULLVERSION+= ${SHLIB_MINOR}
32 .endif
33 SHLIB_FULLVERSION := ${SHLIB_FULLVERSION:ts.}
34 .endif
36 # add additional suffixes not exported.
37 # .po is used for profiling object files.
38 # ${PICO} is used for PIC object files.
39 PICO?= .pico
40 .SUFFIXES: .out .a .ln ${PICO} .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
41 .SUFFIXES: .sh .m4 .m
43 CFLAGS+= ${COPTS}
45 # Originally derrived from NetBSD-1.6
47 # Set PICFLAGS to cc flags for producing position-independent code,
48 # if not already set. Includes -DPIC, if required.
50 # Data-driven table using make variables to control how shared libraries
51 # are built for different platforms and object formats.
52 # OBJECT_FMT: currently either "ELF" or "a.out", from <bsd.own.mk>
53 # SHLIB_SOVERSION: version number to be compiled into a shared library
54 # via -soname. Usually ${SHLIB_MAJOR} on ELF.
55 # NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
56 # SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library.
57 # with ELF, also set shared-lib version for ld.so.
58 # SHLIB_LDSTARTFILE: support .o file, call C++ file-level constructors
59 # SHLIB_LDENDFILE: support .o file, call C++ file-level destructors
60 # FPICFLAGS: flags for ${FC} to compile .[fF] files to ${PICO} objects.
61 # CPPICFLAGS: flags for ${CPP} to preprocess .[sS] files for ${AS}
62 # CPICFLAGS: flags for ${CC} to compile .[cC] files to ${PICO} objects.
63 # CAPICFLAGS flags for {$CC} to compiling .[Ss] files
64 # (usually just ${CPPPICFLAGS} ${CPICFLAGS})
65 # APICFLAGS: flags for ${AS} to assemble .[sS] to ${PICO} objects.
67 MKPICLIB?= yes
69 # sys.mk can override these
70 LD_X?=-X
71 LD_x?=-x
72 LD_r?=-r
74 LD_shared=-shared -Wl,--soname,lib${LIB}.so.${SHLIB_FULLVERSION}
76 .if !empty(SHLIB_MAJOR)
77 .if ${NEED_SOLINKS} && empty(SHLIB_LINKS)
78 .if ${MK_LINKLIB} != "no"
79 SHLIB_LINKS = lib${LIB}.${LD_solink}
80 .endif
81 .if "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
82 SHLIB_LINKS += lib${LIB}.${LD_solink}.${SHLIB_MAJOR}
83 .endif
84 .endif
85 .endif
87 LIBTOOL?=libtool
88 LD_so ?= so.${SHLIB_FULLVERSION}
89 LD_solink ?= so
90 .if empty(LORDER)
91 LD_objs ?= ${OBJS}
92 LD_pobjs ?= ${POBJS}
93 LD_sobjs ?= ${SOBJS}
94 .else
95 LD_objs ?= `${LORDER} ${OBJS} | ${TSORT}`
96 LD_sobjs ?= `${LORDER} ${SOBJS} | ${TSORT}`
97 LD_pobjs ?= `${LORDER} ${POBJS} | ${TSORT}`
98 .endif
99 LD_solib ?= ${LD_sobjs}
100 AR_cq ?= cq
102 # some libs have lots of objects, and scanning all .o, .po and ${PICO} meta files
103 # is a waste of time, this tells meta.autodep.mk to just pick one
104 # (typically ${PICO})
105 # yes, 42 is a random number.
106 .if ${MK_DIRDEPS_BUILD} == "yes" && ${SRCS:Uno:[\#]} > 42
107 OPTIMIZE_OBJECT_META_FILES ?= yes
108 .endif
110 .if ${MK_LIBTOOL} == "yes"
111 # because libtool is so fascist about naming the object files,
112 # we cannot (yet) build profiled libs
113 MK_PROFILE=no
114 _LIBS=lib${LIB}.a
115 .if exists(${.CURDIR}/shlib_version)
116 SHLIB_AGE != . ${.CURDIR}/shlib_version ; echo $$age
117 .endif
118 .else
119 # for the normal .a we do not want to strip symbols
120 .c.o:
121 ${COMPILE.c} ${.IMPSRC}
123 # for the normal .a we do not want to strip symbols
124 ${CXX_SUFFIXES:%=%.o}:
125 ${COMPILE.cc} ${.IMPSRC}
127 .S.o .s.o:
128 @echo ${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
129 @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
131 .if (${LD_X} == "")
132 .c.po:
133 ${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
135 ${CXX_SUFFIXES:%=%.po}:
136 ${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
138 .S${PICO} .s${PICO}:
139 ${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
140 .else
141 .c.po:
142 @echo ${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
143 @${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}.o
144 @${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
145 @rm -f ${.TARGET}.o
147 ${CXX_SUFFIXES:%=%.po}:
148 @echo ${COMPILE.cc} ${CXX_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
149 @${COMPILE.cc} ${CXX_PG} ${.IMPSRC} -o ${.TARGET}.o
150 @${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
151 @rm -f ${.TARGET}.o
153 .S${PICO} .s${PICO}:
154 @echo ${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
155 @${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
156 @${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
157 @rm -f ${.TARGET}.o
158 .endif
160 .if (${LD_x} == "")
161 .c${PICO}:
162 ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
164 ${CXX_SUFFIXES:%=%${PICO}}:
165 ${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
167 .S.po .s.po:
168 ${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
169 .else
171 .c${PICO}:
172 @echo ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
173 @${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
174 @${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
175 @rm -f ${.TARGET}.o
177 ${CXX_SUFFIXES:%=%${PICO}}:
178 @echo ${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
179 @${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
180 @${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
181 @rm -f ${.TARGET}.o
183 .S.po .s.po:
184 @echo ${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
185 @${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
186 @${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
187 @rm -f ${.TARGET}.o
189 .endif
190 .endif
192 .if ${MK_LIBTOOL} != "yes"
194 .if !defined(PICFLAG)
195 PICFLAG=-fpic
196 .endif
198 _LIBS=
200 .if ${MK_ARCHIVE} != "no"
201 _LIBS += lib${LIB}.a
202 .endif
204 .if ${MK_PROFILE} != "no"
205 _LIBS+=lib${LIB}_p.a
206 POBJS+=${OBJS:.o=.po}
207 .endif
209 .if ${MK_PIC} != "no"
210 .if ${MK_PICLIB} == "no"
211 SOLIB ?= lib${LIB}.a
212 .else
213 SOLIB=lib${LIB}_pic.a
214 _LIBS+=${SOLIB}
215 .endif
216 .if !empty(SHLIB_FULLVERSION)
217 _LIBS+=lib${LIB}.${LD_so}
218 .endif
219 .endif
221 # here is where you can define what LIB* are
222 .-include <libnames.mk>
223 .if ${MK_DPADD_MK} == "yes"
224 # lots of cool magic, but might not suit everyone.
225 .include <dpadd.mk>
226 .endif
228 .if empty(LIB)
229 _LIBS=
230 .endif
232 .if !defined(_SKIP_BUILD)
233 realbuild: ${_LIBS}
234 .endif
236 all: _SUBDIRUSE
238 .for s in ${SRCS:N*.h:M*/*}
239 ${.o ${PICO} .po .lo:L:@o@${s:T:R}$o@}: $s
240 .endfor
242 OBJS+= ${SRCS:T:N*.h:R:S/$/.o/g}
243 .NOPATH: ${OBJS}
245 .if ${MK_LIBTOOL} == "yes"
246 .if ${MK_PIC} == "no"
247 LT_STATIC=-static
248 .else
249 LT_STATIC=
250 .endif
251 SHLIB_AGE?=0
253 # .lo's are created as a side effect
254 .s.o .S.o .c.o:
255 ${LIBTOOL} --mode=compile ${CC} ${LT_STATIC} ${CFLAGS} ${CPPFLAGS} ${IMPFLAGS} -c ${.IMPSRC}
257 # can't really do profiled libs with libtool - its too fascist about
258 # naming the output...
259 lib${LIB}.a:: ${OBJS}
260 @rm -f ${.TARGET}
261 ${LIBTOOL} --mode=link ${CC} ${LT_STATIC} -o ${.TARGET:.a=.la} ${OBJS:.o=.lo} -rpath ${SHLIBDIR}:/usr/lib -version-info ${SHLIB_MAJOR}:${SHLIB_MINOR}:${SHLIB_AGE}
262 @ln .libs/${.TARGET} .
264 lib${LIB}.${LD_so}:: lib${LIB}.a
265 @[ -s ${.TARGET}.${SHLIB_AGE} ] || { ln -s .libs/lib${LIB}.${LD_so}* . 2>/dev/null; : }
266 @[ -s ${.TARGET} ] || ln -s ${.TARGET}.${SHLIB_AGE} ${.TARGET}
268 .else # MK_LIBTOOL=yes
270 lib${LIB}.a:: ${OBJS}
271 @echo building standard ${LIB} library
272 @rm -f ${.TARGET}
273 @${AR} ${AR_cq} ${.TARGET} ${LD_objs}
275 POBJS+= ${OBJS:.o=.po}
276 .NOPATH: ${POBJS}
277 lib${LIB}_p.a:: ${POBJS}
278 @echo building profiled ${LIB} library
279 @rm -f ${.TARGET}
280 @${AR} ${AR_cq} ${.TARGET} ${LD_pobjs}
282 SOBJS+= ${OBJS:.o=${PICO}}
283 .NOPATH: ${SOBJS}
284 lib${LIB}_pic.a:: ${SOBJS}
285 @echo building shared object ${LIB} library
286 @rm -f ${.TARGET}
287 @${AR} ${AR_cq} ${.TARGET} ${LD_sobjs}
289 #SHLIB_LDADD?= ${LDADD}
291 .if defined(VERSION_SCRIPT)
292 SHLIB_LDADD+= -Wl,--version-script=${VERSION_SCRIPT}
293 .endif
295 lib${LIB}.${LD_so}: ${SOBJS} ${DPADD} ${VERSION_SCRIPT}
296 @echo building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\)
297 @rm -f ${.TARGET}
298 ${CC} ${CFLAGS} -o ${.TARGET} ${LD_shared} ${LD_solib} ${DLLIB} ${SHLIB_LDADD} -lc
299 .endif
300 .if !empty(SHLIB_LINKS)
301 rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s ${.TARGET} $x;@}
302 .endif
304 .if !target(clean)
305 cleanlib: .PHONY
306 rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
307 rm -f lib${LIB}.a ${OBJS}
308 rm -f lib${LIB}_p.a ${POBJS}
309 rm -f lib${LIB}_pic.a lib${LIB}.so.* ${SOBJS}
310 .if !empty(SHLIB_LINKS)
311 rm -f ${SHLIB_LINKS}
312 .endif
314 clean: _SUBDIRUSE cleanlib
315 cleandir: _SUBDIRUSE cleanlib
316 .else
317 cleandir: _SUBDIRUSE clean
318 .endif
320 .if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
321 afterdepend: .depend
322 @(TMP=/tmp/_depend$$$$; \
323 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1${PICO} \1.ln:/' \
324 < .depend > $$TMP; \
325 mv $$TMP .depend)
326 .endif
328 .if !target(install)
329 .if !target(beforeinstall)
330 beforeinstall:
331 .endif
333 .if !empty(LIBOWN)
334 LIB_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP}
335 .endif
337 .include <links.mk>
339 .if !target(realinstall) && !empty(LIB)
340 realinstall: libinstall
341 .endif
342 .if !target(libinstall)
343 libinstall:
344 ${INSTALL} -d ${LIB_INSTALL_OWN} -m 755 ${DESTDIR}${LIBDIR}
345 .if ${MK_ARCHIVE} != "no"
346 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 lib${LIB}.a \
347 ${DESTDIR}${LIBDIR}
348 chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
349 .endif
350 .if ${MK_PROFILE} != "no"
351 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \
352 lib${LIB}_p.a ${DESTDIR}${LIBDIR}
353 chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
354 .endif
355 .if ${MK_PIC} != "no"
356 .if ${MK_PICLIB} != "no"
357 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \
358 lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
359 chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
360 .endif
361 .if !empty(SHLIB_MAJOR)
362 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
363 lib${LIB}.${LD_so} ${DESTDIR}${LIBDIR}
364 .if !empty(SHLIB_LINKS)
365 (cd ${DESTDIR}${LIBDIR} && { rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s lib${LIB}.${LD_so} $x;@} })
366 .endif
367 .endif
368 .endif
369 .if defined(SYMLINKS) && !empty(SYMLINKS)
370 @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
371 .endif
372 .if defined(LINKS) && !empty(LINKS)
373 @set ${LINKS}; ${_LINKS_SCRIPT}
374 .endif
375 .endif
377 .if ${MK_MAN} != "no"
378 install: maninstall _SUBDIRUSE
379 maninstall: afterinstall
380 .endif
381 afterinstall: realinstall
382 libinstall: beforeinstall
383 realinstall: beforeinstall
384 .endif
386 .if defined(FILES) || defined(FILESGROUPS)
387 .include <files.mk>
388 .endif
390 .if ${MK_MAN} != "no"
391 .include <man.mk>
392 .endif
394 .if ${MK_NLS} != "no"
395 .include <nls.mk>
396 .endif
398 BUILDAFTER+= ${_LIBS} ${OBJS} ${POBJS} ${SOBJS}
400 .include <obj.mk>
401 .include <inc.mk>
402 .include <dep.mk>
403 .include <subdir.mk>
404 .endif
406 # during building we usually need/want to install libs somewhere central
407 # note that we do NOT ch{own,grp} as that would likely fail at this point.
408 # otherwise it is the same as realinstall
409 # Note that we don't need this when using dpadd.mk
410 .libinstall: ${_LIBS}
411 ${INSTALL} -d -m755 ${DESTDIR}${LIBDIR}
412 .for _lib in ${_LIBS:M*.a}
413 ${INSTALL} ${COPY} -m 644 ${_lib} ${DESTDIR}${LIBDIR}
414 .endfor
415 .for _lib in ${_LIBS:M*.${LD_solink}*:O:u}
416 ${INSTALL} ${COPY} -m ${LIBMODE} ${_lib} ${DESTDIR}${LIBDIR}
417 .if !empty(SHLIB_LINKS)
418 (cd ${DESTDIR}${LIBDIR} && { ${SHLIB_LINKS:O:u:@x@ln -sf ${_lib} $x;@}; })
419 .endif
420 .endfor
421 @touch ${.TARGET}
423 .if !empty(LIB)
424 STAGE_LIBDIR?= ${STAGE_OBJTOP}${LIBDIR}
425 stage_libs: ${_LIBS}
426 .endif
428 .include <final.mk>
429 .endif