您的位置:首页 > 其它

autotools精简二(生成libxml2静态库)

2013-08-27 17:39 471 查看
下面是探讨精简的过程(若不精简,因为AC_PROG_LIBTOOL 会自动生成`--enable-shared'`--enable-static',也可生成静态库)

一、Makefile.am制作过程

1)从原始am文件提取要生成的目标和依赖关系,生成新的Makefile.am




 使用awk进行提取:awk ' {if((NR >= 18&& NR <=43)||(NR>=1137&&NR<=1140)||(NR==7))print $0}' Makefile.am.ori > Makefile.am
 生成的Makefile.am源码
 cat Makefile.am
 INCLUDES = -I$(top_builddir)/include -I@srcdir@/include @THREAD_CFLAGS@ @Z_CFLAGS@ 

lib_LTLIBRARIES = libxml2.la

libxml2_la_LIBADD = @THREAD_LIBS@ @Z_LIBS@ $(ICONV_LIBS) @M_LIBS@ @WIN32_EXTRA_LIBADD@

libxml2_la_LDFLAGS = @CYGWIN_EXTRA_LDFLAGS@ @WIN32_EXTRA_LDFLAGS@ -version-info @LIBXML_VERSION_INFO@ @MODULE_PLATFORM_LIBS@

if WITH_TRIO_SOURCES

libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c  \

                parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c  \

                valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c  \

                xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \

                catalog.c globals.c threads.c c14n.c xmlstring.c \

                xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \

                triostr.c trio.c xmlreader.c relaxng.c dict.c SAX2.c \

                xmlwriter.c legacy.c chvalid.c pattern.c xmlsave.c \

                xmlmodule.c schematron.c

else

libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c  \

                parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c  \

                valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c  \

                xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \

                catalog.c globals.c threads.c c14n.c xmlstring.c \

                xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \

                xmlreader.c relaxng.c dict.c SAX2.c \

                xmlwriter.c legacy.c chvalid.c pattern.c xmlsave.c \

                xmlmodule.c schematron.c

endif

cleanup:

        -@(find . -name .\#\* -exec rm {} \;)

        -@(find . -name \*.gcda -o *.gcno -exec rm {} \;)

        -@(find . -name \*.orig -o -name \*.rej -o -name \*.old -exec rm {} \;)
2)修改Makefile.am依赖关系,使之生成静态库,修改后的Makefile.am源码




 cat Makefile.am
INCLUDES = -I$(top_builddir)/include -I@srcdir@/include @THREAD_CFLAGS@ @Z_CFLAGS@ 

lib_LIBRARIES = libxml2.a

#libxml2_a_LIBADD = @THREAD_LIBS@ @Z_LIBS@ $(ICONV_LIBS) @M_LIBS@ @WIN32_EXTRA_LIBADD@

#libxml2_a_LDFLAGS = @CYGWIN_EXTRA_LDFLAGS@ @WIN32_EXTRA_LDFLAGS@ -version-info @LIBXML_VERSION_INFO@ @MODULE_PLATFORM_LIBS@

if WITH_TRIO_SOURCES

libxml2_a_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c  \

                parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c  \

                valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c  \

                xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \

                catalog.c globals.c threads.c c14n.c xmlstring.c \

                xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \

                triostr.c trio.c xmlreader.c relaxng.c dict.c SAX2.c \

                xmlwriter.c legacy.c chvalid.c pattern.c xmlsave.c \

                xmlmodule.c schematron.c

else

libxml2_a_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c  \

                parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c  \

                valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c  \

                xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \

                catalog.c globals.c threads.c c14n.c xmlstring.c \

                xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \

                xmlreader.c relaxng.c dict.c SAX2.c \

                xmlwriter.c legacy.c chvalid.c pattern.c xmlsave.c \

                xmlmodule.c schematron.c

endif

cleanup:

        -@(find . -name .\#\* -exec rm {} \;)

        -@(find . -name \*.gcda -o *.gcno -exec rm {} \;)

        -@(find . -name \*.orig -o -name \*.rej -o -name \*.old -exec rm {} \;)
二、修改configure.in+autogen.sh

1)去掉libtool的相关支持




autogen.sh中注释如下代码   #libtoolize --copy --force
configure.in中注释如下代码   
 #AC_LIBTOOL_WIN32_DLL
 #AM_PROG_LIBTOOL
2)去掉不需要生成的makefile及其他文件声明(configure.in),下面是diff的输出




-AC_OUTPUT(libxml2.spec:libxml.spec.in Makefile include/Makefile include/libxml/Makefile doc/Makefile doc/examples/Makefile doc/devhelp/Makefile example/Makefile python/Makefile python/tests/Makefile xstc/Makefile include/libxml/xmlversion.h
xml2-config libxml-2.0.pc libxml-2.0-uninstalled.pc python/setup.py)
+AC_OUTPUT(libxml2.spec:libxml.spec.in Makefile )
3) 添加AC_PROG_RANLIB(configure.in)



三、编译过程
1)设置环境变量




export ARCH=sh4
export CC=sh4-linux-gcc
export CXX=sh4-linux-g++
export RANLIB=sh4-linux-ranlib
export BUILD_ROOT=/opt/STM/STLinux-2.3/devkit/sh4/target
2)执行./autogen.sh --host=sh4-linux

生成makefile
3)make




 make
make  all-am
make[1]: Entering directory `/home/WebKit-r103151-avit/app/WebKit-r103151-avit/Source/ThirdParty
4000
/lib_src/LIBXML2.7.2'
rm -f libxml2.a
ar cru libxml2.a SAX.o entities.o encoding.o error.o parserInternals.o parser.o tree.o hash.o list.o xmlIO.o xmlmemory.o uri.o valid.o xlink.o HTMLparser.o HTMLtree.o debugXML.o xpath.o xpointer.o xinclude.o nanohttp.o nanoftp.o
DOCBparser.o catalog.o globals.o threads.o c14n.o xmlstring.o xmlregexp.o xmlschemas.o xmlschemastypes.o xmlunicode.o xmlreader.o relaxng.o dict.o SAX2.o xmlwriter.o legacy.o chvalid.o pattern.o xmlsave.o xmlmodule.o schematron.o 
sh4-linux-ranlib libxml2.a
make[1]: Leaving directory `/home/WebKit-r103151-avit/app/WebKit-r103151-avit/Source/ThirdParty/lib_src/LIBXML2.7.2'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息