diff --git a/configure b/configure index e03646fc2d46f230c18a4a764ab89ca15e5d8339..ce553583144690114004dec749b13b68d87efb32 100755 --- a/configure +++ b/configure @@ -324,7 +324,7 @@ sub secondary_variables # all warnings, normal optimization, fPIC for shared library $cflags.=" -fPIC -std=gnu99 -Wall -Wformat -Wstrict-prototypes -O$opt "; - # activate extra gcc format warnings + # activate extra gcc format warnings- if($cc =~/gcc/ && stripversion($compiler_version) >= 5.0) { $cflags .= ' -Wformat-signedness '; diff --git a/meson.build b/meson.build new file mode 100644 index 0000000000000000000000000000000000000000..aa629dff46787a4bb537927fe2f76b3d91b48b6a --- /dev/null +++ b/meson.build @@ -0,0 +1,329 @@ +############################################################ +# meson build file for binary_c +# +# (c) Robert Izzard 10/11/2019 +# +############################################################ + +############################################################ +# define the binary_c project +project( + 'binary_c','c', + version : '2.1.3', + default_options : [ + 'c_std=gnu99' + ] + ) +compiler = meson.get_compiler('c') + +############################################################ +# System information +cpufreq = run_command('meson/cpu_frequency.sh').stdout().strip() + +############################################################ +# get home directory +homedir = run_command('sh','-c','echo $HOME').stdout().strip() + +############################################################ +# get binary_c root location +binary_c = meson.source_root() +binary_c_src = meson.source_root() + '/src' + +############################################################ +# SVN and git information + +git_revision = run_command('sh','-c','meson/git_revision.sh').stdout().strip() +svn_revision = run_command('sh','-c','meson/svn_revision.sh').stdout().strip() +git_url = run_command('sh','-c','meson/git_url.sh').stdout().strip() +svn_url = run_command('sh','-c','meson/svn_url.sh').stdout().strip() + +############################################################ +# default include directories +incdirs = [ '.', './src' ] +libdirs = [ './src' ] +absolute_incdirs = [ binary_c, binary_c_src ] +absolute_libdirs = [ ] + +############################################################ +# list of libraries with which we should link: libs come +# first and are appended to, postlibs come last. +libs = ['-lc','-lm'] +postlibs = ['-lc','-lm','-ldl'] + +############################################################ +# determine whether we're a debug or generic build +have_gnu99 = compiler.has_argument('-std=gnu99') +have_avx = compiler.has_argument('-mavx') + +# global C flags +#add_global_arguments('-DALIGNSIZE=16 -fPIC -std=gnu99 -Wall -Wformat-signedness -Wformat -Wstrict-prototypes -mtune=native -march=native -DCPUFREQ=3500 -DLINUX -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -fPIC -fno-stack-protector -rdynamic -fsignaling-nans -fno-finite-math-only -Og -D__DIFF_STARDATA__ -DGIT_REVISION="$(GIT_REVISION)" -DGIT_URL="$(GIT_URL)" -DGIT_BRANCH="$(GIT_BRANCH)" -D__HAVE_AVX__ -mavx -D__HAVE_DRAND48__ -D__HAVE_GSL__ -DUSE_GSL -I/home/izzard/include -D__HAVE_LIBBACKTRACE__ -D__HAVE_LIBBFD__ -D__HAVE_LIBBSD__ -D__HAVE_LIBIBERTY__ -D__HAVE_LIBMEMOIZE__ -D__HAVE_LIBRINTERPOLATE__ -D__HAVE_MALLOC_H__ -D__HAVE_PKG_CONFIG__ -D__HAVE_VALGRIND__ -D__SHOW_STARDATA__ -fsignaling-nans -fno-finite-math-only -ffast-math -fsignaling-nans -fno-finite-math-only -DCC="\"gcc\"" -DCFLAGS="\" -DALIGNSIZE=16 -fPIC -std=gnu99 -Wall -Wformat-signedness -Wformat -Wstrict-prototypes -mtune=native -march=native -DCPUFREQ=3500 -DLINUX -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -fPIC -fno-stack-protector -rdynamic -fsignaling-nans -fno-finite-math-only -Og -D__DIFF_STARDATA__ -DGIT_REVISION="$(GIT_REVISION)" -DGIT_URL="$(GIT_URL)" -DGIT_BRANCH="$(GIT_BRANCH)" -D__HAVE_AVX__ -mavx -D__HAVE_DRAND48__ -D__HAVE_GSL__ -DUSE_GSL -I_slash_home_slash_izzard_slash_include -D__HAVE_LIBBACKTRACE__ -D__HAVE_LIBBFD__ -D__HAVE_LIBBSD__ -D__HAVE_LIBIBERTY__ -D__HAVE_LIBMEMOIZE__ -D__HAVE_LIBRINTERPOLATE__ -D__HAVE_MALLOC_H__ -D__HAVE_PKG_CONFIG__ -D__HAVE_VALGRIND__ -D__SHOW_STARDATA__ -fsignaling-nans -fno-finite-math-only -ffast-math -fsignaling-nans -fno-finite-math-only\"" -DINCDIRS="\"-I. -I_slash_usr_slash_include -I_slash_home_slash_izzard_slash_include -I_slash_usr_slash_include_slash_libiberty \"" -DLD="\"gcc\"" -DLIBDIRS="\" -L. -L_slash_home_slash_izzard_slash_lib \"" -DLIBS="\" -L_slash_home_slash_izzard_slash_lib -lgsl -lgslcblas -lm -lbacktrace -lbfd -lbsd -lmemoize -lrinterpolate -lc -lm -ldl\""') + +############################################################ +# default C flags (compiler options) + +# TODO: do not omit frame pointer if profile guided +cflags = ['-fPIC','-std=gnu99','-DALIGNSIZE=16'] + +############################################################ +# optional C flags +optional_flags = ['-march=native', + '-mtune=native', + '-ffast-math', + '-fno-finite-math-only', + '-fsignaling-nans', + '-fomit-frame-pointer', + '-fvisibility=hidden', + '-fno-associative-math'] + +############################################################ +# debug C flags +if get_option('buildtype').startswith('debug') + optional_flags += [ '-rdynamic', '-O0' ] +endif + +# flags that are not strictly required, but that help a lot +foreach _flag : optional_flags + if compiler.has_argument(_flag) + cflags += _flag + endif +endforeach + + +############################################################ +# per-compiler options + +if compiler.get_id() == 'clang' + # clang flags + cflags += [] +else + # default to gcc flags + cflags += [] +endif + +libs += [] + +############################################################ +# system options +cflags += '-DCPUFREQ=' + cpufreq + +if host_machine.system() == 'linux' + # Linux system + cflags += ['-DLINUX', '-DLARGEFILE_SOURCE'] + + # check for perf_event_paranoid + _perf_event = run_command('cat','/proc/sys/kernel/perf_event_paranoid').stdout().strip() + if _perf_event == '1' or _perf_event == '2' + cflags += '-D__HAVE_PERF_EVENTS__' + endif +endif + +if compiler.compiles('int main(int argc,char **argv){return 0;}', + args : '-m64', + name : '64-bit check') + # 64-bit system + cflags += '-D_FILE_OFFSET_BITS=64' +else + # assume 32-bit system +endif + +############################################################ +# version control options + +if git_revision != '' + _flag = '-DGIT_REVISION="' + git_revision + '"' + cflags += _flag +endif +if svn_revision != '' + _flag = '-DSVN_REVISION="' + svn_revision + '"' + cflags += _flag +endif + +if git_url != '' + _flag = '-DGIT_URL="' + git_url + '"' + cflags += _flag +endif +if svn_url != '' + _flag = '-DSVN_URL="' + svn_url + '"' + cflags += _flag +endif + + +############################################################ +# dependencies that have pkg-config +libgsl_dep = dependency('gsl') + +############################################################ +# dependencies that usually have no pkg-config +# THESE NEED TO BE SET IN $LIBRARY_PATH (or $LIBPATH on Windoze) + +# required system libraries +libc_dep = compiler.find_library('c', required: true) +libm_dep = compiler.find_library('m', required: true) + +############################################################ +# dependencies + +########### +### GSL ### +########### +# todo : https://mesonbuild.com/Reference-tables.html see "Dependency lookup methods" +if libgsl_dep.found() + cflags += run_command('sh','-c','gsl-config --cflags').stdout().strip().split(' ') + cflags += '-DUSE_GSL' + libs += run_command('sh','-c','gsl-config --libs').stdout().strip().split(' ') + gsl_libdirs = run_command('sh','-c','gsl-config --libs | tr " " "\n"|grep ^-L | tr "\n" " "').stdout().strip().split(' ') + libdirs += gsl_libdirs + incdirs += run_command('sh','-c','gsl-config --prefix').stdout().strip()+'/include' +endif + +############################# +# optional libraries # +# libbacktrace, libbfd etc. # +############################# +foreach libname : ['gsl','bfd','backtrace','bsd','iberty','memoize','rinterpolate'] + _dep = compiler.find_library(libname,required:false) + if _dep.found() + cflags += '-D__HAVE_LIB' + libname.to_upper() +'__' + libs += '-l' + libname + endif +endforeach + +########### +# drand48 # +########### +if compiler.sizeof('drand48_r', + prefix : '#include <stdlib.h>') > 0 + cflags += '-D__HAVE_DRAND48__' +endif + +############ +# malloc.h # +############ +if compiler.has_header('malloc.h') + cflags += '-D__HAVE_MALLOC_H__' +endif + +################################# +# pkg-config (external command) # +################################# +if run_command('pkg-config','--version').returncode() == 0 + cflags += '-D__HAVE_PKG_CONFIG__' +endif + +########################### +# valgrind (header files) # +########################### +if compiler.has_header('valgrind/valgrind.h') + cflags += '-D__HAVE_VALGRIND__' +endif + +################### +# show_starstruct # +################### +if run_command('sh','-c','meson/make_starstruct.sh').returncode() == 0 + cflags += '-D__SHOW_STARDATA__' +endif + +################### +# diff_starstruct # +################### +if run_command('sh','-c','meson/diff_starstruct.sh').returncode() == 0 + cflags += '-D__DIFF_STARDATA__' +endif + + + +############################################################ +# make a list of include directories +my_incdirs = [] +found = false +foreach idir : [ + homedir + '/include', + '/usr/include', + '/usr/local/include', + ] + inc_arg = idir + if not found and compiler.has_header('gsl/gsl_blas.h', + args: inc_arg) + my_incdirs += [inc_arg] + found = true + endif +endforeach + +incdirs += [my_incdirs] + +############################################################ +# data objects +data_objects = run_command('meson/data_object_list.sh').stdout().strip().split(' ') + +############################################################ +# source files +sourcefiles = run_command('meson/sourcefiles.sh',).stdout().strip().split('\n') + +############################################################ +# precompile headers +# +##### BROKEN! ##### +# +############################################################ +if compiler.get_id() == 'clang' + pch_flags = '-MF binary_c.h.gch.d binary_c.h -o binary_c.h.pch' +else + pch_flags = '-MF binary_c.h.gch.d -x c-header binary_c.h' +endif + +############################################################ +# full list of libraries with which we wish to link +libs = libs + postlibs + +############################################################ +# extra quoted flags to pass into binary_c +############################################################ + +cflags_quoted = ' '.join(cflags) # turn to string +cflags_quoted = ''.join(cflags_quoted.split('"')) # remove " +cflags_quoted = '-DCFLAGS=' + ''.join(['"', cflags_quoted , '"']) # surround in " ... " +cc_quoted = '-DCC="' + compiler.get_id() + '"' +ld_quoted = '-DLD="' + compiler.get_id() + '"' +incdirs_quoted = '-DINCDIRS=' + ''.join(['"-I', ' -I'.join(absolute_incdirs),'"']) # make -I... -I... +incdirs_quoted = '_slash_'.join(incdirs_quoted.split('/')) # deslash (convert / to _slash_) +libdirs_quoted = '-DLIBDIRS=' + ''.join(['"-L', ' -L'.join(absolute_libdirs),'"']) # make -L... -L... +libdirs_quoted = '_slash_'.join(libdirs_quoted.split('/')) # deslash +libs_quoted = '-DLIBS=' + ''.join(['"', ' '.join(libs),'"']) +libs_quoted = '_slash_'.join(libs_quoted.split('/')) + + +quoted_cflags_list = [ cflags_quoted, cc_quoted, incdirs_quoted, ld_quoted, libdirs_quoted, libs_quoted ] + +############################################################ +# compiler warning flags +############################################################ +warn_flags = [] +foreach _arg : ['all','format','strict-prototypes','format-signedness'] + _warn_arg = '-W' + _arg + if compiler.has_argument(_warn_arg) + warn_flags += _warn_arg + endif +endforeach +cflags += warn_flags + +############################################################ +# make executable +executable = executable( + 'binary_c', + sources : sourcefiles, + #c_pch : 'pch/binary_c_pch.h', + include_directories: include_directories(incdirs), + dependencies : [libgsl_dep], + c_args : [ cflags, quoted_cflags_list ], + link_args : libs, + objects : data_objects, +) + + +############################################################ +# TODO: +# +# make shared library +# +# shared_library('binary_c') diff --git a/meson/cpu_frequency.sh b/meson/cpu_frequency.sh new file mode 100755 index 0000000000000000000000000000000000000000..26fa8af9098cbbe50acc7430d5a9671b8f5ba6f3 --- /dev/null +++ b/meson/cpu_frequency.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# wrapper script to show maximum CPU frequency in Mhz + + +SYSFILE="/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; + +if [ -f $SYSFILE ]; then + # standard on Linux + gawk "{print int(\$1/1000.0)}" $SYSFILE + +elif [ command sysctl >/dev/null 2>/dev/null ]; then + # this might work on a Mac + sysctl -a |gawk "{print \$2}" + +elif [ -f /proc/cpuinfo ]; then + + # crude backup: burst the CPU and look at cpuinfo + #echo "Using /proc/cpuinfo" + seq 4 | xargs -P0 -n1 timeout 0.5 yes > /dev/null + grep -i Mhz /proc/cpuinfo | gawk "{print int(\$4)}"|head -1 + +else + # default to 1000 Mhz + echo 1000 +fi + + diff --git a/meson/data_object_list.sh b/meson/data_object_list.sh new file mode 100755 index 0000000000000000000000000000000000000000..24fd33777a67222f067535c2896b37b543cc979f --- /dev/null +++ b/meson/data_object_list.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# wrapper for data_object_list.sh +cd src +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 diff --git a/meson/diff_starstruct.sh b/meson/diff_starstruct.sh new file mode 100755 index 0000000000000000000000000000000000000000..b6fd736815f9cd157f8ad8009e8dac921beaad10 --- /dev/null +++ b/meson/diff_starstruct.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# wrapper for diff_starstruct + +./src/perl/scripts/make_showstruct.pl src/binary_c_structures.h libbinary_c_stardata_t stardata\* expand_pointer_list=common,star,model,preferences,store,discs,thermal_zones outfile=src/debug/stardata_diff.h diff=1 +N=$? +[ $N -eq 0 ] || exit 1 diff --git a/meson/git_revision.sh b/meson/git_revision.sh new file mode 100755 index 0000000000000000000000000000000000000000..6fe511baf126ba22825a863b51f1b21f985e1559 --- /dev/null +++ b/meson/git_revision.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# wrapper to output the git revision + +d=`date +%Y%m%d` +c=`git rev-list --full-history --all --abbrev-commit | /usr/bin/wc -l | sed -e 's/^ *//'` +h=`git rev-list --full-history --all --abbrev-commit | head -1` +echo ${c}:${d}:${h} \ No newline at end of file diff --git a/meson/git_url.sh b/meson/git_url.sh new file mode 100755 index 0000000000000000000000000000000000000000..db3e070e358a5202a74bb02acd3b2ec3005414d2 --- /dev/null +++ b/meson/git_url.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# wrapper to output the git url +git config --get remote.origin.url \ No newline at end of file diff --git a/meson/make_starstruct.sh b/meson/make_starstruct.sh new file mode 100755 index 0000000000000000000000000000000000000000..fc6bc039aacd167a4d22aa7f61f7d677eecc57d5 --- /dev/null +++ b/meson/make_starstruct.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# wrapper for show_starstruct + +./src/perl/scripts/make_showstruct.pl src/binary_c_structures.h libbinary_c_stardata_t stardata\* expand_pointer_list=common,star,model,preferences,store,tmpstore,discs,thermal_zones outfile=src/debug/stardata.h +N=$? +echo "N = $N" +[ $N -eq 0 ] || exit 1 diff --git a/meson/sourcefiles.sh b/meson/sourcefiles.sh new file mode 100755 index 0000000000000000000000000000000000000000..16edb1d941172828fd4e65a9e4b92ad391bc4336 --- /dev/null +++ b/meson/sourcefiles.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# list binary_c source files for meson +ls src/*.c +ls src/*/*.c diff --git a/meson/svn_revision.sh b/meson/svn_revision.sh new file mode 100755 index 0000000000000000000000000000000000000000..77105805b4c9a73a3401eb9266828117f2bb4466 --- /dev/null +++ b/meson/svn_revision.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +svn info 2>&1|grep Revision|head -1|cut -d' ' -f2 | sed -e 's/\//_slash_/g' diff --git a/meson/svn_url.sh b/meson/svn_url.sh new file mode 100755 index 0000000000000000000000000000000000000000..ed3e13d8db1cf86d87a73c41fb7b9c564ca3e3d8 --- /dev/null +++ b/meson/svn_url.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +svn info .. 2>&1|grep URL|head -n 1|cut -d' ' -f2| sed -e 's/\//_slash_/g' diff --git a/src/binary_c_code_options.h b/src/binary_c_code_options.h index c49c5a3d20cc386e2ab64ef98fd6631a2fb09079..d2137d222bc7fc6231c95771c3f109cf51bfc1b6 100644 --- a/src/binary_c_code_options.h +++ b/src/binary_c_code_options.h @@ -66,7 +66,7 @@ */ #define __DO_EXPAND(M) M ## 1 #define __EXPAND(M) __DO_EXPAND(M) -#if (!defined(SVN_REVISION)||(__EXPAND(SVN_REVISION)==1)) +#if !defined(SVN_REVISION) #undef SVN_REVISION #undef SVN_URL #endif diff --git a/src/debug/backtrace-symbols.c b/src/debug/backtrace-symbols.c index b6bfce7cb22d8dbe0c05e1b7b0e5db49b7106619..87b56e81d727b48937ce321af61637799dc39e5e 100644 --- a/src/debug/backtrace-symbols.c +++ b/src/debug/backtrace-symbols.c @@ -34,7 +34,7 @@ #define _GNU_SOURCE #ifdef __HAVE_LIBIBERTY__ -#include <libiberty.h> +#include <libiberty/libiberty.h> #endif #include <string.h> #include <malloc.h> diff --git a/src/perl/scripts/make_showstruct.pl b/src/perl/scripts/make_showstruct.pl index 4b493bab18ae9c05bff68231b719fb2d14ef5f68..3fc514aeca6dd5b173a844fe59e215cedf6fc0bb 100755 --- a/src/perl/scripts/make_showstruct.pl +++ b/src/perl/scripts/make_showstruct.pl @@ -27,6 +27,12 @@ use strict; # NB This script should not use non-stanard external modules # because it will be called as part of the configure process. # +# +# Exit code: +# +# 0 on success, 1 on failure. This is REQUIRED for the meson +# build process. +# ############################################################ my $args = "@ARGV"; @@ -110,7 +116,9 @@ finalise(); output(); -exit; +# exit 0 on success: this is required for the build process +exit(0); + ############################################################ sub output @@ -205,7 +213,7 @@ sub recurse_struct else { print STDERR "We cannot yet parse >=2D arrays of nested structs\n"; - exit; + exit(1); } } else diff --git a/tbse b/tbse index 13937aecd6199e3b7d197d0ed7cdf31a771c5790..63000af9f10f1c6fa9cf5b800a874eebe624f3fb 100755 --- a/tbse +++ b/tbse @@ -167,7 +167,7 @@ RANDOM_SKIP=0 # # Core mass limits MAX_TPAGB_CORE_MASS=1.38 -CHANDRASEKHAR_MASS=1.3238 +CHANDRASEKHAR_MASS=1.44 # mass above which neutron stars collapse to black holes MAX_NEUTRON_STAR_MASS=1.8 @@ -1209,7 +1209,7 @@ TIMESTEP_MODULATOR=1.0 # below). # ############################################################ -NOVA_TIMESTEP_ACCELERATOR_NUM=0 # 100 +NOVA_TIMESTEP_ACCELERATOR_NUM=100 # 100 NOVA_TIMESTEP_ACCELERATOR_INDEX=0.5 # 0.5 NOVA_TIMESTEP_ACCELERATOR_MAX=-1 # -1