linux中autotools工具生成Makefile文件及使用过程

操作系统:中标麒麟操作系统

CPU:龙芯

autotools使用步骤:

1、autoscan

2、vi configure.scan //修改内容

3、mv configure.scan configure.ac (或者configure.in 有的是这个) //重命名

4、aclocal  //生成.m4文件

5、autoconf  //生成configure文件

6、autoheader 

7、vi Makefile.am   //添加内容

8、automake

9、./configure //生成Makefile文件

10、make //编译生成可执行文件

11、./random //运行

12、make install  //安装到指定目录

13、运行 random  //查看是否运行

14、make dist   /打包在本目录下 .tar.gz文件

15、tar xf random-1.0.tar.gz

16、cd random-10/ 

17、make

18、make install 

19、random

实际操作:

[root@localhost random]# ls

printf.c  printf.h  random.c

[root@localhost random]# cat printf.h

#ifndef __PRINTF_H__

#define __PRINTF_H__

#include

void pri(void);

#endif  //__PRINTF_H__

 

[root@localhost random]# cat printf.c

#include "printf.h"

void pri(void){

  printf("你好\n");

}

 

[root@localhost random]# cat random.c

#include

#include

#include

#include

#include "printf.h"

int main(void){

   int i,j;

   FILE *fp = NULL;

   if((fp=fopen("random.r","w")) == NULL){

     printf("open error!");

   

   }

   

   srand(time(NULL)); //置随机数种子

   printf("Ten random numbers from 0 to 99 \n");

   int num;

   for(i=0;i<1;i++){

     num = rand() % 100;

     printf("%d\n",num);

     

     fprintf(fp,"%d",num);

     fprintf(fp,"\n");

   }

 

   fclose(fp); //关闭文件

   pri();

   return 0;

}

 

[root@localhost random]# autoscan 

[root@localhost random]# ls

autoscan.log  configure.scan  printf.c  printf.h  random.c

[root@localhost random]# vi configure.scan 

#                                               -*- Autoconf -*-

# Process this file with autoconf to produce a configure script.

 

AC_PREREQ(2.69)

AC_INIT(random,0.1)

AM_INIT_AUTOMAKE(random,0.1)

AC_CONFIG_SRCDIR([printf.h])

AC_CONFIG_HEADERS([config.h])

# Checks for programs.

AC_PROG_CC

# Checks for libraries.

# Checks for header files.

AC_CHECK_HEADERS([stdlib.h])

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_OUTPUT(Makefile)

 

[root@localhost random]# cp configure.scan configure.ac

[root@localhost random]# cp configure.scan configure.in

[root@localhost random]# aclocal

aclocal: warning: autoconf input should be named 'configure.ac', not 'configure.in'

aclocal: warning: 'configure.ac' and 'configure.in' both present.

aclocal: proceeding with 'configure.ac'

[root@localhost random]# ls

aclocal.m4      autoscan.log  configure.in    printf.c  random.c

autom4te.cache  configure.ac  configure.scan  printf.h

[root@localhost random]# rm configure.in

rm:是否删除普通文件 "configure.in"?y

[root@localhost random]# aclocal

[root@localhost random]# ls

aclocal.m4      autoscan.log  configure.scan  printf.h

autom4te.cache  configure.ac  printf.c        random.c

[root@localhost random]# autoconf

[root@localhost random]# autoheader

[root@localhost random]# vi Makefile.am

AUTOMAKE_OPTIONS=foreign

bin_PROGRAMS=random

random_SOURCES=printf.c printf.h random.c

[root@localhost random]# automake

configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:

configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation

configure.ac:12: error: required file './compile' not found

configure.ac:12:   'automake --add-missing' can install 'compile'

configure.ac:6: error: required file './install-sh' not found

configure.ac:6:   'automake --add-missing' can install 'install-sh'

configure.ac:6: error: required file './missing' not found

configure.ac:6:   'automake --add-missing' can install 'missing'

Makefile.am: error: required file './depcomp' not found

Makefile.am:   'automake --add-missing' can install 'depcomp'

[root@localhost random]# ls

aclocal.m4      autoscan.log  configure     configure.scan  printf.c  random.c

autom4te.cache  config.h.in   configure.ac  Makefile.am     printf.h

[root@localhost random]# automake -add-missing

automake: error: unrecognized option '-dd-missing'.

automake: Try '/usr/bin/automake --help' for more information.

[root@localhost random]# automake -dd-missing

automake: error: unrecognized option '-dd-missing'.

automake: Try '/usr/bin/automake --help' for more information.

[root@localhost random]# automake --add-missing

configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:

configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation

configure.ac:12: installing './compile'

configure.ac:6: installing './install-sh'

configure.ac:6: installing './missing'

Makefile.am: installing './depcomp'

[root@localhost random]# ./configure

checking for a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

checking for a thread-safe mkdir -p... /usr/bin/mkdir -p

checking for gawk... gawk

checking whether make sets $(MAKE)... yes

checking whether make supports nested variables... yes

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 for style of include used by make... GNU

checking dependency style of gcc... gcc3

checking how to run the C preprocessor... gcc -E

checking for grep that handles long lines and -e... /usr/bin/grep

checking for egrep... /usr/bin/grep -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 stdlib.h... (cached) yes

checking that generated files are newer than configure... done

configure: creating ./config.status

config.status: creating Makefile

config.status: creating config.h

config.status: executing depfiles commands

[root@localhost random]# make

make  all-am

make[1]: Entering directory '/diskE/InterFace2019.8.7/InterfaceTest/src/random'

gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT printf.o -MD -MP -MF .deps/printf.Tpo -c -o printf.o printf.c

mv -f .deps/printf.Tpo .deps/printf.Po

gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT random.o -MD -MP -MF .deps/random.Tpo -c -o random.o random.c

mv -f .deps/random.Tpo .deps/random.Po

gcc  -g -O2   -o random printf.o random.o  

make[1]: Leaving directory '/diskE/InterFace2019.8.7/InterfaceTest/src/random'

[root@localhost random]# ran

random  ranlib  

[root@localhost random]# random 

Ten random numbers from 0 to 99

63

你好

[root@localhost random]# make dist

make  dist-gzip am__post_remove_distdir='@:'

make[1]: Entering directory '/diskE/InterFace2019.8.7/InterfaceTest/src/random'

if test -d "random-0.1"; then find "random-0.1" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "random-0.1" || { sleep 5 && rm -rf "random-0.1"; }; else :; fi

test -d "random-0.1" || mkdir "random-0.1"

test -n "" \

|| find "random-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/sh /diskE/InterFace2019.8.7/InterfaceTest/src/random/install-sh -c -m a+r {} {} \; \

|| chmod -R a+r "random-0.1"

tardir=random-0.1 && ${TAR-tar} chof - "$tardir" | GZIP=--best gzip -c >random-0.1.tar.gz

make[1]: Leaving directory '/diskE/InterFace2019.8.7/InterfaceTest/src/random'

if test -d "random-0.1"; then find "random-0.1" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "random-0.1" || { sleep 5 && rm -rf "random-0.1"; }; else :; fi

[root@localhost random]# ls

aclocal.m4      config.log      install-sh   printf.h           random.r

autom4te.cache  config.status   Makefile     printf.o           stamp-h1

autoscan.log    configure       Makefile.am  random

compile         configure.ac    Makefile.in  random-0.1.tar.gz

config.h        configure.scan  missing      random.c

config.h.in     depcomp         printf.c     random.o

[root@localhost random]# tar xf random-0.1.tar.gz 

[root@localhost random]# ls

aclocal.m4      config.log      install-sh   printf.h           random.o

autom4te.cache  config.status   Makefile     printf.o           random.r

autoscan.log    configure       Makefile.am  random             stamp-h1

compile         configure.ac    Makefile.in  random-0.1

config.h        configure.scan  missing      random-0.1.tar.gz

config.h.in     depcomp         printf.c     random.c

[root@localhost random]# cd random-0.1

[root@localhost random-0.1]# la

bash: la: 未找到命令...

[root@localhost random-0.1]# ls

aclocal.m4   configure     install-sh   missing   random.c

compile      configure.ac  Makefile.am  printf.c

config.h.in  depcomp       Makefile.in  printf.h

[root@localhost random-0.1]# ./configure 

checking for a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

checking for a thread-safe mkdir -p... /usr/bin/mkdir -p

checking for gawk... gawk

checking whether make sets $(MAKE)... yes

checking whether make supports nested variables... yes

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 for style of include used by make... GNU

checking dependency style of gcc... gcc3

checking how to run the C preprocessor... gcc -E

checking for grep that handles long lines and -e... /usr/bin/grep

checking for egrep... /usr/bin/grep -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 stdlib.h... (cached) yes

checking that generated files are newer than configure... done

configure: creating ./config.status

config.status: creating Makefile

config.status: creating config.h

config.status: executing depfiles commands

[root@localhost random-0.1]# make

make  all-am

make[1]: Entering directory '/diskE/InterFace2019.8.7/InterfaceTest/src/random/random-0.1'

gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT printf.o -MD -MP -MF .deps/printf.Tpo -c -o printf.o printf.c

mv -f .deps/printf.Tpo .deps/printf.Po

gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT random.o -MD -MP -MF .deps/random.Tpo -c -o random.o random.c

mv -f .deps/random.Tpo .deps/random.Po

gcc  -g -O2   -o random printf.o random.o  

make[1]: Leaving directory '/diskE/InterFace2019.8.7/InterfaceTest/src/random/random-0.1'

[root@localhost random-0.1]# ran

random  ranlib  

[root@localhost random-0.1]# random

Ten random numbers from 0 to 99

42

你好

[root@localhost random-0.1]# make install

make[1]: Entering directory '/diskE/InterFace2019.8.7/InterfaceTest/src/random/random-0.1'

 /usr/bin/mkdir -p '/usr/local/bin'

  /usr/bin/install -c random '/usr/local/bin'

make[1]: Nothing to be done for 'install-data-am'.

make[1]: Leaving directory '/diskE/InterFace2019.8.7/InterfaceTest/src/random/random-0.1'

 

你可能感兴趣的:(Linux,交叉编译移植篇)