diff --git a/getarch.c b/getarch.c index 842a843fa..e55aa70ca 100644 --- a/getarch.c +++ b/getarch.c @@ -78,7 +78,20 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #include +#include #include +FILE *output_stream = NULL; +int custom_printf(const char *format, ...) { + va_list args; + va_start(args, format); + int ret = vfprintf(output_stream, format, args); + va_end(args); + return ret; +} + +// Redefine printf to custom_printf +#define printf custom_printf + #ifdef OS_WINDOWS #include #endif @@ -1900,6 +1913,18 @@ static int get_num_cores(void) { } int main(int argc, char *argv[]){ + char resp = argv[1][0]; + if (argc > 1 && resp == '3') { + output_stream = fopen("config.h", "w"); + if (!output_stream) { + perror("Failed to open config.h for writing"); + return 1; + } + // Always generate config.h + resp = '1'; + } else { + output_stream = stdout; + } #ifdef FORCE char buffer[8192], *p, *q; @@ -1908,7 +1933,7 @@ int main(int argc, char *argv[]){ if (argc == 1) return 0; - switch (argv[1][0]) { + switch (resp) { case '0' : /* for Makefile */ @@ -2075,7 +2100,11 @@ printf("ELF_VERSION=2\n"); break; } - fflush(stdout); + fflush(output_stream); + // Close the file if it was opened + if (output_stream != stdout) { + fclose(output_stream); + } return 0; } diff --git a/meson.build b/meson.build index fb2aed30a..b6d40508c 100644 --- a/meson.build +++ b/meson.build @@ -22,12 +22,6 @@ openblas_version = f'@openblas_major_version@.@openblas_minor_version@.@openblas # Skip the check for valid CC cc = meson.get_compiler('c') -# Makefile.system -# Ignoring all the hostarch checks and conflits for arch in BSD for now -_inc = include_directories('.') -# subdir('lapack-netlib') -subdir('interface') - # System configuration build_single = get_option('build_single') build_double = get_option('build_double') @@ -57,7 +51,33 @@ else no_affinity = false endif -# Example for handling options: -if build_without_lapack - # configure build to exclude LAPACK and LAPACKE -endif +# Makefile.prebuild stuff +# TODO: Handle cpuidemu, and the target falgs +getarch = executable('getarch', + ['getarch.c', 'cpuid.S']) +getarch_two = executable('getarch_2nd', + ['getarch_2nd.c']) +config_h = custom_target('gen_config_h', + # input: ['getarch.c'], + output: ['config.h'], + command: [getarch, '3'] + ) + +# run_target('generate_config_h', +# command: [meson.current_build_dir() + '/getarch', '1'], +# depends: getarch) + +# gch = run_command(meson.current_build_dir() + '/getarch', '1') +# outp = gch.stdout().strip() + +# conf_data = configuration_data() +# configure_file(input : meson.current_build_dir() + '/config.h', +# output : 'config.h', +# configuration : conf_data) + +# Makefile.system +# Ignoring all the hostarch checks and conflicts for arch in BSD for now +_inc = include_directories('.') +# subdir('lapack-netlib') +subdir('interface') +# subdir('kernel')