博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GNU make: Learning notes
阅读量:6894 次
发布时间:2019-06-27

本文共 4323 字,大约阅读时间需要 14 分钟。

before talking about Makefiles, compilers are important pre-knowledge.

first compile a executable ELF file, by:

gcc code.c -o program# run it by:./program

if we are going to compile one/several object file first, and put them into a shared object file:

# compile without linking(-c) compatible with shared obj(-fpic), to a.o & b.ogcc -c -fpic a.cgcc -c -fpic b.c# put a.o & b.o into a shared obj(.so) called libtest.sogcc -shared -o libtest.so a.o b.o

if we are going to install the generated libtest.so to system, mv it to /usr/lib and do a sudo ldconfig, of-course if removing an lib from /usr/lib, do a sudo ldconfig to clear cache of libs.

to compile a program against a lib which can be found by ldconfig -p|grep libtest.so: (keep in mind, gcc auto cuts the lib & .so part of a lib's name, thus libtest.so is used as test, together with -l, makes -ltest)

gcc -ltest -o program code.c# run it by:./program

according to , finding specific lib link name by pkg-config:

pkg-config --libs --cflags python# where --libs gives compiler link usage, --cflags gives compiler include usage

 

Standard Makefile Targets:

make allBuild programs, libraries, documentation, etc. (same as make).make installInstall what needs to be installed, copying the files from the package’s tree to system-wide directories.make install-stripSame as make install, then strip debugging symbols. Some users like to trade space for useful bug reports...make uninstallThe opposite of make install: erase the installed files. (This needs to be run from the same build tree that was installed.)make cleanErase from the build tree the files built by make all.make distcleanAdditionally erase anything ./configure created.make checkRun the test suite, if any.make installcheckCheck the installed programs or libraries, if supported.make distRecreate package-version.tar.gz from all the source files.

Standard Directory Variables:

Directory variable    Default valueprefix    /usr/local  exec_prefix    ${prefix}    bindir    ${exec_prefix}/bin    libdir    ${exec_prefix}/lib    …  includedir    ${prefix}/include  datarootdir    ${prefix}/share    datadir    ${datarootdir}    mandir    ${datarootdir}/man    infodir    ${datarootdir}/info    docdir    ${datarootdir}/doc/${PACKAGE}  …

Some Standard Configuration Variables: If wondering the difference between CFLAGS/CPPFALGS/CXXFLAGS, see

CCC compiler commandCFLAGSC compiler flagsCXXC++ compiler commandCXXFLAGSC++ compiler flagsLDFLAGSlinker flagsCPPFLAGSC/C++ preprocessor flags…

We can create a config.site for each directory/share that when selecting this directory as -prefix, the directory/share/config.site will always be included when doing ./configure -prefix=directory.

For more info about config.site, goto .

VPATH build tree: we can configure from another dir such as build.. 

~/amhello-1.0 % mkdir build && cd build~/amhello-1.0/build % ../configure…~/amhello-1.0/build % make…

<!--build gcc for cross compile to other platform.. />

./configure --target i686-pc-linux-gnu # --build --host ..

to make install program with prefix/suffix name..

--program-prefix=prefixPrepend prefix to installed program names.--program-suffix=suffixAppend suffix to installed program names.--program-transform-name=programRun sed program on installed program names../configure --program-prefix test-

is an example of make install with staged-installation-dir.. after that the packed tgz can be unpacked and install to other hosts.. without the need to run make..

~/amhello-1.0 % make DESTDIR=$HOME/inst install…~/amhello-1.0 % cd ~/inst~/inst % find . -type f -print > ../files.lst~/inst % tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`./usr/bin/hello./usr/share/doc/amhello/README

we can also build a tarball with make distcheck

also, if we compile something for one time, we dont need to generate a dependency tree for renew compilings..

--disable-dependency-tracking  Speed up one-time builds.--enable-dependency-tracking  Do not reject slow dependency extractors.

Important AM suffixes:

_PROGRAMS,_SOURCES,_LDADD,_TEXINFOS

If the environment variable AUTOMAKE_JOBS contains a positive number, it is taken as the maximum number of Perl threads to use inautomake for generating multiple Makefile.in files concurrently. This is an experimental feature.

 

转载于:https://www.cnblogs.com/sansna/p/6699406.html

你可能感兴趣的文章
云储存将成未来大规模视频监控储存主要模式
查看>>
添加和删除虚拟用户
查看>>
shell 变量
查看>>
IDEA远程仓库版本回滚
查看>>
linux 如何进入grub模式
查看>>
JAVA操作Trip数据库2
查看>>
Powershell技巧 判断一个AD账户是否存在
查看>>
LINQ系列:Linq to Object限制操作符
查看>>
tnginx调用lua模块编译安装
查看>>
虚拟主机的配置
查看>>
我的友情链接
查看>>
Hadoop的MapReduce执行流程图
查看>>
[转]Underscore.js 入门-常用方法介绍
查看>>
(八)saltstack项目实战_安装mysql
查看>>
案例:努力却不爽的员工与无辜的主管
查看>>
我的友情链接
查看>>
C++投票系统说明文档
查看>>
php 5.6.6 源码安装配置
查看>>
selenium grid解决多台电脑进行并发执行测试脚本
查看>>
UltraISO 对光盘镜像常用操作方法图解
查看>>