1 # $Id: lib.mk,v 1.51 2014/05/23 01:30:36 sjg Exp $
3 .if
!target
(__
${.PARSEFILE
}__
)
8 .if
${OBJECT_FMT} == "ELF"
12 .if exists
(${.CURDIR
}/shlib_version
)
13 SHLIB_MAJOR
!= .
${.CURDIR
}/shlib_version
; echo
$$major
14 SHLIB_MINOR
!= .
${.CURDIR
}/shlib_version
; echo
$$minor
18 .if defined
(SHLIB_MAJOR
) && ${MK_PIC} != "no"
25 .if defined
(SHLIB_MINOR
) && ${MK_PIC} != "no"
32 .if defined
(SHLIB_TEENY
) && ${MK_PIC} != "no"
38 SHLIB_FULLVERSION ?
= ${${SHLIB_MAJOR} ${SHLIB_MINOR} ${SHLIB_TEENY}:L
:ts.
}
39 SHLIB_FULLVERSION
:= ${SHLIB_FULLVERSION}
41 # add additional suffixes not exported.
42 # .po is used for profiling object files.
43 # .so is used for PIC object files.
44 .SUFFIXES
: .out .a .ln .so .po .o .s .S .c .
cc .C .m .F .f .r .y .l .cl .p .h
49 # Derrived from NetBSD-1.6
51 # Set PICFLAGS to cc flags for producing position-independent code,
52 # if not already set. Includes -DPIC, if required.
54 # Data-driven table using make variables to control how shared libraries
55 # are built for different platforms and object formats.
56 # OBJECT_FMT: currently either "ELF" or "a.out", from <bsd.own.mk>
57 # SHLIB_SOVERSION: version number to be compiled into a shared library
58 # via -soname. Usually ${SHLIB_MAJOR} on ELF.
59 # NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
61 # SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library.
62 # with ELF, also set shared-lib version for ld.so.
63 # SHLIB_LDSTARTFILE: support .o file, call C++ file-level constructors
64 # SHLIB_LDENDFILE: support .o file, call C++ file-level destructors
65 # FPICFLAGS: flags for ${FC} to compile .[fF] files to .so objects.
66 # CPPICFLAGS: flags for ${CPP} to preprocess .[sS] files for ${AS}
67 # CPICFLAGS: flags for ${CC} to compile .[cC] files to .so objects.
68 # CAPICFLAGS flags for {$CC} to compiling .[Ss] files
69 # (usually just ${CPPPICFLAGS} ${CPICFLAGS})
70 # APICFLAGS: flags for ${AS} to assemble .[sS] to .so objects.
72 .if
${TARGET_OSNAME} == "NetBSD"
73 .if
${MACHINE_ARCH} == "alpha"
74 # Alpha-specific shared library flags
76 CPICFLAGS ?
= -fPIC
-DPIC
78 CAPICFLAGS?
= ${CPPPICFLAGS} ${CPICFLAGS}
80 .elif
${MACHINE_ARCH} == "mipsel" ||
${MACHINE_ARCH} == "mipseb"
81 # mips-specific shared library flags
83 # On mips, all libs are compiled with ABIcalls, not just sharedlibs.
86 # so turn shlib PIC flags on for ${AS}.
91 .elif
${MACHINE_ARCH} == "vax" && ${OBJECT_FMT} == "ELF"
92 # On the VAX, all object are PIC by default, not just sharedlibs.
95 .elif
(${MACHINE_ARCH} == "sparc" ||
${MACHINE_ARCH} == "sparc64") && \
96 ${OBJECT_FMT} == "ELF"
97 # If you use -fPIC you need to define BIGPIC to turn on 32-bit
98 # relocations in asm code
100 CPICFLAGS ?
= -fPIC
-DPIC
101 CPPPICFLAGS?
= -DPIC
-DBIGPIC
102 CAPICFLAGS?
= ${CPPPICFLAGS} ${CPICFLAGS}
107 # Platform-independent flags for NetBSD a.out shared libraries
108 SHLIB_SOVERSION
=${SHLIB_FULLVERSION}
111 CPICFLAGS?
= -fPIC
-DPIC
113 CAPICFLAGS?
= ${CPPPICFLAGS} ${CPICFLAGS}
118 # Platform-independent linker flags for ELF shared libraries
119 .if
${OBJECT_FMT} == "ELF"
120 SHLIB_SOVERSION
= ${SHLIB_MAJOR}
121 SHLIB_SHFLAGS
= -soname lib
${LIB}.so.
${SHLIB_SOVERSION}
122 SHLIB_LDSTARTFILE?
= /usr
/lib
/crtbeginS.o
123 SHLIB_LDENDFILE?
= /usr
/lib
/crtendS.o
126 # for compatibility with the following
127 CC_PIC?
= ${CPICFLAGS}
128 LD_shared
=${SHLIB_SHFLAGS}
132 .if
${TARGET_OSNAME} == "FreeBSD"
133 .if
${OBJECT_FMT} == "ELF"
134 SHLIB_SOVERSION
= ${SHLIB_MAJOR}
135 SHLIB_SHFLAGS
= -soname lib
${LIB}.so.
${SHLIB_SOVERSION}
137 SHLIB_SHFLAGS
= -assert pure-text
142 LD_shared
=${SHLIB_SHFLAGS}
148 # sys.mk can override these
153 # Non BSD machines will be using bmake.
154 .if
${TARGET_OSNAME} == "SunOS"
155 LD_shared
=-assert pure-text
156 .if
${OBJECT_FMT} == "ELF" ||
${MACHINE} == "solaris"
158 LD_shared
=-h lib
${LIB}.so.
${SHLIB_MAJOR} -G
160 .elif
${TARGET_OSNAME} == "HP-UX"
164 # HPsUX lorder does not grok anything but .o
165 LD_sobjs
=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
166 LD_pobjs
=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
167 .elif
${TARGET_OSNAME} == "OSF1"
168 LD_shared
= -msym
-shared
-expect_unresolved
'*'
169 LD_solib
= -all lib
${LIB}_pic.a
171 # lorder does not grok anything but .o
172 LD_sobjs
=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
173 LD_pobjs
=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
175 .elif
${TARGET_OSNAME} == "FreeBSD"
176 LD_solib
= lib
${LIB}_pic.a
177 .elif
${TARGET_OSNAME} == "Linux"
179 # this is ambiguous of course
180 LD_shared
=-shared
-Wl
,"-h lib${LIB}.so.${SHLIB_MAJOR}"
181 LD_solib
= -Wl
,--whole-archive lib
${LIB}_pic.a
-Wl
,--no-whole-archive
182 # Linux uses GNU ld, which is a multi-pass linker
183 # so we don't need to use lorder or tsort
187 .elif
${TARGET_OSNAME} == "Darwin"
189 SHLIB_INSTALL_VERSION ?
= ${SHLIB_MAJOR}
190 SHLIB_COMPATABILITY_VERSION ?
= ${SHLIB_MAJOR}.
${SHLIB_MINOR
:U0
}
191 SHLIB_COMPATABILITY ?
= \
192 -compatibility_version
${SHLIB_COMPATABILITY_VERSION} \
193 -current_version
${SHLIB_FULLVERSION}
194 LD_shared
= -dynamiclib \
195 -flat_namespace
-undefined suppress \
196 -install_name
${LIBDIR}/lib
${LIB}.
${SHLIB_INSTALL_VERSION}.
${LD_solink} \
197 ${SHLIB_COMPATABILITY}
199 .for v in
${SHLIB_COMPATABILITY_VERSION} ${SHLIB_INSTALL_VERSION}
200 .if
"$v" != "${SHLIB_FULLVERSION}"
201 SHLIB_LINKS
+= lib
${LIB}.
$v.
${LD_solink}
204 .if
${MK_LINKLIB} != "no"
205 SHLIB_LINKS
+= lib
${LIB}.
${LD_solink}
208 LD_so
= ${SHLIB_FULLVERSION}.dylib
209 LD_sobjs
= ${SOBJS
:O
:u
}
210 LD_solib
= ${LD_sobjs}
213 .if
${MACHINE_ARCH} == "i386"
216 PICFLAG ?
= -fPIC
-fno-common
223 .if
!empty
(SHLIB_MAJOR
)
224 .if
${NEED_SOLINKS} && empty
(SHLIB_LINKS
)
225 .if
${MK_LINKLIB} != "no"
226 SHLIB_LINKS
= lib
${LIB}.
${LD_solink}
228 .if
"${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
229 SHLIB_LINKS
+= lib
${LIB}.
${LD_solink}.
${SHLIB_MAJOR}
235 LD_shared ?
= -Bshareable
-Bforcearchive
236 LD_so ?
= so.
${SHLIB_FULLVERSION}
243 LD_objs ?
= `${LORDER} ${OBJS} | ${TSORT}`
244 LD_sobjs ?
= `${LORDER} ${SOBJS} | ${TSORT}`
245 LD_pobjs ?
= `${LORDER} ${POBJS} | ${TSORT}`
247 LD_solib ?
= ${LD_sobjs}
249 .if exists
(/netbsd
) && exists
(${DESTDIR}/usr
/lib
/libdl.so
)
253 # some libs have lots of objects, and scanning all .o, .po and .So meta files
254 # is a waste of time, this tells meta.autodep.mk to just pick one
256 # yes, 42 is a random number.
257 .if
${MK_META_MODE} == "yes" && ${SRCS
:Uno
:[\
#]} > 42
258 OPTIMIZE_OBJECT_META_FILES ?
= yes
262 .if
${MK_LIBTOOL} == "yes"
263 # because libtool is so fascist about naming the object files,
264 # we cannot (yet) build profiled libs
267 .if exists
(${.CURDIR
}/shlib_version
)
268 SHLIB_AGE
!= .
${.CURDIR
}/shlib_version
; echo
$$age
271 # for the normal .a we do not want to strip symbols
273 ${COMPILE.c
} ${.IMPSRC
}
275 # for the normal .a we do not want to strip symbols
277 ${COMPILE.
cc} ${.IMPSRC
}
280 @echo
${COMPILE.S
} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
}
281 @
${COMPILE.S
} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
}
285 ${COMPILE.c
} ${CC_PG} ${PROFFLAGS} ${.IMPSRC
} -o
${.TARGET
}
288 ${COMPILE.
cc} -pg
${.IMPSRC
} -o
${.TARGET
}
291 ${COMPILE.S
} ${PICFLAG} ${CC_PIC} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}
294 @echo
${COMPILE.c
} ${CC_PG} ${PROFFLAGS} ${.IMPSRC
} -o
${.TARGET
}
295 @
${COMPILE.c
} ${CC_PG} ${PROFFLAGS} ${.IMPSRC
} -o
${.TARGET
}.o
296 @
${LD} ${LD_X} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
300 @echo
${COMPILE.
cc} ${CXX_PG} ${PROFFLAGS} ${.IMPSRC
} -o
${.TARGET
}
301 @
${COMPILE.
cc} ${CXX_PG} ${.IMPSRC
} -o
${.TARGET
}.o
302 @
${LD} ${LD_X} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
306 @echo
${COMPILE.S
} ${PICFLAG} ${CC_PIC} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}
307 @
${COMPILE.S
} ${PICFLAG} ${CC_PIC} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}.o
308 @
${LD} ${LD_x} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
314 ${COMPILE.c
} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}
317 ${COMPILE.
cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}
320 ${COMPILE.S
} ${PROFFLAGS} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}
324 @echo
${COMPILE.c
} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}
325 @
${COMPILE.c
} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}.o
326 @
${LD} ${LD_x} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
330 @echo
${COMPILE.
cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}
331 @
${COMPILE.
cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC
} -o
${.TARGET
}.o
332 @
${LD} ${LD_x} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
336 @echo
${COMPILE.S
} ${PROFFLAGS} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}
337 @
${COMPILE.S
} ${PROFFLAGS} ${CFLAGS
:M-
[ID
]*} ${AINC} ${.IMPSRC
} -o
${.TARGET
}.o
338 @
${LD} ${LD_X} ${LD_r} ${.TARGET
}.o
-o
${.TARGET
}
345 ${LINT} ${LINTFLAGS} ${CFLAGS
:M-
[IDU
]*} -i
${.IMPSRC
}
347 .if
${MK_LIBTOOL} != "yes"
349 .if
!defined
(PICFLAG
)
355 .if
${MK_ARCHIVE} != "no"
359 .if
${MK_PROFILE} != "no"
361 POBJS
+=${OBJS
:.o
=.po
}
364 .if
${MK_PIC} != "no"
365 .if
${MK_PICLIB} == "no"
368 SOLIB
=lib
${LIB}_pic.a
371 .if
!empty
(SHLIB_FULLVERSION
)
372 _LIBS
+=lib
${LIB}.
${LD_so}
376 .if
${MK_LINT} != "no"
377 _LIBS
+=llib-l
${LIB}.ln
380 # here is where you can define what LIB* are
381 .
-include <libnames.mk
>
382 .if
${MK_DPADD_MK} == "yes"
383 # lots of cool magic, but might not suit everyone.
387 .if
!defined
(_SKIP_BUILD
)
388 all: prebuild .WAIT
${_LIBS}
389 # a hook for things that must be done early
391 .if
!defined
(.PARSEDIR
)
392 # no-op is the best we can do if not bmake.
398 .for s in
${SRCS
:N
*.h
:M
*/*}
399 ${.o .so .po .lo
:L
:@o@
${s
:T
:R
}$o@
}: $s
402 OBJS
+= ${SRCS
:T
:N
*.h
:R
:S
/$/.o
/g
}
405 .if
${MK_LIBTOOL} == "yes"
406 .if
${MK_PIC} == "no"
413 # .lo's are created as a side effect
415 ${LIBTOOL} --mode
=compile
${CC} ${LT_STATIC} ${CFLAGS} ${CPPFLAGS} ${IMPFLAGS} -c
${.IMPSRC
}
417 # can't really do profiled libs with libtool - its too fascist about
418 # naming the output...
419 lib
${LIB}.a
:: ${OBJS}
421 ${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}
422 @ln .libs
/${.TARGET
} .
424 lib
${LIB}.
${LD_so}:: lib
${LIB}.a
425 @
[ -s
${.TARGET
}.
${SHLIB_AGE} ] ||
{ ln
-s .libs
/lib
${LIB}.
${LD_so}* .
2>/dev
/null
; : }
426 @
[ -s
${.TARGET
} ] || ln
-s
${.TARGET
}.
${SHLIB_AGE} ${.TARGET
}
428 .
else # MK_LIBTOOL=yes
430 lib
${LIB}.a
:: ${OBJS}
431 @echo building standard
${LIB} library
433 @
${AR} ${AR_cq} ${.TARGET
} ${LD_objs}
436 POBJS
+= ${OBJS
:.o
=.po
}
438 lib
${LIB}_p.a
:: ${POBJS}
439 @echo building profiled
${LIB} library
441 @
${AR} ${AR_cq} ${.TARGET
} ${LD_pobjs}
444 SOBJS
+= ${OBJS
:.o
=.so
}
446 lib
${LIB}_pic.a
:: ${SOBJS}
447 @echo building shared object
${LIB} library
449 @
${AR} ${AR_cq} ${.TARGET
} ${LD_sobjs}
452 #SHLIB_LDADD?= ${LDADD}
454 # bound to be non-portable...
455 # this is known to work for NetBSD 1.6 and FreeBSD 4.2
456 lib
${LIB}.
${LD_so}: ${SOLIB} ${DPADD}
457 @echo building shared
${LIB} library \
(version
${SHLIB_FULLVERSION}\
)
459 .if
${TARGET_OSNAME} == "NetBSD" ||
${TARGET_OSNAME} == "FreeBSD"
460 .if
${OBJECT_FMT} == "ELF"
461 ${SHLIB_LD} -x
-shared
${SHLIB_SHFLAGS} -o
${.TARGET
} \
462 ${SHLIB_LDSTARTFILE} \
463 --whole-archive
${SOLIB} --no-whole-archive
${SHLIB_LDADD} \
466 ${SHLIB_LD} ${LD_x} ${LD_shared} \
467 -o
${.TARGET
} ${SOLIB} ${SHLIB_LDADD}
470 ${SHLIB_LD} -o
${.TARGET
} ${LD_shared} ${LD_solib} ${DLLIB} ${SHLIB_LDADD}
473 .if
!empty
(SHLIB_LINKS
)
474 rm -f
${SHLIB_LINKS}; ${SHLIB_LINKS
:O
:u
:@x@ln
-s
${.TARGET
} $x;@
}
477 LOBJS
+= ${LSRCS
:.c
=.ln
} ${SRCS
:M
*.c
:.c
=.ln
}
480 llib-l
${LIB}.ln
: ${LOBJS}
481 @echo building llib-l
${LIB}.ln
482 @
rm -f llib-l
${LIB}.ln
483 @
${LINT} -C
${LIB} ${LOBJS} ${LLIBS}
487 rm -f a.out
[Ee
]rrs mklog core
*.core
${CLEANFILES}
488 rm -f lib
${LIB}.a
${OBJS}
489 rm -f lib
${LIB}_p.a
${POBJS}
490 rm -f lib
${LIB}_pic.a lib
${LIB}.so.
*.
* ${SOBJS}
491 rm -f llib-l
${LIB}.ln
${LOBJS}
492 .if
!empty
(SHLIB_LINKS
)
496 clean: _SUBDIRUSE cleanlib
497 cleandir
: _SUBDIRUSE cleanlib
499 cleandir
: _SUBDIRUSE
clean
502 .if defined
(SRCS
) && (!defined
(MKDEP
) ||
${MKDEP} != autodep
)
504 @
(TMP
=/tmp
/_depend
$$$$; \
505 sed
-e
's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
511 .if
!target
(beforeinstall
)
516 LIB_INSTALL_OWN ?
= -o
${LIBOWN} -g
${LIBGRP}
521 .if
!target
(realinstall
)
522 realinstall
: libinstall
524 .if
!target
(libinstall
)
526 [ -d
${DESTDIR}/${LIBDIR} ] || \
527 ${INSTALL} -d
${LIB_INSTALL_OWN} -m
775 ${DESTDIR}${LIBDIR}
528 .if
${MK_ARCHIVE} != "no"
529 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m
600 lib
${LIB}.a \
531 ${RANLIB} ${DESTDIR}${LIBDIR}/lib
${LIB}.a
532 chmod
${LIBMODE} ${DESTDIR}${LIBDIR}/lib
${LIB}.a
534 .if
${MK_PROFILE} != "no"
535 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m
600 \
536 lib
${LIB}_p.a
${DESTDIR}${LIBDIR}
537 ${RANLIB} ${DESTDIR}${LIBDIR}/lib
${LIB}_p.a
538 chmod
${LIBMODE} ${DESTDIR}${LIBDIR}/lib
${LIB}_p.a
540 .if
${MK_PIC} != "no"
541 .if
${MK_PICLIB} != "no"
542 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m
600 \
543 lib
${LIB}_pic.a
${DESTDIR}${LIBDIR}
544 ${RANLIB} ${DESTDIR}${LIBDIR}/lib
${LIB}_pic.a
545 chmod
${LIBMODE} ${DESTDIR}${LIBDIR}/lib
${LIB}_pic.a
547 .if
!empty
(SHLIB_MAJOR
)
548 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m
${LIBMODE} \
549 lib
${LIB}.
${LD_so} ${DESTDIR}${LIBDIR}
550 .if
!empty
(SHLIB_LINKS
)
551 (cd
${DESTDIR}${LIBDIR} && { rm -f
${SHLIB_LINKS}; ${SHLIB_LINKS
:O
:u
:@x@ln
-s lib
${LIB}.
${LD_so} $x;@
} })
555 .if
${MK_LINT} != "no" && ${MK_LINKLIB} != "no" && !empty
(LOBJS
)
556 ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m
${LIBMODE} \
557 llib-l
${LIB}.ln
${DESTDIR}${LINTLIBDIR}
559 .if defined
(LINKS
) && !empty
(LINKS
)
560 @set
${LINKS}; ${_LINKS_SCRIPT}
564 install: maninstall _SUBDIRUSE
565 maninstall
: afterinstall
566 afterinstall
: realinstall
567 realinstall
: beforeinstall
570 .if
${MK_MAN} != "no"
574 .if
${MK_NLS} != "no"
584 # during building we usually need/want to install libs somewhere central
585 # note that we do NOT ch{own,grp} as that would likely fail at this point.
586 # otherwise it is the same as realinstall
587 # Note that we don't need this when using dpadd.mk
588 .libinstall
: ${_LIBS}
589 test -d
${DESTDIR}${LIBDIR} ||
${INSTALL} -d
-m775
${DESTDIR}${LIBDIR}
590 .for _lib in
${_LIBS
:M
*.a
}
591 ${INSTALL} ${COPY} -m
644 ${_lib} ${DESTDIR}${LIBDIR}
592 ${RANLIB} ${DESTDIR}${LIBDIR}/${_lib}
594 .for _lib in
${_LIBS
:M
*.
${LD_solink}*:O
:u
}
595 ${INSTALL} ${COPY} -m
${LIBMODE} ${_lib} ${DESTDIR}${LIBDIR}
596 .if
!empty
(SHLIB_LINKS
)
597 (cd
${DESTDIR}${LIBDIR} && { ${SHLIB_LINKS
:O
:u
:@x@ln
-sf
${_lib} $x;@
}; })