In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "Linux Automake tools to generate Makefile software implementation process", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux Automake tools to generate Makefile software implementation process"!
In the environment used, the program mentioned in this article is based on the Linux distribution: Fedora Core release 1, which contains the Linux Automake,automake we are going to use. Starting with helloworld, let's start with the most commonly used example program, helloworld. In a nutshell, the following process is: create three new files:
Helloworld.c
Configure.in
Makefile.am
Then execute:
Aclocal; autoconf; automake-- add-missing;. / configure; make;. / helloworld
You can see that the Makefile is generated and the helloworld.c can be compiled through.
Very simple, a few commands can make a conventional Makefile, how does it feel?
Now let's introduce the detailed process of generating the implementation steps of the Makefile software by the Linux Automake tool:
1. Build a catalogue
Create a helloworld directory under your working directory, which we use to store helloworld programs and related files, such as under / home/my/build:
$mkdir helloword
$cd helloworld
2 、 helloworld.c
Then write a hellowrold.c file with your favorite editor, such as the command: vi helloworld.c. Use the following code as the content of helloworld.c.
Int main (int argc, char** argv) {printf ("Hello, Linux World!\ n"); return 0;}
Save and exit when you are finished.
Now you should have a helloworld.c written by yourself in the helloworld directory.
3. Generate configure
We use the autoscan command to help us generate a template file for configure.in from the source code in the directory.
Command:
$autoscan
$ls
Configure.scan helloworld.c
After execution, a file is generated in the hellowrold directory: configure.scan, which we can use as a blueprint for configure.in.
Now rename configure.scan to configure.in, and edit it, modify it as follows, and remove extraneous statements:
Configure.in content starts
#-*-Autoconf-*-# Process this file with autoconf to produce a configure script AC_INIT (helloworld.c) AM_INIT_AUTOMAKE (helloworld, 1. 0) # 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 (Makefile)
End of configure.in content
Then execute the commands aclocal and autoconf, resulting in two files, aclocal.m4 and configure, respectively:
$aclocal $ls aclocal.m4 configure.in helloworld.c $autoconf $ls aclocal.m4 autom4te.cache configure configure.in helloworld.c
You can see that the configure.in content is a number of macro definitions, these macros after autoconf processing will become shell scripts to check system features, environment variables, and parameters necessary for the software. Autoconf is a tool used to generate automatic configuration software source code scripts (configure). Configure scripts can be run independently of autoconf and can be run without user intervention. To generate the configure file, you must tell autoconf how to find the macro you are using. The way is to use the aclocal program to generate your aclocal.m4.
Aclocal automatically generates configure.in files according to the contents of aclocal.m4 files. Aclocal is a perl script defined as "aclocal-create aclocal.m4 by scanning configure.ac". Autoconf creates a configure from configure.in, a template file that enumerates the various parameters needed to compile the software. Autoconf requires a GNU M4 macro processor to process aclocal.m4 and generate configure scripts. M4 is a macro processor. Copy the input to the output and expand the macro. Macros can be embedded or user-defined. In addition to expanding macros, M4 has some built-in functions for referencing files, executing commands, integer operations, text operations, loops, and so on. M4 can be used either as the front end of the compiler or as a separate macro processor.
4. Create a new Makefile.am
To create a new Makefile.am file, command:
$vi Makefile.am
The contents are as follows:
AUTOMAKE_OPTIONS=foreign
Bin_PROGRAMS=helloworld
Helloworld_SOURCES=helloworld.c
Automake will automatically generate Makefile.in based on the Makefile.am you write.
The macros and targets defined in Makefile.am instruct automake to generate the specified code. For example, the macro bin _ PROGRAMS will cause the compilation and connection targets to be generated.
5. Run automake
Command:
$automake-- add-missing configure.in: installing `. / install-sh' configure.in: installing`. / mkinstalldirs' configure.in: installing `. / missing' Makefile.am: installing`. / depcomp'
Automake generates files from the Makefile.am file, including the most important Makefile.in.
6. Execute configure to generate Makefile
$. / configure 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... 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: executing depfiles commands $ls-l Makefile-rw-rw-r-- 1 yutao yutao 15035 Oct 15 10:40 Makefile
As you can see, Makefile has already been generated at this time.
7. Use Makefile to compile code
$make if gcc-DPACKAGE_NAME= "- DPACKAGE_TARNAME="-DPACKAGE_VERSION= "- DPACKAGE_STRING="-DPACKAGE_BUGREPORT= "- DPACKAGE=" helloworld "- DVERSION=" 1.0 "- I. -I. -g-O2-MT helloworld.o-MD-MP-MF ".deps / helloworld.Tpo"\-c-o helloworld.o `deps-f 'helloworld.c' | | echo'. / '`helloworld.c;\ then mv-f ".deps / helloworld.Tpo" .deps / helloworld.Po ";\ else rm-f" .deps / helloworld.Tpo "; exit 1;\ fi gcc-g-O2-o helloworld helloworld.o run helloworld $. / helloworld Hello, Linux World! Thank you for your reading, the above is the content of "Linux Automake tools generate Makefile software implementation process". After the study of this article, I believe you have a deeper understanding of the process of generating Makefile software implementation of Linux Automake tools, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.