📄 makefile.shared
字号:
## Helper makefile to link shared libraries in a portable way.# This is much simpler than libtool, and hopefully not too error-prone.## The following variables need to be set on the command line to build# properly# CC contains the current compiler. This one MUST be definedCC=ccCFLAGS=$(CFLAG)# LDFLAGS contains flags to be used when temporary object files (when building# shared libraries) are created, or when an application is linked.# SHARED_LDFLAGS contains flags to be used when the shared library is created.LDFLAGS=SHARED_LDFLAGS=# LIBNAME contains just the name of the library, without prefix ("lib"# on Unix, "cyg" for certain forms under Cygwin...) or suffix (.a, .so,# .dll, ...). This one MUST have a value when using this makefile to# build shared libraries.# For example, to build libfoo.so, you need to do the following:#LIBNAME=fooLIBNAME=# APPNAME contains just the name of the application, without suffix (""# on Unix, ".exe" on Windows, ...). This one MUST have a value when using# this makefile to build applications.# For example, to build foo, you need to do the following:#APPNAME=fooAPPNAME=# OBJECTS contains all the object files to link together into the application.# This must contain at least one object file.#OBJECTS=foo.oOBJECTS=# LIBEXTRAS contains extra modules to link together with the library.# For example, if a second library, say libbar.a needs to be linked into# libfoo.so, you need to do the following:#LIBEXTRAS=libbar.a# Note that this MUST be used when using the link_o targets, to hold the# names of all object files that go into the target library.LIBEXTRAS=# LIBVERSION contains the current version of the library.# For example, to build libfoo.so.1.2, you need to do the following:#LIBVERSION=1.2LIBVERSION=# LIBCOMPATVERSIONS contains the compatibility versions (a list) of# the library. They MUST be in decreasing order.# For example, if libfoo.so.1.2.1 is backward compatible with libfoo.so.1.2# and libfoo.so.1, you need to do the following:#LIBCOMPATVERSIONS=1.2 1# Note that on systems that use sonames, the last number will appear as# part of it.# It's also possible, for systems that support it (Tru64, for example),# to add extra compatibility info with more precision, by adding a second# list of versions, separated from the first with a semicolon, like this:#LIBCOMPATVERSIONS=1.2 1;1.2.0 1.1.2 1.1.1 1.1.0 1.0.0LIBCOMPATVERSIONS=# LIBDEPS contains all the flags necessary to cover all necessary# dependencies to other libraries.LIBDEPS=#------------------------------------------------------------------------------# The rest is private to this makefile.SET_X=:#SET_X=set -xtop: echo "Trying to use this makefile interactively? Don't."CALC_VERSIONS= \ SHLIB_COMPAT=; SHLIB_SOVER=; \ if [ -n "$(LIBVERSION)$(LIBCOMPATVERSIONS)" ]; then \ prev=""; \ for v in `echo "$(LIBVERSION) $(LIBCOMPATVERSIONS)" | cut -d';' -f1`; do \ SHLIB_SOVER_NODOT=$$v; \ SHLIB_SOVER=.$$v; \ if [ -n "$$prev" ]; then \ SHLIB_COMPAT="$$SHLIB_COMPAT .$$prev"; \ fi; \ prev=$$v; \ done; \ fiLINK_APP= \ ( $(SET_X); \ LIBDEPS="$${LIBDEPS:-$(LIBDEPS)}"; \ LDCMD="$${LDCMD:-$(CC)}"; LDFLAGS="$${LDFLAGS:-$(CFLAGS)}"; \ LIBPATH=`for x in $$LIBDEPS; do if echo $$x | grep '^ *-L' > /dev/null 2>&1; then echo $$x | sed -e 's/^ *-L//'; fi; done | uniq`; \ LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \ LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \ $${LDCMD} $${LDFLAGS} -o $${APPNAME:=$(APPNAME)} $(OBJECTS) $${LIBDEPS} )LINK_SO= \ ( $(SET_X); \ LIBDEPS="$${LIBDEPS:-$(LIBDEPS)}"; \ SHAREDCMD="$${SHAREDCMD:-$(CC)}"; \ SHAREDFLAGS="$${SHAREDFLAGS:-$(CFLAGS) $(SHARED_LDFLAGS)}"; \ nm -Pg $$SHOBJECTS | grep ' [BDT] ' | cut -f1 -d' ' > lib$(LIBNAME).exp; \ LIBPATH=`for x in $$LIBDEPS; do if echo $$x | grep '^ *-L' > /dev/null 2>&1; then echo $$x | sed -e 's/^ *-L//'; fi; done | uniq`; \ LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \ LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \ $${SHAREDCMD} $${SHAREDFLAGS} \ -o $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \ $$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS \ ) && $(SYMLINK_SO); \ ( $(SET_X); rm -f lib$(LIBNAME).exp )SYMLINK_SO= \ if [ -n "$$INHIBIT_SYMLINKS" ]; then :; else \ prev=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \ if [ -n "$$SHLIB_COMPAT" ]; then \ for x in $$SHLIB_COMPAT; do \ ( $(SET_X); rm -f $$SHLIB$$x$$SHLIB_SUFFIX; \ ln -s $$prev $$SHLIB$$x$$SHLIB_SUFFIX ); \ prev=$$SHLIB$$x$$SHLIB_SUFFIX; \ done; \ fi; \ if [ -n "$$SHLIB_SOVER" ]; then \ ( $(SET_X); rm -f $$SHLIB$$SHLIB_SUFFIX; \ ln -s $$prev $$SHLIB$$SHLIB_SUFFIX ); \ fi; \ fiLINK_SO_A= SHOBJECTS="lib$(LIBNAME).a $(LIBEXTRAS)"; $(LINK_SO)LINK_SO_O= SHOBJECTS="$(LIBEXTRAS)"; $(LINK_SO)LINK_SO_A_VIA_O= \ SHOBJECTS=lib$(LIBNAME).o; \ ALL=$$ALLSYMSFLAGS; ALLSYMSFLAGS=; NOALLSYMSFLAGS=; \ ( $(SET_X); \ ld $(LDFLAGS) -r -o lib$(LIBNAME).o $$ALL lib$(LIBNAME).a $(LIBEXTRAS) ); \ $(LINK_SO) && rm -f $(LIBNAME).oLINK_SO_A_UNPACKED= \ UNPACKDIR=link_tmp.$$$$; rm -rf $$UNPACKDIR; mkdir $$UNPACKDIR; \ (cd $$UNPACKDIR; ar x ../lib$(LIBNAME).a) && \ ([ -z "$(LIBEXTRAS)" ] || cp $(LIBEXTRAS) $$UNPACKDIR) && \ SHOBJECTS=$$UNPACKDIR/*.o; \ $(LINK_SO) && rm -rf $$UNPACKDIRDETECT_GNU_LD=(${CC} -Wl,-V /dev/null 2>&1 | grep '^GNU ld' )>/dev/nullDO_GNU_SO=$(CALC_VERSIONS); \ SHLIB=lib$(LIBNAME).so; \ SHLIB_SUFFIX=; \ ALLSYMSFLAGS='-Wl,--whole-archive'; \ NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"DO_GNU_APP=LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBRPATH)"#This is rather special. It's a special target with which one can link#applications without bothering with any features that have anything to#do with shared libraries, for example when linking against static#libraries. It's mostly here to avoid a lot of conditionals everywhere#else...link_app.: $(LINK_APP)link_o.gnu: @ $(DO_GNU_SO); $(LINK_SO_O)link_a.gnu: @ $(DO_GNU_SO); $(LINK_SO_A)link_app.gnu: @ $(DO_GNU_APP); $(LINK_APP)link_o.bsd: @if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \ $(CALC_VERSIONS); \ SHLIB=lib$(LIBNAME).so; \ SHLIB_SUFFIX=; \ LIBDEPS=" "; \ ALLSYMSFLAGS="-Wl,-Bforcearchive"; \ NOALLSYMSFLAGS=; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -nostdlib"; \ fi; $(LINK_SO_O)link_a.bsd: @if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \ $(CALC_VERSIONS); \ SHLIB=lib$(LIBNAME).so; \ SHLIB_SUFFIX=; \ LIBDEPS=" "; \ ALLSYMSFLAGS="-Wl,-Bforcearchive"; \ NOALLSYMSFLAGS=; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -nostdlib"; \ fi; $(LINK_SO_A)link_app.bsd: @if ${DETECT_GNU_LD}; then $(DO_GNU_APP); else \ LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBPATH)"; \ fi; $(LINK_APP)# For Darwin AKA Mac OS/X (dyld)link_o.darwin: @ $(CALC_VERSIONS); \ SHLIB=lib$(LIBNAME); \ SHLIB_SUFFIX=.dylib; \ ALLSYMSFLAGS='-all_load'; \ NOALLSYMSFLAGS=''; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS)"; \ if [ -n "$(LIBVERSION)" ]; then \ SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \ fi; \ if [ -n "$$SHLIB_SOVER_NODOT" ]; then \ SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \ fi; \ $(LINK_SO_O)link_a.darwin: @ $(CALC_VERSIONS); \ SHLIB=lib$(LIBNAME); \ SHLIB_SUFFIX=.dylib; \ ALLSYMSFLAGS='-all_load'; \ NOALLSYMSFLAGS=''; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS)"; \ if [ -n "$(LIBVERSION)" ]; then \ SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \ fi; \ if [ -n "$$SHLIB_SOVER_NODOT" ]; then \ SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \ fi; \ $(LINK_SO_A)link_app.darwin: # is there run-path on darwin? $(LINK_APP)link_o.cygwin: @ $(CALC_VERSIONS); \ INHIBIT_SYMLINKS=yes; \ SHLIB=cyg$(LIBNAME); \ expr $(PLATFORM) : 'mingw' > /dev/null && SHLIB=$(LIBNAME)eay32; \ SHLIB_SUFFIX=.dll; \ LIBVERSION="$(LIBVERSION)"; \ SHLIB_SOVER=${LIBVERSION:+"-$(LIBVERSION)"}; \ ALLSYMSFLAGS='-Wl,--whole-archive'; \ NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \ $(LINK_SO_O)link_a.cygwin: @ $(CALC_VERSIONS); \ INHIBIT_SYMLINKS=yes; \ SHLIB=cyg$(LIBNAME); \ expr $(PLATFORM) : 'mingw' > /dev/null && SHLIB=$(LIBNAME)eay32; \ SHLIB_SUFFIX=.dll; \ SHLIB_SOVER=-$(LIBVERSION); \ ALLSYMSFLAGS='-Wl,--whole-archive'; \ NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \ base=; [ $(LIBNAME) = "crypto" ] && base=-Wl,--image-base,0x63000000; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \ [ -f apps/$$SHLIB$$SHLIB_SUFFIX ] && rm apps/$$SHLIB$$SHLIB_SUFFIX; \ [ -f test/$$SHLIB$$SHLIB_SUFFIX ] && rm test/$$SHLIB$$SHLIB_SUFFIX; \ $(LINK_SO_A) || exit 1; \ cp -p $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX apps/; \ cp -p $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX test/link_app.cygwin: $(LINK_APP)link_o.alpha-osf1: @ if ${DETECT_GNU_LD}; then \ $(DO_GNU_SO); \ else \ SHLIB=lib$(LIBNAME).so; \ SHLIB_SUFFIX=; \ SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \ if [ -n "$$SHLIB_HIST" ]; then \ SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \ else \ SHLIB_HIST="$(LIBVERSION)"; \ fi; \ SHLIB_SOVER=; \ ALLSYMSFLAGS='-all'; \ NOALLSYMSFLAGS='-none'; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared"; \ if [ -n "$$SHLIB_HIST" ]; then \ SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \ fi; \ fi; \ $(LINK_SO_O)link_a.alpha-osf1: @ if ${DETECT_GNU_LD}; then \ $(DO_GNU_SO); \ else \ SHLIB=lib$(LIBNAME).so; \ SHLIB_SUFFIX=; \ SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \ if [ -n "$$SHLIB_HIST" ]; then \ SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \ else \ SHLIB_HIST="$(LIBVERSION)"; \ fi; \ SHLIB_SOVER=; \ ALLSYMSFLAGS='-all'; \ NOALLSYMSFLAGS='-none'; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared"; \ if [ -n "$$SHLIB_HIST" ]; then \ SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \ fi; \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -