Date: Thu, 17 Nov 2011 17:24:37 +0100 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no> To: arch@freebsd.org Subject: Different CFLAGS for shared and static libraries Message-ID: <868vnepvi2.fsf@ds4.des.no>
next in thread | raw e-mail | index | archive | help
--=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable The attached patch adds support for using different CFLAGS for shared and static libraries. Specifically, it adds SHARED_{C,CXX}FLAGS variables which are added to the cc / cxx command line when building shared libraries, and STATIC_{C,CXX}FLAGS which are used when building static libraries. The rationale is that certain libraries (libpam, possibly also libnss) contain code which is specific to either shared or static libraries. It is possible (with some effort) to detect this by inspecting certain preprocessor macros, but not in a reliable or portable manner, whether across platforms or compilers. For instance, IIRC, MIPS code is always compiled with -DPIC. The downside is that the .c.o rule is no longer implicit. Using this patch, I was able to greatly simplify the libpam build. It is no longer a prebuild lib and no longer needs to be built twice. This also means that certain other libraries - libssh, for one - can move out of _prebuild_libs. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=static_cflags.diff Index: share/mk/bsd.lib.mk =================================================================== --- share/mk/bsd.lib.mk (revision 227616) +++ share/mk/bsd.lib.mk (working copy) @@ -67,23 +67,29 @@ PO_FLAG=-pg +.c.o: + ${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} + .c.po: - ${CC} ${PO_FLAG} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET} @[ -z "${CTFCONVERT}" -o -n "${NO_CTF}" ] || \ (${ECHO} ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} && \ ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}) .c.So: - ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} @[ -z "${CTFCONVERT}" -o -n "${NO_CTF}" ] || \ (${ECHO} ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} && \ ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}) +.cc.o: + ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} + .cc.po .C.po .cpp.po .cxx.po: - ${CXX} ${PO_FLAG} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} .cc.So .C.So .cpp.So .cxx.So: - ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} .f.po: ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} --=-=-=--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?868vnepvi2.fsf>