1 # $Id: lib.mk,v 1.61 2017/05/06 17:30:09 sjg Exp $
3 .if
!target
(__
${.PARSEFILE
}__
)
8 .if
${OBJECT_FMT} == "ELF"
12 SHLIB_VERSION_FILE?
= ${.CURDIR
}/shlib_version
13 .if
!defined
(SHLIB_MAJOR
) && exists
(${SHLIB_VERSION_FILE})
14 .
include "${SHLIB_VERSION_FILE}"
19 .for x in major minor teeny
21 .if defined
(SHLIB_
${x
:tu
}) && ${MK_PIC} != "no"
22 @echo
${SHLIB_
${x
:tu
}}
28 .
ifndef SHLIB_FULLVERSION
29 SHLIB_FULLVERSION
= ${SHLIB_MAJOR}
30 .if
!empty
(SHLIB_MINOR
)
31 SHLIB_FULLVERSION
+= ${SHLIB_MINOR}
33 SHLIB_FULLVERSION
:= ${SHLIB_FULLVERSION
:ts.
}
36 # add additional suffixes not exported.
37 # .po is used for profiling object files.
38 # ${PICO} is used for PIC object files.
40 .SUFFIXES
: .out .a .ln
${PICO} .po .o .s .S .c .
cc .C .m .F .f .r .y .l .cl .p .h
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.
69 # sys.mk can override these
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}
81 .if
"${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
82 SHLIB_LINKS
+= lib
${LIB}.
${LD_solink}.
${SHLIB_MAJOR}
88 LD_so ?
= so.
${SHLIB_FULLVERSION}
95 LD_objs ?
= `${LORDER} ${OBJS} | ${TSORT}`
96 LD_sobjs ?
= `${LORDER} ${SOBJS} | ${TSORT}`
97 LD_pobjs ?
= `${LORDER} ${POBJS} | ${TSORT}`
99 LD_solib ?
= ${LD_sobjs}
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
110 .if
${MK_LIBTOOL} == "yes"
111 # because libtool is so fascist about naming the object files,
112 # we cannot (yet) build profiled libs
115 .if exists
(${.CURDIR
}/shlib_version
)
116 SHLIB_AGE
!= .
${.CURDIR
}/shlib_version
; echo
$$age
119 # for the normal .a we do not want to strip symbols
121 ${COMPILE.c
} ${.IMPSRC
}
123 # for the normal .a we do not want to strip symbols
124 ${CXX_SUFFIXES
:%=%.o
}:
125 ${COMPILE.
cc} ${.IMPSRC
}
128 @echo
${COMPILE.S
} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
}
129 @
${COMPILE.S
} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
}
133 ${COMPILE.c
} ${CC_PG} ${PROFFLAGS} ${.IMPSRC
} -o
${.TARGET
}
135 ${CXX_SUFFIXES
:%=%.po
}:
136 ${COMPILE.
cc} -pg
${.IMPSRC
} -o
${.TARGET
}
139 ${COMPILE.S
} ${PICFLAG} ${CC_PIC} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}
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
}
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
}
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
}
162 ${COMPILE.c
} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}
164 ${CXX_SUFFIXES
:%=%${PICO}}:
165 ${COMPILE.
cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}
168 ${COMPILE.S
} ${PROFFLAGS} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}
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
}
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
}
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
}
192 .if
${MK_LIBTOOL} != "yes"
194 .if
!defined
(PICFLAG
)
200 .if
${MK_ARCHIVE} != "no"
204 .if
${MK_PROFILE} != "no"
206 POBJS
+=${OBJS
:.o
=.po
}
209 .if
${MK_PIC} != "no"
210 .if
${MK_PICLIB} == "no"
213 SOLIB
=lib
${LIB}_pic.a
216 .if
!empty
(SHLIB_FULLVERSION
)
217 _LIBS
+=lib
${LIB}.
${LD_so}
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.
232 .if
!defined
(_SKIP_BUILD
)
238 .for s in
${SRCS
:N
*.h
:M
*/*}
239 ${.o
${PICO} .po .lo
:L
:@o@
${s
:T
:R
}$o@
}: $s
242 OBJS
+= ${SRCS
:T
:N
*.h
:R
:S
/$/.o
/g
}
245 .if
${MK_LIBTOOL} == "yes"
246 .if
${MK_PIC} == "no"
253 # .lo's are created as a side effect
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}
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
273 @
${AR} ${AR_cq} ${.TARGET
} ${LD_objs}
275 POBJS
+= ${OBJS
:.o
=.po
}
277 lib
${LIB}_p.a
:: ${POBJS}
278 @echo building profiled
${LIB} library
280 @
${AR} ${AR_cq} ${.TARGET
} ${LD_pobjs}
282 SOBJS
+= ${OBJS
:.o
=${PICO}}
284 lib
${LIB}_pic.a
:: ${SOBJS}
285 @echo building shared object
${LIB} library
287 @
${AR} ${AR_cq} ${.TARGET
} ${LD_sobjs}
289 #SHLIB_LDADD?= ${LDADD}
291 .if defined
(VERSION_SCRIPT
)
292 SHLIB_LDADD
+= -Wl
,--version-script
=${VERSION_SCRIPT}
295 lib
${LIB}.
${LD_so}: ${SOBJS} ${DPADD} ${VERSION_SCRIPT}
296 @echo building shared
${LIB} library \
(version
${SHLIB_FULLVERSION}\
)
298 ${CC} ${CFLAGS} -o
${.TARGET
} ${LD_shared} ${LD_solib} ${DLLIB} ${SHLIB_LDADD} -lc
300 .if
!empty
(SHLIB_LINKS
)
301 rm -f
${SHLIB_LINKS}; ${SHLIB_LINKS
:O
:u
:@x@ln
-s
${.TARGET
} $x;@
}
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
)
314 clean: _SUBDIRUSE cleanlib
315 cleandir
: _SUBDIRUSE cleanlib
317 cleandir
: _SUBDIRUSE
clean
320 .if defined
(SRCS
) && (!defined
(MKDEP
) ||
${MKDEP} != autodep
)
322 @
(TMP
=/tmp
/_depend
$$$$; \
323 sed
-e
's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1${PICO} \1.ln:/' \
329 .if
!target
(beforeinstall
)
334 LIB_INSTALL_OWN ?
= -o
${LIBOWN} -g
${LIBGRP}
339 .if
!target
(realinstall
) && !empty
(LIB
)
340 realinstall
: libinstall
342 .if
!target
(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 \
348 chmod
${LIBMODE} ${DESTDIR}${LIBDIR}/lib
${LIB}.a
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
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
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;@
} })
369 .if defined
(SYMLINKS
) && !empty
(SYMLINKS
)
370 @set
${SYMLINKS}; ${_SYMLINKS_SCRIPT}
372 .if defined
(LINKS
) && !empty
(LINKS
)
373 @set
${LINKS}; ${_LINKS_SCRIPT}
377 .if
${MK_MAN} != "no"
378 install: maninstall _SUBDIRUSE
379 maninstall
: afterinstall
381 afterinstall
: realinstall
382 libinstall
: beforeinstall
383 realinstall
: beforeinstall
386 .if defined
(FILES
) || defined
(FILESGROUPS
)
390 .if
${MK_MAN} != "no"
394 .if
${MK_NLS} != "no"
398 BUILDAFTER
+= ${_LIBS} ${OBJS} ${POBJS} ${SOBJS}
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}
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;@
}; })
424 STAGE_LIBDIR?
= ${STAGE_OBJTOP}${LIBDIR}