Linux作业 使用make命令和分析makefile文件

书读的越多而不加思考,你就会觉得你知道得很多;而当你读书而思考得越多的时候,你就会越清楚地看到,你知道得很少。

导读:本篇文章讲解 Linux作业 使用make命令和分析makefile文件,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

使用make命令和分析makefile文件

  diction是一个经典的Unix小工具,用来检测使用不当的英文短语。

  请前往 http://www.gnu.org/software/diction/ 下载diction源码包

下载地址

(diction源码包:http://ftp.gnu.org/gnu/diction/,diction-0.7.tar.gz)

在这里插入图片描述

1.按以下命令将diction安装到当前目录

./configure –prefix=$PREFIX

make

make install

(其中,PREFIX请先在当前目录创建dic目录,并使用dic目录的绝对路径)

测试diction命令的使用,(测试用例请参考share/diction/C中的短语)

(1).下载完成放到Linux系统中如下图

在这里插入图片描述

(2). 解包

使用命令tar -xvf
在这里插入图片描述

完成后得到一个diction-0.7目录文件
在这里插入图片描述
里面的文件如图

(3). 进入目录 使用./configure –prefix=安装路径

–prefix=安装路径

创建了一个目录ddd,指明了使用make命令后文件会安装到ddd目录下
在这里插入图片描述
命令执行完后,会出现Makefile文件
在这里插入图片描述

(4). 使用make install命令安装在这里插入图片描述

在这里插入图片描述
检查一下ddd目录

在这里插入图片描述
得到了安装好的文件

2. 请简要分析Makefile文件

(参考Makefile使用指南 https://makefiletutorial.com/ )

(1). 使用vim文本编辑器,查看Makefile文件

来到Makefike所在的文件夹

vim Makefile

在这里插入图片描述

(2). 分析

在这里插入图片描述

VERSION=        0.7 # 版本号                                                                                                                                                                                      
srcdir=         .   # 源目录                                                                                                                                                                                      
prefix=         ../dir/ # 安装目录                                                                                                                                                                                
exec_prefix=    ${prefix} # 执行目录, 这里引用了变量prefix, 所以值为 ../dir/                                                                                                                                                                                                                                                                                                                                                        
BINDIR=         ${exec_prefix}/bin                                                                                                                                                                                
MANDIR=         ${prefix}/man # man命令的路径, 在安装目录下的/man                                                                                                                                                 
SHAREDIR=       ${prefix}/share                                                                                                                                                                                   
INSTALL=        /usr/bin/install -c                                                                                                                                                                               
INSTALL_PROGRAM=${INSTALL}                                                                                                                                                                                        
INSTALL_DATA=   ${INSTALL} -m 644 # 安装时间                                                                                                                                                                      
CC=             gcc # CC变量的值为gcc, 以后引用均用gcc代替                                                                                                                                                        
CFLAGS=         -g -O2 -g -Wmissing-prototypes -Wstrict-prototypes -Wcast-qual -Wpointer-arith -
Wcast-align -Wwrite-strings -Wmissing-declarations -Wnested-externs -pedantic -fno-common 
# 每个系统有不一样的参数
CPPFLAGS=       -I.  -DSHAREDIR=\"$(SHAREDIR)\" -DVERSION=\"$(VERSION)\" # C++文件的参数                                                                                                                          
LDFLAGS=        -g      # 变量LDFLAGS的值为 -g                                                                                                                                                                    
LIBM=           -lm # 链接库                                                                                                                                                                                      
# 第一条规则 名字是 all                                                                                                                                                                                           
all:            diction style diction.1                                                                                                                                                                                                                                                                                                                                                                                             
	diction:        diction.o sentence.o misc.o getopt.o getopt1.o                                                                                                                                                                    
	$(CC) -o $@ $(LDFLAGS) diction.o sentence.o misc.o \ # gcc -o diction.o sentence.o misc.o getopt.o 
	getopt1.o -g diction.o sentence.o misc.o 使用gcc, 生成目标文件                                                 
	getopt.o getopt1.o $(LIBS)                                                                                                                                                                                                                                                                                                                                                                                          
style:          style.o sentence.o misc.o getopt.o getopt1.o                                                                                                                                                                      
	$(CC) -o $@ $(LDFLAGS) style.o sentence.o misc.o \                                                                                                                                                                
	getopt.o getopt1.o $(LIBM) $(LIBS)                                                                                                                                                                                                                                                                                                                                                                                  
diction.1:      diction.1.in Makefile                                                                                                                                                                                             
	sed -e s+/usr/share+$(SHAREDIR)+ diction.1.in >$@                                                                                                                                                 
# install规则, 执行完all的命令后, 会执行下面的一系列命令                                                                                                                                                          
install:        all                                                                                                                                                                                                               
	$(INSTALL) -m 755 -d $(BINDIR)                                                                                                                                                                                    
	$(INSTALL_PROGRAM) -s diction $(BINDIR)/diction                                                                                                                                                                   
	$(INSTALL_PROGRAM) -s style $(BINDIR)/style                                                                                                                                                                       
	$(INSTALL) -m 755 -d $(SHAREDIR)/diction                                                                                                                                                                          
	$(INSTALL_DATA) de $(SHAREDIR)/diction/de                                                                                                                                                                         
	$(INSTALL_DATA) en $(SHAREDIR)/diction/en                                                                                                                                                                         
	(cd $(SHAREDIR)/diction; rm -f C; ln en C)                                                                                                                                                                        
	$(INSTALL) -m 755 -d $(MANDIR)/man1                                                                                                                                                                               
	$(INSTALL_DATA) diction.1 $(MANDIR)/man1/diction.1                                                                                                                                                                
	$(INSTALL_DATA) style.1 $(MANDIR)/man1/style.1                                                                                                                                                                                                                                                                                                                                                                      
	install.msg:                                                                                                                                                                                                                      
	gencat -o ${prefix}/share/locale/en_US/LC_MESSAGES/diction.cat diction-en.msg sentence-en.msg                                                                                                                     
	gencat -o ${prefix}/share/locale/en_US/LC_MESSAGES/style.cat style-en.msg sentence-en.msg                                                                                                                                                                                                                                                                                                                           
#{{{script}}}#{{{  clean                                                                                                                                                                                          
clean:                                                                                                                                                                                                                            
	rm -f *.out core *.o diction.1 # clean规则, 使用rm命令, 删除所有指定的文件                                                                                                                        
#}}}                                                                                                                                                                                                              
#{{{  clobber                                                                                                                                                                                                     
# 该规则执行完clean规则后, 还要执行rm -f ...                                                                                                                                                                      
clobber:        clean                                                                                                                                                                                                             
	rm -f diction style config.cache config.h config.log config.status Makefile                                                                                                                       
#}}}                                                                                                                                                                                                              
#{{{  tar                                                                                                                                                                                                         
# tar规则                                                                                                                                                                                                         
tar:            clobber                                                                                                                                                                                                           
	(b=`pwd`; b=`basename $$b`; cd ..; tar zcvf $$b.tar.gz $$b/COPYING $$b/INSTALL $$b/Makefile.in 
$$b/README $$b/configure $$b/install-sh $$b/de $$b/en $$b/[a-z]*.*)                                
#}}}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/122830.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!