简体   繁体   English

Autotools库和目标文件输出控件

[英]Autotools library and object file output control

My goal is to have all object files built in a .objs directory instead of the root of the Makefile, and to have the binaries (and libraries) copied into the project's bin/ directory. 我的目标是将所有目标文件构建在.objs目录而不是Makefile的根目录中,并将二进制文件(和库)复制到项目的bin /目录中。 But I have been unable to find any resources to explain how to do this. 但我一直无法找到任何资源来解释如何做到这一点。 How would I go about doing this? 我该怎么做呢?

Here is my configure.ac and src/Makefile.am - I have similar Makefile.am files for two shared libraries that are referenced. 这是我的configure.ac和src / Makefile.am - 我有两个类似的Makefile.am文件,用于引用的两个共享库。 They compile, and after copying them to the bin/ directory work as they should. 他们编译,并在将它们复制到bin /目录之后工作。 I'm just looking to automate this process. 我只是想自动化这个过程。

configure.ac configure.ac

AC_PREREQ([2.63])
AC_INIT([gtkworkbook], [0.12], [j_bellone@users.sourceforge.net])
AC_CONFIG_SRCDIR([gtkworkbook/cell.c])
AM_INIT_AUTOMAKE([gtkworkbook], [0.12])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_LIBTOOL
AC_PROG_CC_C_O

AC_CHECK_LIB([pthread], [pthread_mutex_init], [], [
            echo "pthread library is missing. pthread is required for this program"
            exit -1])

# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_SIZE_T

# Checks for library functions.
AC_CHECK_FUNCS([gethostbyname memset socket])

AC_OUTPUT([Makefile
       csv/Makefile
       gtkworkbook/Makefile
       src/Makefile])

src/Makefile.am SRC / Makefile.am

AUTOMAKE_OPTIONS= foreign

C_FLAGS= -I/usr/local/include -I/usr/include -I/usr/local/include/gtkextra-2.0 -I$(top_srcdir)/include `pkg-config gtk+-2.0 glib-2.0 --cflags`
L_FLAGS= -L/usr/local/lib -L/usr/lib -L$(top_srcdir)/lib `pkg-config gtk+-2.0 glib-2.0 --libs` -lgtkextra-x11-2.0

bin_PROGRAMS= gtkworkbook
gtkworkbook_SOURCES= application.c config.c main.c parse.c plugin.c
gtkworkbook_CFLAGS= -Wall -lgthread-2.0 -std=c99 $(C_FLAGS)  
gtkworkbook_LFLAGS= -ldl $(L_FLAGS)
gtkworkbook_LDFLAGS= $(L_FLAGS)
gtkworkbook_LDADD= ../gtkworkbook/libgtkworkbook.la ../csv/libcsv.la

lib_LTLIBRARIES= realtime.la
realtime_la_SOURCES= realtime/CsvParser.cpp realtime/Network.cpp realtime/Packet.cpp realtime/plugin_main.cpp \
    realtime/thread_main.cpp realtime/concurrent/Mutex.cpp realtime/concurrent/Semaphore.cpp \
    realtime/concurrent/Thread.cpp realtime/concurrent/ThreadGroup.cpp realtime/concurrent/ThreadPool.cpp \
    realtime/proactor/Dispatcher.cpp realtime/proactor/Event.cpp realtime/proactor/Proactor.cpp \
    realtime/proactor/InputDispatcher.cpp realtime/proactor/Worker.cpp realtime/network/Tcp.cpp
realtime_la_CPPFLAGS= -Wall -Wno-write-strings $(C_FLAGS)
realtime_la_LFLAGS= -lgtkworkbook -lcsv $(L_FLAGS)
realtime_la_LDFLAGS= -module -export-dynamic 
realtime_la_LIBADD= ../gtkworkbook/libgtkworkbook.la ../csv/libcsv.la

So, my question is how to specify the output directories for the compile results of each Makefile (I wish them to be copied to bin/ , and for the object files to be in .obj of each project instead of in the root of the Makefile. 所以,我的问题是如何为每个Makefile的编译结果指定输出目录(我希望它们被复制到bin / ,并且目标文件在每个项目的.obj中而不是在Makefile的根目录中) 。

Thanks for the help thus far.. this website has been a great resource, and I have learned a lot from the links provided already. 感谢您的帮助到目前为止..这个网站是一个很好的资源,我从已经提供的链接中学到了很多东西。

The GNU Build System does not use obj/ directories, so the autotools are not designed to support that. GNU Build System不使用obj/目录,因此autotools不支持它。

However I can think of two ways to work around this. 但是,我可以想出两种方法来解决这个问题。

As an installer, you can build any package out of its source directory by typing 作为安装程序,您可以通过键入来构建其源目录中的任何包

mkdir builddir
cd builddir
../path-to-sourcedir/configure
make

Then any output file will be created in the builddir/ directory. 然后将在builddir/目录中创建任何输出文件。 This compilation scheme makes it possible to compile source code out stored in a readonly directory (this made more sense back in the years where the FSF was distributing CDs with uncompressed source code), or to compile the same source with differents settings (or even for different architectures). 这种编译方案可以编译存储在只读目录中的源代码(这在FSF使用未压缩源代码分发CD的年份更有意义),或者使用不同的设置编译相同的源(甚至对于不同的架构)。

As a packager, the only way you could force your package to build everything in obj/ is to put your Makefile.am in obj/ , and declare all your build rules there. 作为一个打包器,你可以强制你的包在obj/构建所有东西的唯一方法是将你的Makefile.am放在obj/ ,然后在那里声明你所有的构建规则。 This would mean a obj/Makefile.am looking like: 这意味着obj/Makefile.am看起来像:

bin_PROGRAMS = foo bar
foo_SOURCES = ../src/foo/main.c ../src/foo/help.c ../src/foo/list.c
bar_SOURCES = ../src/bar/bar.c 

etc. I remember that 10 years ago, POSE, the Palm OS Emulator, was using a setup like the above. 我记得10年前,Palm OS仿真器POSE正在使用如上所述的设置。 I don't recommend it as it's not really maintainable. 我不推荐它,因为它不是真的可维护。 It's really better to stick with the philosophy of the tools, and use a build systems that work like the other GNU packages. 坚持工具的理念,并使用与其他GNU包一样工作的构建系统,真的更好。

For an introduction to the GNU Build System, I recommend reading the introduction of the Automake manual: http://www.gnu.org/software/automake/manual/automake.html#GNU-Build-System 有关GNU Build System的介绍,我建议阅读Automake手册的介绍: http//www.gnu.org/software/automake/manual/automake.html#GNU-Build-System

Especially the Use-Cases section. 特别是用例部分。 If you don't care about these use cases, I think your best course is NOT to use Automake, and build your own Makefiles. 如果您不关心这些用例,我认为您最好的方法是不要使用Automake,并构建自己的Makefile。 Otherwise you will keep trying to force Automake doing something it is not designed for, and you'll quickly hate it. 否则你会继续试图强迫Automake做一些不适合的事情,你很快就会讨厌它。

EDIT 2013-08-26 : Note that an Automake project using a subdirectory named using obj/ is not portable to BSD make. 编辑2013-08-26 :请注意,使用以obj/命名的子目录的Automake项目不能移植到BSD make。

The easiest way to do this would be to set "libdir" to the directory you want these files to end up in, and use the install target to copy them there. 最简单的方法是将“libdir”设置为您希望这些文件最终进入的目录,并使用安装目标将其复制到那里。

This would prevent you from using the install target in the conventional sense though. 这会阻止您使用传统意义上的安装目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM