In this example, we assume that a software package of simserver1 is to be generated, and the source file is only one, namely, simserver1.cpp. The pthread library is used.
1. Run the autoscan scan source code directory.
Run
$ Autoscan
Execute the command to generate configure. scan.
2. Edit the configure. in File
After step 1 is executed, configure. scan is generated. in this step, copy the file, name it configure. in, and edit the file.
The command is as follows:
$ Cp configure. scan configure. in
$ Vim configure. in
After opening the file in the vim editor, the original content of the file is as follows:
Configure. scan starts
#-*-Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ (2.61)
AC_INIT (FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR ([simserver1.cpp])
AC_CONFIG_HEADER ([config. h])
# Checks for programs.
AC_PROG_CXX
# Checks for libraries.
# FIXME: Replace 'main with a function in'-lpthread:
AC_CHECK_LIB ([pthread], [main])
# Checks for header files.
AC_CHECK_HEADERS ([arpa/inet. h netinet/in. h sys/socket. h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_HEADER_STDC
AC_CHECK_FUNCS ([bzero inet_ntoa socket])
AC_CONFIG_FILES ([Makefile])
AC_OUTPUT
Configure. scan ends
Edit to the following content:
Start configure. in
#-*-Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_INIT (simserver1.cpp) # This macro is used to check the path of the source code and put it at the beginning of the file.
AM_INIT_AUTOMAKE (simserver1, 1.0) # describe the package name and version number
# Checks for programs.
AC_PROG_CXX # use C ++
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS ([arpa/inet. h netinet/in. h sys/socket. h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_HEADER_STDC
AC_CHECK_FUNCS ([bzero inet_ntoa socket])
AC_OUTPUT (Makefile) # This macro is the name of the Makefile to be output.
Configure. in ended
3. Run aclocal to generate the aclocal. m4 File
After editing and saving the configure. in file, run the aclocal command to generate the aclocal. m4 file.
Run the following command:
$ Aclocal
Then, use ls to list the generated files. If the aclocal. m4 file is not found, the configure. in file is incorrect. Modify the file and try again.
4. Run autoconf to generate the configure file
Use the autoconf command to generate the configure executable file.
Run the following command:
$ Autoconf
Then use ls to check whether configure is successfully generated.
5. Create a Makefile. am File
Makefile. am is used to generate Makefile. in, which requires manual writing. Makefile. am defines some content:
AUTOMAKE_OPTIONS
This is the automake option. When running automake, it checks whether there are various files in the standard GNU software package, such as AUTHORS, ChangeLog, and NEWS files in the directory. When we set it to foreign, automake will use the standard of the general software package to check.
Bin_PROGRAMS
This is the name of the executable file to be generated. If you want to generate multiple executable files, separate them by spaces.
Helloworld_SOURCES
This is the source code required to generate "helloworld. If multiple source files are used, separate them with spaces. For example, if you need helloworld. h and helloworld. c, write helloworld_SOURCES = helloworld. h helloworld. c.
If you have defined multiple executable files in bin_PROGRAMS, the corresponding filename_SOURCES must be defined for each executable file.
LIBS
This is used to specify the library of the link. For example, LIBS + =-lpthread, specify the link to the pthread library.
Run the following command:
$ Vim Makefilemam
On the editing page, enter the following content:
AUTOMAKE_OPTIONS = foreign
Bin_PROGRAMS = simserver1 # package name
Simserver‑sources = simserver1.cpp # source file list. Separate multiple source files with spaces.
LIBS + =-lpthread # link to the pthread Library
6. Run automake
Execute automake -- add-missing to generate Makefile. in.
$ Automake -- add-missing
The Makefile. in file should be generated after execution.
7. Run configure to generate Makefile
Run:
$./Configure
8. Execute make to generate an executable file
$ Make
Compile and output the simserver1 executable file after execution.
Make also has the following commands:
Make install can install simserver1 to the/usr/local/bin directory;
Make clean can clear the last compilation result
Make distcan package the code into a packagename-ver.tar.gz file.
Make distcheck is used to check whether the package is normal.