Repository: lucy-clownfish Updated Branches: refs/heads/perl_build_with_make [created] ed813dc0f
Top-down order for functions in charmonizer.main It's a matter of taste but it makes the code more readable in my opinion. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/ec8ee394 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/ec8ee394 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/ec8ee394 Branch: refs/heads/perl_build_with_make Commit: ec8ee3940536dc378ef3470e59161290ae6f9a90 Parents: f3d7d80 Author: Nick Wellnhofer <[email protected]> Authored: Wed Oct 29 20:33:35 2014 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Sat Nov 8 15:36:37 2014 +0100 ---------------------------------------------------------------------- compiler/common/charmonizer.main | 137 ++++++++++---------- runtime/common/charmonizer.main | 231 ++++++++++++++++++---------------- 2 files changed, 196 insertions(+), 172 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ec8ee394/compiler/common/charmonizer.main ---------------------------------------------------------------------- diff --git a/compiler/common/charmonizer.main b/compiler/common/charmonizer.main index 4794e7d..2c5a376 100644 --- a/compiler/common/charmonizer.main +++ b/compiler/common/charmonizer.main @@ -29,6 +29,58 @@ typedef struct SourceFileContext { } SourceFileContext; static void +S_add_compiler_flags(struct chaz_CLI *cli); + +static void +S_write_makefile(struct chaz_CLI *cli); + +static void +S_source_file_callback(const char *dir, char *file, void *context); + +int main(int argc, const char **argv) { + /* Initialize. */ + chaz_CLI *cli + = chaz_CLI_new(argv[0], "charmonizer: Probe C build environment"); + chaz_CLI_set_usage(cli, "Usage: charmonizer [OPTIONS] [-- [CFLAGS]]"); + { + int result = chaz_Probe_parse_cli_args(argc, argv, cli); + if (!result) { + chaz_Probe_die_usage(); + } + chaz_Probe_init(cli); + S_add_compiler_flags(cli); + } + + /* Define stdint types in charmony.h. */ + chaz_ConfWriter_append_conf("#define CHY_EMPLOY_INTEGERTYPES\n\n"); + chaz_ConfWriter_append_conf("#define CHY_EMPLOY_INTEGERLITERALS\n\n"); + + /* Run probe modules. */ + chaz_BuildEnv_run(); + chaz_DirManip_run(); + chaz_Headers_run(); + chaz_AtomicOps_run(); + chaz_FuncMacro_run(); + chaz_Booleans_run(); + chaz_Integers_run(); + chaz_Strings_run(); + chaz_Memory_run(); + chaz_SymbolVisibility_run(); + chaz_UnusedVars_run(); + chaz_VariadicMacros_run(); + + if (chaz_CLI_defined(cli, "enable-makefile")) { + S_write_makefile(cli); + } + + /* Clean up. */ + chaz_CLI_destroy(cli); + chaz_Probe_clean_up(); + + return 0; +} + +static void S_add_compiler_flags(struct chaz_CLI *cli) { chaz_CFlags *extra_cflags = chaz_CC_get_extra_cflags(); @@ -64,34 +116,6 @@ S_add_compiler_flags(struct chaz_CLI *cli) { } static void -S_source_file_callback(const char *dir, char *file, void *context) { - SourceFileContext *sfc = (SourceFileContext*)context; - const char *dir_sep = chaz_OS_dir_sep(); - const char *obj_ext = chaz_CC_obj_ext(); - size_t file_len = strlen(file); - char *obj_file; - - if (strcmp(file, "CFCParseHeader.c") == 0) { return; } - - /* Strip extension */ - if (file_len <= 2 || memcmp(file + file_len - 2, ".c", 2) != 0) { - chaz_Util_warn("Unexpected source file name: %s", file); - return; - } - file[file_len-2] = '\0'; - - obj_file = chaz_Util_join("", dir, dir_sep, file, obj_ext, NULL); - if (strlen(file) >= 7 && memcmp(file, "CFCTest", 7) == 0) { - chaz_MakeVar_append(sfc->test_cfc_objs, obj_file); - } - else { - chaz_MakeVar_append(sfc->common_objs, obj_file); - } - - free(obj_file); -} - -static void S_write_makefile(struct chaz_CLI *cli) { SourceFileContext sfc; @@ -248,47 +272,32 @@ S_write_makefile(struct chaz_CLI *cli) { free(test_cfc_exe); } -int main(int argc, const char **argv) { - /* Initialize. */ - chaz_CLI *cli - = chaz_CLI_new(argv[0], "charmonizer: Probe C build environment"); - chaz_CLI_set_usage(cli, "Usage: charmonizer [OPTIONS] [-- [CFLAGS]]"); - { - int result = chaz_Probe_parse_cli_args(argc, argv, cli); - if (!result) { - chaz_Probe_die_usage(); - } - chaz_Probe_init(cli); - S_add_compiler_flags(cli); - } - - /* Define stdint types in charmony.h. */ - chaz_ConfWriter_append_conf("#define CHY_EMPLOY_INTEGERTYPES\n\n"); - chaz_ConfWriter_append_conf("#define CHY_EMPLOY_INTEGERLITERALS\n\n"); +static void +S_source_file_callback(const char *dir, char *file, void *context) { + SourceFileContext *sfc = (SourceFileContext*)context; + const char *dir_sep = chaz_OS_dir_sep(); + const char *obj_ext = chaz_CC_obj_ext(); + size_t file_len = strlen(file); + char *obj_file; - /* Run probe modules. */ - chaz_BuildEnv_run(); - chaz_DirManip_run(); - chaz_Headers_run(); - chaz_AtomicOps_run(); - chaz_FuncMacro_run(); - chaz_Booleans_run(); - chaz_Integers_run(); - chaz_Strings_run(); - chaz_Memory_run(); - chaz_SymbolVisibility_run(); - chaz_UnusedVars_run(); - chaz_VariadicMacros_run(); + if (strcmp(file, "CFCParseHeader.c") == 0) { return; } - if (chaz_CLI_defined(cli, "enable-makefile")) { - S_write_makefile(cli); + /* Strip extension */ + if (file_len <= 2 || memcmp(file + file_len - 2, ".c", 2) != 0) { + chaz_Util_warn("Unexpected source file name: %s", file); + return; } + file[file_len-2] = '\0'; - /* Clean up. */ - chaz_CLI_destroy(cli); - chaz_Probe_clean_up(); + obj_file = chaz_Util_join("", dir, dir_sep, file, obj_ext, NULL); + if (strlen(file) >= 7 && memcmp(file, "CFCTest", 7) == 0) { + chaz_MakeVar_append(sfc->test_cfc_objs, obj_file); + } + else { + chaz_MakeVar_append(sfc->common_objs, obj_file); + } - return 0; + free(obj_file); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ec8ee394/runtime/common/charmonizer.main ---------------------------------------------------------------------- diff --git a/runtime/common/charmonizer.main b/runtime/common/charmonizer.main index d3a7105..cf7250d 100644 --- a/runtime/common/charmonizer.main +++ b/runtime/common/charmonizer.main @@ -47,6 +47,94 @@ static const char cfish_version[] = "0.4.0"; static const char cfish_major_version[] = "0.4"; static void +S_add_compiler_flags(struct chaz_CLI *cli); + +static void +S_write_makefile(struct chaz_CLI *cli); + +static void +S_c_file_callback(const char *dir, char *file, void *context); + +static void +S_cfh_file_callback(const char *dir, char *file, void *context); + +static int +S_ends_with(const char *string, const char *postfix); + +int main(int argc, const char **argv) { + /* Initialize. */ + chaz_CLI *cli + = chaz_CLI_new(argv[0], "charmonizer: Probe C build environment"); + chaz_CLI_register(cli, "disable-threads", "whether to disable threads", + CHAZ_CLI_NO_ARG); + chaz_CLI_set_usage(cli, "Usage: charmonizer [OPTIONS] [-- [CFLAGS]]"); + if (!chaz_Probe_parse_cli_args(argc, argv, cli)) { + chaz_Probe_die_usage(); + } + chaz_Probe_init(cli); + S_add_compiler_flags(cli); + + /* Employ integer features but don't define stdint types in charmony.h. */ + chaz_ConfWriter_append_conf( + "#define CHY_EMPLOY_INTEGERLIMITS\n" + "#define CHY_EMPLOY_INTEGERLITERALS\n" + "#define CHY_EMPLOY_INTEGERFORMATSTRINGS\n\n" + ); + + /* Run probe modules. Booleans, DirManip and LargeFiles are only needed for + * the Charmonizer tests. + */ + chaz_BuildEnv_run(); + chaz_DirManip_run(); + chaz_Headers_run(); + chaz_AtomicOps_run(); + chaz_FuncMacro_run(); + chaz_Booleans_run(); + chaz_Integers_run(); + chaz_Floats_run(); + chaz_LargeFiles_run(); + chaz_Memory_run(); + chaz_VariadicMacros_run(); + + /* Write custom postamble. */ + chaz_ConfWriter_append_conf( + "#ifdef CHY_HAS_SYS_TYPES_H\n" + " #include <sys/types.h>\n" + "#endif\n\n" + ); + chaz_ConfWriter_append_conf( + "#ifdef CHY_HAS_ALLOCA_H\n" + " #include <alloca.h>\n" + "#elif defined(CHY_HAS_MALLOC_H)\n" + " #include <malloc.h>\n" + "#elif defined(CHY_ALLOCA_IN_STDLIB_H)\n" + " #include <stdlib.h>\n" + "#endif\n\n" + ); + chaz_ConfWriter_append_conf( + "#ifdef CHY_HAS_WINDOWS_H\n" + " /* Target Windows XP. */\n" + " #ifndef WINVER\n" + " #define WINVER 0x0500\n" + " #endif\n" + " #ifndef _WIN32_WINNT\n" + " #define _WIN32_WINNT 0x0500\n" + " #endif\n" + "#endif\n\n" + ); + + if (chaz_CLI_defined(cli, "enable-makefile")) { + S_write_makefile(cli); + } + + /* Clean up. */ + chaz_CLI_destroy(cli); + chaz_Probe_clean_up(); + + return 0; +} + +static void S_add_compiler_flags(struct chaz_CLI *cli) { chaz_CFlags *extra_cflags = chaz_CC_get_extra_cflags(); @@ -91,50 +179,6 @@ S_add_compiler_flags(struct chaz_CLI *cli) { } } -static int -S_ends_with(const char *string, const char *postfix) { - size_t len = strlen(string); - size_t postfix_len = strlen(postfix); - return len >= postfix_len - && memcmp(string + len - postfix_len, postfix, postfix_len) == 0; -} - -static void -S_c_file_callback(const char *dir, char *file, void *context) { - SourceFileContext *sfc = (SourceFileContext*)context; - const char *dir_sep = chaz_OS_dir_sep(); - const char *obj_ext = chaz_CC_obj_ext(); - size_t file_len = strlen(file); - char *obj_file; - - /* Strip extension */ - if (!S_ends_with(file, ".c")) { - chaz_Util_warn("Unexpected C filename: %s", file); - return; - } - file[file_len-2] = '\0'; - - obj_file = chaz_Util_join("", dir, dir_sep, file, obj_ext, NULL); - chaz_MakeVar_append(sfc->var, obj_file); - free(obj_file); -} - -static void -S_cfh_file_callback(const char *dir, char *file, void *context) { - SourceFileContext *sfc = (SourceFileContext*)context; - const char *dir_sep = chaz_OS_dir_sep(); - char *cfh_file; - - if (!S_ends_with(file, ".cfh")) { - chaz_Util_warn("Unexpected Clownfish header filename: %s", file); - return; - } - - cfh_file = chaz_Util_join(dir_sep, dir, file, NULL); - chaz_MakeVar_append(sfc->var, cfh_file); - free(cfh_file); -} - static void S_write_makefile(struct chaz_CLI *cli) { SourceFileContext sfc; @@ -354,77 +398,48 @@ S_write_makefile(struct chaz_CLI *cli) { free(test_command); } -int main(int argc, const char **argv) { - /* Initialize. */ - chaz_CLI *cli - = chaz_CLI_new(argv[0], "charmonizer: Probe C build environment"); - chaz_CLI_register(cli, "disable-threads", "whether to disable threads", - CHAZ_CLI_NO_ARG); - chaz_CLI_set_usage(cli, "Usage: charmonizer [OPTIONS] [-- [CFLAGS]]"); - if (!chaz_Probe_parse_cli_args(argc, argv, cli)) { - chaz_Probe_die_usage(); - } - chaz_Probe_init(cli); - S_add_compiler_flags(cli); +static void +S_c_file_callback(const char *dir, char *file, void *context) { + SourceFileContext *sfc = (SourceFileContext*)context; + const char *dir_sep = chaz_OS_dir_sep(); + const char *obj_ext = chaz_CC_obj_ext(); + size_t file_len = strlen(file); + char *obj_file; - /* Employ integer features but don't define stdint types in charmony.h. */ - chaz_ConfWriter_append_conf( - "#define CHY_EMPLOY_INTEGERLIMITS\n" - "#define CHY_EMPLOY_INTEGERLITERALS\n" - "#define CHY_EMPLOY_INTEGERFORMATSTRINGS\n\n" - ); + /* Strip extension */ + if (!S_ends_with(file, ".c")) { + chaz_Util_warn("Unexpected C filename: %s", file); + return; + } + file[file_len-2] = '\0'; - /* Run probe modules. Booleans, DirManip and LargeFiles are only needed for - * the Charmonizer tests. - */ - chaz_BuildEnv_run(); - chaz_DirManip_run(); - chaz_Headers_run(); - chaz_AtomicOps_run(); - chaz_FuncMacro_run(); - chaz_Booleans_run(); - chaz_Integers_run(); - chaz_Floats_run(); - chaz_LargeFiles_run(); - chaz_Memory_run(); - chaz_VariadicMacros_run(); + obj_file = chaz_Util_join("", dir, dir_sep, file, obj_ext, NULL); + chaz_MakeVar_append(sfc->var, obj_file); + free(obj_file); +} - /* Write custom postamble. */ - chaz_ConfWriter_append_conf( - "#ifdef CHY_HAS_SYS_TYPES_H\n" - " #include <sys/types.h>\n" - "#endif\n\n" - ); - chaz_ConfWriter_append_conf( - "#ifdef CHY_HAS_ALLOCA_H\n" - " #include <alloca.h>\n" - "#elif defined(CHY_HAS_MALLOC_H)\n" - " #include <malloc.h>\n" - "#elif defined(CHY_ALLOCA_IN_STDLIB_H)\n" - " #include <stdlib.h>\n" - "#endif\n\n" - ); - chaz_ConfWriter_append_conf( - "#ifdef CHY_HAS_WINDOWS_H\n" - " /* Target Windows XP. */\n" - " #ifndef WINVER\n" - " #define WINVER 0x0500\n" - " #endif\n" - " #ifndef _WIN32_WINNT\n" - " #define _WIN32_WINNT 0x0500\n" - " #endif\n" - "#endif\n\n" - ); +static void +S_cfh_file_callback(const char *dir, char *file, void *context) { + SourceFileContext *sfc = (SourceFileContext*)context; + const char *dir_sep = chaz_OS_dir_sep(); + char *cfh_file; - if (chaz_CLI_defined(cli, "enable-makefile")) { - S_write_makefile(cli); + if (!S_ends_with(file, ".cfh")) { + chaz_Util_warn("Unexpected Clownfish header filename: %s", file); + return; } - /* Clean up. */ - chaz_CLI_destroy(cli); - chaz_Probe_clean_up(); + cfh_file = chaz_Util_join(dir_sep, dir, file, NULL); + chaz_MakeVar_append(sfc->var, cfh_file); + free(cfh_file); +} - return 0; +static int +S_ends_with(const char *string, const char *postfix) { + size_t len = strlen(string); + size_t postfix_len = strlen(postfix); + return len >= postfix_len + && memcmp(string + len - postfix_len, postfix, postfix_len) == 0; }
