C语言用GNU源码编译建构系统工具(GNU BUILD SYSTEM)编译创建动态库
C语言用GNU源码编译建构系统工具(GNU BUILD SYSTEM)编译创建动态库
- 首先看一下这篇博文:C语言数据结构之顺序结构(Sequence)
- 此次目的是将sequence.c改造一下,创建为一个动态链接库同时打包一个可发布的源码包,包括源码、头文件、测试文件!
创建工作目录
- 工作目录libmg(mg即muggles,一定要有一个自己的名称空间namespace)
工作目录结构如下所示:
libmg
\- Makefile.am
\- src
\- Makefile.am
\- sequence.c
\- libmg.h
\- mg
\- Makefile.am
\- types.h
\- sequence.h
\- tests
\- Makefile.am
\- test_seq.c
每个子目录下都编辑一个Makefile.am文件!!!
- 主目录libmg/Makefile.am内容如下:
SUBDIRS = src tests
- 源码目录libmg/src/Makefile.am内容如下:
SUBDIRS = mg
lib_LTLIBRARIES = libmg.la
libmg_la_SOURCES = libmg.h \
mg/types.h \
sequence.c mg/sequence.h
libmg_la_LDFLAGS = -release 1.0
include_HEADERS = libmg.h
nobase_include_HEADERS = \
mg/types.h \
mg/sequence.h
- 源码目录下子目录mg的libmg/src/mg/Makefile.am内容如下:
EXTRA_DIST = types.h sequence.h
- 测试目录tests/Makefile.am内容如下:
AM_CFLAGS = -I ../src -I .
AM_LDFLAGS = -L../src -lmg
check_PROGRAMS = test_seq
test_seq_SOURCES = test_seq.c
TESTS = $(check_PROGRAMS)
将源码sequence.c改造一下
- 主头文件libmg/src/libmg.h代码如下:
/* filename : libmg.h */
#ifndef __LIBMG_HEAD
#define __LIBMG_HEAD
#include "mg/types.h"
#include "mg/sequence.h"
#endif/*__LIBMG_HEAD*/
- 主源码文件libmg/src/sequence.c代码如下:
/* filename: sequence.c */
#include <stdio.h>
#include <stdlib.h>
#include "mg/sequence.h"
/* create a new sequence */
Sequence *
mg_sequence_new (int pagesize)
{
Sequence *seq = (Sequence*) malloc (sizeof(Sequence));
seq->pagesize = pagesize;
seq->pages = 1;
seq->size = 0;
seq->elts = (void**) malloc (seq->pages * seq->pagesize * sizeof(void*));
for (int i = 0; i < seq->pagesize; i++)
seq->elts[i] = NULL;
return seq;
}
/* free every elements */
void
mg_sequence_free_elements (Sequence *seq)
{
for (int i = 0; i < seq->size; i++)
free (seq->elts[i]);
}
/* free the sequence */
void
mg_sequence_free (Sequence *seq)
{
free (seq->elts);
free (seq);
}
/* sequence is empty return 1 else return 0 */
int
mg_sequence_is_empty (Sequence *seq)
{
if (seq->size == 0) return 1;
return 0;
}
/* sequence is full return 1 else return 0 */
/*int
mg_sequence_is_full (Sequence *seq)
{
if (seq->size == seq->maxsize) return 1;
return 0;
}
*/
/* get sequence size */
int
mg_sequence_size (Sequence *seq)
{
return seq->size;
}
/* append a val into sequence */
void
mg_sequence_append (Sequence *seq, void *val)
{
seq->elts[seq->size] = val;
seq->size = seq->size + 1;
if (seq->size == seq->pages * seq->pagesize)
{
seq->pages = seq->pages + 1;
seq->elts = realloc (seq->elts, seq->pages * seq->pagesize * sizeof(void*));
}
}
/* insert a val at idx into sequence */
void
mg_sequence_insert (Sequence *seq, int idx, void *val)
{
for (int i = seq->size - 1; i >= idx; i--)
seq->elts[i+1] = seq->elts[i];
seq->elts[idx] = val;
seq->size = seq->size + 1;
}
/* set a val at idx of sequence */
void
mg_sequence_set (Sequence *seq, int idx, void *val)
{
seq->elts[idx] = val;
}
/* remove a val at idx of sequence */
void
mg_sequence_remove (Sequence *seq, int idx)
{
for (int i = idx; i <= seq->size; i++)
seq->elts[i] = seq->elts[i+1];
seq->size = seq->size - 1;
}
/* get a val at idx of sequence */
void *
mg_sequence_get (Sequence *seq, int idx)
{
return seq->elts[idx];
}
/* reverse the sequence */
void
mg_sequence_reverse (Sequence *seq)
{
for (int i = 0, j = seq->size - 1; i < seq->size / 2; i++, j--)
{
void *tmp = seq->elts[i];
seq->elts[i] = seq->elts[j];
seq->elts[j] = tmp;
}
}
/* call mgfunc on each element */
void
mg_sequence_foreach (Sequence *seq, MgFunc mgfunc)
{
for (int i = 0; i < seq->size; i++)
mgfunc (seq->elts[i]);
}
/* ---------------------------------------- */
- 自定义数据类型头文件libmg/src/mg/types.h代码如下:
/* filename : types.h */
#ifndef __TYPES_HEAD
#define __TYPES_HEAD
/* define base int datatype */
typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned short ushort;
/* define function pointer with void* arg and without return */
typedef void (*MgFunc) (void *val);
#endif/*__TYPES_HEAD*/
- 自定义sequence头文件libmg/src/mg/sequence.h代码如下:
/* filename : sequence.h */
#ifndef __SEQUENCE_HEAD
#define __SEQUENCE_HEAD
#include "types.h"
/* define Sequence datatype */
typedef struct _Sequence Sequence;
struct _Sequence {
int pagesize; //page size
int pages; //pages
int size; //size
void **elts; //elements
};
/* create a new sequence */
Sequence*
mg_sequence_new (int pagesize);
/* free every elements */
void
mg_sequence_free_elements (Sequence *seq);
/* free the sequence */
void
mg_sequence_free (Sequence *seq);
/* sequence is empty return 1 else return 0 */
int
mg_sequence_is_empty (Sequence *seq);
/* get sequence size */
int
mg_sequence_size (Sequence *seq);
/* append a val into sequence */
void
mg_sequence_append (Sequence *seq, void *val);
/* insert a val at idx into sequence */
void
mg_sequence_insert (Sequence *seq, int idx, void *val);
/* set a val at idx of sequence */
void
mg_sequence_set (Sequence *seq, int idx, void *val);
/* remove a val at idx of sequence */
void
mg_sequence_remove (Sequence *seq, int idx);
/* get a val at idx of sequence */
void *
mg_sequence_get (Sequence *seq, int idx);
/* reverse the sequence */
void
mg_sequence_reverse (Sequence *seq);
/* call mgfunc on each element */
void
mg_sequence_foreach (Sequence *seq, MgFunc mgfunc);
#endif/*__SEQUENCE_HEAD*/
- 源码测试文件libmg/tests/test_seq.c代码如下:
/* filename : test_seq.c */
#include <stdio.h>
#include <stdlib.h>
#include "libmg.h"
/* define function for MgFunc to output long int */
void
out_longint (void *val)
{
printf ("%ld ", (long)(val));
}
/* test append insert foreach reverse remove */
void
test_sequence_longint (void)
{
Sequence *seq = mg_sequence_new (8);
for (long i = 0; i < 10; i++)
mg_sequence_append (seq, (void*)(i + 1000));
printf ("Test sequence new, append, foreach method:\n");
mg_sequence_foreach (seq, out_longint);
printf ("\nTest sequence insert method:\n");
mg_sequence_insert (seq, 5, (void*)(8888));
mg_sequence_foreach (seq, out_longint);
printf ("\nTest sequence reverse method:\n");
mg_sequence_reverse (seq);
mg_sequence_foreach (seq, out_longint);
printf ("\nTest sequence remove method:\n");
mg_sequence_remove (seq, 5);
mg_sequence_foreach (seq, out_longint);
printf ("\nSequence page size : %d\n", seq->pagesize);
printf ("Sequence size : %d\n", seq->size);
printf ("Sequence page : %d\n", seq->pages);
printf ("Sequence val at index 9 is %ld\n", (long)mg_sequence_get(seq, 9));
mg_sequence_free (seq);
}
/* define function for MgFunc to output char* */
void
out_string (void *val)
{
printf ("%s ", (char*)val);
}
/* test sequence new free append foreach */
void
test_sequence_string (void)
{
char *buff[6] = {"Not", "Only", "Test", "Here", "Another", "Behind"};
Sequence *seq = mg_sequence_new (8);
for (int i = 0; i < 6; i++)
mg_sequence_append (seq, buff[i]);
mg_sequence_foreach(seq, out_string);
printf ("\n");
mg_sequence_free (seq);
}
/* test sequence free elements */
void
test_sequence_string_malloc (void)
{
Sequence *seq = mg_sequence_new (8);
for (int i = 1000; i < 1010; i++)
{
char *buf = (char*) malloc (16);
sprintf (buf, "demo-%d", i);
mg_sequence_append (seq, buf);
}
mg_sequence_foreach(seq, out_string);
printf ("\n");
mg_sequence_free_elements (seq);
mg_sequence_free (seq);
}
/**/
int
main (int argc, char *argv[])
{
printf ("------------------------------\n");
test_sequence_longint ();
printf ("------------------------------\n");
test_sequence_string ();
printf ("------------------------------\n");
test_sequence_string_malloc ();
printf ("------------------------------\n");
return 0;
}
/* -----(:/.^.\:)-----*/
- 注意libmg.h头文件,用到sequence相关函数的话,包含libmg.h即可!!!
运行autoscan命令,生成配置文件
- 运行 autoscan
- 更改文件名 mv configure.scan configure.ac
编辑配置文件configure.ac,修改以下四处
- 修改包名字、版本号、报错邮件地址 AC_INIT([libmg], [0.1], [gwsong52@qq.com])
- 添加AUTOMAKE宏 AM_INIT_AUTOMAKE([ -Wall -Werror foreign ])
- 添加检查ar工具宏 AM_PROG_AR
- 添加检查LIBTOOL宏 LT_INIT
修改后内容如下:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([libmg], [0.1], [gwsong52@qq.com])
AM_INIT_AUTOMAKE([ -Wall -Werror foreign ])
AC_CONFIG_SRCDIR([tests/test_seq.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AM_PROG_AR
AC_PROG_CC
#
LT_INIT
# Checks for libraries.
# FIXME: Replace `main' with a function in `-lmg':
# AC_CHECK_LIB([mg], [main])
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CONFIG_FILES([Makefile
src/Makefile
src/mg/Makefile
tests/Makefile])
AC_OUTPUT
运行命令:autoreconf --install 生成 configure 脚本
如下所示:
songvm@ubuntu:~/works/xdn/aoo/libmg$ ls
autoscan.log configure.ac Makefile.am src tests
songvm@ubuntu:~/works/xdn/aoo/libmg$ autoreconf --install
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac,
libtoolize: and rerunning libtoolize and aclocal.
libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
configure.ac:11: installing './ar-lib'
configure.ac:11: installing './compile'
configure.ac:15: installing './config.guess'
configure.ac:15: installing './config.sub'
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
src/Makefile.am: installing './depcomp'
parallel-tests: installing './test-driver'
songvm@ubuntu:~/works/xdn/aoo/libmg$
运行 configure 脚本,生成 Makefile
- 运行命令:./configure --prefix=/tmp/boo ,注意加参数!!!
如下所示:
songvm@ubuntu:~/works/xdn/aoo/libmg$ ls
aclocal.m4 compile configure ltmain.sh src
ar-lib config.guess configure.ac Makefile.am test-driver
autom4te.cache config.h.in depcomp Makefile.in tests
autoscan.log config.sub install-sh missing
songvm@ubuntu:~/works/xdn/aoo/libmg$ ./configure --prefix=/tmp/boo
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for ar... ar
checking the archiver (ar) interface... ar
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1635000
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for stdlib.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible realloc... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating src/mg/Makefile
config.status: creating tests/Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
songvm@ubuntu:~/works/xdn/aoo/libmg$
编译 make
- 编译命令make默认参数为all
如下所示:
songvm@ubuntu:~/works/xdn/aoo/libmg$ make
make all-recursive
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg”
Making all in src
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src”
Making all in mg
make[3]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[3]: 对“all”无需做任何事。
make[3]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[3]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src”
/bin/bash ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT sequence.lo -MD -MP -MF .deps/sequence.Tpo -c -o sequence.lo sequence.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT sequence.lo -MD -MP -MF .deps/sequence.Tpo -c sequence.c -fPIC -DPIC -o .libs/sequence.o
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT sequence.lo -MD -MP -MF .deps/sequence.Tpo -c sequence.c -o sequence.o >/dev/null 2>&1
mv -f .deps/sequence.Tpo .deps/sequence.Plo
/bin/bash ../libtool --tag=CC --mode=link gcc -g -O2 -release 1.0 -o libmg.la -rpath /tmp/boo/lib sequence.lo
libtool: link: gcc -shared -fPIC -DPIC .libs/sequence.o -g -O2 -Wl,-soname -Wl,libmg-1.0.so -o .libs/libmg-1.0.so
libtool: link: (cd ".libs" && rm -f "libmg.so" && ln -s "libmg-1.0.so" "libmg.so")
libtool: link: ar cru .libs/libmg.a sequence.o
ar: `u' modifier ignored since `D' is the default (see `U')
libtool: link: ranlib .libs/libmg.a
libtool: link: ( cd ".libs" && rm -f "libmg.la" && ln -s "../libmg.la" "libmg.la" )
make[3]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src”
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src”
Making all in tests
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[2]: 对“all”无需做任何事。
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg”
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg”
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg”
songvm@ubuntu:~/works/xdn/aoo/libmg$
编译测试 make check
- make check 编译测试目录中的源码并运行,运行输出结果保存到.log文件中!
如下所示:
songvm@ubuntu:~/works/xdn/aoo/libmg$ make check
Making check in src
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src”
Making check in mg
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[2]: 对“check”无需做任何事。
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src”
make[2]: 对“check-am”无需做任何事。
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src”
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src”
Making check in tests
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg/tests”
make test_seq
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/tests”
gcc -DHAVE_CONFIG_H -I. -I.. -I ../src -I . -g -O2 -MT test_seq.o -MD -MP -MF .deps/test_seq.Tpo -c -o test_seq.o test_seq.c
mv -f .deps/test_seq.Tpo .deps/test_seq.Po
/bin/bash ../libtool --tag=CC --mode=link gcc -I ../src -I . -g -O2 -L../src -lmg -o test_seq test_seq.o
libtool: link: gcc -I ../src -I . -g -O2 -o .libs/test_seq test_seq.o -L../src /home/songvm/works/xdn/aoo/libmg/src/.libs/libmg.so -Wl,-rpath -Wl,/tmp/boo/lib
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/tests”
make check-TESTS
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[3]: 进入目录“/home/songvm/works/xdn/aoo/libmg/tests”
PASS: test_seq
============================================================================
Testsuite summary for libmg 0.1
============================================================================
# TOTAL: 1
# PASS: 1
# SKIP: 0
# XFAIL: 0
# FAIL: 0
# XPASS: 0
# ERROR: 0
============================================================================
make[3]: 离开目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg”
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg”
songvm@ubuntu:~/works/xdn/aoo/libmg$
- 输出结果文件libmg/tests/test_seq.log内容如下:
------------------------------
Test sequence new, append, foreach method:
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
Test sequence insert method:
1000 1001 1002 1003 1004 8888 1005 1006 1007 1008 1009
Test sequence reverse method:
1009 1008 1007 1006 1005 8888 1004 1003 1002 1001 1000
Test sequence remove method:
1009 1008 1007 1006 1005 1004 1003 1002 1001 1000
Sequence page size : 8
Sequence size : 10
Sequence page : 2
Sequence val at index 9 is 1000
------------------------------
Not Only Test Here Another Behind
------------------------------
demo-1000 demo-1001 demo-1002 demo-1003 demo-1004 demo-1005 demo-1006 demo-1007 demo-1008 demo-1009
------------------------------
PASS test_seq (exit status: 0)
打包源码 make dist
- make dist 生成源码包 libmg-0.1.tar.gz
如下所示:
songvm@ubuntu:~/works/xdn/aoo/libmg$ make dist
make dist-gzip am__post_remove_distdir='@:'
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg”
if test -d "libmg-0.1"; then find "libmg-0.1" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "libmg-0.1" || { sleep 5 && rm -rf "libmg-0.1"; }; else :; fi
test -d "libmg-0.1" || mkdir "libmg-0.1"
(cd src && make top_distdir=../libmg-0.1 distdir=../libmg-0.1/src \
am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src”
(cd mg && make top_distdir=../../libmg-0.1 distdir=../../libmg-0.1/src/mg \
am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)
make[3]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[3]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src”
(cd tests && make top_distdir=../libmg-0.1 distdir=../libmg-0.1/tests \
am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/tests”
test -n "" \
|| find "libmg-0.1" -type d ! -perm -755 \
-exec chmod u+rwx,go+rx {} \; -o \
! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
! -type d ! -perm -400 -exec chmod a+r {} \; -o \
! -type d ! -perm -444 -exec /bin/bash /home/songvm/works/xdn/aoo/libmg/install-sh -c -m a+r {} {} \; \
|| chmod -R a+r "libmg-0.1"
tardir=libmg-0.1 && ${TAR-tar} chof - "$tardir" | eval GZIP= gzip --best -c >libmg-0.1.tar.gz
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg”
if test -d "libmg-0.1"; then find "libmg-0.1" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "libmg-0.1" || { sleep 5 && rm -rf "libmg-0.1"; }; else :; fi
songvm@ubuntu:~/works/xdn/aoo/libmg$ ls
aclocal.m4 config.h configure.ac Makefile test-driver
ar-lib config.h.in depcomp Makefile.am tests
autom4te.cache config.log install-sh Makefile.in
autoscan.log config.status libmg-0.1.tar.gz missing
compile config.sub libtool src
config.guess configure ltmain.sh stamp-h1
songvm@ubuntu:~/works/xdn/aoo/libmg$
安装和缷载 make install / make uninstall
- 安装 make install
如下所示:
songvm@ubuntu:~/works/xdn/aoo/libmg$ make install
Making install in src
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src”
Making install in mg
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[3]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[3]: 对“install-exec-am”无需做任何事。
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src”
make[3]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src”
/bin/mkdir -p '/tmp/boo/lib'
/bin/bash ../libtool --mode=install /usr/bin/install -c libmg.la '/tmp/boo/lib'
libtool: install: /usr/bin/install -c .libs/libmg-1.0.so /tmp/boo/lib/libmg-1.0.so
libtool: install: (cd /tmp/boo/lib && { ln -s -f libmg-1.0.so libmg.so || { rm -f libmg.so && ln -s libmg-1.0.so libmg.so; }; })
libtool: install: /usr/bin/install -c .libs/libmg.lai /tmp/boo/lib/libmg.la
libtool: install: /usr/bin/install -c .libs/libmg.a /tmp/boo/lib/libmg.a
libtool: install: chmod 644 /tmp/boo/lib/libmg.a
libtool: install: ranlib /tmp/boo/lib/libmg.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/sbin" ldconfig -n /tmp/boo/lib
----------------------------------------------------------------------
Libraries have been installed in:
/tmp/boo/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/bin/mkdir -p '/tmp/boo/include'
/usr/bin/install -c -m 644 libmg.h '/tmp/boo/include'
/bin/mkdir -p '/tmp/boo/include'
/bin/mkdir -p '/tmp/boo/include/mg'
/usr/bin/install -c -m 644 mg/types.h mg/sequence.h '/tmp/boo/include/mg'
make[3]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src”
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src”
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src”
Making install in tests
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg”
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg”
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg”
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg”
songvm@ubuntu:~/works/xdn/aoo/libmg$
- 检查一下安装的头文件和动态库,是否如预期安装到相对应的目录中去了!!!
如下所示:
songvm@ubuntu:~/works/xdn/aoo/libmg$ ls /tmp/boo/
include lib
songvm@ubuntu:~/works/xdn/aoo/libmg$ ls /tmp/boo/include/
libmg.h mg
songvm@ubuntu:~/works/xdn/aoo/libmg$ ls /tmp/boo/include/mg
sequence.h types.h
songvm@ubuntu:~/works/xdn/aoo/libmg$ ls /tmp/boo/lib
libmg-1.0.so libmg.a libmg.la libmg.so
songvm@ubuntu:~/works/xdn/aoo/libmg$ ll /tmp/boo/lib
总用量 44
drwxrwxr-x 2 songvm songvm 4096 10月 23 13:48 ./
drwxrwxr-x 4 songvm songvm 4096 10月 23 13:48 ../
-rwxr-xr-x 1 songvm songvm 14320 10月 23 13:48 libmg-1.0.so*
-rw-r--r-- 1 songvm songvm 13182 10月 23 13:48 libmg.a
-rwxr-xr-x 1 songvm songvm 917 10月 23 13:48 libmg.la*
lrwxrwxrwx 1 songvm songvm 12 10月 23 13:48 libmg.so -> libmg-1.0.so*
songvm@ubuntu:~/works/xdn/aoo/libmg$
- 缷载 make uninstall
如下所示:
songvm@ubuntu:~/works/xdn/aoo/libmg$ make uninstall
Making uninstall in src
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src”
Making uninstall in mg
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[2]: 对“uninstall”无需做任何事。
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src/mg”
make[2]: 进入目录“/home/songvm/works/xdn/aoo/libmg/src”
( cd '/tmp/boo/include' && rm -f libmg.h )
/bin/bash ../libtool --mode=uninstall rm -f '/tmp/boo/lib/libmg.la'
libtool: uninstall: rm -f /tmp/boo/lib/libmg.la /tmp/boo/lib/libmg-1.0.so /tmp/boo/lib/libmg-1.0.so /tmp/boo/lib/libmg.so /tmp/boo/lib/libmg.a
( cd '/tmp/boo/include' && rm -f mg/types.h mg/sequence.h )
make[2]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src”
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg/src”
Making uninstall in tests
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[1]: 对“uninstall”无需做任何事。
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg/tests”
make[1]: 进入目录“/home/songvm/works/xdn/aoo/libmg”
make[1]: 对“uninstall-am”无需做任何事。
make[1]: 离开目录“/home/songvm/works/xdn/aoo/libmg”
songvm@ubuntu:~/works/xdn/aoo/libmg$
关于Makefile.am文件的更多语法,多读一下AUTOCONF、AUTOMAKE、LIBTOOL的说明文档吧!
下一步研究稍复杂的数据结构!!!