1. preparation:
Autoscan aclocal autoheader automake Autoconf make and other tools are required.
2. Compile the test program:
Create directory: mkdir include SRC
Program writing: Include/Str. h
{
Function anonymous ()
{
Copycode ($ ('code0 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code0 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
# Include <stdio. h>
Int STR (char * string );
Program: src/Str. c
{
Function anonymous ()
{
Copycode ($ ('code1 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code1 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
# Include "str. H"
// Print string
Int STR (char * string ){
Printf ("/n ---- print string ----/n/" % S/"/N", string );
Return 0;
}
// Interface of this program
Int main (INT argc, char ** argv ){
Char str_read [1024];
Printf ("Please input something end by [enter]/n ");
Scanf ("% s", str_read );
Return STR (str_read );
}
3. Generate Configure. AC
Configure. AC is the input file of automake, so it must be converted into this file.
Run the following command:
{
Function anonymous ()
{
Copycode ($ ('code2 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code2 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
[Root @ localhost STR] # ls
Include SRC
[Root @ localhost STR] # autoscan
Autom4te: Configure. AC: no such file or directory
Autoscan:/usr/bin/autom4te failed with exit status: 1
[Root @ localhost STR] # ls
Autoscan. Log Configure. Scan include SRC
[Root @ localhost STR] # cp Configure. Scan Configure. AC
Modify Configure. AC
{
Function anonymous ()
{
Copycode ($ ('code3 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code3 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
#-*-Autoconf -*-
# Process this file with Autoconf to produce a configure script.
Ac_prereq (2.59)
Ac_init (full-package-name, version, bug-Report-address)
Ac_config_srcdir ([INCLUDE/Str. H])
Ac_config_header ([config. H])
# Checks for programs.
Ac_prog_cc
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
Ac_output
Modify
{
Function anonymous ()
{
Copycode ($ ('code4 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code4 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
Ac_init (full-package-name, version, bug-Report-address)
Is
Code: ac_init (STR, 0.0.1, [bug@sounos.org])
Full-package-name indicates the program name, version indicates the current version, and bug-Report-Address indicates the bug report address.
Add am_init_automake
Add ac_config_files ([makefile])
Code: #-*-Autoconf -*-
# Process this file with Autoconf to produce a configure script.
Ac_prereq (2.59)
# Ac_init (full-package-name, version, bug-Report-address)
Ac_init (STR, 0.0.1, [bug@sounos.org])
Am_init_automake
Ac_config_srcdir ([INCLUDE/Str. H])
Ac_config_header ([config. H])
# Checks for programs.
Ac_prog_cc
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
Ac_config_files ([makefile])
Ac_output
4. Execute aclocal
Code: [root @ localhost STR] # aclocal
/Usr/share/aclocal/libfame. M4: 6: Warning: underquoted definition of am_path_libfame
Run info' (automake) extending aclocal'
Or see http://sources.redhat.com/automake/automake.html#Extending-aclocal
5. Create makefile. AM
Code: [root @ localhost STR] # Cat makefile. AM
# Makefile. AM
Bin_programs = Str
Str_sources = include/Str. h src/Str. c
Str_cppflags =-I include/
6. autoheader
{
Function anonymous ()
{
Copycode ($ ('code9 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code9 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
[Root @ localhost STR] # autoheader
7. automake files are required:
{
Function anonymous ()
{
Copycode ($ ('code10 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code10 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
* Install-SH
* Missing
* Install
* News
* Readme
* Authors
* Changelog
* Copying
* Depcomp
Where
{
Function anonymous ()
{
Copycode ($ ('code11 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code11 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
* Install-SH
* Missing
* Install
* Copying
* Depcomp
You can use the automake-A option to automatically generate the file.
{
Function anonymous ()
{
Copycode ($ ('code12 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code12 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
[Root @ localhost STR] # Touch news readme authors changelog
8. Execute automake
{
Function anonymous ()
{
Copycode ($ ('code13 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code13 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
[Root @ localhost STR] # automake-
Configure. AC: Installing './install-Sh'
Configure. AC: Installing './missing'
Makefile. AM: Installing './install'
Makefile. AM: Installing './copying'
Makefile. AM: Installing './compile'
Makefile. AM: Installing './depcomp'
9. Autoconf
{
Function anonymous ()
{
Copycode ($ ('code14 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code14 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
[Root @ localhost STR] # Autoconf
[Root @ localhost STR] # ls
Aclocal. M4 autoscan. Log config. H. In Configure. Scan include makefile. Am news
Authors changelog configure copying install makefile. In readme
Autom4te. cache compile Configure. AC depcomp install-SH missing SRC
10. perform the test:
Execute./configure
{
Function anonymous ()
{
Copycode ($ ('code15 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code15 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
[Root @ localhost STR] #./configure -- prefix =/u
Checking for a BSD-compatible install.../usr/bin/install-C
Checking whether build environment is sane... yes
Checking for gawk... gawk
Checking whether make sets $ (make)... yes
Checking for GCC... gcc
Checking for C compiler default output file name... A. Out
Checking whether the C compiler works... yes
Checking whether we are cross compiling... no
Checking for Suffix of executables...
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 ansi c... None needed
Checking for style of include used by make... GNU
Checking dependency style of GCC... gcc3
Configure: Creating./config. Status
Config. Status: Creating makefile
Config. Status: Creating config. h
Config. Status: config. H is unchanged
Config. Status: executing depfiles commands
Execute make
{
Function anonymous ()
{
Copycode ($ ('code16 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code16 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
[Root @ localhost STR] # Make
Make all-AM
Make [1]: Entering directory '/data/devel/C/str'
If gcc-dhave_config_h-I. -I. -I. -I include/-g-O2-MT str-str.o-MD-MP-MF ". deps/str-str.Tpo "-c-o str-str.o 'test-F' src/Str. c' | echo '. /''src/Str. C ;/
Then MV-F ". deps/str-str.Tpo" ". deps/str-str.Po"; else Rm-F ". deps/str-str.Tpo"; Exit 1; FI
Gcc-g-O2-o str str-str.o
Make [1]: Leaving directory '/data/devel/C/str'
Run make install
{
Function anonymous ()
{
Copycode ($ ('code17 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code17 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
[Root @ localhost STR] # make install
Make [1]: Entering directory '/data/devel/C/str'
Test-z "/u/bin" | mkdir-p -- "/u/bin"
/Usr/bin/install-C 'str''/u/bin/str'
Make [1]: Nothing to be done for 'Install-data-am '.
Make [1]: Leaving directory '/data/devel/C/str'
11. Test procedure:
{
Function anonymous ()
{
Copycode ($ ('code18 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code18 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
[Root @ localhost STR] #/u/bin/Str
Please input something end by [enter]
Abcksdhfklsdklfdjlkfd
---- Print string ----
"Abcksdhfklsdklfdjlkfd"
Conclusion: This is just a small example. If you want to use it well, you need to continue to hone your skills .... Haha.
-----
Add test package:
{
Function anonymous ()
{
Copycode ($ ('code19 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code19 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
[Root @ localhost STR] # Make dist-Gzip
{Test! -D str-0.0.1 | {find str-0.0.1-type D! -Perm-200-exec chmod U + W {}'; '& Rm-fr str-0.0.1 ;};}
Mkdir str-0.0.1
Find str-0.0.1-type D! -Perm-777-exec chmod A + rwx {}/;-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/sh/data/devel/C/str/install-sh-C-m a + R {}{}/;/
| Chmod-r a + R str-0.0.1
Tardir = str-0.0.1 & amp;/bin/sh/data/devel/C/str/missing -- run tar chof-"$ tardir" | gzip = -- best gzip-C> str-0.0.1.tar.gz
{Test! -D str-0.0.1 | {find str-0.0.1-type D! -Perm-200-exec chmod U + W {}'; '& Rm-fr str-0.0.1 ;};}
Add a package that supports sub-directories, static libraries, and custom configure options
Supports subdirectory makefile. Am option subdir =
{
Function anonymous ()
{
Copycode ($ ('code20 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code20 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
# Automake Interface
Subdirs = SRC
Supports static library makefile. AM
Extra_dist is used to add files except the source code to the DIST package.
{
Function anonymous ()
{
Copycode ($ ('code21 '));
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # "> {
Function anonymous ()
{
Toggle_collapse ('code21 ');
}
} "Href =" http://bbs.chinaunix.net/viewthread.php? Tid = 727270 # ">
Code:
# Automake Interface
Bin_programs = Hello
Hello_sources = Hello. c lib/sbase. h
Hello_cppflags =-I lib
Hello_ldflags =-static lib/libsbase.
Extra_dist = lib/libsbase.
Configure. AC
Code: ac_prereq (2.59)
# Ac_init (full-package-name, version, bug-Report-address)
Ac_init (hello, 0.0.1, [SounOS@gmail.com])
# Am statement
Am_init_automake
Ac_config_srcdir ([src/Hello. C])
Ac_config_header ([config. H])
# Checks for programs.
Ac_prog_cc
# Checks for libraries.
# Checks for header files.
Ac_header_stdc
Ac_check_headers ([stdint. h stdlib. h sys/socket. H])
# Checks for typedefs, structures, and compiler characteristics.
Ac_c_const
Ac_type_size_t
Ac_type_uint32_t
Ac_type_uint64_t
# For custom configure options, see acinclude. AM
Ac_check_extra_options
# Checks for library functions.
Ac_config_files ([makefile
Src/makefile])
Ac_output