I'm trying to add to the output executable filename of a autotool project the version number.
With libs is very simple: you can add -version-info option to Makefile.am
How can I do the same thing with bin_PROGRAMS
So far I tried:
HELLO_VERSION_CURRENT = 1
HELLO_VERSION_REVISION = 2
HELLO_VERSION_AGE = 1
bin_PROGRAMS = hello_${HELLO_VERSION_CURRENT}_${HELLO_VERSION_REVISION}_${HELLO_VERSION_AGE}
hello_SOURCES = hello.c
In this way it doesn't compile because of SOURCES must be: hello_1_2_1_SOURCES, but I don't know how to tell to automake that.
Another way could be to run a post-build script: how can I add post-build action to Makefile.am?
How about using some preset autoconf output variables in your Makefile.am:
bin_PROGRAMS = hello_#PACKAGE_VERSION#
hello_#PACKAGE_VERSION#_SOURCES = hello.c
The preceding works for me on Darwin with autoconf v2.69 and automake v1.15.
Using the PACKAGE_VERSION from within your source code is even easier: #include "config.h", that's where all the autoconf output variables are #defined. E.g.:
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
...
#define PACKAGE_VERSION "1.2.3-rc-whatever"
Reference:
https://www.gnu.org/software/autoconf/manual/autoconf#Output-Variable-Index
You can do it like this:
HELLO_VERSION_CURRENT = 1
HELLO_VERSION_REVISION = 2
HELLO_VERSION_AGE = 1
bin_PROGRAMS = hello_$(HELLO_VERSION_CURRENT)_$(HELLO_VERSION_REVISION)_$(HELLO_VERSION_AGE)
hello_$(HELLO_VERSION_CURRENT)_$(HELLO_VERSION_REVISION)_$(HELLO_VERSION_AGE)_SOURCES = hello.c
Although, in that case, I'd suggest making shorter variable names...
At the end I add the following to my Makefile.am
all:
cp ./.libs/hello ./.libs/hello_${HELLO_VERSION_CURRENT}_${HELLO_VERSION_REVISION}_${HELLO_VERSION_AGE}
EDIT
I found a new solution
HELLO_VERSION_CURRENT = 1
HELLO_VERSION_REVISION = 2
HELLO_VERSION_AGE = 1
bin_PROGRAMS = hello_$(HELLO_VERSION_CURRENT)_$(HELLO_VERSION_REVISION)_$(HELLO_VERSION_AGE)
hello___HELLO_VERSION_CURRENT____HELLO_VERSION_REVISION____HELLO_VERSION_AGE__SOURCES = hello.c
hello___HELLO_VERSION_CURRENT____HELLO_VERSION_REVISION____HELLO_VERSION_AGE__CFLAGS =
hello___HELLO_VERSION_CURRENT____HELLO_VERSION_REVISION____HELLO_VERSION_AGE__LDFLAGS =
AM_CFLAGS = #hello___HELLO_VERSION_CURRENT____HELLO_VERSION_REVISION____HELLO_VERSION_AGE__CFLAGS#
AM_LDFLAGS = #hello___HELLO_VERSION_CURRENT____HELLO_VERSION_REVISION____HELLO_VERSION_AGE__LDFLAGS#
CLEANFILES = *~
Related
I'm trying to compile the PCRE library into a testing executable.
The documentation states that running Make and then configure should generate the library.
In the PCRE source directory:
Make
./configure
gcc -o test test.c -L . -lpcre
However the following error returns:
/usr/bin/ld: cannot find -pcre
collect2: error: ld returned 1 exit status
Note: I've also tried flag -libpcre. I was able to sucessfully run this on MacOS (seperately compiled but same library source code and same testiing source code).
Directory Contents:
132html pcre16_globals.c
aclocal.m4 pcre16_jit_compile.c
AUTHORS pcre16_maketables.c
ChangeLog pcre16_newline.c
CheckMan pcre16_ord2utf16.c
CleanTxt pcre16_printint.c
cmake pcre16_refcount.c
CMakeLists.txt pcre16_string_utils.c
compile pcre16_study.c
config-cmake.h.in pcre16_tables.c
config.guess pcre16_ucd.c
config.h pcre16_utf16_utils.c
config.h.generic pcre16_valid_utf16.c
config.h.in pcre16_version.c
config.log pcre16_xclass.c
config.status pcre32_byte_order.c
config.sub pcre32_chartables.c
configure pcre32_compile.c
configure.ac pcre32_config.c
COPYING pcre32_dfa_exec.c
depcomp pcre32_exec.c
Detrail pcre32_fullinfo.c
dftables.c pcre32_get.c
doc pcre32_globals.c
HACKING pcre32_jit_compile.c
INSTALL pcre32_maketables.c
install-sh pcre32_newline.c
libpcre16.pc pcre32_ord2utf32.c
libpcre16.pc.in pcre32_printint.c
libpcre32.pc pcre32_refcount.c
libpcre32.pc.in pcre32_string_utils.c
libpcrecpp.la pcre32_study.c
libpcrecpp_la-pcrecpp.lo pcre32_tables.c
libpcrecpp_la-pcrecpp.o pcre32_ucd.c
libpcrecpp_la-pcre_scanner.lo pcre32_utf32_utils.c
libpcrecpp_la-pcre_scanner.o pcre32_valid_utf32.c
libpcrecpp_la-pcre_stringpiece.lo pcre32_version.c
libpcrecpp_la-pcre_stringpiece.o pcre32_xclass.c
libpcrecpp.pc pcre_byte_order.c
libpcrecpp.pc.in pcre_chartables.c
libpcre.la pcre_chartables.c.dist
libpcre_la-pcre_byte_order.lo pcre_compile.c
libpcre_la-pcre_byte_order.o pcre-config
libpcre_la-pcre_chartables.lo pcre_config.c
libpcre_la-pcre_chartables.o pcre-config.in
libpcre_la-pcre_compile.lo pcrecpparg.h
libpcre_la-pcre_compile.o pcrecpparg.h.in
libpcre_la-pcre_config.lo pcrecpp.cc
libpcre_la-pcre_config.o pcrecpp.h
libpcre_la-pcre_dfa_exec.lo pcrecpp_internal.h
libpcre_la-pcre_dfa_exec.o pcrecpp_unittest
libpcre_la-pcre_exec.lo pcrecpp_unittest.cc
libpcre_la-pcre_exec.o pcrecpp_unittest-pcrecpp_unittest.o
libpcre_la-pcre_fullinfo.lo pcredemo
libpcre_la-pcre_fullinfo.o pcredemo.c
libpcre_la-pcre_get.lo pcre_dfa_exec.c
libpcre_la-pcre_get.o pcre_exec.c
libpcre_la-pcre_globals.lo pcre_fullinfo.c
libpcre_la-pcre_globals.o pcre_get.c
libpcre_la-pcre_jit_compile.lo pcregexp.pas
libpcre_la-pcre_jit_compile.o pcre_globals.c
libpcre_la-pcre_maketables.lo pcregrep
libpcre_la-pcre_maketables.o pcregrep.c
libpcre_la-pcre_newline.lo pcregrep-pcregrep.o
libpcre_la-pcre_newline.o pcre.h
libpcre_la-pcre_ord2utf8.lo pcre.h.generic
libpcre_la-pcre_ord2utf8.o pcre.h.in
libpcre_la-pcre_refcount.lo pcre_internal.h
libpcre_la-pcre_refcount.o pcre_jit_compile.c
libpcre_la-pcre_string_utils.lo pcre_jit_test.c
libpcre_la-pcre_string_utils.o pcre_maketables.c
libpcre_la-pcre_study.lo pcre_newline.c
libpcre_la-pcre_study.o pcre_ord2utf8.c
libpcre_la-pcre_tables.lo pcreposix.c
libpcre_la-pcre_tables.o pcreposix.h
libpcre_la-pcre_ucd.lo pcre_printint.c
libpcre_la-pcre_ucd.o pcre_refcount.c
libpcre_la-pcre_valid_utf8.lo pcre_scanner.cc
libpcre_la-pcre_valid_utf8.o pcre_scanner.h
libpcre_la-pcre_version.lo pcre_scanner_unittest
libpcre_la-pcre_version.o pcre_scanner_unittest.cc
libpcre_la-pcre_xclass.lo pcre_scanner_unittest-pcre_scanner_unittest.o
libpcre_la-pcre_xclass.o pcre_stringpiece.cc
libpcre.pc pcre_stringpiece.h
libpcre.pc.in pcre_stringpiece.h.in
libpcreposix.la pcre_stringpiece_unittest
libpcreposix_la-pcreposix.lo pcre_stringpiece_unittest.cc
libpcreposix_la-pcreposix.o pcre_stringpiece_unittest-pcre_stringpiece_unittest.o
libpcreposix.pc pcre_string_utils.c
libpcreposix.pc.in pcre_study.c
libtool pcre_tables.c
LICENCE pcretest
ltmain.sh pcre_test.c
m4 pcretest.c
Makefile pcretest-pcre_printint.o
Makefile.am pcretest-pcretest.o
Makefile.in pcre_ucd.c
makevp.bat pcre_valid_utf8.c
makevp_c.txt pcre_version.c
makevp_l.txt pcre_xclass.c
missing perltest.pl
NEWS PrepareRelease
NON-AUTOTOOLS-BUILD README
NON-UNIX-USE RunGrepTest
pcre16_byte_order.c RunTest
pcre16_chartables.c RunTest.bat
pcre16_compile.c sljit
pcre16_config.c stamp-h1
pcre16_dfa_exec.c test.c
pcre16_exec.c testdata
pcre16_fullinfo.c ucp.h
pcre16_get.c
Try -lpcre not -libpcre when you link. -l assumes the lib prefix and takes the name of the lib so -lpcre looks for libpcre
I will like to compile files in the following steps using SCons:
.c -> .asm(assembly file) -> .o
I tried to define different builders for this.
I managed to do something like: .asm -> .o and .c -> .o
I don't know how to make SCons aware of the .asm files generated from .c files and then to use the object builder.
Is there any possibility to use current SCons implementation for this ?
EDIT: This is what I tried :
-> To define two builders: Builder 1 (c_to_asm) is intended to do .c -> .asm step
Builder 2 (asm_to_o) is intended to do .asm -> .o . After these two builders are executed for all the files defined in my SConscript I expect the Program builder to create the final executable.
SCons.Tool.createProgBuilder(env)
c_to_asm = SCons.Builder.Builder(action = {},
emitter = {},
prefix = '',
suffix = '.asm',
src_builder = '',
source_scanner = '',
single_source = 1)
c_to_asm_action = SCons.Action.Action('c to asm command line', 'Executing .c to .asm builder')
c_to_asm.add_action('.c', c_to_asm_action)
asm_to_o = SCons.Builder.Builder(action = {},
emitter = {},
prefix = '',
suffix = '.o',
src_builder = ['CTOASM'],
source_scanner = '',
single_source = 1)
asm_to_o_action = SCons.Action.Action('asm to o command line', 'Executing .asm to .o builder...')
asm_to_o.add_action('.asm', asm_to_o_action)
env['BUILDERS']['CTOASM'] = c_to_asm
env['BUILDERS']['Object'] = asm_to_o
I see the execution string for each builder but no command is executed.
I don't know how to establish in which order these builders execute actions and how to trigger this builders.
Your approach is a little complicated. From the top of my head I'd try something like this (untested, but hopefully gives you a direction to continue with):
import SCons.Action
import SCons.Builder
# Automatically inits "nasm" Tool, if it is in the $PATH
env = Environment()
c_to_asm_action = SCons.Action.Action('c to asm command line', 'Executing .c to .asm builder')
c_to_asm = SCons.Builder.Builder(action = c_to_asm_action,
suffix = '.asm',
single_source = 1)
env['BUILDERS']['CTOASM'] = c_to_asm
# Creates first.asm and second.asm
env.CTOASM(['first.c', 'second.c'])
# Compiles final program, finds the newly created ASM files via Glob
env.Program('foo', Glob('*.asm') + list_of_your_other_sources_and_libs)
I am currently experiencing a really strange bug when compiling for u-boot:
The vector
init_fnc_t *init_sequence[] ={...}
is filled with 0's / NULLs instead of function pointers. I thought I outsmarted the compiler by calling all those functions 'by hand'. However this bug has even more ramifications as the driver struct also gets 0 / NULL pointers:
static struct serial_device my_serial_drv = {
.name = "my_serial",
.start = my_serial_init,
.stop = NULL,
.setbrg = my_serial_setbrg,
.putc = my_serial_putc,
.puts = my_serial_puts,
.getc = my_serial_getc,
.tstc = my_serial_tstc,
};
which, of course, when I call
'my_serial_drv'->start();
sets the pc to 0 and subsequently crashes everything.
Fun fact: the .name reaches the binary, so the .data sections are probably fine once they are set.
I have tested this with aarch64-linux-gnu-*-4.7 and aarch64-linux-gnu-*-4.9 binaries.
You can find 4.9 from:
http://releases.linaro.org/latest/components/toolchain/binaries.
Any help would be greatly appreciated :)
The u-boot.bin file seems allright. After investigating why this works I saw that u-boot's make is running a separate command to fix the bin:
start=$(aarch64-linux-gnu-nm u-boot | grep __rel_dyn_start | cut -f 1 -d ' ');
end=$(aarch64-linux-gnu-nm u-boot | grep __rel_dyn_end | cut -f 1 -d ' ');
tools/relocate-rela u-boot.bin 0x3e900000 $start $end
(these were a single line but I split it for readability )
I am porting an application, the existing MakeFile has the following...
ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes
ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES))
EXTRA_CPPFLAGS = \
-DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"'
So I tried recreating it with...
LOCAL_CFLAGS := -DNO_GETTEXT -DSHA1_HEADER="openssl/sha.h" -DETC_GITATTRIBUTES=/scard/.app
The code both of these are calling is...
system_wide = system_path(ETC_GITATTRIBUTES)
But the second one gives me the following error...
./src/attr.c:476:30: error: expected expression before '/' token
If I hardcode like this...
system_wide = system_path("/sdcard/.app");
This works fine. How do I properly declare my variable in the Android.mk?
Update
I also tried this...
LOCAL_CFLAGS := -DNO_GETTEXT -DSHA1_HEADER="openssl/sha.h" -DETC_GITATTRIBUTES="/scard/.app"
The code after the C-Preprocessor is done looks like this:
system_wide = system_path(/scard/.app)
This is because ETC_GITATTRIBUTES is literally replaced by /scard/.ap. So you'd need to do:
-DETC_GITATTRIBUTES="/scard/.app"
Previous answer was "close" but you needed to escape the quotes apparently...
LOCAL_CFLAGS := -DNO_GETTEXT -DSHA1_HEADER="openssl/sha.h" -DETC_GITATTRIBUTES=\"/scard/.app\"
The waf command waf build shows compiler errors (if there are any) while waf debug or waf release does not and always fails, utilizing the following wscript file (or maybe the wscript file has some other shortcomings I am currently not aware of):
APPNAME = 'waftest'
VERSION = '0.0.1'
def configure(ctx):
ctx.load('compiler_c')
ctx.define('VERSION', VERSION)
ctx.define('GETTEXT_PACKAGE', APPNAME)
ctx.check_cfg(atleast_pkgconfig_version='0.1.1')
ctx.check_cfg(package='glib-2.0', uselib_store='GLIB', args=['--cflags', '--libs'], mandatory=True)
ctx.check_cfg(package='gobject-2.0', uselib_store='GOBJECT', args=['--cflags', '--libs'], mandatory=True)
ctx.check_cfg(package='gtk+-3.0', uselib_store='GTK3', args=['--cflags', '--libs'], mandatory=True)
ctx.check_cfg(package='libxml-2.0', uselib_store='XML', args=['--cflags', '--libs'], mandatory=True)
ctx.check_large_file(mandatory=False)
ctx.check_endianness(mandatory=False)
ctx.check_inline(mandatory=False)
ctx.setenv('debug')
ctx.env.CFLAGS = ['-g', '-Wall']
ctx.define('DEBUG',1)
ctx.setenv('release')
ctx.env.CFLAGS = ['-O2', '-Wall']
ctx.define('RELEASE',1)
def pre(ctx):
print ('Building [[[' + ctx.variant + ']]] ...')
def post(ctx):
print ('Building is complete.')
def build(ctx):
ctx.add_pre_fun(pre)
ctx.add_post_fun(post)
# if not ctx.variant:
# ctx.fatal('Do "waf debug" or "waf release"')
exe = ctx.program(
features = ['c', 'cprogram'],
target = APPNAME+'.bin',
source = ctx.path.ant_glob(['src/*.c']),
includes = ['src/'],
export_includes = ['src/'],
uselib = 'GOBJECT GLIB GTK3 XML'
)
# for item in exe.includes:
# print(item)
from waflib.Build import BuildContext
class release(BuildContext):
cmd = 'release'
variant = 'release'
class debug(BuildContext):
cmd = 'debug'
variant = 'debug'
Error resulting from waf debug :
Build failed
-> task in 'waftest.bin' failed (exit status -1):
{task 46697488: c qqq.c -> qqq.c.1.o}
[useless filepaths]
I had a look at the waf demos, read the wafbook at section 6.2.2 but those did not supply me with valuable information in order to fix this issue.
What's wrong, and how do I fix it?
You need to do at least the following:
def configure(ctx):
...
ctx.setenv('debug')
ctx.load('compiler_c')
...
Since the cfg.setenv function resets whole previous environment. If you want to save previous environment, you can do cfg.setenv('debug', env=cfg.env.derive()).
Also, you don't need to explicitly specify the features = ['c', 'cprogram'], since, it's redundant, when you call bld.program(...).
P.S. Don't forget to reconfigure after modifying wscript file.