diff --git a/meson.build b/meson.build index e979e2f894aff03ef731792924f41d6d222c512f..84e99cb2a405c4739d157b63904991e0771d004f 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -############################################################ +########################################################### # meson build file for binary_c # # (c) Robert Izzard 07/12/2019 @@ -46,6 +46,13 @@ project( version : '2.1.6', # should agree with binary_c_version.h ) +############################################################ +# variables for later +# +binary_c_subdir_objects = [] +binary_c_subdir_deps = [] +dependencies = [ ] + ############################################################ # require Meson 0.52.0 or later # @@ -409,10 +416,6 @@ if svn_url != '' cflags += _flag endif -############################################################ -# dependencies are put in the list called dependencies -# -dependencies = [ ] ############################################################ # dependencies that usually have no pkg-config @@ -668,30 +671,7 @@ endif # run_command('meson/make_version_macros.pl') -############################################################ -# data objects -# -# list and build them -if os != 'darwin' - message('Checking and building data objects') - - data_objects_compilation = run_command('meson/data_object_list_and_build.sh') - - if data_objects_compilation.returncode() != 0 - error('There was a problem building the data objects. Please check that you have objcopy installed, and try running meson/data_object_list_and_build.sh from the binary_c root directory manually to check for errors') - endif - data_objects = data_objects_compilation.stdout().strip().split(' ') - - if get_option('clean_data_objects') == true - run_command('meson/clean_data_objects.sh') - endif -else - data_objects = [] -endif -############################################################ -# data objects V2 -# ############################################################ @@ -870,6 +850,67 @@ else endif + + +############################################################ +# data objects +# +# list and build them +#if os != 'darwin' +if 1 == 1 + message('Checking and building data objects') + + data_objects_compilation = run_command('meson/data_object_list_and_build.sh') + + if data_objects_compilation.returncode() != 0 + error('There was a problem building the data objects. Please check that you have objcopy installed, and try running meson/data_object_list_and_build.sh from the binary_c root directory manually to check for errors') + endif + data_objects = data_objects_compilation.stdout().strip().split(' ') + + if get_option('clean_data_objects') == true + run_command('meson/clean_data_objects.sh') + endif +else + + + data_object_sourcefiles = run_command('meson/data_object_list_files.sh') + + if data_object_sourcefiles.returncode() != 0 + error('There was a problem identifying the data object source file.') + endif + + # get data objects source (.h) files + data_objects_source = run_command('meson/data_object_list_files.sh').stdout().strip().split(' ') + + # list data objects (.o) files + data_objects_files = run_command('meson/make_data_object.sh', + 'dummy', + data_objects_source).stdout().strip().split(' ') + + # build data objects + data_objects = custom_target( + 'binary_c_data_objects', + input: [ + data_objects_source, + ], + command: [ + 'meson/make_data_object.sh', + 'build', + '@INPUT@', + ], + output: [ + ], + ) + + binary_c_subdir_deps += declare_dependency( + sources: data_objects + ) + + data_objects = [] + +endif + + ############################################################ # command to install binary_c in its 'legacy' locations # (required for binary_grid2) @@ -952,8 +993,6 @@ endif # many .o files and this makes the command line too long # (even in Linux) which means the linking fails. # -binary_c_subdir_objects = [] -binary_c_subdir_deps = [] src_subdirs = run_command('meson/source_directories.sh').stdout().strip().split('\n') src_root_sourcefiles = run_command('meson/source_files.sh','./src').stdout().strip().split('\n') diff --git a/meson/data_object_list_files.sh b/meson/data_object_list_files.sh new file mode 100755 index 0000000000000000000000000000000000000000..bcda5fd83f802290c7a2deabedc32515bda3f3da --- /dev/null +++ b/meson/data_object_list_files.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# list of source files associated with data objects +meson/data_object_list.sh | sed 's/.o\ /.h\ /g' | sed 's/.o$/.h/' diff --git a/meson/make_data_object.sh b/meson/make_data_object.sh new file mode 100755 index 0000000000000000000000000000000000000000..5a6374847082f6aaf88e4895c36fa120ed2a2328 --- /dev/null +++ b/meson/make_data_object.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +#!/bin/bash + +# make generic data objects for binary_c +# http://gareus.org/wiki/embedding_resources_in_executables + +: "${CC:="gcc"}" +: "${OBJCOPY_ARCH:=$(objdump -f /bin/bash |grep architecture | gawk "{print \$2}" | sed s/,//)}" +: "${OBJCOPY_TARGET:=$(objdump -f /bin/bash | grep format | gawk "{print \$4}")}" +: "${OBJCOPY_OPTS:="-I binary -B $OBJCOPY_ARCH -O $OBJCOPY_TARGET"}" +#: "${OBJCOPY_SUBOPTS:="--rename-section .data=.rodata,alloc,load,readonly,data,contents "}" + +OBJCOPY_SUBOPTS="" +DBUILT="false" + +COMMAND=$1 +shift + +for HFILE in "$@"; do + + TMPFILE=$(printf "%s" "$HFILE" | sed s/\.h$/.tmp/) + OBJFILE=$(printf "%s/%s" "${MESON_BUILD_ROOT}" "$HFILE" | sed s/\.h$/.o/ | sed s/\\//_/g) + + #echo "H $HFILE" + #echo "T $TMPFILE" + #echo "O $OBJFILE" + + if [ "$COMMAND" = "build" ] ; then + if [ "$HFILE" -nt "$OBJFILE" ] ; then + if [ "$DBUILT" = true ]; then + # first time, build double2bin + $CC double2bin.c -o ./double2bin + fi + tr , ' ' < "$HFILE" | sed s/\\\\// | grep -v define |grep -v "\\*" | ./double2bin > "$TMPFILE" + objcopy $OBJCOPY_OPTS $OBJCOPY_SUBOPTS "$TMPFILE" "$OBJFILE" + rm "$TMPFILE" + DBUILT=true + fi + fi + + echo -n "$OBJFILE " + #ls -l $OBJFILE + #echo +done + +echo diff --git a/src/API/binary_c_help_all.c b/src/API/binary_c_help_all.c new file mode 100644 index 0000000000000000000000000000000000000000..1e492e24d9bbbc549b313c28f864e583be996585 --- /dev/null +++ b/src/API/binary_c_help_all.c @@ -0,0 +1,31 @@ +#include "../binary_c.h" + +#ifdef BINARY_C_API + +void binary_c_API_function binary_c_help_all(struct stardata_t * RESTRICT const stardata) +{ + /* + * API function to put help associated arguments into the + * buffer. stardata must be non-NULL for this to work, + * because the buffer must be defined. + */ + if(stardata != NULL) + { + struct tmpstore_t * tmpstore = stardata->tmpstore; + if(tmpstore == NULL) + { + build_tmpstore_contents(tmpstore); + stardata->tmpstore = tmpstore; + } + binary_c_help_all_from_arg( + tmpstore->cmd_line_args, + stardata, // required for the buffer + NULL, // dummy pointer + 0, // dummy var + tmpstore->arg_count, // arg_count + NULL, // dummy pointer + -1 // must be negative + ); + } +} +#endif//BINARY_C_API