在“make install”中,我希望安装用户能够设置一个符号链接“hello”,它链接到静态链接的prog,“helloStatic”或动态链接的prog,“helloShared。 “看到我的回答。
我目前正在构建并安装:
我也想安装Hello,它是HelloShared或HelloStatic的符号链接。
我猜是通过提供配置或制作选项来做出选择?
我主要关注* nix或cygwin,虽然在Windows安装中如何做也很不错。
回顾一下,我想安装两个构建的可执行文件,另外还有一个指向安装人员希望成为“普通”版本的可执行文件的符号链接。理想情况下,如果没有选择,也是默认链接。
从一些源文件开始,我创建了一个带有autoscan的configure.ac,然后根据需要构建它。
我的工作流程是:
让我得到:
$ file hello*
helloShared: Bourne-Again shell script, ASCII text executable, with very long lines
helloStatic: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=f56d94fbc40359aced749759231d3e7ae39587a0, not stripped
我的档案:
$ tree -a
├── configure.ac
├── lib
│ ├── say.c
│ └── say.h
├── m4
├── Makefile.am
└── src
└── main.c
3 directories, 5 files
##########
$ cat configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([Hello], [0.1])
AC_CONFIG_SRCDIR([lib/say.h])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_MACRO_DIRS([m4])
# Checks for programs.
AC_PROG_CC
AM_PROG_AR
LT_INIT
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT
##########
$ cat Makefile.am
ACLOCAL_AMFLAGS = -I m4
pkglib_LTLIBRARIES = libsay.la
libsay_la_SOURCES = \
lib/say.c
libsay_la_CFLAGS = -I lib
pkglib_LIBRARIES = libsay.a
libsay_a_SOURCES = \
lib/say.c
libsay_a_CFLAGS = -I lib
include_HEADERS = \
lib/say.h
bin_PROGRAMS = helloShared helloStatic
helloShared_SOURCES = \
src/main.c
helloShared_CFLAGS = -I lib
helloShared_LDADD = libsay.la
helloStatic_SOURCES = \
src/main.c
helloStatic_CFLAGS = -I lib
helloStatic_LDADD = libsay.a
答案 0 :(得分:1)
写一个目标
install-exec-hook: ln whatever
文档中的一个示例: https://www.gnu.org/software/automake/manual/automake.html#Extending
答案 1 :(得分:0)
这是我对自己问题的解决方案(目前)。我没有把它标记为被接受,因为:
configure.ac:
AC_PROG_LN_S
Makefile.am:
LINK_HELLO_TO ?= helloStatic
install-exec-hook:
(cd ${bindir}; $(LN_S) $(LINK_HELLO_TO) hello)
uninstall-hook:
(cd ${bindir}; rm -f hello)
开发工作流程:
$ autoreconf
$ ./configure
$ make
$ sudo make install # Accept default sym link.
# Or explicitly set default:
$ sudo make install LINK_HELLO_TO=helloStatic
# Or set to link to executable that links to shared lib.
$ sudo make install LINK_HELLO_TO=helloShared
$ ll -gGF /usr/local/bin/hello*
lrwxrwxrwx 1 11 Feb 19 20:40 /usr/local/bin/hello -> helloShared*
-rwxr-xr-x 1 9.5K Feb 19 20:40 /usr/local/bin/helloShared*
-rwxr-xr-x 1 12K Feb 19 20:40 /usr/local/bin/helloStatic*