In my project that uses autoconf and automake, I have two executables, say "foo" and "bar". Suppose "foo.c" looks like
int main()
{
exec ("bar");
return 0;
}
I.e., "foo" uses "bar". This works fine once I do./configure && make && make install. However, the autoconf provides an option to transform program names. For example, I could do ./configure --program-suffix=-2.0. Then "foo" and "bar" will be installed instead as
/usr/bin/foo-2.0
/usr/bin/bar-2.0
In that case, the reference to "bar" inside "foo" would be incorrect, because there will be no bar in the system (should be bar-2.0). Is there any way I can let autoconf/automake adjust this reference automatically?
In your Makefile you may run the $(program_transform_name) sed script to create a header file with the final names.
For instance, assuming your program names are foo and bar, create a names.h.in file containing:
#define FOO_NAME "@foo-name@"
#define BAR_NAME "@bar-name@"
Then equip your Makefile.am to have rules to generate names.h from names.h.in:
BUILT_SOURCES = names.h
EXTRA_DIST = names.h.in
edit = sed \
-e 's/@foo-name@/'`echo foo | sed '$(program_transform_name)'`'/g;' \
-e 's/@bar-name@/'`echo bar | sed '$(program_transform_name)'`'/g;'
names.h: $(srcdir)/names.h.in Makefile
$(edit) < $(srcdir)/names.h.in > $@
and finally include names.h and use FOO_NAME and BAR_NAME in your source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With