Automake Variables to tidy up Makefile.am

2020-08-13 05:15发布

I have a directory /src containing all of my source files, and /bin to store all binary after running make command. The directory is something like below:

/BuildDirectory
- - /src
- - /bin
- - configure
- - Makefile.am
- - configure.ac 
- - ... 

Now in Makefile.am, I have to specified:

bin_PROGRAMS = bin/x bin/y bin/z bin/k ...

bin_x_SOURCES = src/x.cpp
bin_y_SOURCES = src/y.cpp
bin_z_SOURCES = src/z.cpp

Is there any variable that can help to get rid of all "bin/" and "src/" ? For example I just specify:

$BIN = bin
$SRC = src 

And they will look for the correct files in correct folders and compile it to the correct places.

Thanks

3条回答
SAY GOODBYE
2楼-- · 2020-08-13 05:38

You could take advantage of remote building. Place this makefile in the bin dir:

VPATH = ../src
bin_PROGRAMS = x y z k ...

x_SOURCES = x.cpp
y_SOURCES = y.cpp
z_SOURCES = z.cpp

Now replace the current Makefile.am with this one:

SUBDIRS = bin

Now tweak your configure.ac to also generate bin/Makefile

AC_CONFIG_FILES([Makefile
        bin/Makefile])

and you should be set for life.

查看更多
迷人小祖宗
3楼-- · 2020-08-13 05:40

If what you're trying to do is what I think you're trying to do, you're trying to achieve something like:

SRCDIR  = src
BINDIR  = bin

bin_PROGRAMS = $(BINDIR)/x $(BINDIR)/y $(BINDIR)/z

bin_x_SOURCES = $(SRCDIR)/x.cpp
bin_y_SOURCES = $(SRCDIR)/y.cpp
bin_z_SOURCES = $(SRCDIR)/z.cpp

I've tested this a few times in various forms, and it won't compile the code as it would with your example; I somehow convinced it that it was compiling C at one stage:

gmake[1]: *** No rule to make target `bin/x.c', needed by `x.o'.  Stop.

I'm thus fairly certain that it's not possible. Sorry.

查看更多
Root(大扎)
4楼-- · 2020-08-13 05:53

Not to my knowledge. If you're looking to separate your compiled files from your source files, remember that you can build outside of the tree:

$ cd foo-1.2.3
$ mkdir build
$ cd build
$ ../configure
$ make
$ make install

If this is what you're looking to do, you can make the Makefile.am simpler by creating binaries without a directory prefix (and still referencing things in src/ by hand).

查看更多
登录 后发表回答