From abb8008f34e6ad7fd7665c4bb808259bce46b5b2 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 3 Dec 2018 20:26:47 +0100 Subject: [PATCH] Move bin2h and read_file into shared/, so that Nageru can also use it. --- futatabi/flow.cpp | 48 +--------------------------------- futatabi/meson.build | 6 +---- {futatabi => shared}/bin2h.cpp | 0 shared/meson.build | 7 ++++- 4 files changed, 8 insertions(+), 53 deletions(-) rename {futatabi => shared}/bin2h.cpp (100%) diff --git a/futatabi/flow.cpp b/futatabi/flow.cpp index 5125d26..a10d83b 100644 --- a/futatabi/flow.cpp +++ b/futatabi/flow.cpp @@ -5,6 +5,7 @@ #include "embedded_files.h" #include "gpu_timers.h" #include "util.h" +#include "shared/read_file.h" #include #include @@ -50,53 +51,6 @@ int find_num_levels(int width, int height) return levels; } -string read_file(const string &filename, const unsigned char *start = nullptr, const size_t size = 0) -{ - FILE *fp = fopen(filename.c_str(), "r"); - if (fp == nullptr) { - // Fall back to the version we compiled in. (We prefer disk if we can, - // since that makes it possible to work on shaders without recompiling - // all the time.) - if (start != nullptr) { - return string(reinterpret_cast(start), - reinterpret_cast(start) + size); - } - - perror(filename.c_str()); - exit(1); - } - - int ret = fseek(fp, 0, SEEK_END); - if (ret == -1) { - perror("fseek(SEEK_END)"); - exit(1); - } - - int disk_size = ftell(fp); - - ret = fseek(fp, 0, SEEK_SET); - if (ret == -1) { - perror("fseek(SEEK_SET)"); - exit(1); - } - - string str; - str.resize(disk_size); - ret = fread(&str[0], disk_size, 1, fp); - if (ret == -1) { - perror("fread"); - exit(1); - } - if (ret == 0) { - fprintf(stderr, "Short read when trying to read %d bytes from %s\n", - disk_size, filename.c_str()); - exit(1); - } - fclose(fp); - - return str; -} - GLuint compile_shader(const string &shader_src, GLenum type) { GLuint obj = glCreateShader(type); diff --git a/futatabi/meson.build b/futatabi/meson.build index 55611e8..dd94984 100644 --- a/futatabi/meson.build +++ b/futatabi/meson.build @@ -49,14 +49,10 @@ foreach shader : shaders run_command('ln', '-s', join_paths(meson.current_source_dir(), shader), meson.current_build_dir()) endforeach -bin2h = executable('bin2h', 'bin2h.cpp') -bin2h_gen = generator(bin2h, \ - output : ['@PLAINNAME@.cpp'], - arguments : ['@INPUT@', '@PLAINNAME@', '@OUTPUT@']) shader_srcs = bin2h_gen.process(shaders) srcs += shader_srcs executable('futatabi', srcs, dependencies: [shareddep, qt5deps, libjpegdep, movitdep, libmicrohttpddep, protobufdep, sqlite3dep, vax11dep, vadrmdep, x11dep, libavformatdep, libavcodecdep, libavutildep, libswscaledep], link_with: shared) -executable('flow', 'flow_main.cpp', 'flow.cpp', 'gpu_timers.cpp', shader_srcs, dependencies: [epoxydep, sdl2dep, sdl2_imagedep]) +executable('flow', 'flow_main.cpp', 'flow.cpp', 'gpu_timers.cpp', shader_srcs, dependencies: [shareddep, epoxydep, sdl2dep, sdl2_imagedep]) executable('eval', 'eval.cpp', 'util.cpp') executable('vis', 'vis.cpp', 'util.cpp') diff --git a/futatabi/bin2h.cpp b/shared/bin2h.cpp similarity index 100% rename from futatabi/bin2h.cpp rename to shared/bin2h.cpp diff --git a/shared/meson.build b/shared/meson.build index 7ef0b3f..acb2c9a 100644 --- a/shared/meson.build +++ b/shared/meson.build @@ -2,8 +2,13 @@ qt5 = import('qt5') qt5deps = dependency('qt5', modules: ['OpenGL']) libmicrohttpddep = dependency('libmicrohttpd') -srcs = ['memcpy_interleaved.cpp', 'metacube2.cpp', 'ffmpeg_raii.cpp', 'mux.cpp', 'metrics.cpp', 'context.cpp', 'httpd.cpp', 'disk_space_estimator.cpp'] +srcs = ['memcpy_interleaved.cpp', 'metacube2.cpp', 'ffmpeg_raii.cpp', 'mux.cpp', 'metrics.cpp', 'context.cpp', 'httpd.cpp', 'disk_space_estimator.cpp', 'read_file.cpp'] shared = static_library('shared', srcs, include_directories: top_include, dependencies: [qt5deps, libmicrohttpddep]) shareddep = declare_dependency( include_directories: top_include, link_with: shared) + +bin2h = executable('bin2h', 'bin2h.cpp') +bin2h_gen = generator(bin2h, \ + output : ['@PLAINNAME@.cpp'], + arguments : ['@INPUT@', '@PLAINNAME@', '@OUTPUT@']) -- 2.39.2