MAINT,TMP: Hacky replacement to be meson friendly

Generates a file by overriding printf, done globally since some of the
functions call out to other files.
This commit is contained in:
Rohit Goswami 2024-03-10 23:58:37 +00:00 committed by Mateusz Sokół
parent 69dd74dedf
commit b0ed105573
2 changed files with 61 additions and 12 deletions

View File

@ -78,7 +78,20 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
#include <string.h> #include <string.h>
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 #ifdef OS_WINDOWS
#include <windows.h> #include <windows.h>
#endif #endif
@ -1900,6 +1913,18 @@ static int get_num_cores(void) {
} }
int main(int argc, char *argv[]){ 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 #ifdef FORCE
char buffer[8192], *p, *q; char buffer[8192], *p, *q;
@ -1908,7 +1933,7 @@ int main(int argc, char *argv[]){
if (argc == 1) return 0; if (argc == 1) return 0;
switch (argv[1][0]) { switch (resp) {
case '0' : /* for Makefile */ case '0' : /* for Makefile */
@ -2075,7 +2100,11 @@ printf("ELF_VERSION=2\n");
break; break;
} }
fflush(stdout); fflush(output_stream);
// Close the file if it was opened
if (output_stream != stdout) {
fclose(output_stream);
}
return 0; return 0;
} }

View File

@ -22,12 +22,6 @@ openblas_version = f'@openblas_major_version@.@openblas_minor_version@.@openblas
# Skip the check for valid CC # Skip the check for valid CC
cc = meson.get_compiler('c') 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 # System configuration
build_single = get_option('build_single') build_single = get_option('build_single')
build_double = get_option('build_double') build_double = get_option('build_double')
@ -57,7 +51,33 @@ else
no_affinity = false no_affinity = false
endif endif
# Example for handling options: # Makefile.prebuild stuff
if build_without_lapack # TODO: Handle cpuidemu, and the target falgs
# configure build to exclude LAPACK and LAPACKE getarch = executable('getarch',
endif ['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')