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 MAPFILE_VERS?
= ${.CURDIR
}/mapfile-vers
13 .if exists
(${MAPFILE_VERS})
15 SHLIB_LDADD
+= -M
${MAPFILE_VERS}
18 SHLIB_VERSION_FILE?
= ${.CURDIR
}/shlib_version
19 .if
!defined
(SHLIB_MAJOR
) && exists
(${SHLIB_VERSION_FILE})
20 SHLIB_MAJOR
!= .
${SHLIB_VERSION_FILE} ; echo
$$major
21 SHLIB_MINOR
!= .
${SHLIB_VERSION_FILE} ; echo
$$minor
22 SHLIB_TEENY
!= .
${SHLIB_VERSION_FILE} ; echo
$$teeny
25 .for x in major minor teeny
27 .if defined
(SHLIB_
${x
:tu
}) && ${MK_PIC} != "no"
28 @echo
${SHLIB_
${x
:tu
}}
35 SHLIB_FULLVERSION ?
= ${${SHLIB_MAJOR} ${SHLIB_MINOR} ${SHLIB_TEENY}:L
:ts.
}
36 SHLIB_FULLVERSION
:= ${SHLIB_FULLVERSION}
38 # add additional suffixes not exported.
39 # .po is used for profiling object files.
40 # ${PICO} is used for PIC object files.
42 .SUFFIXES
: .out .a .ln
${PICO} .po .o .s .S .c .
cc .C .m .F .f .r .y .l .cl .p .h
47 # Originally derrived from NetBSD-1.6
49 # Set PICFLAGS to cc flags for producing position-independent code,
50 # if not already set. Includes -DPIC, if required.
52 # Data-driven table using make variables to control how shared libraries
53 # are built for different platforms and object formats.
54 # OBJECT_FMT: currently either "ELF" or "a.out", from <bsd.own.mk>
55 # SHLIB_SOVERSION: version number to be compiled into a shared library
56 # via -soname. Usually ${SHLIB_MAJOR} on ELF.
57 # NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
59 # SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library.
60 # with ELF, also set shared-lib version for ld.so.
61 # SHLIB_LDSTARTFILE: support .o file, call C++ file-level constructors
62 # SHLIB_LDENDFILE: support .o file, call C++ file-level destructors
63 # FPICFLAGS: flags for ${FC} to compile .[fF] files to ${PICO} objects.
64 # CPPICFLAGS: flags for ${CPP} to preprocess .[sS] files for ${AS}
65 # CPICFLAGS: flags for ${CC} to compile .[cC] files to ${PICO} objects.
66 # CAPICFLAGS flags for {$CC} to compiling .[Ss] files
67 # (usually just ${CPPPICFLAGS} ${CPICFLAGS})
68 # APICFLAGS: flags for ${AS} to assemble .[sS] to ${PICO} objects.
72 # sys.mk can override these
77 LD_shared
=-h lib
${LIB}.so.
${SHLIB_MAJOR} -G
-Bdirect
81 .if
!empty
(SHLIB_MAJOR
)
82 .if
${NEED_SOLINKS} && empty
(SHLIB_LINKS
)
83 .if
${MK_LINKLIB} != "no"
84 SHLIB_LINKS
= lib
${LIB}.
${LD_solink}
86 .if
"${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
87 SHLIB_LINKS
+= lib
${LIB}.
${LD_solink}.
${SHLIB_MAJOR}
93 LD_shared ?
= -Bshareable
-Bforcearchive
94 LD_so ?
= so.
${SHLIB_FULLVERSION}
101 LD_objs ?
= `${LORDER} ${OBJS} | ${TSORT}`
102 LD_sobjs ?
= `${LORDER} ${SOBJS} | ${TSORT}`
103 LD_pobjs ?
= `${LORDER} ${POBJS} | ${TSORT}`
105 LD_solib ?
= ${LD_sobjs}
108 # some libs have lots of objects, and scanning all .o, .po and ${PICO} meta files
109 # is a waste of time, this tells meta.autodep.mk to just pick one
110 # (typically ${PICO})
111 # yes, 42 is a random number.
112 .if
${MK_DIRDEPS_BUILD} == "yes" && ${SRCS
:Uno
:[\
#]} > 42
113 OPTIMIZE_OBJECT_META_FILES ?
= yes
116 .if
${MK_LIBTOOL} == "yes"
117 # because libtool is so fascist about naming the object files,
118 # we cannot (yet) build profiled libs
121 .if exists
(${.CURDIR
}/shlib_version
)
122 SHLIB_AGE
!= .
${.CURDIR
}/shlib_version
; echo
$$age
125 # for the normal .a we do not want to strip symbols
127 ${COMPILE.c
} ${.IMPSRC
}
129 # for the normal .a we do not want to strip symbols
130 ${CXX_SUFFIXES
:%=%.o
}:
131 ${COMPILE.
cc} ${.IMPSRC
}
134 @echo
${COMPILE.S
} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
}
135 @
${COMPILE.S
} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
}
139 ${COMPILE.c
} ${CC_PG} ${PROFFLAGS} ${.IMPSRC
} -o
${.TARGET
}
141 ${CXX_SUFFIXES
:%=%.po
}:
142 ${COMPILE.
cc} -pg
${.IMPSRC
} -o
${.TARGET
}
145 ${COMPILE.S
} ${PICFLAG} ${CC_PIC} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}
148 @echo
${COMPILE.c
} ${CC_PG} ${PROFFLAGS} ${.IMPSRC
} -o
${.TARGET
}
149 @
${COMPILE.c
} ${CC_PG} ${PROFFLAGS} ${.IMPSRC
} -o
${.TARGET
}.o
150 @
${LD} ${LD_X} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
153 ${CXX_SUFFIXES
:%=%.po
}:
154 @echo
${COMPILE.
cc} ${CXX_PG} ${PROFFLAGS} ${.IMPSRC
} -o
${.TARGET
}
155 @
${COMPILE.
cc} ${CXX_PG} ${.IMPSRC
} -o
${.TARGET
}.o
156 @
${LD} ${LD_X} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
160 @echo
${COMPILE.S
} ${PICFLAG} ${CC_PIC} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}
161 @
${COMPILE.S
} ${PICFLAG} ${CC_PIC} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}.o
162 @
${LD} ${LD_x} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
168 ${COMPILE.c
} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}
170 ${CXX_SUFFIXES
:%=%${PICO}}:
171 ${COMPILE.
cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}
174 ${COMPILE.S
} ${PROFFLAGS} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}
178 @echo
${COMPILE.c
} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}
179 @
${COMPILE.c
} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}.o
180 @
${LD} ${LD_x} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
183 ${CXX_SUFFIXES
:%=%${PICO}}:
184 @echo
${COMPILE.
cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}
185 @
${COMPILE.
cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}.o
186 @
${LD} ${LD_x} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
190 @echo
${COMPILE.S
} ${PROFFLAGS} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}
191 @
${COMPILE.S
} ${PROFFLAGS} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}.o
192 @
${LD} ${LD_X} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
198 .if
${MK_LIBTOOL} != "yes"
200 .if
!defined
(PICFLAG
)
206 .if
${MK_ARCHIVE} != "no"
210 .if
${MK_PROFILE} != "no"
212 POBJS
+=${OBJS
:.o
=.po
}
215 .if
${MK_PIC} != "no"
216 .if
${MK_PICLIB} == "no"
219 SOLIB
=lib
${LIB}_pic.a
222 .if
!empty
(SHLIB_FULLVERSION
)
223 _LIBS
+=lib
${LIB}.
${LD_so}
227 # here is where you can define what LIB* are
228 .
-include <libnames.mk
>
229 .if
${MK_DPADD_MK} == "yes"
230 # lots of cool magic, but might not suit everyone.
238 .if
!defined
(_SKIP_BUILD
)
244 .for s in
${SRCS
:N
*.h
:M
*/*}
245 ${.o
${PICO} .po .lo
:L
:@o@
${s
:T
:R
}$o@
}: $s
248 OBJS
+= ${SRCS
:T
:N
*.h
:R
:S
/$/.o
/g
}
251 .if
${MK_LIBTOOL} == "yes"
252 .if
${MK_PIC} == "no"
259 # .lo's are created as a side effect
261 ${LIBTOOL} --mode
=compile
${CC} ${LT_STATIC} ${CFLAGS} ${CPPFLAGS} ${IMPFLAGS} -c
${.IMPSRC
}
263 # can't really do profiled libs with libtool - its too fascist about
264 # naming the output...
265 lib
${LIB}.a
:: ${OBJS}
267 ${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}
268 @ln .libs
/${.TARGET
} .
270 lib
${LIB}.
${LD_so}:: lib
${LIB}.a
271 @
[ -s
${.TARGET
}.
${SHLIB_AGE} ] ||
{ ln
-s .libs
/lib
${LIB}.
${LD_so}* .
2>/dev
/null
; : }
272 @
[ -s
${.TARGET
} ] || ln
-s
${.TARGET
}.
${SHLIB_AGE} ${.TARGET
}
274 .
else # MK_LIBTOOL=yes
276 lib
${LIB}.a
:: ${OBJS}
277 @echo building standard
${LIB} library
279 @
${AR} ${AR_cq} ${.TARGET
} ${LD_objs}
281 POBJS
+= ${OBJS
:.o
=.po
}
283 lib
${LIB}_p.a
:: ${POBJS}
284 @echo building profiled
${LIB} library
286 @
${AR} ${AR_cq} ${.TARGET
} ${LD_pobjs}
288 SOBJS
+= ${OBJS
:.o
=${PICO}}
290 lib
${LIB}_pic.a
:: ${SOBJS}
291 @echo building shared object
${LIB} library
293 @
${AR} ${AR_cq} ${.TARGET
} ${LD_sobjs}
295 #SHLIB_LDADD?= ${LDADD}
297 lib
${LIB}.
${LD_so}: ${SOBJS} ${DPADD}
298 @echo building shared
${LIB} library \
(version
${SHLIB_FULLVERSION}\
)
300 ${SHLIB_LD} -o
${.TARGET
} ${LD_shared} ${LD_solib} ${DLLIB} ${SHLIB_LDADD} -lc
302 .if
!empty
(SHLIB_LINKS
)
303 rm -f
${SHLIB_LINKS}; ${SHLIB_LINKS
:O
:u
:@x@ln
-s
${.TARGET
} $x;@
}
308 rm -f a.out
[Ee
]rrs mklog core
*.core
${CLEANFILES}
309 rm -f lib
${LIB}.a
${OBJS}
310 rm -f lib
${LIB}_p.a
${POBJS}
311 rm -f lib
${LIB}_pic.a lib
${LIB}.so.
* ${SOBJS}
312 .if
!empty
(SHLIB_LINKS
)
316 clean: _SUBDIRUSE cleanlib
317 cleandir
: _SUBDIRUSE cleanlib
319 cleandir
: _SUBDIRUSE
clean
322 .if defined
(SRCS
) && (!defined
(MKDEP
) ||
${MKDEP} != autodep
)
324 @
(TMP
=/tmp
/_depend
$$$$; \
325 sed
-e
's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1${PICO} \1.ln:/' \
331 .if
!target
(beforeinstall
)
336 LIB_INSTALL_OWN ?
= -o
${LIBOWN} -g
${LIBGRP}
341 .if
!target
(realinstall
) && !empty
(LIB
)
342 realinstall
: libinstall
344 .if
!target
(libinstall
)
346 ${INSTALL} -d
${LIB_INSTALL_OWN} -m
755 ${DESTDIR}${LIBDIR}
347 .if
${MK_ARCHIVE} != "no"
348 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m
600 lib
${LIB}.a \
350 chmod
${LIBMODE} ${DESTDIR}${LIBDIR}/lib
${LIB}.a
352 .if
${MK_PROFILE} != "no"
353 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m
600 \
354 lib
${LIB}_p.a
${DESTDIR}${LIBDIR}
355 chmod
${LIBMODE} ${DESTDIR}${LIBDIR}/lib
${LIB}_p.a
357 .if
${MK_PIC} != "no"
358 .if
${MK_PICLIB} != "no"
359 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m
600 \
360 lib
${LIB}_pic.a
${DESTDIR}${LIBDIR}
361 chmod
${LIBMODE} ${DESTDIR}${LIBDIR}/lib
${LIB}_pic.a
363 .if
!empty
(SHLIB_MAJOR
)
364 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m
${LIBMODE} \
365 lib
${LIB}.
${LD_so} ${DESTDIR}${LIBDIR}
366 .if
!empty
(SHLIB_LINKS
)
367 (cd
${DESTDIR}${LIBDIR} && { rm -f
${SHLIB_LINKS}; ${SHLIB_LINKS
:O
:u
:@x@ln
-s lib
${LIB}.
${LD_so} $x;@
} })
371 .if defined
(LINKS
) && !empty
(LINKS
)
372 @set
${LINKS}; ${_LINKS_SCRIPT}
376 .if
${MK_MAN} != "no"
377 install: maninstall _SUBDIRUSE
378 maninstall
: afterinstall
380 afterinstall
: realinstall
381 libinstall
: beforeinstall
382 realinstall
: beforeinstall
385 .if defined
(FILES
) || defined
(FILESGROUPS
)
389 .if
${MK_MAN} != "no"
393 .if
${MK_NLS} != "no"
403 # during building we usually need/want to install libs somewhere central
404 # note that we do NOT ch{own,grp} as that would likely fail at this point.
405 # otherwise it is the same as realinstall
406 # Note that we don't need this when using dpadd.mk
407 .libinstall
: ${_LIBS}
408 ${INSTALL} -d
-m755
${DESTDIR}${LIBDIR}
409 .for _lib in
${_LIBS
:M
*.a
}
410 ${INSTALL} ${COPY} -m
644 ${_lib} ${DESTDIR}${LIBDIR}
412 .for _lib in
${_LIBS
:M
*.
${LD_solink}*:O
:u
}
413 ${INSTALL} ${COPY} -m
${LIBMODE} ${_lib} ${DESTDIR}${LIBDIR}
414 .if
!empty
(SHLIB_LINKS
)
415 (cd
${DESTDIR}${LIBDIR} && { ${SHLIB_LINKS
:O
:u
:@x@ln
-sf
${_lib} $x;@
}; })
421 STAGE_LIBDIR?
= ${STAGE_OBJTOP}${LIBDIR}