【Linux笔记】【基础系列】 Automake基础使用 4
本篇记录如何打包发布软件和安装发布的软件。
基于上一篇笔记Automake基础使用 3生成的文件。
打包很简单,只要执行一个命令。
执行 make dist 命令。
pi@raspberrypi:~/Desktop/automaketest3 $ make dist
make dist-gzip am__post_remove_distdir='@:'
make[1]: 进入目录“/home/pi/Desktop/automaketest3”
make distdir-am
make[2]: 进入目录“/home/pi/Desktop/automaketest3”
if test -d "automaketest-3.0.0"; then find "automaketest-3.0.0" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "automaketest-3.0.0" || { sleep 5 && rm -rf "automaketest-3.0.0"; }; else :; fi
test -d "automaketest-3.0.0" || mkdir "automaketest-3.0.0"
(cd src && make top_distdir=../automaketest-3.0.0 distdir=../automaketest-3.0.0/src \
am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)
make[3]: 进入目录“/home/pi/Desktop/automaketest3/src”
make distdir-am
make[4]: 进入目录“/home/pi/Desktop/automaketest3/src”
make[4]: 离开目录“/home/pi/Desktop/automaketest3/src”
make[3]: 离开目录“/home/pi/Desktop/automaketest3/src”
test -n "" \
|| find "automaketest-3.0.0" -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/bash /home/pi/Desktop/automaketest3/install-sh -c -m a+r {} {} \; \
|| chmod -R a+r "automaketest-3.0.0"
make[2]: 离开目录“/home/pi/Desktop/automaketest3”
tardir=automaketest-3.0.0 && ${TAR-tar} chof - "$tardir" | eval GZIP= gzip --best -c >automaketest-3.0.0.tar.gz
make[1]: 离开目录“/home/pi/Desktop/automaketest3”
if test -d "automaketest-3.0.0"; then find "automaketest-3.0.0" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "automaketest-3.0.0" || { sleep 5 && rm -rf "automaketest-3.0.0"; }; else :; fi
查看目录下的文件:
pi@raspberrypi:~/Desktop/automaketest3 $ ls
aclocal.m4 compile configure.ac Makefile src
AUTHORS config.h COPYING Makefile.am stamp-h1
autom4te.cache config.h.in depcomp Makefile.in test.c
automaketest-3.0.0.tar.gz config.log include missing
autoscan.log config.status INSTALL NEWS
ChangeLog configure install-sh README
可以看到多出了一个 automaketest-3.0.0.tar.gz 的压缩包,这个就是发布的软件。
接下来是如何使用发布的软件。
-
获取 automaketest-3.0.0.tar.gz
这里我们就将压缩包拷贝到另一个文件夹里。
-
解压 automaketest-3.0.0.tar.gz
执行 tar -zxvf automaketest-3.0.0.tar.gz 命令进行解压。
pi@raspberrypi:~/Desktop/automaketest4 $ tar -zxvf automaketest-3.0.0.tar.gz automaketest-3.0.0/ automaketest-3.0.0/src/ automaketest-3.0.0/src/Makefile.am automaketest-3.0.0/src/isOdd.c automaketest-3.0.0/src/Makefile.in automaketest-3.0.0/src/isPrime.c automaketest-3.0.0/aclocal.m4 automaketest-3.0.0/Makefile.am automaketest-3.0.0/test.c automaketest-3.0.0/compile automaketest-3.0.0/NEWS automaketest-3.0.0/missing automaketest-3.0.0/INSTALL automaketest-3.0.0/install-sh automaketest-3.0.0/ChangeLog automaketest-3.0.0/configure.ac automaketest-3.0.0/configure automaketest-3.0.0/AUTHORS automaketest-3.0.0/include/ automaketest-3.0.0/include/isOdd.h automaketest-3.0.0/include/isPrime.h automaketest-3.0.0/Makefile.in automaketest-3.0.0/README automaketest-3.0.0/config.h.in automaketest-3.0.0/COPYING automaketest-3.0.0/depcomp
-
进入目录中,执行 ./configure 命令, 生成 Makefile 文件,完成配置初始化。
pi@raspberrypi:~/Desktop/automaketest4 $ cd automaketest-3.0.0/ pi@raspberrypi:~/Desktop/automaketest4/automaketest-3.0.0 $ ls aclocal.m4 compile configure.ac include Makefile.am NEWS test.c AUTHORS config.h.in COPYING INSTALL Makefile.in README ChangeLog configure depcomp install-sh missing src pi@raspberrypi:~/Desktop/automaketest4/automaketest-3.0.0 $ ./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... /bin/mkdir -p checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for ranlib... ranlib 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 whether make supports the include directive... yes (GNU style) checking dependency style of gcc... gcc3 checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /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 for sqrt... no checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating src/Makefile config.status: creating config.h config.status: executing depfiles commands
-
执行 make 命令,编译代码。
pi@raspberrypi:~/Desktop/automaketest4/automaketest-3.0.0 $ make make all-recursive make[1]: 进入目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0” Making all in src make[2]: 进入目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0/src” gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT isOdd.o -MD -MP -MF .deps/isOdd.Tpo -c -o isOdd.o isOdd.c mv -f .deps/isOdd.Tpo .deps/isOdd.Po gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT isPrime.o -MD -MP -MF .deps/isPrime.Tpo -c -o isPrime.o isPrime.c mv -f .deps/isPrime.Tpo .deps/isPrime.Po rm -f libnumtest.a ar cru libnumtest.a isOdd.o isPrime.o ar: `u' 修饰符被忽略,因为 `D' 为默认(参见 `U') ranlib libnumtest.a make[2]: 离开目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0/src” make[2]: 进入目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0” gcc -DHAVE_CONFIG_H -I. -I./include -g -O2 -MT test.o -MD -MP -MF .deps/test.Tpo -c -o test.o test.c mv -f .deps/test.Tpo .deps/test.Po gcc -I./include -g -O2 -o test test.o src/libnumtest.a -lm make[2]: 离开目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0” make[1]: 离开目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0”
这个时候就可以在当前目录中运行测试程序了。
-
执行 make install 命令安装编译后的软件到系统中。
我这里需要 root 权限,所以加了 sudo。
pi@raspberrypi:~/Desktop/automaketest4/automaketest-3.0.0 $ sudo make install Making install in src make[1]: 进入目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0/src” make[2]: 进入目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0/src” make[2]: 对“install-exec-am”无需做任何事。 /bin/mkdir -p '/usr/local/include' /usr/bin/install -c -m 644 ../include/isOdd.h ../include/isPrime.h '/usr/local/include' make[2]: 离开目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0/src” make[1]: 离开目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0/src” make[1]: 进入目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0” make[2]: 进入目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0” /bin/mkdir -p '/usr/local/bin' /usr/bin/install -c test '/usr/local/bin' make[2]: 对“install-data-am”无需做任何事。 make[2]: 离开目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0” make[1]: 离开目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0”
这里会将 isOdd.h 和 isPrime.h 添加到 /usr/local/include 目录中,可执行文件添加在 /usr/local/bin 目录中。
这里就已经完成了发布软件的安装。
-
运行软件
这个时候我们可以退出当前目录,在其他路径下直接运行这个测试程序。
pi@raspberrypi:~/Desktop $ sudo test 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 1 3 5 7 9
-
卸载软件
如果不需要这个软件了,就可以将其从系统中卸载掉。
执行 make uninstall 命令:
pi@raspberrypi:~/Desktop/automaketest4/automaketest-3.0.0 $ sudo make uninstall Making uninstall in src make[1]: 进入目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0/src” ( cd '/usr/local/include' && rm -f isOdd.h isPrime.h ) make[1]: 离开目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0/src” make[1]: 进入目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0” ( cd '/usr/local/bin' && rm -f test ) make[1]: 离开目录“/home/pi/Desktop/automaketest4/automaketest-3.0.0”
这个时候在 /usr/local/bin 目录中就看不到 test 测试程序了,完成了发布软件的卸载。
还可以修改软件的安装路径。
默认情况下,在执行完 make install 命令后,软件会被安装在 /usr/local/include 目录, /usr/local/bin 目录和 /usr/local/lib 目录中。我们可以修改安装路径,在执行 ./configure 命令时通过–prefix= 指定安装路径,例如:
./configure --prefix=/home/pi/Desktop/automaketest5/
这会让 ./configure 生成 Makefile 时,配置 make install 命令执行时的文件安装路径。
下面执行一次:
pi@raspberrypi:~/Desktop/automaketest5/automaketest-3.0.0 $ ./configure --prefix=/home/pi/Desktop/automaketest5/
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for ranlib... ranlib
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 whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /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 for sqrt... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating config.h
config.status: executing depfiles commands
pi@raspberrypi:~/Desktop/automaketest5/automaketest-3.0.0 $
pi@raspberrypi:~/Desktop/automaketest5/automaketest-3.0.0 $ make
make all-recursive
make[1]: 进入目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0”
Making all in src
make[2]: 进入目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0/src”
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT isOdd.o -MD -MP -MF .deps/isOdd.Tpo -c -o isOdd.o isOdd.c
mv -f .deps/isOdd.Tpo .deps/isOdd.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT isPrime.o -MD -MP -MF .deps/isPrime.Tpo -c -o isPrime.o isPrime.c
mv -f .deps/isPrime.Tpo .deps/isPrime.Po
rm -f libnumtest.a
ar cru libnumtest.a isOdd.o isPrime.o
ar: `u' 修饰符被忽略,因为 `D' 为默认(参见 `U')
ranlib libnumtest.a
make[2]: 离开目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0/src”
make[2]: 进入目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0”
gcc -DHAVE_CONFIG_H -I. -I./include -g -O2 -MT test.o -MD -MP -MF .deps/test.Tpo -c -o test.o test.c
mv -f .deps/test.Tpo .deps/test.Po
gcc -I./include -g -O2 -o test test.o src/libnumtest.a -lm
make[2]: 离开目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0”
make[1]: 离开目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0”
pi@raspberrypi:~/Desktop/automaketest5/automaketest-3.0.0 $ make install
Making install in src
make[1]: 进入目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0/src”
make[2]: 进入目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0/src”
make[2]: 对“install-exec-am”无需做任何事。
/bin/mkdir -p '/home/pi/Desktop/automaketest5/include'
/usr/bin/install -c -m 644 ../include/isOdd.h ../include/isPrime.h '/home/pi/Desktop/automaketest5/include'
make[2]: 离开目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0/src”
make[1]: 离开目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0/src”
make[1]: 进入目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0”
make[2]: 进入目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0”
/bin/mkdir -p '/home/pi/Desktop/automaketest5/bin'
/usr/bin/install -c test '/home/pi/Desktop/automaketest5/bin'
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0”
make[1]: 离开目录“/home/pi/Desktop/automaketest5/automaketest-3.0.0”
查看目录
pi@raspberrypi:~/Desktop/automaketest5 $ ls
automaketest-3.0.0 automaketest-3.0.0.tar.gz bin include
多了 bin 和 include 文件夹。
可以看到安装到了这个目录下:
pi@raspberrypi:~/Desktop/automaketest5 $ ls bin include/
bin:
test
include/:
isOdd.h isPrime.h
【参考资料】
本文链接:https://blog.csdn.net/u012028275/article/details/125156546