From 6bdd81448a17bbf8e079dcf1d122c8c41c022696 Mon Sep 17 00:00:00 2001 From: Robert Izzard <r.izzard@surrey.ac.uk> Date: Tue, 26 Nov 2019 16:23:20 +0800 Subject: [PATCH] fix typo in docs (librinterpolate should have been libmemoize) fix issue where the linker line in meson was too long : now we build each src subdir into its own static library then link all the static libraries. This should not hit the command-line length limit. add some more meson helper scripts --- doc/binary_c2.lyx | 2 +- meson.build | 81 ++++++++++++++++++++++++-- meson/c_sourcefiles.sh | 2 +- meson/count_header_files.sh | 10 ++++ meson/count_source_files.sh | 9 +++ meson/data_object_list.sh | 2 +- meson/data_object_list_and_build.sh | 2 +- meson/h_sourcefiles.sh | 2 +- meson/header_files.sh | 6 ++ meson/source_directories.sh | 6 ++ meson/source_files.sh | 6 ++ src/main.c | 1 + src/setup/argument_setting_functions.c | 3 +- 13 files changed, 121 insertions(+), 11 deletions(-) create mode 100755 meson/count_header_files.sh create mode 100755 meson/count_source_files.sh create mode 100755 meson/header_files.sh create mode 100755 meson/source_directories.sh create mode 100755 meson/source_files.sh diff --git a/doc/binary_c2.lyx b/doc/binary_c2.lyx index 3044a721f..95962fe7d 100644 --- a/doc/binary_c2.lyx +++ b/doc/binary_c2.lyx @@ -1560,7 +1560,7 @@ git clone gitlab@gitlab.eps.surrey.ac.uk:ri0005/libmemoize.git \begin_layout Plain Layout -cd $HOME/git/librinterpolate/src +cd $HOME/git/libmemoize/src \end_layout \begin_layout Plain Layout diff --git a/meson.build b/meson.build index 352ae0ccf..99bdb1a6e 100644 --- a/meson.build +++ b/meson.build @@ -793,6 +793,70 @@ endif # We're not really interested in the static library that # results, but it gets the job done. # + +binary_c_subdir_objects = [] + +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') + +# build the objects from each subdir into their own static library +foreach src_subdir : src_subdirs + _target_name = 'binary_c_objects_' + src_subdir.underscorify() + #message('src subdir : ' + src_subdir) + + # count the number of source and header files in this subdir + _source_count = run_command('meson/count_source_files.sh',src_subdir).stdout().strip().to_int() + _header_count = run_command('meson/count_header_files.sh',src_subdir).stdout().strip().to_int() + + #message('source file count ' + _source_count.to_string()) + #message('header file count ' + _header_count.to_string()) + + # if we have source files, proceed + if _source_count > 0 + + # get a list of the source files for compilation + _sources = run_command('meson/source_files.sh',src_subdir).stdout().strip().split('\n') + #message('sources : ' + ' '.join(_sources)) + + # get the headers (or an empty list if there are none) + if _header_count > 0 + _headers = run_command('meson/header_files.sh',src_subdir).stdout().strip().split('\n') + else + _headers = [] + endif + #message('headers : ' + ' '.join(_sources)) + + # make the build target and append to binary_c_subdir_objects + binary_c_subdir_objects += build_target( + _target_name, + build_by_default: false, + pic : true, + target_type : 'static_library', + sources : [ + precompiled_headers, + _sources, + _headers, + ], + include_directories: include_directories(incdirs), + dependencies : [ + dependencies + ], + c_args : [ + cflags, + quoted_cflags_list, + ], + objects : data_objects, + link_args : [ + libs, + ], + link_language: 'c', + ) + endif +endforeach + +# binary_c objects references all the binary_c_subdir_objects +# as well as the src/*.c files binary_c_objects = build_target( 'binary_c_objects', build_by_default: true, @@ -800,20 +864,27 @@ binary_c_objects = build_target( target_type : 'static_library', # pretend we're a static library! sources : [ precompiled_headers, - c_sourcefiles, + src_root_sourcefiles, h_sourcefiles, ], include_directories: include_directories(incdirs), - dependencies : [ dependencies ], + dependencies : [ + dependencies, + ], c_args : [ cflags, - quoted_cflags_list, ], - objects : data_objects, + objects : [ + data_objects, + ], link_args : [ libs, ], - ) + link_with : [ + binary_c_subdir_objects, + ], + link_language: 'c', +) ############################################################ # diff --git a/meson/c_sourcefiles.sh b/meson/c_sourcefiles.sh index 5192c8132..31eb1cba5 100755 --- a/meson/c_sourcefiles.sh +++ b/meson/c_sourcefiles.sh @@ -1,4 +1,4 @@ #!/bin/bash # list binary_c C source files for meson -ls -1 src/*.c src/*/*.c +ls -1 ./src/*.c ./src/*/*.c diff --git a/meson/count_header_files.sh b/meson/count_header_files.sh new file mode 100755 index 000000000..26df06905 --- /dev/null +++ b/meson/count_header_files.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# count .h files in $DIR +DIR="$1" +COUNT=0 +for i in "$DIR"/*.h; do [[ -e "$i" ]] && ((COUNT = COUNT+1)); done +echo $COUNT + + + diff --git a/meson/count_source_files.sh b/meson/count_source_files.sh new file mode 100755 index 000000000..12d376859 --- /dev/null +++ b/meson/count_source_files.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# count .c files in $DIR +DIR="$1" +COUNT=0 +for i in "$DIR"/*.c; do [[ -e "$i" ]] && ((COUNT = COUNT+1)); done +echo $COUNT + + diff --git a/meson/data_object_list.sh b/meson/data_object_list.sh index 2d63dfd20..e7f8a4422 100755 --- a/meson/data_object_list.sh +++ b/meson/data_object_list.sh @@ -4,6 +4,6 @@ # list them cd src || exit -env INCDIRS="-I. -I/usr/include -I/home/izzard/include -I/usr/include/libiberty " ../data_object_list.sh | sed -e s/^/src\\// | sed s/\ /\ src\\//g +env INCDIRS="-I. -I/usr/include -I/home/izzard/include -I/usr/include/libiberty " ../data_object_list.sh | sed -e s/^/src\\// |sed -e 's/[[:space:]]*$//' | sed s/\ /\ src\\//g diff --git a/meson/data_object_list_and_build.sh b/meson/data_object_list_and_build.sh index ab616ae32..66ac3d880 100755 --- a/meson/data_object_list_and_build.sh +++ b/meson/data_object_list_and_build.sh @@ -10,6 +10,6 @@ ############################################################ # list them cd src || exit -env INCDIRS="-I. -I/usr/include -I/home/izzard/include -I/usr/include/libiberty " ../data_object_list.sh | sed -e s/^/src\\// | sed s/\ /\ src\\//g +env INCDIRS="-I. -I/usr/include -I/home/izzard/include -I/usr/include/libiberty " ../data_object_list.sh | sed -e s/^/src\\// |sed -e 's/[[:space:]]*$//'| sed s/\ /\ src\\//g diff --git a/meson/h_sourcefiles.sh b/meson/h_sourcefiles.sh index da72810b1..9a245c949 100755 --- a/meson/h_sourcefiles.sh +++ b/meson/h_sourcefiles.sh @@ -1,4 +1,4 @@ #!/bin/bash # list binary_c header source files for meson -ls -1 src/*.h src/*/*.h +ls -1 ./src/*.h ./src/*/*.h diff --git a/meson/header_files.sh b/meson/header_files.sh new file mode 100755 index 000000000..4d8d8dd17 --- /dev/null +++ b/meson/header_files.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# list .h files in $DIR +DIR="$1" +ls "$DIR"/*.h 2>/dev/null + diff --git a/meson/source_directories.sh b/meson/source_directories.sh new file mode 100755 index 000000000..2a23ba73e --- /dev/null +++ b/meson/source_directories.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# list all potential source directories +count=0 +for i in ./src/*; do test -d "$i" && echo "$i" && ((count=count+1)); done + diff --git a/meson/source_files.sh b/meson/source_files.sh new file mode 100755 index 000000000..e56b0ff28 --- /dev/null +++ b/meson/source_files.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# list .c files in $DIR +DIR="$1" +ls "$DIR"/*.c 2>/dev/null + diff --git a/src/main.c b/src/main.c index d35e5a710..47a60552f 100644 --- a/src/main.c +++ b/src/main.c @@ -38,6 +38,7 @@ int main (int argc, * options, make a stardata, then call binary_c main * with the stardata. */ + printf("ok\n"); #if !defined SEGFAULTS char * altstack = setup_segfaults(); #endif diff --git a/src/setup/argument_setting_functions.c b/src/setup/argument_setting_functions.c index 024554c24..4182dd1fc 100644 --- a/src/setup/argument_setting_functions.c +++ b/src/setup/argument_setting_functions.c @@ -10,7 +10,8 @@ static char * arg_variable_default_string( void binary_c_warmup_cpu(ARG_SUBROUTINE_DECLARATION) { (*c)++; - int secs = atoi(argv[*c]); + const int secs = atoi(argv[*c]); + printf("secs warmup %d\n",secs); if(secs!=0)warmup_cpu(stardata,secs); } -- GitLab