makefile.am Writing syntax

Source: Internet
Author: User

makefile.am, is a file, is a kind of technology, other documents written in a simple, but you have to follow the rules to write, like the Makefile file, so do not think makefile.am file is very mysterious, it and Makefile file, is just a more than Makefile A higher compilation rule file for the file abstraction program. When you use, as long as you specify what directory you want to generate, it is generated by what source, compile the time depends on which libraries, to install to what directory and so on, the next work is all handed to Automake and autoconf (about how these two work, I have a simple blog in front of the write), in general, Its rules are also very simple.

The following diagram lists the executable, static library, header, and data files, and four general rules for writing makefile.am files. As I said in front of Automake and autoconf usage, the makefile.am file written in two words:

Bin_programs = autotest//Indicates the compiled application name (can be installed). Non-installable replacement: Noinst_programs = Autotes

Autotest_source = autotest.c//Indicates the compiled source file.

Basic Format



For executables and Static library types, if you want to compile only, do not want to install into the system, you can use Noinst_programs instead of bin_programs,noinst_libraries instead of lib_libraries.

Available Global Variables


These global variables can be used in all the compiled items above.

Basic relative Path

When writing the makefile.am file, as far as possible with the relative path, or in different places to compile, the installation may be to a different directory,

Standard Installation path

The default installation path is: $ (prefix) =/usr/local, which can be overridden by the./configure--prefix= method.
Other predefined directories include: Bindir = $ (prefix)/bin, Libdir = $ (prefix)/lib, DataDir = $ (prefix)/share, Sysconfdir = $ (prefix)/etc, and so on.

define a new installation path file directory

If you want to build a directory under the installation directory, this time, you can do so.
For example, you want to create a new test directory. You can define TestDir = $ (prefix)/test, and then Test_data =test1 test2, the TEST1,TEST2 is installed as a data file under the prefix directory.

For example, I add the following two lines in my makefile.am of the top-level directory of my actual project,
DataDir = ${prefix}/data
Data_data = Package//result is in my installation directory, a DATA directory appears, the directory has a file

Compiling library files
If you have a Lib directory under the program directory, you can write it in this directory makefile.am

Noinst_libraries=libswap.a
Libswap_a_sources=swap.c
includes=-i$ (Top_srcdir)/src/include//Include file, note the use of-I.


swapincludedir=$ (Includedir)/swap
swapinclude_headers=$ (Top_srcdir)/src/include/swap.h
The last two lines mean to install the swap.h into the ${prefix}/include/swap directory. For a practical example, my header file for a library file, named Serverd.h,
serverdincludedir=$ (Includedir)/serverd
serverdinclude_headers=$ (Top_srcdir)/serverd/serverd.h
This is also placed in the top-level directory, these two lines can be in the installation directory under the Include directory to create a serverd directory, and then put Serverd.h in.

compiling the installation program

There are some previous foundations, write this directly below.

Noinst_programs=autotest
Autotest_sources=autotest.c
autotest_ldadd=$ (Top_srcdir)/src/..... A.O $ (Top_srcdir)/SRC/LIB/LIBSWAP.A//included library directory

makefile.am Writing syntax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.