diff --git a/scconfig/src/default/.svn/entries b/scconfig/src/default/.svn/entries deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/default/.svn/entries +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/default/.svn/format b/scconfig/src/default/.svn/format deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/default/.svn/format +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/default/.svn/pristine/05/05fb3ec6dba50036ca9ab2442886da16bdc7e818.svn-base b/scconfig/src/default/.svn/pristine/05/05fb3ec6dba50036ca9ab2442886da16bdc7e818.svn-base deleted file mode 100644 index 7f1e7abc..00000000 --- a/scconfig/src/default/.svn/pristine/05/05fb3ec6dba50036ca9ab2442886da16bdc7e818.svn-base +++ /dev/null @@ -1,194 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "log.h" -#include "libs.h" -#include "db.h" -#include "dep.h" -#include "regex.h" - -static void zap(char **str) -{ - const char *pat = get("/arg/sys/pkg-config-zap"); - char *n; - - if (pat == NULL) - return; - if (re_comp(pat) != NULL) - return; - while (re_exec(*str)) { - n = re_subs_dup(""); - free(*str); - *str = n; - } -} - -int run_gen_config(int logdepth, const char *confname, const char *pkgname, char **cflags, char **ldflags) -{ - char cmd[256]; - - if (strlen(confname) + strlen(pkgname) > sizeof(cmd) - 16) { - logprintf(logdepth, "run_gen_config(): confname and/or pkgname too long\n"); - return -1; - } - - if (cflags != NULL) { - sprintf(cmd, "%s --cflags %s", confname, pkgname); - if (run(logdepth, cmd, cflags) != 0) { - report("not found: %s --cflags failed.", confname); - logprintf(logdepth, "not found: %s --cflags failed.\n", confname); - return -1; - } - if (*cflags != NULL) { - zap(cflags); - strip(*cflags); - } - } - - if (ldflags != NULL) { - sprintf(cmd, "%s --libs %s", confname, pkgname); - if (run(logdepth, cmd, ldflags) != 0) { - report("not found: %s --libs failed.", confname); - logprintf(logdepth, "not found: %s --libs failed.\n", confname); - if (cflags != NULL) - free(*cflags); - return -1; - } - if (*ldflags != NULL) { - zap(ldflags); - strip(*ldflags); - } - } - - return 0; -} - -const char *pkg_config_name() -{ - const char *name; - name = get("/arg/sys/pkg-config"); - if (name != NULL) - return name; - return "pkg-config"; /* fallback */ -} - -/** run_pkg_config_modversion: - run `pkg-config` on @pkgname: - - with `--modversion` if @modversion is not NULL, storing the result in @modversion (malloc()'d) - Returns 0 on success. -*/ -int run_pkg_config_modversion(int logdepth, const char *pkgname, char **modversion) -{ - char cmd[256]; - const char *confname = pkg_config_name(); - - if (strlen(confname) + strlen(pkgname) > sizeof(cmd) - 16) { - logprintf(logdepth, "run_pkg_config_modversion(): confname and/or pkgname too long\n"); - return -1; - } - - if (modversion != NULL) { - sprintf(cmd, "%s --modversion %s", confname, pkgname); - if (run(logdepth, cmd, modversion) != 0) { - /*report("Module version not found: %s --modversion %s failed.", confname, pkgname); - logprintf(logdepth, "Module version not found: %s --modversion %s failed.\n", confname, pkgname); */ - return -1; - } - zap(modversion); - strip(*modversion); - } - - return 0; -} - -/** run_pkg_config_modversion_db: - run `pkg-config --modversion` on @pkgname to find module (or package) version - and store the result in @node/modversion - Returns 0 on success. -*/ -int run_pkg_config_modversion_db(int logdepth, const char *node, const char *pkgname /*, char **modversion */ ) -{ - char *modversion; - char *tmp; - - if (run_pkg_config_modversion(logdepth, pkgname, &modversion) != 0) { - return -1; - } - /* Store the module version in node */ - tmp = str_concat("/", node, "modversion", NULL); - put(tmp, modversion); - free(tmp); - free(modversion); - - return 0; -} - -int run_pkg_config(int logdepth, const char *pkgname, char **cflags, char **ldflags) -{ - - return run_gen_config(logdepth, pkg_config_name(), pkgname, cflags, ldflags); -} - -void run_pkg_config_lst(int logdepth, const char *pkgpat, int *argc, char ***argv) -{ - char *end, *s, *next; - int n = 0, a = 0; - char **sf = NULL; - static const char *pkg_cfg_cache = NULL; - static char no_pkg_cfg; - char *list; - - if (pkg_cfg_cache == &no_pkg_cfg) - goto error; - - if (pkg_cfg_cache == NULL) { - char *cmd = str_concat(" ", pkg_config_name(), "--list-all", NULL); - run(logdepth, cmd, (char **) &pkg_cfg_cache); - free(cmd); - if (pkg_cfg_cache == NULL) { - pkg_cfg_cache = &no_pkg_cfg; - goto error; - } - } - - if (re_comp(pkgpat) != NULL) - goto error; - - s = list = strclone(pkg_cfg_cache); - for (;;) { - while (isspace(*s)) - s++; - if (*s == '\0') - break; - next = strpbrk(s, "\r\n"); - if (next != NULL) - *next = '\0'; - if (re_exec(s)) { - if ((n + 2) >= a) { /* n+2: make sure there's always room for the NULL at the end */ - a += 16; - sf = realloc(sf, sizeof(char *) * a); - } - end = strpbrk(s, " \t"); - if (end != NULL) - *end = '\0'; - - sf[n] = strclone(s); - sf[n + 1] = re_subs_dup(""); -/* report("\ns='%s' sf='%s'\n", s, sf[n]);*/ - n += 2; - } - s = next + 1; - } - - if (sf != NULL) - sf[n] = NULL; - - free(list); -error:; - *argc = n; - *argv = sf; - return; -} diff --git a/scconfig/src/default/.svn/pristine/06/064c1b7ecd2a31714f6845ba4c1d25206ac7509c.svn-base b/scconfig/src/default/.svn/pristine/06/064c1b7ecd2a31714f6845ba4c1d25206ac7509c.svn-base deleted file mode 100644 index a50f48ac..00000000 --- a/scconfig/src/default/.svn/pristine/06/064c1b7ecd2a31714f6845ba4c1d25206ac7509c.svn-base +++ /dev/null @@ -1,106 +0,0 @@ -/* - scconfig - command line argument processing - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include "db.h" -#include "arg.h" -#include "dep.h" -#include "log.h" -#include "libs.h" - -argtbl_t main_argument_table[] = { - {"import", NULL, import_args, "Import saved config (sub)tree"}, - {"target", "/arg/sys/target", NULL, "set cross compilation target (prefix)"}, - {"target-name", "/arg/sys/target-name", NULL, "set cross compilation target (system name)"}, - {"target-shell","/arg/sys/target-shell",NULL, "set the shell on cross compilation target"}, - {"emu", "/arg/sys/emu", NULL, "emulator for testing cross compiled executables with"}, - {"pkg-config", "/arg/sys/pkg-config", NULL, "path to pkg-config to use"}, - {"pkg-config-zap","/arg/sys/pkg-config-zap",NULL, "ignore pkg-config results by this regex pattern"}, - -/* wildcard rules for icl() control */ - {"^ldflags/", NULL, import_icl, NULL}, - {"^cflags/", NULL, import_icl, NULL}, - {"^includes/", NULL, import_icl, NULL}, - {"^prefix/", NULL, import_icl, NULL}, - -/* the followings are autoconf compatibility translations */ - {"CC", "/arg/cc/cc", NULL, "Force using a C compiler (command line)"}, - {"CFLAGS", "/arg/cc/cflags", NULL, "Force using a CFLAGS for C compilation"}, - {"LDFLAGS", "/arg/cc/ldflags", NULL, "Force using a LDFLAGS for linking"}, - {"LDL", "/arg/libs/ldl", NULL, "Force using -ldl string"}, - - {"gpmi-prefix", "/arg/gpmi/prefix", NULL, NULL}, - {NULL, NULL, NULL, NULL} -}; - -void process_args(int argc, char *argv[]) -{ - int n; - char *key, *value; - argtbl_t *a; - int found, tainted = 0; - - db_mkdir("/arg"); - - logprintf(0, "CLI arg 0: '%s'\n", argv[0]); - for(n = 1; n < argc; n++) { - key = argv[n]; - logprintf(0, "CLI arg %d: '%s'\n", n, key); - while(*key == '-') key++; - value = str_chr(key, '='); - found = 0; - if (value != NULL) { - *value = '\0'; - value++; - /* Look in the argument translate table */ - for(a = main_argument_table; a->arg != NULL; a++) { - if (((a->arg[0] == '^') && (strncmp(a->arg+1, key, strlen(a->arg+1)) == 0)) || (strcmp(a->arg, key) == 0)) { - found = 1; - if (a->callback != NULL) { - if (a->callback(key, value) != 0) { - error("Processing argument '%s' failed in the callback\n", argv[n]); - abort(); - } - } - if (a->path != NULL) - put(a->path, value); - } - } - /* Look in known deps table or /arg */ - if (found == 0) { - if ((is_dep_known(key)) || (strncmp(key, "/arg/", 5) == 0)) { - put(key, value); - found = 1; - } - } - } - if (found == 0) { - if (custom_arg(key, value) == 0) { - error("Unknown argument '%s'\n", key); - tainted++; - } - } - } - if (tainted) - exit(1); -} diff --git a/scconfig/src/default/.svn/pristine/07/07d35b456a77b4b070121075ae3e692017167b68.svn-base b/scconfig/src/default/.svn/pristine/07/07d35b456a77b4b070121075ae3e692017167b68.svn-base deleted file mode 100644 index afd015c3..00000000 --- a/scconfig/src/default/.svn/pristine/07/07d35b456a77b4b070121075ae3e692017167b68.svn-base +++ /dev/null @@ -1,122 +0,0 @@ -/* - scconfig - detection of standard library features: strings - Copyright (C) 2017 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_strcasecmp(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " if ((strcasecmp(\"foo\", \"FoO\") == 0) && (strcasecmp(\"foo\", \"bar\") != 0))" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for strcasecmp()... "); - logprintf(logdepth, "find_fs_strcasecmp: trying to find strcasecmp...\n"); - logdepth++; - - if (try_icl(logdepth, "str/strcasecmp", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "str/strcasecmp"); -} - - -int find_strncasecmp(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " if ((strncasecmp(\"foo1\", \"FoO2\", 3) == 0) && (strncasecmp(\"foo1\", \"bar2\", 3) != 0))" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for strncasecmp()... "); - logprintf(logdepth, "find_fs_strncasecmp: trying to find strncasecmp...\n"); - logdepth++; - - if (try_icl(logdepth, "str/strncasecmp", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "str/strncasecmp"); -} - - -int find_stricmp(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " if ((stricmp(\"foo\", \"FoO\") == 0) && (stricmp(\"foo\", \"bar\") != 0))" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for stricmp()... "); - logprintf(logdepth, "find_fs_stricmp: trying to find stricmp...\n"); - logdepth++; - - if (try_icl(logdepth, "str/stricmp", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "str/stricmp"); -} - - -int find_strnicmp(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " if ((strnicmp(\"foo1\", \"FoO2\", 3) == 0) && (strnicmp(\"foo1\", \"bar2\", 3) != 0))" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for strnicmp()... "); - logprintf(logdepth, "find_fs_strnicmp: trying to find strnicmp...\n"); - logdepth++; - - if (try_icl(logdepth, "str/strnicmp", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "str/strnicmp"); -} - diff --git a/scconfig/src/default/.svn/pristine/0b/0b3b778890420625ba71f0e2e1cf2522f42f657f.svn-base b/scconfig/src/default/.svn/pristine/0b/0b3b778890420625ba71f0e2e1cf2522f42f657f.svn-base deleted file mode 100644 index 58c35e37..00000000 --- a/scconfig/src/default/.svn/pristine/0b/0b3b778890420625ba71f0e2e1cf2522f42f657f.svn-base +++ /dev/null @@ -1,203 +0,0 @@ -/* - scconfig - detection of standard library features - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -static int trydlc(int logdepth, const char *test_c_dlc, const char *cflagsf, const char *ldflagsf, const char *dlc) -{ - char *cflags, *ldflags; - - cflags = malloc(strlen(dlc) + 64); - ldflags = malloc(strlen(dlc)*2 + 256); - sprintf(cflags, cflagsf, dlc); - sprintf(ldflags, ldflagsf, dlc, dlc); - if (try_icl(logdepth, NULL, test_c_dlc, NULL, cflags, ldflags)) { - *cflags = ' '; - append("cc/cflags", cflags); - put("libs/ldl", ldflags); - put("libs/dl-compat", strue); - report("OK (%s and %s)\n", cflags, ldflags); - free(cflags); - free(ldflags); - return 1; - } - free(cflags); - free(ldflags); - return 0; -} - -int find_lib_ldl(const char *name, int logdepth, int fatal) -{ - const char *ldl, *dlc; - char *s; - - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " void *handle;" - NL " handle = dlopen(\"/this file does not exist.\", RTLD_NOW);" - NL " if (handle == NULL) printf(\"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - char *test_c_dlc = - NL "#include " - NL "#include " - NL "int main() {" - NL " void *handle;" - NL " handle = dlopen(\"/this file does not exist.\", RTLD_NOW);" - NL " if (handle == NULL) printf(\"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - s = get("libs/ldl/presents"); - if (s != NULL) - return !istrue(s); - - require("cc/cc", logdepth, fatal); - - report("Checking for -ldl... "); - logprintf(logdepth, "find_lib_ldl: trying to find ldl...\n"); - logdepth++; - - ldl = get("/arg/libs/ldl"); - if (ldl == NULL) { - dlc = get("/arg/libs/dl-compat"); - - if (dlc == NULL) { - /* If dlc is not explicitly requested by the user, try standard - dl (see whether we need -ldl for dlopen()) */ - if (try_icl(logdepth, NULL, test_c, NULL, NULL, NULL)) { - put("libs/ldl", ""); - put("libs/ldl/includes", "#include \\n"); - put("libs/ldl/presents", strue); - report("OK ()\n"); - return 0; - } - if (try_icl(logdepth, NULL, test_c, NULL, NULL, "-ldl")) { - put("libs/ldl", "-ldl"); - put("libs/ldl/includes", "#include \\n"); - put("libs/ldl/presents", strue); - report("OK (-ldl)\n"); - return 0; - } - } - /* try dl-compat (dl compatibility lib) */ - if (dlc != NULL) { - /* test at user supplied dlc prefix: - - first assume the linker will find it - - next assume gcc and pass rpath to the linker - - finally try static linking */ - if (trydlc(logdepth, test_c_dlc, "-I%s/include", "-L%s/lib -ldl-compat\000%s", dlc)) { - put("libs/ldl/includes", "#include \\n"); - return 0; - } - if (trydlc(logdepth, test_c_dlc, "-I%s/include", "-L%s/lib -Wl,-rpath=%s/lib -ldl-compat", dlc)) { - put("libs/ldl/includes", "#include \\n"); - return 0; - } - if (trydlc(logdepth, test_c_dlc, "-I%s/include", "%s/lib/libdl-compat.a\000%s", dlc)) { - put("libs/ldl/includes", "#include \\n"); - return 0; - } - } - else if (try_icl(logdepth, NULL, test_c_dlc, NULL, NULL, "-ldl-compat")) { - /* check at normal system installation */ - put("libs/ldl", "-ldl-compat"); - put("libs/ldl/includes", "#include \\n"); - put("libs/ldl/presents", strue); - report("OK (-ldl-compat)\n"); - return 0; - } - } - else { - report("User provided... "); - s = strclone(ldl); - if (try_icl(logdepth, NULL, test_c, NULL, NULL, s)) { - put("libs/ldl", ldl); - put("libs/ldl/includes", "#include \\n"); - put("libs/ldl/presents", strue); - report("OK (%s)\n", ldl); - free(s); - return 0; - } - free(s); - } - put("libs/ldl/presents", sfalse); - report("Not found\n"); - return 1; -} - -int find_lib_LoadLibrary(const char *name, int logdepth, int fatal) -{ - /*char *s;*/ - - char *test_c = - NL "#include " - NL "int main() {" - NL " void *handle;" - NL " handle = LoadLibrary(\"/this file does not exist.\");" - NL " if (handle == NULL) printf(\"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for LoadLibrary... "); - logprintf(logdepth, "find_lib_LoadLibrary: trying to find LoadLibrary...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/LoadLibrary", test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/LoadLibrary"); -} - -int find_lib_errno(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " errno = 0;" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for errno.h... "); - logprintf(logdepth, "find_lib_errno: trying to find errno...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/errno", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/errno"); -} diff --git a/scconfig/src/default/.svn/pristine/1e/1e62b9dcab50a9e652b45132847aba0e0304e2f6.svn-base b/scconfig/src/default/.svn/pristine/1e/1e62b9dcab50a9e652b45132847aba0e0304e2f6.svn-base deleted file mode 100644 index 7817a24b..00000000 --- a/scconfig/src/default/.svn/pristine/1e/1e62b9dcab50a9e652b45132847aba0e0304e2f6.svn-base +++ /dev/null @@ -1,1134 +0,0 @@ -/* - scconfig - detection of cc and compiler features - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - - - -static int try_flags(int logdepth, const char *cc, const char *test_c, const char *cflags, const char *ldflags, const char *expected) -{ - char *out; - - logprintf(logdepth, "trying cc:try_flags with cc='%s' cflags='%s' ldflags='%s'\n", (cc == NULL ? get("cc/cc") : cc), cflags == NULL ? "" : cflags, ldflags == NULL ? "" : ldflags); - - if (compile_run(logdepth+1, test_c, cc, cflags, ldflags, &out) == 0) { - if (((out == NULL) && (iscross)) || (strncmp(out, expected, strlen(expected)) == 0)) { - free(out); - return 1; - } - free(out); - } - return 0; -} - -static int try_flags_inv(int logdepth, const char *cc, const char *test_c, const char *cflags, const char *ldflags, const char *expected_bad) -{ - char *out; - - logprintf(logdepth, "trying cc:try_flags with cc='%s' cflags='%s' ldflags='%s'\n", (cc == NULL ? get("cc/cc") : cc), cflags == NULL ? "" : cflags, ldflags == NULL ? "" : ldflags); - - if (compile_run(logdepth+1, test_c, cc, cflags, ldflags, &out) == 0) { - if (((out == NULL) && (iscross)) || (strncmp(out, expected_bad, strlen(expected_bad)) != 0)) { - free(out); - return 1; - } - free(out); - } - return 0; -} - -static int try(int logdepth, const char *cc, const char *test_c, const char *expected) -{ - return try_flags(logdepth, cc, test_c, NULL, NULL, expected); -} - - -static int trycc(int logdepth, const char *cc, const char *test_c) -{ - int ret; - - if (cc == NULL) - return 0; - - ret = try(logdepth, cc, test_c, "OK"); - if (ret) - put("cc/cc", cc); - return ret; -} - -int find_cc(const char *name, int logdepth, int fatal) -{ - char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL, *targetcc; - const char *cc, *cflags, *ldflags, *target, *sys; - int len; - - require("sys/name", logdepth, fatal); - - sys = istarget(db_cwd) ? "target" : "host"; - report("Checking for cc (%s)... ", sys); - logprintf(logdepth, "find_cc: trying to find cc (%s)...\n", sys); - logdepth++; - - /* cflags */ - cflags = get("/arg/cc/cflags"); - if (cflags != NULL) { - logprintf(logdepth+1, "using user supplied cflags '%s'\n", cflags); - put("cc/cflags", cflags); - } - - /* ldflags */ - ldflags = get("/arg/cc/ldflags"); - if (ldflags != NULL) { - logprintf(logdepth+1, "using user supplied ldflags '%s'\n", ldflags); - put("cc/ldflags", ldflags); - } - - cc = get("/arg/cc/cc"); - if (cc == NULL) { - target = get("sys/target"); - if (target != NULL) { - logprintf(logdepth+1, "find_cc: crosscompiling for '%s', looking for target cc\n", target); - len = strlen(target); - targetcc = malloc(len + 8); - memcpy(targetcc, target, len); - strcpy(targetcc + len, "-gcc"); - if (!trycc(logdepth+1, targetcc, test_c)) { - strcpy(targetcc + len, "-cc"); - if (!trycc(logdepth+1, targetcc, test_c)) { - report("FAILED: failed to find crosscompiler for target '%s'\n", target); - logprintf(logdepth, "find_cc: FAILED to find a crosscompiler for target '%s'\n", target); - return 1; - } - } - put("cc/cc", targetcc); - } - else { - cc = getenv("CC"); - logprintf(logdepth, "find_cc: Detecting cc (host)\n"); - /* Find a working cc (no arguments) */ - if (!(((cc != NULL) && (trycc(logdepth+1, cc, test_c))) || trycc(logdepth+1, "gcc", test_c) || trycc(logdepth+1, "cc", test_c))) { - report("FAILED to find a compiler\n"); - logprintf(logdepth, "find_cc: FAILED to find a compiler\n"); - return 1; - } - } - } - else { - put("cc/cc", cc); - logprintf(logdepth+1, "using user supplied '%s' (will test later)\n", cc); - } - - /* cflags (again) */ - if (cflags == NULL) { - logprintf(logdepth, "find_cc: Detecting -pipe\n"); - - if (compile_run(logdepth+1, test_c, NULL, "-pipe", "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - append("cc/cflags", " -pipe"); - } - free(out); - } - } - if (get("cc/cflags") == NULL) - put("cc/cflags", ""); - - /* ldflags (again) */ - if (get("cc/ldflags") == NULL) - put("cc/ldflags", ""); - - /* Final test of all arguments together */ - logprintf(logdepth, "find_cc: final test on cc and all flags \n"); - if (compile_run(logdepth+1, test_c, NULL, NULL, NULL, &out) != 0) { - report("FAILED to get the compiler and all flags to work together\n"); - logprintf(logdepth, "find_cc: the compiler and all the flags don't work well together, aborting\n"); - if (out != NULL) - free(out); - return 1; - } - - report("OK ('%s', '%s', '%s')\n", get("cc/cc"), get("cc/cflags"), get("cc/ldflags")); - logprintf(logdepth, "find_cc: conclusion: cc='%s' cflags='%s' ldflags='%s'\n", get("cc/cc"), get("cc/cflags"), get("cc/ldflags")); - if (out != NULL) - free(out); - return 0; -} - -int find_cc_argstd(const char *det_name, int logdepth, int fatal) -{ - char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL; - char **flg, *flags[] = {"-ansi", "-pedantic", "-Wall", "-std=c89", "-std=c99", "-Werror", "-Wextra", "-W", "-pg", "-no-pie", "-static-pie", NULL}; - const char *det_target = det_list_target(det_name); - - require("cc/cc", logdepth, fatal); - - logprintf(logdepth, "find_cc: Detecting CC args %s\n", det_target); - report("Checking for cc args for std %s... ", det_target); - - for(flg = flags; *flg != NULL; flg++) { - char name[128], *end; - const char *found = ""; - sprintf(name, "cc/argstd/%s", (*flg)+1); - end = strchr(name, '='); - if (end != NULL) - *end = '_'; - if (!asked_for(name, det_name)) - continue; - if (compile_run(logdepth+1, test_c, NULL, *flg, "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - found = *flg; - report(" "); - report(found); - } - free(out); - } - put(name, found); - } - - if (is_dep_wild(det_name)) - put("cc/argstd/presents", strue); /* to avoid re-detection*/ - - report("\n"); - return 0; -} - -int find_cc_argmachine(const char *name, int logdepth, int fatal) -{ -#define ARGM(flag) "-m" #flag , "-mno-" #flag - const char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL; - const char **flg, *flags[] = { ARGM(mmx), ARGM(sse), ARGM(sse2), ARGM(sse3), ARGM(ssse3), ARGM(sse4), ARGM(sse4.1), ARGM(sse4.2), ARGM(avx), ARGM(avx2), NULL}; - - require("cc/cc", logdepth, fatal); - - logprintf(logdepth, "find_cc: Detecting CC machine args\n"); - report("Checking for cc args for machine... "); - - for(flg = flags; *flg != NULL; flg++) { - char name[128], *end; - const char *found = ""; - { - const char* ptr = (*flg) + 1; - strcpy(name, "cc/argmachine/"); - end = name + strlen(name); - while(*ptr) { - if('.'!=*ptr && '-'!=*ptr) *end++ = *ptr; - ++ptr; - } - *end = '\0'; - } - end = strchr(name, '='); - if (end != NULL) - *end = '_'; - if (compile_run(logdepth+1, test_c, NULL, *flg, "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - found = *flg; - report(" "); - report(found); - } - free(out); - } - put(name, found); - } - - report("\n"); - return 0; -#undef ARGM -} - -int find_inline(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "static inline void test_inl()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test_inl();" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for inline... "); - logprintf(logdepth, "find_inline: trying to find inline...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/inline", strue); - report("Found.\n"); - return 0; - } - put("cc/inline", sfalse); - report("Not found.\n"); - return 1; -} - -int find_varargmacro(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#define pr(fmt, x...) {printf(\"PR \"); printf(fmt, x); }" - NL "int main() {" - NL " pr(\"%d %d %s\", 42, 8192, \"test\");" - NL " puts(\"\");" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for vararg macro... "); - logprintf(logdepth, "find_varargmacro: trying to find vararg macro...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "PR 42 8192 test")) { - put("cc/varargmacro", strue); - report("Found.\n"); - return 0; - } - put("cc/varargmacro", sfalse); - report("Not found.\n"); - return 1; -} - -int find_funcmacro(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " printf(\"%s\\n\", __func__);" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for __func__ macro... "); - logprintf(logdepth, "find_funcmacro: trying to find __func__ macro...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "main")) { - put("cc/funcmacro", strue); - report("Found.\n"); - return 0; - } - put("cc/funcmacro", sfalse); - report("Not found.\n"); - return 1; -} - -int find_constructor(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "void startup() __attribute__ ((constructor));" - NL "void startup()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for constructor... "); - logprintf(logdepth, "find_constructor: trying to find constructor...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/constructor", strue); - report("Found.\n"); - return 0; - } - put("cc/constructor", sfalse); - report("Not found.\n"); - return 1; -} - -int find_destructor(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "void startup() __attribute__ ((destructor));" - NL "void startup()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for destructor... "); - logprintf(logdepth, "find_destructor: trying to find destructor...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/destructor", strue); - report("Found.\n"); - return 0; - } - put("cc/destructor", sfalse); - report("Not found.\n"); - return 1; -} - -static int test_fattr(const char *name, int logdepth, int fatal, const char *fattr) -{ - char path[64]; - char test_c[256]; - const char *test_c_tmp = - NL "#include " - NL "static void test1() __attribute__ ((%s));" - NL "static void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - sprintf(test_c, test_c_tmp, fattr); - sprintf(path, "cc/func_attr/%s/presents", fattr); - - report("Checking for function attribute %s... ", fattr); - logprintf(logdepth, "test_fattr: trying to find %s...\n", fattr); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put(path, strue); - report("Found.\n"); - return 0; - } - put(path, sfalse); - report("Not found.\n"); - return 1; -} - -int find_fattr_unused(const char *name, int logdepth, int fatal) -{ - return test_fattr(name, logdepth, fatal, "unused"); -} - -static int test_declspec(const char *name, int logdepth, int fatal, const char *dspec) -{ - char path[64]; - char test_c[256]; - const char *test_c_tmp = - NL "#include " - NL "void __declspec (%s) test1();" - NL "void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test1();" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - sprintf(test_c, test_c_tmp, dspec); - sprintf(path, "cc/declspec/%s/presents", dspec); - - report("Checking for declspec %s... ", dspec); - logprintf(logdepth, "test_declspec: trying to find %s...\n", dspec); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put(path, strue); - report("Found.\n"); - return 0; - } - put(path, sfalse); - report("Not found.\n"); - return 1; -} - -int find_declspec_dllimport(const char *name, int logdepth, int fatal) -{ - return test_declspec(name, logdepth, fatal, "dllimport"); -} - -int find_declspec_dllexport(const char *name, int logdepth, int fatal) -{ - return test_declspec(name, logdepth, fatal, "dllexport"); -} - -static int test_dll_auxfile(const char *name, int logdepth, int fatal, const char *path, const char *ldflag, const char *filename) -{ - char *ldflags; - char test_c[256]; - const char *test_c_template = - NL "#include " - NL "void %s test1();" - NL "void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test1();" - NL " return 0;" - NL "}" - NL ; - const char *dspec; - - require("cc/cc", logdepth, fatal); - require("cc/declspec/dllexport/*", logdepth, 0); - - if (istrue("cc/declspec/dllexport/presents")) - dspec = " __declspec(dllexport) "; - else - dspec = ""; - - sprintf(test_c, test_c_template, dspec); - - report("Checking for DLL flag %s... ", ldflag); - logprintf(logdepth, "test_dll_auxfile: trying to find %s...\n", ldflag); - logdepth++; - ldflags = str_concat("", ldflag, ",", filename, " ", get("cc/ldflags"), NULL); - if (try_flags(logdepth, NULL, test_c, NULL, ldflags, "OK")) { - unlink(filename); - put(path, ldflag); - free(ldflags); - report("Found.\n"); - return 0; - } - unlink(filename); - free(ldflags); - report("Not found.\n"); - return 1; -} - -int find_cc_wloutimplib(const char *name, int logdepth, int fatal) -{ - return test_dll_auxfile(name, logdepth, fatal, "cc/wloutimplib", "-Wl,--out-implib", "libscconfig_0.a"); -} - -int find_cc_wloutputdef(const char *name, int logdepth, int fatal) -{ - return test_dll_auxfile(name, logdepth, fatal, "cc/wloutputdef", "-Wl,--output-def", "libscconfig_0.def"); -} - -/* Hello world program to test compiler flags */ -static const char *test_hello_world = - NL "#include " - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -static int try_hello(int logdepth, const char *cflags, const char *ldflags, const char *name, const char *value) -{ - if (try_flags(logdepth, NULL, test_hello_world, cflags, ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - return 1; - } - return 0; -} - -int find_rdynamic(const char *name, int logdepth, int fatal) -{ - const char *node = "cc/rdynamic"; - - require("cc/cc", logdepth, fatal); - - report("Checking for rdynamic... "); - logprintf(logdepth, "find_rdynamic: trying to find rdynamic...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-rdynamic", node, "-rdynamic")) return 0; - if (try_hello(logdepth, NULL, "-Wl,-export-dynamic", node, "-Wl,-export-dynamic")) return 0; - if (try_hello(logdepth, NULL, NULL, node, "")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_cc_fpie(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - /* TODO: what about -fpic? */ - - report("Checking for -fpie... "); - logprintf(logdepth, "find_cc_fpie: trying to find -fpie...\n"); - logdepth++; - - /* NOTE: some gcc configuration might not pass the -pie flag to the linker, so */ - /* try to detect whether we can force it to the linker */ - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fpie", "-pie -Wl,-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fPIE", "-pie -Wl,-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fpie", "-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fPIE", "-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fpie"); -} - -int find_cc_fnopie(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - - report("Checking for -fno-pie... "); - logprintf(logdepth, "find_cc_fnopie: trying to find -fno-pie...\n"); - logdepth++; - - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, "-fno-pie", NULL)) return 0; - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, "-fno-pie", "-static")) return 0; - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fnopie"); -} - -int find_cc_fnopic(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - - report("Checking for -fno-pic... "); - logprintf(logdepth, "find_cc_fnopic: trying to find -fno-pic...\n"); - logdepth++; - - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, "-fno-pic", NULL)) return 0; - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, "-fno-pic", "-static")) return 0; - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fnopic"); -} - -int find_soname(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for soname... "); - logprintf(logdepth, "find_soname: trying to find soname...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-Wl,-soname,libscconfig.0", "cc/soname", "-Wl,-soname,")) return 0; - if (try_hello(logdepth, NULL, NULL, "cc/soname", "")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_so_undefined(const char *name, int logdepth, int fatal) -{ - static const char *test_c = - NL "#include " - NL "void intentionally_undefined_symbol(void);" - NL "int main() {" - NL " intentionally_undefined_symbol();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - const char **t, *try_ldflags[] = { - "", - "-undefined dynamic_lookup", /* OSX + clang */ - NULL - }; - - require("cc/cc", logdepth, fatal); - require("cc/ldflags_dynlib", logdepth, fatal); - - report("Checking for so_undefined... "); - logprintf(logdepth, "find_so_undefined: trying to find so_undefined...\n"); - logdepth++; - - for(t = try_ldflags; *t != NULL; t++) { - const char *fpic; - char *ldf, *oname = ".o", *libname_dyn, *cflags_c; - int res1, res2; - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - cflags_c = str_concat(" ", "-c", fpic, NULL); - - libname_dyn = (char *)get("sys/ext_dynlib"); - ldf = str_concat(" ", get("cc/ldflags_dynlib"), *t, NULL); - res1 = compile_code(logdepth, test_c, &oname, NULL, cflags_c, NULL); - res2 = compile_file(logdepth, oname, &libname_dyn, NULL, NULL, ldf); - unlink(libname_dyn); - unlink(oname); - free(libname_dyn); - free(oname); - free(cflags_c); - - if ((res1 == 0) && (res2 == 0)) { - put(name, *t); - report("OK (%s)\n", *t); - return 0; - } - } - - report("Not found.\n"); - return 1; -} - - -int find_wlrpath(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for rpath... "); - logprintf(logdepth, "find_wlrpath: trying to find rpath...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-Wl,-rpath=.", "cc/wlrpath", "-Wl,-rpath=")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_fpic(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for -fpic... "); - logprintf(logdepth, "find_fpic: trying to find -fpic...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-fPIC", "cc/fpic", "-fPIC")) return 0; - if (try_hello(logdepth, NULL, "-fpic", "cc/fpic", "-fpic")) return 0; - if (try_hello(logdepth, NULL, NULL, "cc/fpic", "")) return 0; - - report("Not found.\n"); - return 1; -} - -/* Hello world lib... */ -static const char *test_lib = - NL "#include " - NL "int hello() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -/* ...and the corresponding host application */ -static const char *test_host = - NL "#include " - NL "#include " - NL "#include %s" - NL "int main() {" - NL " void *handle = NULL;" - NL " void (*func)() = NULL;" - NL " char *error;" - NL - NL " handle = dlopen(\"%s\", RTLD_NOW);" - NL " if (handle == NULL) {" - NL " printf(\"dlopen fails: %%s\", dlerror());" - NL " return 1;" - NL " }" - NL " func = dlsym(handle, \"hello\");" - NL " if (func == NULL) {" - NL " printf(\"dlsym fails: %%s\", dlerror());" - NL " return 1;" - NL " }" - NL " func();" - NL " return 0;" - NL "}" - NL ; - -static int try_dynlib(int logdepth, const char *cflags, char *concated_ldflags, const char *name, const char *value, const char *host_app_cflags, const char *host_app_ldflags) -{ - char test_host_app[1024]; - const char *fpic; - const char *ld_include; - const char *dlc; - char *libname, *libname_dyn; - char *cflags_c; - char *oname = ".o"; - int ret = 0; - - - dlc = get("libs/dl-compat"); - if ((dlc != NULL) && (strcmp(dlc, strue) == 0)) - ld_include = ""; - else - ld_include = ""; - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - if (cflags == NULL) - cflags=""; - - cflags_c = malloc(strlen(cflags) + 8 + strlen(fpic)); - sprintf(cflags_c, "%s -c %s", cflags, fpic); - - - libname_dyn = libname = (char *)get("sys/ext_dynlib"); - if ((compile_code(logdepth, test_lib, &oname, NULL, cflags_c, NULL) != 0) || - (compile_file(logdepth, oname, &libname_dyn, NULL, NULL, concated_ldflags) != 0)) { - report("FAILED (compiling dynlib)\n"); - } - else { - sprintf(test_host_app, test_host, ld_include, libname_dyn); - if (try_flags(logdepth, NULL, test_host_app, host_app_cflags, host_app_ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - ret = 1; - } - } - unlink(libname_dyn); - unlink(oname); - if (libname != libname_dyn) - free(libname_dyn); - free(oname); - free(concated_ldflags); - free(cflags_c); - return ret; -} - - -int find_ldflags_dynlib(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - require("cc/rdynamic", logdepth, fatal); - require("cc/fpic", logdepth, fatal); - require("libs/ldl", logdepth, fatal); - - report("Checking for dynamic library ldflags... "); - logprintf(logdepth, "find_ldflags_dynlib: trying to find dynamic library ldflags...\n"); - logdepth++; - - if (try_dynlib(logdepth, NULL, concat_nodes("-dynamic -shared", "cc/rdynamic", "libs/ldl", NULL), "cc/ldflags_dynlib", "-dynamic -shared", NULL, get("libs/ldl"))) return 0; - if (try_dynlib(logdepth, NULL, concat_nodes("-shared", "cc/rdynamic", "libs/ldl", NULL), "cc/ldflags_dynlib", "-shared", NULL, get("libs/ldl"))) return 0; - report("Not found.\n"); - return 1; -} - -static int try_dll_or_so(int logdepth, int is_dll, const char *lib_ldflags, const char *name, const char *value, - const char *dspec_dllexport, const char *dspec_dllimport, - const char *app_cflags, const char *app_ldflags) -{ - static const char *test_lib_template = - NL "#include " - NL "%s void hello();" - NL "void hello() {" - NL " puts(\"OK\");" - NL "}" - NL ; - static const char *test_app_template = - NL "%s void hello();" - NL "int main() {" - NL " hello();" - NL " return 0;" - NL "}" - NL ; - char test_lib[1024]; - char test_app[1024]; - const char *fpic; - char *cflags_c; - char *oname, *oname_ext; - char *libname, *libname_ext; - char *appname = NULL, *appname_ext = NULL; - char *lib_filename = NULL, *lib_dirname = NULL; - char *lib_ldflags_new = NULL; - char *app_ldflags_new = NULL; - size_t len, ii; - int ret = 0; - - ++logdepth; - - require("cc/cc", logdepth, 0); - require("cc/cflags", logdepth, 0); - require("cc/ldflags", logdepth, 0); - require("cc/fpic", logdepth, 0); - require("sys/ext_exe", logdepth, 0); - require("sys/ext_dynlib_native", logdepth, 0); - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - if (app_cflags == NULL) - app_cflags = ""; - - if (app_ldflags == NULL) - app_ldflags = ""; - - cflags_c = str_concat(" ", get("cc/cflags"), "-c", fpic, NULL); - - oname = oname_ext = ".o"; - libname = libname_ext = (char *)get("sys/ext_dynlib_native"); - sprintf(test_lib, test_lib_template, dspec_dllexport); - lib_ldflags_new = str_concat(" ", get("cc/ldflags"), lib_ldflags, NULL); - if ((compile_code(logdepth, test_lib, &oname, NULL, cflags_c, NULL) != 0) || - (compile_file(logdepth, oname, &libname, NULL, NULL, lib_ldflags_new) != 0)) { - report("FAILED (compiling %s)\n", (is_dll?"DLL":"SO")); - } - else { - lib_filename = file_name(libname); - lib_dirname = dir_name(libname); - - if (!is_dll) { - len = strlen(lib_filename) - strlen(libname_ext); - for (ii=3; ii" - NL "int main() {" - NL " char *s;" - NL " s = alloca(128);" - NL " if (s != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -static int try_alloca(int logdepth, const char *cflags, const char *ldflags, const char *name, const char *value) -{ - if (try_flags(logdepth, NULL, test_alloca, cflags, ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - return 1; - } - return 0; -} - -int find_alloca(const char *name, int logdepth, int fatal) -{ - require("cc/cc", logdepth, fatal); - - report("Checking for alloca()... "); - logprintf(logdepth, "find_alloca: trying to find alloca()...\n"); - logdepth++; - - if (try_alloca(logdepth, NULL, NULL, "cc/alloca/presents", "true")) return 0; - - put("cc/alloca/presents", "false"); - report("Not found.\n"); - return 1; -} - - -int find__exit(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " _exit(0);" - NL " puts(\"BAD\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for _exit()... "); - logprintf(logdepth, "find__exit: trying to find _exit()...\n"); - logdepth++; - - if (try_flags_inv(logdepth, NULL, test_c, NULL, NULL, "BAD")) { - put("cc/_exit/presents", strue); - report("found\n"); - return 0; - } - - put("cc/_exit/presents", sfalse); - report("Not found.\n"); - return 1; -} - -int find_cc_pragma_message(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#define DO_PRAGMA(arg) _Pragma(#arg)" - NL "#define TODO(x) DO_PRAGMA(message(\"TODO: \" #x))" - NL "TODO(test)" - NL "int main()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for _Pragma(message)... "); - logprintf(logdepth, "find_cc_pragma_message: trying to find pragma_message...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/pragma_message", strue); - report("Found.\n"); - return 0; - } - put("cc/pragma_message", sfalse); - report("Not found.\n"); - return 1; -} - -int find_cc_static_libgcc(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - const char *key = "cc/static_libgcc"; - - require("cc/cc", logdepth, fatal); - - report("Checking for -static-libgcc... "); - logprintf(logdepth, "find_cc_static_libgcc: trying to find -static-libgcc...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, NULL, NULL, "-static-libgcc")) return 0; - return try_fail(logdepth, key); -} diff --git a/scconfig/src/default/.svn/pristine/21/2174b9b5bb548e5fbe042cf14715093fe2360e72.svn-base b/scconfig/src/default/.svn/pristine/21/2174b9b5bb548e5fbe042cf14715093fe2360e72.svn-base deleted file mode 100644 index 9f9c86bb..00000000 --- a/scconfig/src/default/.svn/pristine/21/2174b9b5bb548e5fbe042cf14715093fe2360e72.svn-base +++ /dev/null @@ -1,6 +0,0 @@ -#define MAX_CUSTOM_REQS 32 -extern char *custom_reqs[MAX_CUSTOM_REQS]; -extern int num_custom_reqs; - -int custom_arg(const char *key, const char *value); - diff --git a/scconfig/src/default/.svn/pristine/24/2466492946c2781979e3a05099083326292f3e15.svn-base b/scconfig/src/default/.svn/pristine/24/2466492946c2781979e3a05099083326292f3e15.svn-base deleted file mode 100644 index ad3824d9..00000000 --- a/scconfig/src/default/.svn/pristine/24/2466492946c2781979e3a05099083326292f3e15.svn-base +++ /dev/null @@ -1,837 +0,0 @@ -/* - scconfig - detection of standard library features: file system specific calls - Copyright (C) 2010 Tibor Palinkas - Copyright (C) 2018 Aron Barath - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_fs_realpath(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "#ifdef PATH_MAX" - NL "char out_buf[PATH_MAX];" - NL "#else" - NL "char out_buf[32768];" - NL "#endif" - NL "int main() {" - NL " if (realpath(\".\", out_buf) == out_buf)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for realpath()... "); - logprintf(logdepth, "find_fs_realpath: trying to find realpath...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/realpath", test_c, NULL, NULL, NULL)) return 0; - if (try_icl(logdepth, "libs/fs/realpath", test_c, "#define _DEFAULT_SOURCE", NULL, NULL)) return 0; - if (try_icl(logdepth, "libs/fs/realpath", test_c, "#define _BSD_SOURCE", NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/realpath"); -} - - -int find_fs__fullpath(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "#include " - NL "int main() {" - NL " char full[_MAX_PATH];" - NL " if (_fullpath(full, \".\", _MAX_PATH) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for _fullpath()... "); - logprintf(logdepth, "find_fs__fullpath: trying to find _fullpath...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/_fullpath", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/_fullpath"); -} - - -int find_fs_readdir(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " DIR *dirp;" - NL " struct dirent *dp;" - NL " int found = 0;" - NL " if ((dirp = opendir(\".\")) == 0)" - NL " return -1;" - NL " while ((dp = readdir(dirp)) != 0)" - NL " if (strcmp(dp->d_name, \"configure\") == 0)" - NL " found++;" - NL " closedir(dirp);" - NL " if (found == 1)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - char *includes[] = { - "#include ", - "#include ", /* 4.2BSD */ - NULL - }; - char **i; - - require("cc/cc", logdepth, fatal); - - report("Checking for readdir()... "); - logprintf(logdepth, "find_fs_readdir: trying to find readdir...\n"); - logdepth++; - - for (i = includes; *i != NULL; i++) - if (try_icl(logdepth, "libs/fs/readdir", test_c, *i, NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/fs/readdir"); -} - - -int find_fs_findnextfile(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "int main(int argc, char *argv[]) {" - NL " WIN32_FIND_DATA fd;" - NL " HANDLE h;" - NL " int found=0;" - NL " h = FindFirstFile(argv[0], &fd);" - NL " if (h == INVALID_HANDLE_VALUE)" - NL " return -1;" - NL " while (FindNextFile(h, &fd) != 0);" - NL " found++;" - NL " FindClose(h);" - NL " if (found > 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for FindNextFile()... "); - logprintf(logdepth, "find_fs_findnextfile: trying to find FindNextFile...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/findnextfile", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/findnextfile"); -} - -int find_fs_access(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "int my_test() { return access(\".\", 0); }" - NL "#include " - NL "int main() {" - NL " if (my_test() == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char* includes[] = { "#include ", "#include \n#include ", "#include ", NULL }; - const char** inc; - - require("cc/cc", logdepth, fatal); - - report("Checking for access()... "); - logprintf(logdepth, "find_fs_access: trying to find access...\n"); - logdepth++; - - for (inc=includes; *inc; ++inc) - if (try_icl(logdepth, "libs/fs/access", test_c, *inc, NULL, NULL)) return 0; - - return try_fail(logdepth, "libs/fs/access"); -} - -int find_fs_access_macros(const char *rname, int logdepth, int fatal) -{ - char *test_c_templ = - NL "%s" - NL "void my_test() { int a = %s; }" - NL "#include " - NL "int main() {" - NL " my_test();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - char test_c[256]; - - char *names[][3] = { - {"F_OK", "F_OK", NULL}, - {"R_OK", "R_OK", NULL}, - {"W_OK", "W_OK", NULL}, - {"X_OK", "X_OK", NULL}, - {NULL, NULL, NULL} - }; - char **n; - const char* access_includes; - int name, pr; - char nodename[128]; - - require("cc/cc", logdepth, fatal); - if (require("libs/fs/access/*", logdepth, fatal)!=0 || - !istrue(get("libs/fs/access/presents"))) { - put("libs/fs/access/macros/presents", sfalse); - return 1; - } - access_includes = get("libs/fs/access/includes"); - - report("Checking for access macros:\n"); - logprintf(logdepth, "find_fs_access_macros: trying to find access macros...\n"); - logdepth++; - - pr = 0; - for(name = 0; *names[name] != NULL; name++) { - report(" %s...\t", names[name][0]); - for(n = &names[name][0]; *n != NULL; n++) { - sprintf(test_c, test_c_templ, access_includes, *n); - if (try_icl(logdepth, NULL, test_c, NULL, NULL, NULL)) { - sprintf(nodename, "libs/fs/access/macros/%s", names[name][0]); - put(nodename, *n); - report("found as %s\n", *n); - pr++; - goto found; - } - } - report("not found\n"); - found:; - } - - put("libs/fs/access/macros/presents", ((pr > 0) ? (strue) : (sfalse))); - return (pr == 0); -} - -int find_fs_stat_macros(const char *rname, int logdepth, int fatal) -{ - char *test_c_templ = - NL "#include " - NL "#include " - NL "void my_test() { int a = %s(0); }" - NL "#include " - NL "int main() {" - NL " my_test();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - char test_c[256]; - - char *names[][3] = { - {"S_ISREG", "S_IFREG", NULL}, - {"S_ISDIR", "S_IFDIR", NULL}, - {"S_ISCHR", "S_IFCHR", NULL}, - {"S_ISBLK", "S_IFBLK", NULL}, - {"S_ISFIFO", "S_IFFIFO", NULL}, - {"S_ISLNK", "S_IFLNK", NULL}, - {"S_ISCHR", "S_IFCHR", NULL}, - {"S_ISSOCK", "S_IFSOCK", NULL}, - {NULL, NULL, NULL} - }; - char **n; - int name, pr; - char nodename[128]; - - require("cc/cc", logdepth, fatal); - - report("Checking for stat macros:\n"); - logprintf(logdepth, "find_fs_stat_macros: trying to find stat macros...\n"); - logdepth++; - - pr = 0; - for(name = 0; *names[name] != NULL; name++) { - report(" %s...\t", names[name][0]); - for(n = &names[name][0]; *n != NULL; n++) { - sprintf(test_c, test_c_templ, *n); - if (try_icl(logdepth, NULL, test_c, NULL, NULL, NULL)) { - sprintf(nodename, "libs/fs/stat/macros/%s", names[name][0]); - put(nodename, *n); - report("found as %s\n", *n); - pr++; - goto found; - } - } - report("not found\n"); - found:; - } - - put("libs/fs/stat/macros/presents", ((pr > 0) ? (strue) : (sfalse))); - return (pr == 0); -} - -int find_fs_stat_fields(const char *rname, int logdepth, int fatal) -{ - char *test_c_templ = - NL "#include " - NL "#include " - NL "#include " - NL "int main() {" - NL " struct stat st;" - NL " (void)st.%s;" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - char test_c[256]; - - char *names[] = {"st_blksize", "st_blocks", "st_rdev", "st_mtim", "st_mtime", "st_birthtim", "st_birthtime", NULL }; - int name, pr; - char nodename[128]; - - require("cc/cc", logdepth, fatal); - - report("Checking for stat macros:\n"); - logprintf(logdepth, "find_fs_stat_fields: trying to find stat macros...\n"); - logdepth++; - - pr = 0; - for(name = 0; names[name] != NULL; name++) { - report(" %s...\t", names[name]); - sprintf(test_c, test_c_templ, names[name]); - sprintf(nodename, "libs/fs/stat/fields/%s/presents", names[name]); - if (try_icl(logdepth, NULL, test_c, NULL, NULL, NULL)) { - put(nodename, strue); - report("found\n"); - pr++; - } - else { - report("not found\n"); - put(nodename, sfalse); - } - } - return (pr == 0); -} - -static int find_fs_any_lstat(const char *name, int logdepth, int fatal, char *fn) -{ - /* make sure does not affect our lstat() detection */ - const char *test_c_in = - NL "void my_puts(const char *s);" - NL "int main() {" - NL " struct stat buf;" - NL " if (%s(\".\", &buf) == 0)" - NL " my_puts(\"OK\");" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - char test_c[384], node[64]; - const char *incs[] = {"#include ", "#include ", "#include \n#include \n#include ", NULL}; - const char **inc; - - require("cc/cc", logdepth, fatal); - - sprintf(node, "libs/fs/%s", fn); - sprintf(test_c, test_c_in, fn); - - report("Checking for %s... ", fn); - logprintf(logdepth, "find_fs_%s: trying to find lstat()...\n", fn); - logdepth++; - - for (inc = incs; *inc; ++inc) { - if (try_icl(logdepth, node, test_c, *inc, NULL, NULL)) - return 0; - } - - return try_fail(logdepth, node); -} - -int find_fs_lstat(const char *name, int logdepth, int fatal) -{ - return find_fs_any_lstat(name, logdepth, fatal, "lstat"); -} - -int find_fs_statlstat(const char *name, int logdepth, int fatal) -{ - return find_fs_any_lstat(name, logdepth, fatal, "statlstat"); -} - - -int find_fs_getcwd(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " char b[1024];" - NL " if (getcwd(b, sizeof(b)) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for getcwd... "); - logprintf(logdepth, "find_fs_getcwd: trying to find getcwd()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/getcwd", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/getcwd"); -} - -int find_fs__getcwd(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " char b[1024];" - NL " if (_getcwd(b, sizeof(b)) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for _getcwd... "); - logprintf(logdepth, "find_fs__getcwd: trying to find _getcwd()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/_getcwd", test_c, "#include ", NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/_getcwd"); -} - - -int find_fs_getwd(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " char b[8192];" - NL " if (getwd(b) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for getwd... "); - logprintf(logdepth, "find_fs_getwd: trying to find getwd()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/getwd", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/getwd"); -} - -int find_fs_mkdir(const char *name, int logdepth, int fatal) -{ - char *dir; - char test_c[1024]; - char *test_c_in = - NL "#include " - NL "int main() {" - NL no_implicit(int, "mkdir", "mkdir") - NL " if (mkdir(\"%s\"%s) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - dir = tempfile_new(""); - unlink(dir); - - report("Checking for mkdir... "); - logprintf(logdepth, "find_fs_mkdir: trying to find mkdir()...\n"); - logdepth++; - - /* POSIX, 2 arguments, standard includes */ - sprintf(test_c, test_c_in, dir, ", 0755"); - if (try_icl(logdepth, "libs/fs/mkdir", test_c, "#include \n#include \n", NULL, NULL)) { - if (!is_dir(dir)) - goto oops1; - put("libs/fs/mkdir/num_args", "2"); - rmdir(dir); - return 0; - } - - /* POSIX, 2 arguments, no includes */ - oops1:; - sprintf(test_c, test_c_in, dir, ", 0755"); - if (try_icl(logdepth, "libs/fs/mkdir", test_c, NULL, NULL, NULL)) { - if (!is_dir(dir)) - goto oops2; - put("libs/fs/mkdir/num_args", "2"); - rmdir(dir); - return 0; - } - - /* win32, 1 argument, with */ - oops2:; - sprintf(test_c, test_c_in, dir, ""); - if (try_icl(logdepth, "libs/fs/mkdir", test_c, "#include \n", NULL, NULL)) { - if (!is_dir(dir)) - goto oops3; - put("libs/fs/mkdir/num_args", "1"); - rmdir(dir); - return 0; - } - - oops3:; - put("libs/fs/mkdir/includes", ""); - put("libs/fs/mkdir/ldflags", ""); - put("libs/fs/mkdir/cdflags", ""); - - rmdir(dir); - return try_fail(logdepth, "libs/fs/mkdir"); -} - -int find_fs__mkdir(const char *name, int logdepth, int fatal) -{ - char *dir; - char test_c[1024]; - char *test_c_in = - NL "#include " - NL "int main() {" - NL " if (_mkdir(\"%s\"%s) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - dir = tempfile_new(""); - unlink(dir); - - report("Checking for _mkdir... "); - logprintf(logdepth, "find_fs__mkdir: trying to find _mkdir()...\n"); - logdepth++; - - /* win32, 2 arguments, standard includes */ - sprintf(test_c, test_c_in, dir, ", 0755"); - if (try_icl(logdepth, "libs/fs/_mkdir", test_c, "#include \n", NULL, NULL)) { - if (!is_dir(dir)) - goto oops1; - put("libs/fs/_mkdir/num_args", "2"); - rmdir(dir); - return 0; - } - - oops1:; - /* win32, 1 argument, standard includes */ - sprintf(test_c, test_c_in, dir, ""); - if (try_icl(logdepth, "libs/fs/_mkdir", test_c, "#include \n", NULL, NULL)) { - if (!is_dir(dir)) - goto oops2; - put("libs/fs/_mkdir/num_args", "1"); - rmdir(dir); - return 0; - } - - oops2:; - put("libs/fs/_mkdir/includes", ""); - put("libs/fs/_mkdir/ldflags", ""); - put("libs/fs/_mkdir/cdflags", ""); - - rmdir(dir); - return try_fail(logdepth, "libs/fs/_mkdir"); -} - -int find_fs_mkdtemp(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "int main() {" - NL " char fn[32], *o;" - NL " strcpy(fn, \"scc.XXXXXX\");" - NL " o = mkdtemp(fn);" - NL " if ((o != NULL) && (strstr(o, \"scc.\") != NULL)) {" - NL " remove(o);" - NL " puts(\"OK\");" - NL " }" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for mkdtemp... "); - logprintf(logdepth, "find_fs_mkdtemp: trying to find mkdtemp()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/mkdtemp", test_c, "#include \n", NULL, NULL)) return 0; - if (try_icl(logdepth, "libs/fs/mkdtemp", test_c, "#define _BSD_SOURCE\n#include \n", NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/mkdtemp"); -} - -int find_fs_mmap(const char *name, int logdepth, int fatal) -{ - char test_c[1024]; - char *tmp; - FILE *f; - char *test_c_in = - NL "#include " - NL "#include " - NL "#include " - NL "#include " - NL "#include " - NL "#include " - NL "int main() {" - NL " int fd, size = 11;" - NL " void *p;" - NL " fd = open(\"%s\", O_RDONLY);" - NL " p = mmap(0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0);" - NL " if (p == NULL) {" - NL " puts(\"mmap fail\");" - NL " return 0;" - NL " }" - NL " if (strcmp(p, \"hello world\") != 0) {" - NL " puts(\"strcmp fail\");" - NL " return 0;" - NL " }" - NL " if (munmap(p, size) != 0) {" - NL " puts(\"munmap fail\");" - NL " return 0;" - NL " }" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - tmp = tempfile_new(""); - f = fopen(tmp, "w"); - fprintf(f, "hello world"); - fclose(f); - sprintf(test_c, test_c_in, tmp); - - report("Checking for mmap... "); - logprintf(logdepth, "find_fs_mmap: trying to find mmap()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/mmap", test_c, "#include \n", NULL, NULL)) { - unlink(tmp); - free(tmp); - return 0; - } - - unlink(tmp); - free(tmp); - return try_fail(logdepth, "libs/fs/mmap"); -} - -/* Haiku/BeOS next_dev */ -int find_fsmount_next_dev(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " int32 pos = 0;" - NL " dev_t res = next_dev(&pos);" - NL " if (res >= 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for next_dev... "); - logprintf(logdepth, "find_fsmount_next_dev: trying to find next_dev()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fsmount/next_dev", test_c, "#include \n", NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fsmount/next_dev"); -} - -int find_fsmount_fsstat_fields(const char *name, int logdepth, int fatal) -{ - const char *fields[] = {"f_fstypename", NULL}; - return try_icl_sfields(logdepth, "libs/fsmount/struct_fsstat", "struct fsstat", fields, "#include ", NULL, NULL, 0); -} - -int find_fsmount_statfs_fields(const char *name, int logdepth, int fatal) -{ - const char *fields[] = {"f_fstypename", "f_type", NULL}; - return try_icl_sfields(logdepth, "libs/fsmount/struct_statfs", "struct statfs", fields, "#include ", NULL, NULL, 0); -} - -int find_fsmount_statvfs_fields(const char *name, int logdepth, int fatal) -{ - const char *fields[] = {"f_fstypename", "f_type", "f_basetype", NULL}; - return try_icl_sfields(logdepth, "libs/fsmount/struct_statvfs", "struct statvfs", fields, "#include ", NULL, NULL, 0); -} - -int find_fs_ustat(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/fs/ustat"; - const char *test_c = - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " struct stat stat_buf;" - NL " struct ustat ustat_buf;" - NL " if (stat(\".\", &stat_buf) == 0 &&" - NL " ustat(stat_buf.st_dev, &ustat_buf) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for ustat... "); - logprintf(logdepth, "find_fs_ustat: trying to find ustat()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - if (try_icl(logdepth, key, test_c, "#include \n#include ", NULL, NULL)) return 0; - if (try_icl(logdepth, key, test_c, "#include \n#include \n#include ", NULL, NULL)) return 0; - return try_fail(logdepth, key); -} - -int find_fs_statfs(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/fs/statfs"; - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " struct statfs statfs_buf;" - NL " if (statfs(\".\", &statfs_buf) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for statfs... "); - logprintf(logdepth, "find_fs_statfs: trying to find statfs()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - return try_fail(logdepth, key); -} - -int find_fs_statvfs(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/fs/statvfs"; - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " struct statvfs statvfs_buf;" - NL " if (statvfs(\".\", &statvfs_buf) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for statvfs... "); - logprintf(logdepth, "find_fs_statvfs: trying to find statvfs()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - return try_fail(logdepth, key); -} - -int find_fs_flock(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/fs/flock"; - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " if (flock(1, LOCK_UN) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for flock... "); - logprintf(logdepth, "find_fs_flock: trying to find flock()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - return try_fail(logdepth, key); -} - -int find_fs_makedev(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/fs/makedev"; - const char *test_c = - NL "#include " - NL "int main() {" - NL " if (1 == major(makedev(1, 2)) && 2 == minor(makedev(1, 2)))" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *includes[] = { - "#include ", - NULL - }; - const char **i; - - require("cc/cc", logdepth, fatal); - - report("Checking for makedev()... "); - logprintf(logdepth, "find_fs_makedev: trying to find makedev...\n"); - logdepth++; - - for (i = includes; *i != NULL; i++) - if (try_icl(logdepth, key, test_c, *i, NULL, NULL)) - return 0; - return try_fail(logdepth, key); -} diff --git a/scconfig/src/default/.svn/pristine/24/24cef6f2620ce0208386da704719575a2532a31b.svn-base b/scconfig/src/default/.svn/pristine/24/24cef6f2620ce0208386da704719575a2532a31b.svn-base deleted file mode 100644 index c7f46f83..00000000 --- a/scconfig/src/default/.svn/pristine/24/24cef6f2620ce0208386da704719575a2532a31b.svn-base +++ /dev/null @@ -1,141 +0,0 @@ -/* - scconfig - detection of standard library features - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -static int try_bad(int logdepth, const char *test_c, char *cflags, char *ldflags) -{ - char *out = NULL; - - logprintf(logdepth, "trying signal (neg) with ldflags '%s'\n", ldflags == NULL ? get("cc/ldflags") : ldflags); - if (compile_run(logdepth+1, test_c, NULL, cflags, ldflags, &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "BAD", 3) == 0)) { - free(out); - return 0; - } - free(out); - } - return 1; -} - - -int find_signal_raise(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "int main(int argc, char *argv[]) {" - NL " printf(\"OK\\n\");" - NL " if (argc == 16)" - NL " raise(1);" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for raise()... "); - logprintf(logdepth, "find_signal_raise: trying to find raise()...\n"); - logdepth++; - - if (try_icl(logdepth, "signal/raise", test_c, NULL, NULL, NULL)) - return 0; - return try_fail(logdepth, "signal/raise"); -} - - -int find_signal_names(const char *rname, int logdepth, int fatal) -{ - char *test_c_exists = - NL "#include " - NL "#include " - NL "int main(int argc, char *argv[]) {" - NL " printf(\"OK\\n\");" - NL " if (argc == 16)" - NL " raise(%s);" - NL " return 0;" - NL "}" - NL; - char *test_c_terms = - NL "#include " - NL "#include " - NL "int main() {" - NL " raise(%s);" - NL " printf(\"BAD\\n\");" - NL " return 0;" - NL "}" - NL; - char test_c[256]; - const char *names[] = {"SIGINT", "SIGABRT", "SIGKILL", "SIGTERM", "SIGQUIT", "SIGHUP", "SIGFPE", "SIGSEGV", "SIGPIPE", NULL}; - const char **name; - char path[256], *pathend; - const char *prefix = "signal/names/"; - - require("cc/cc", logdepth, fatal); - require("signal/raise/*", logdepth, fatal); - - strcpy(path, prefix); - pathend = path + strlen(prefix); - - for(name = names; *name != NULL; name++) { - /* check whether it exists */ - report("Checking whether %s exists... ", *name); - logprintf(logdepth, "find_signal_names: checking whether %s exists\n", *name); - logdepth++; - sprintf(test_c, test_c_exists, *name); - strcpy(pathend, *name); - if (!try_icl(logdepth, path, test_c, NULL, NULL, NULL)) { - logdepth--; - continue; - } - - /* check whether it exists */ - logdepth--; - report("Checking whether %s terminates... ", *name); - logprintf(logdepth, "find_signal_names: checking whether %s terminates\n", *name); - logdepth++; - - sprintf(test_c, test_c_terms, *name); - sprintf(pathend, "%s/terminates", *name); - if (try_bad(logdepth, test_c, NULL, "")) { - put(path, strue); - report("terminates\n"); - } - else { - report("does not terminate\n"); - put(path, sfalse); - } - logdepth--; - } - -/* to avoid redetection */ - put("signal/names/presents", strue); - - return 0; -} - diff --git a/scconfig/src/default/.svn/pristine/27/27d93578ddc03a16544ecc88000972a3469267a3.svn-base b/scconfig/src/default/.svn/pristine/27/27d93578ddc03a16544ecc88000972a3469267a3.svn-base deleted file mode 100644 index 16d74426..00000000 --- a/scconfig/src/default/.svn/pristine/27/27d93578ddc03a16544ecc88000972a3469267a3.svn-base +++ /dev/null @@ -1,111 +0,0 @@ -/* - scconfig - test code for default and scripts - Copyright (C) 2009..2016 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "db.h" -#include "find.h" -#include "log.h" -#include "arg.h" -#include "dep.h" -#include "deps_default.h" -#include "libs.h" -#include "hooks.h" -#include "regex.h" -#include "main_custom_args.h" -#include "main_lib.h" - -void re_fail(char *s, char c) -{ - fprintf(stderr, "Regex error: %s [opcode %o]\n", s, c); - abort(); -} - -int no_autodetect_sys = 0; -int no_save_cache = 0; -int main(int argc, char *argv[]) -{ - int blind_save; - - if (main_init() != 0) - return 1; - - if (main_process_args(argc, argv) != 0) - return 1; - - if (!no_autodetect_sys) { - find_target("", 0, 1); - blind_save = cross_blind; - cross_blind = 0; - printf("--- Detecting host\n"); - - require("sys/name", 0, 1); - } - - if (hook_detect_host()) { - fprintf(stderr, "hook_detect_host failed, exiting\n"); - return 1; - } - - cross_blind = blind_save; - if (!no_autodetect_sys) { - if (!iscross) - printf("--- Detecting target (same as host)\n"); - else - printf("--- Detecting target (differs from host)\n"); - } - db_cd("/target"); - run_custom_reqs(); - - - if (hook_detect_target()) { - fprintf(stderr, "hook_detect_target failed, exiting\n"); - return 1; - } - -#ifdef RUNTIME - if (!no_autodetect_sys) { - if (!iscross) - printf("--- Detecting runtime (same as host)\n"); - else - printf("--- Detecting runtime (differs from host)\n"); - } - db_cd("/runtime"); - if (hook_detect_runtime()) { - fprintf(stderr, "hook_detect_runtime failed, exiting\n"); - return 1; - } -#endif - - if (hook_generate()) { - fprintf(stderr, "hook_generate failed, exiting\n"); - return 1; - } - - if (!no_save_cache) - export("config.cache", 1, "/"); - - main_uninit(); - return 0; -} - diff --git a/scconfig/src/default/.svn/pristine/31/31e68f6736a68a7c7474662588130057c647501c.svn-base b/scconfig/src/default/.svn/pristine/31/31e68f6736a68a7c7474662588130057c647501c.svn-base deleted file mode 100644 index fcf53b74..00000000 --- a/scconfig/src/default/.svn/pristine/31/31e68f6736a68a7c7474662588130057c647501c.svn-base +++ /dev/null @@ -1,443 +0,0 @@ -/* - scconfig - database - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include "db.h" -#include "log.h" -#include "libs.h" - -ht_t *DBs = NULL; -char *db_cwd = NULL; - -void append(const char *key, const char *value) -{ - const char *orig; - char *new; - int l1, l2; - - assert(key != NULL); - assert(value != NULL); - if (*value == '\0') - return; - - orig = get(key); - if (orig == NULL) { - put(key, value); - return; - } - - l1 = strlen(orig); - l2 = strlen(value); - new = malloc(l1 + l2 + 1); - memcpy(new, orig, l1); - memcpy(new + l1, value, l2); - new[l1+l2] = '\0'; - put(key, new); -} - - -static const char *db_split_path(const char *key, ht_t **ht, char **fld) -{ - size_t fld_len; - const char *path; - char first_level_dir[32]; - - path = str_chr((char *)(key+1), '/'); - assert(path != NULL); - fld_len = path - key; - path++; - if (*path == '\0') { - *ht = NULL; - if (fld != NULL) - *fld = NULL; - return NULL; - } - assert(fld_len < sizeof(first_level_dir)); - strncpy(first_level_dir, key, fld_len); - first_level_dir[fld_len] = '\0'; - *ht = ht_get(DBs, first_level_dir+1); - if (fld != NULL) - *fld = first_level_dir; - return path; -} - -static void export_qs(FILE *f, const char *s) -{ - fputc('"', f); - for(;*s != '\0';s++) { - switch(*s) { - case '"': fputc('\\', f); fputc('"', f); break; - case '\n': fputc('\\', f); fputc('n', f); break; - case '\r': fputc('\\', f); fputc('r', f); break; - case '\t': fputc('\\', f); fputc('t', f); break; - default: fputc(*s, f); - } - } - - fputc('"', f); - fputc('\n', f); -} - -static int needs_quote(const char *s) { - for(; *s != '\0'; s++) - if ((*s < 32) || (*s > 126) || (*s == '"')) return 1; - return 0; -} - -int export_(FILE *f, int export_empty, ht_t *table, const char *fld) -{ - ht_entry_t *h; - - for(h = ht_first(table); h != NULL; h = ht_next(table, h)) - if (export_empty || ((h->value != NULL) && (*(char *)h->value != '\0'))) { - fprintf(f, "/%s/%s=", fld, h->key); - if (h->value != NULL) { - if (needs_quote((char *)h->value)) - export_qs(f, (const char *)h->value); - else - fprintf(f, "%s\n", (char *)h->value); - } - else - fprintf(f, "\n"); - } - return 0; -} - -int export(const char *fn, int export_empty, const char *root) -{ - FILE *f; - int ret = 0; -/* ht_t *table; */ - ht_entry_t *h; - - if (fn != NULL) { - f = fopen(fn, "w"); - if (f == NULL) - return -1; - } - else - f = stdout; - - if ((root == NULL) || ((root[0] == '/') && (root[1] == '\0'))) { - /* export all directories */ - for(h = ht_first(DBs); h != NULL; h = ht_next(DBs, h)) - ret += export_(f, export_empty, h->value, h->key); - } - else { - error("not yet implemented\n"); - abort(); - /* db_split_path(); */ - } - - if (f != stdout) - fclose(f); - - return ret; -} - -/* append a single character, grow the buffer as needed */ -#define qappend(chr) \ -do { \ - if (used >= alloced) { \ - alloced += 256; \ - res = realloc(res, alloced); \ - } \ - res[used] = chr; \ - used++; \ -} while(0) - -/* read until end of quote and interpret backslash sequences if do_esc is non-zero */ -static char *readq(FILE *f, char *str, long strmax, int quote, int do_esc, int *num_lines, const char *fn) -{ - int bs = 0; - long used = 0, alloced = 0; - char *res = NULL, *s; - - for(;;) { - for(s = str; *s != '\0'; s++) { - if (*s == '\n') (*num_lines)++; - - if (bs) { /* character escaped by backslash */ - switch(*s) { - case '\\': qappend('\\'); break; - case 'n': qappend('\n'); break; - case 'r': qappend('\r'); break; - case 't': qappend('\t'); break; - default: qappend(*s); break; - } - bs = 0; - } - else if (*s == quote) { /* end */ - qappend('\0'); - if ((s[1] != '\r') && (s[1] != '\n') && (s[1] != '\0')) - fprintf(stderr, "Warning: trailing text after quote ignored in %s:%d\n", fn, (*num_lines)+1); - return res; - } - else if (do_esc && (*s == '\\')) bs = 1; /* backslash start */ - else qappend(*s); /* plain character */ - } - - /* get the next chunk */ - fgets(str, strmax, f); - } - - return NULL; /* can't get here */ -} - -int import(const char *fn) -{ - char line[1024]; - char *key, *value, *nl, *slash; - int num_records, num_lines; - FILE *f; - - f = fopen(fn, "r"); - if (f == NULL) - return -1; - - for(num_records = 0, num_lines = 0; !feof(f); num_lines++) { - *line = '\0'; - fgets(line, sizeof(line) - 1, f); - if ((*line != '#') && (*line != '\n') && (*line != '\r') && (*line != '\0')) { - int quote, do_esc=0; - key = line; - value = str_chr(key, '='); - if (value == NULL) { - error("Error importing: missing '=' in line %d in file %s.\n", num_lines, fn); - abort(); - } - num_records++; - *value = '\0'; - value++; - if (*value == '"') { - quote=*value; - value++; - do_esc=1; - } - else if (*value == '\'') { - quote=*value; - value++; - } - else - quote=0; - - if (!quote) { - nl = str_chr(value, '\n'); - if (nl != NULL) - *nl = '\0'; - } - else - value = readq(f, value, sizeof(line) - (value - line) - 4, quote, do_esc, &num_lines, fn); - - slash = str_chr(key+1, '/'); - if (slash == NULL) { - error("Error importing: no directory name for %s.\n", key); - abort(); - } - *slash = '\0'; - db_mkdir(key); - *slash = '/'; - put(key, value); - logprintf(0, "(Import from '%s': '%s'='%s')\n", fn, key, value); - if (quote) - free(value); - } - } - - fclose(f); - return num_records; -} - -int import_args(const char *key, const char *fn) -{ - (void) key; /* suppress compiler warnings for unused key; needed because function pointers to this function from arg.c */ - db_mkdir("/target"); - db_mkdir("/host"); - - return import(fn) < 0; -} - - -static const char *db_get(const char *key) -{ - const char *path; - ht_t *ht; - - path = db_split_path(key, &ht, NULL); - if (ht == NULL) - return NULL; - return ht_get(ht, path); -} - -static const char *db_put(const char *key, const char *value) -{ - const char *path; - ht_t *ht; - - path = db_split_path(key, &ht, NULL); - if (ht == NULL) { - error("db_put: can't find top level hash for '%s'\n", key); - abort(); - } - return ht_set(ht, path, (void *)value); -} - -#define assamble_path \ - assert(strlen(key) + strlen(db_cwd) < sizeof(tmp)-1); \ - sprintf(tmp, "%s/%s", db_cwd, key); - -const char *get(const char *key) -{ - char tmp[256]; - - if (*key == '/') - return db_get(key); - assamble_path; - return db_get(tmp); -} - -const char *put(const char *key, const char *value) -{ - char tmp[256]; - - if (*key == '/') - return db_put(key, value); - assamble_path; - return db_put(tmp, value); -} - -void db_init(void) -{ - DBs = ht_resize(ht_alloc(0), 16); -} - -void db_uninit(void) -{ - ht_entry_t *h; - ht_t *dir; - - for(h = ht_first(DBs); h != NULL; h = ht_next(DBs, h)) { - dir = h->value; - dir->refcount--; - if (dir->refcount == 0) - ht_free(dir); - } - ht_free(DBs); - if (db_cwd != NULL) - free(db_cwd); -/* Just in case someone calls db_init again... */ - db_cwd = NULL; - DBs = NULL; -} - -void db_cd(const char *path) -{ - assert(*path == '/'); - if (db_cwd != NULL) - free(db_cwd); - db_cwd = strclone(path); -} - -void db_mkdir(const char *path) -{ - ht_t *ht, *target; - assert(*path == '/'); - target = ht_get(DBs, path+1); - if (target == NULL) { - ht = ht_resize(ht_alloc(1), 256); - ht_set(DBs, path+1, ht); - } -} - -void db_rmdir(const char *path) -{ - ht_t *ht; - assert(*path == '/'); - ht = ht_get(DBs, path+1); - if (ht == NULL) - return; - ht_del(DBs, path+1); -/* ht_free(ht); */ -} - -void db_link(const char *existing, const char *new) -{ - ht_t *ht; - - assert(*new == '/'); - ht = ht_get(DBs, existing+1); - assert(ht != NULL); - ht_set(DBs, new+1, ht); - ht->refcount++; -} - -char *concat_nodes(const char *prefix, ...) -{ - char *buff; - const char *node, *value; - int allocated = 256, len, totallen; - - va_list ap; - va_start(ap, prefix); - buff = malloc(allocated); - if (prefix != NULL) { - strcpy(buff, prefix); - totallen = strlen(prefix); - buff[totallen] = ' '; - totallen++; - } - else - totallen = 0; - - while((node = va_arg(ap, const char *)) != NULL) { - value = get(node); - if (value != NULL) { - len = strlen(value); - if (totallen + len >= allocated) { - allocated = totallen + len + 256; - buff = realloc(buff, allocated); - } - memcpy(buff + totallen, value, len); - totallen += len; - buff[totallen] = ' '; - totallen++; - - buff[totallen] = '\0'; - } - } - - buff[totallen - 1] = '\0'; - va_end(ap); - return buff; -} - -int node_istrue(const char *key) -{ - const char *s = get(key); - if (s == NULL) - return 0; - return istrue(s); -} diff --git a/scconfig/src/default/.svn/pristine/32/32833d829255f5899869cd2c5a387e1f76464247.svn-base b/scconfig/src/default/.svn/pristine/32/32833d829255f5899869cd2c5a387e1f76464247.svn-base deleted file mode 100644 index 4ab793b0..00000000 --- a/scconfig/src/default/.svn/pristine/32/32833d829255f5899869cd2c5a387e1f76464247.svn-base +++ /dev/null @@ -1,223 +0,0 @@ -/* - scconfig - detection of standard library features - Copyright (C) 2009,2017 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_lib_lpthread(const char *name, int logdepth, int fatal) -{ - const char *lpthread; - char *s; - int ret = 0; - - char *test_c_recursive = - NL "#define _GNU_SOURCE 1 /* Needed for recursive thread-locking */" - NL "#include " - NL "pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;" - NL "int main() {" - NL " pthread_attr_t a;" - NL " if (pthread_attr_init(&a) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - - char *test_c_simple = - NL "#include " - NL "int main() {" - NL " pthread_attr_t a;" - NL " if (pthread_attr_init(&a) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for -lpthread... "); - logprintf(logdepth, "find_lib_lpthread: trying to find lpthread...\n"); - logdepth++; - - lpthread = get("/arg/libs/lpthread"); - - if (lpthread != NULL) { - put("libs/lpthread", lpthread); - report("User provided... "); - s = strclone(lpthread); - } - else - s = strclone("-lpthread"); - - if (try_icl(logdepth, NULL, test_c_recursive, NULL, NULL, s)) { - put("libs/lpthread", s); - put("libs/lpthread-recursive", strue); - report("OK, recursive (%s)\n", s); - } - else if (try_icl(logdepth, NULL, test_c_simple, NULL, NULL, s)) { - put("libs/lpthread", s); - put("libs/lpthread-recursive", sfalse); - report("OK, NOT RECURSIVE (%s)\n", s); - } - else - ret = 1; - - free(s); - return ret; -} - -int find_thread_semget(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " int semid = semget(IPC_PRIVATE, 1, IPC_CREAT);" - NL " if (semid < 0) return 0;" - NL " if(semctl(semid, 0, IPC_RMID) < 0) return 0;" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "thread/semget"; - char **inc, *incs[] = {"#include \n#include \n#include ", "#include \n#include ", "#include \n#include ", NULL}; - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for semget... "); - logprintf(logdepth, "find_semget:\n"); - logdepth++; - - for(inc = incs; *inc != NULL; inc++) - if (try_icl(logdepth, node, test_c, *inc, NULL, NULL) != 0) - return 0; - - return try_fail(logdepth, node); -} - -int find_thread_pthread_create(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "void* test_thread(void* param)" - NL "{" - NL " return NULL;" - NL "}" - NL "int main()" - NL "{" - NL " pthread_t pt;" - NL " if (pthread_create(&pt, NULL, test_thread, NULL) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "thread/pthread_create"; - char **inc, *incs[] = {"#include ", "#include \n#include ", NULL}; - const char *lpthread; - char* s; - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for pthread_create... "); - logprintf(logdepth, "find_pthread_create:\n"); - logdepth++; - - lpthread = get("/arg/libs/lpthread"); - - if (lpthread != NULL) { - report("User provided... "); - s = strclone(lpthread); - } - else - s = strclone("-lpthread"); - - for(inc = incs; *inc != NULL; inc++) - if (try_icl(logdepth, node, test_c, *inc, NULL, s) != 0) { - free(s); - return 0; - } - - free(s); - return try_fail(logdepth, node); -} - -int find_thread_CreateSemaphore(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " if (CreateSemaphore(NULL, 1, 1, NULL))" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "thread/CreateSemaphore"; - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for CreateSemaphore... "); - logprintf(logdepth, "find_thread_CreateSemaphore:\n"); - logdepth++; - - if (try_icl(logdepth, node, test_c, "#include ", NULL, NULL) != 0) - return 0; - - return try_fail(logdepth, node); -} - -int find_thread_CreateThread(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "DWORD WINAPI test_thread(void* param)" - NL "{" - NL " return 0;" - NL "}" - NL "int main()" - NL "{" - NL " if (CreateThread(NULL, 0, test_thread, NULL, 0, NULL))" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "thread/CreateThread"; - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for CreateThread... "); - logprintf(logdepth, "find_thread_CreateThread:\n"); - logdepth++; - - if (try_icl(logdepth, node, test_c, "#include ", NULL, NULL) != 0) - return 0; - - return try_fail(logdepth, node); -} diff --git a/scconfig/src/default/.svn/pristine/32/32f2dc441d5a9ba913062eada1972cf9579235ac.svn-base b/scconfig/src/default/.svn/pristine/32/32f2dc441d5a9ba913062eada1972cf9579235ac.svn-base deleted file mode 100644 index 45192727..00000000 --- a/scconfig/src/default/.svn/pristine/32/32f2dc441d5a9ba913062eada1972cf9579235ac.svn-base +++ /dev/null @@ -1,182 +0,0 @@ -/* - scconfig - dependency list of default tests - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "dep.h" -#include "find.h" - -void deps_default_init(void) -{ - dep_add("cc/cc", find_cc); - dep_add("cc/argstd/*", find_cc_argstd); - dep_add("cc/cflags", find_cc); - dep_add("cc/ldflags", find_cc); - dep_add("cc/inline", find_inline); - dep_add("cc/varargmacro", find_varargmacro); - dep_add("cc/funcmacro", find_funcmacro); - dep_add("cc/constructor", find_constructor); - dep_add("cc/destructor", find_destructor); - dep_add("cc/rdynamic", find_rdynamic); - dep_add("cc/soname", find_soname); - dep_add("cc/so_undefined", find_so_undefined); - dep_add("cc/wlrpath", find_wlrpath); - dep_add("cc/wloutimplib", find_cc_wloutimplib); - dep_add("cc/wloutputdef", find_cc_wloutputdef); - dep_add("cc/fpic", find_fpic); - dep_add("cc/fpie/*", find_cc_fpie); - dep_add("cc/fnopie/*", find_cc_fnopie); - dep_add("cc/fnopic/*", find_cc_fnopic); - dep_add("cc/alloca/*", find_alloca); - dep_add("cc/_exit/*", find__exit); - dep_add("cc/ldflags_dynlib", find_ldflags_dynlib); - dep_add("cc/ldflags_dll", find_ldflags_dll); - dep_add("cc/ldflags_so", find_ldflags_so); - dep_add("cc/func_attr/unused/*", find_fattr_unused); - dep_add("cc/declspec/dllimport/*", find_declspec_dllimport); - dep_add("cc/declspec/dllexport/*", find_declspec_dllexport); - dep_add("cc/argmachine/*", find_cc_argmachine); - dep_add("cc/pragma_message/*", find_cc_pragma_message); - dep_add("cc/static_libgcc/*", find_cc_static_libgcc); - - dep_add("libs/ldl", find_lib_ldl); - dep_add("libs/LoadLibrary/*", find_lib_LoadLibrary); - dep_add("libs/lpthread", find_lib_lpthread); - dep_add("libs/lpthread-recursive", find_lib_lpthread); - dep_add("thread/semget/*", find_thread_semget); - dep_add("thread/pthread_create/*", find_thread_pthread_create); - dep_add("thread/CreateSemaphore/*", find_thread_CreateSemaphore); - dep_add("thread/CreateThread/*", find_thread_CreateThread); - dep_add("libs/errno/*", find_lib_errno); - dep_add("libs/printf_x", find_printf_x); - dep_add("libs/printf_ptrcast", find_printf_ptrcast); - dep_add("libs/snprintf", find_snprintf); - dep_add("libs/snprintf_safe", find_snprintf); - dep_add("libs/dprintf", find_dprintf); - dep_add("libs/vdprintf", find_vdprintf); - dep_add("libs/vsnprintf", find_vsnprintf); - dep_add("libs/proc/_spawnvp/*", find_proc__spawnvp); - dep_add("libs/proc/fork/*", find_proc_fork); - dep_add("libs/proc/wait/*", find_proc_wait); - dep_add("libs/proc/_getpid/*", find_proc__getpid); - dep_add("libs/proc/CreateProcessA/*",find_proc_CreateProcessA); - dep_add("libs/proc/getexecname/*", find_proc_getexecname); - dep_add("libs/proc/GetModuleFileNameA/*",find_proc_GetModuleFileNameA); - dep_add("libs/proc/shmget/*", find_proc_shmget); - dep_add("libs/proc/CreateFileMappingA/*",find_proc_CreateFileMappingA); - dep_add("libs/fs/realpath/*", find_fs_realpath); - dep_add("libs/fs/_fullpath/*", find_fs__fullpath); - dep_add("libs/fs/readdir/*", find_fs_readdir); - dep_add("libs/fs/findnextfile/*", find_fs_findnextfile); - dep_add("libs/fs/stat/macros/*", find_fs_stat_macros); - dep_add("libs/fs/stat/fields/*", find_fs_stat_fields); - dep_add("libs/fs/access/*", find_fs_access); - dep_add("libs/fs/access/macros/*", find_fs_access_macros); - dep_add("libs/fs/lstat/*", find_fs_lstat); - dep_add("libs/fs/statlstat/*", find_fs_statlstat); - dep_add("libs/fs/getcwd/*", find_fs_getcwd); - dep_add("libs/fs/_getcwd/*", find_fs__getcwd); - dep_add("libs/fs/getwd/*", find_fs_getwd); - dep_add("libs/fs/mkdir/*", find_fs_mkdir); - dep_add("libs/fs/_mkdir/*", find_fs__mkdir); - dep_add("libs/fs/mkdtemp/*", find_fs_mkdtemp); - dep_add("libs/fs/mmap/*", find_fs_mmap); - dep_add("libs/fsmount/next_dev/*", find_fsmount_next_dev); - dep_add("libs/fsmount/struct_fsstat/*",find_fsmount_fsstat_fields); - dep_add("libs/fsmount/struct_statfs/*",find_fsmount_statfs_fields); - dep_add("libs/fsmount/struct_statvfs/*",find_fsmount_statvfs_fields); - dep_add("libs/fs/ustat/*", find_fs_ustat); - dep_add("libs/fs/statfs/*", find_fs_statfs); - dep_add("libs/fs/statvfs/*", find_fs_statvfs); - dep_add("libs/fs/flock/*", find_fs_flock); - dep_add("libs/fs/makedev/*", find_fs_makedev); - - dep_add("libs/io/pipe/*", find_io_pipe); - dep_add("libs/io/dup2/*", find_io_dup2); - dep_add("libs/io/fileno/*", find_io_fileno); - dep_add("libs/io/lseek/*", find_io_lseek); - dep_add("libs/io/popen/*", find_io_popen); - dep_add("libs/time/usleep/*", find_time_usleep); - dep_add("libs/types/stdint/*", find_types_stdint); - dep_add("sys/types/size/*", find_types_sizes); - dep_add("libs/time/Sleep/*", find_time_Sleep); - dep_add("libs/time/gettimeofday/*", find_time_gettimeofday); - dep_add("libs/time/ftime/*", find_time_ftime); - dep_add("libs/time/timegm/*", find_time_timegm); - dep_add("libs/time/_mkgmtime/*", find_time_mkgmtime); - dep_add("libs/time/gmtime_r/*", find_time_gmtime_r); - dep_add("libs/time/gmtime_s/*", find_time_gmtime_s); - dep_add("libs/time/localtime_r/*", find_time_localtime_r); - dep_add("libs/time/localtime_s/*", find_time_localtime_s); - dep_add("libs/env/main_3arg/*", find_main_arg3); - dep_add("libs/env/putenv/*", find_putenv); - dep_add("libs/env/setenv/*", find_setenv); - dep_add("libs/env/environ/*", find_environ); - dep_add("signal/raise/*", find_signal_raise); - dep_add("signal/names/*", find_signal_names); - dep_add("fstools/cp", find_fstools_cp); - dep_add("fstools/ln", find_fstools_ln); - dep_add("fstools/mv", find_fstools_mv); - dep_add("fstools/rm", find_fstools_rm); - dep_add("fstools/mkdir", find_fstools_mkdir); - dep_add("fstools/ar", find_fstools_ar); - dep_add("fstools/ranlib", find_fstools_ranlib); - dep_add("fstools/awk", find_fstools_awk); - dep_add("fstools/cat", find_fstools_cat); - dep_add("fstools/sed", find_fstools_sed); - dep_add("fstools/file_l", find_fstools_file_l); - dep_add("fstools/file", find_fstools_file); - dep_add("fstools/chmodx", find_fstools_chmodx); - dep_add("sys/name", find_uname); - dep_add("sys/uname", find_uname); - dep_add("sys/triplet", find_triplet); - dep_add("sys/sysid", find_sysid); - dep_add("sys/shell", find_shell); - dep_add("sys/shell_needs_quote", find_shell); - dep_add("sys/tmp", find_tmp); - dep_add("sys/shell_eats_backslash", find_tmp); - dep_add("sys/ext_exe", find_uname); - dep_add("sys/ext_dynlib", find_uname); - dep_add("sys/ext_dynlib_native", find_uname); - dep_add("sys/ext_stalib", find_uname); - dep_add("sys/class", find_uname); - dep_add("sys/path_sep", find_uname); - dep_add("sys/ptrwidth", find_sys_ptrwidth); - dep_add("sys/byte_order", find_sys_byte_order); - dep_add("sys/types/size_t/*", find_types_size_t); - dep_add("sys/types/off_t/*", find_types_off_t); - dep_add("sys/types/off64_t/*", find_types_off64_t); - dep_add("sys/types/gid_t/*", find_types_gid_t); - dep_add("sys/types/uid_t/*", find_types_uid_t); - dep_add("sys/types/pid_t/*", find_types_pid_t); - dep_add("sys/types/mode_t/*", find_types_mode_t); - dep_add("sys/types/nlink_t/*", find_types_nlink_t); - dep_add("sys/types/ptrdiff_t/*", find_types_ptrdiff_t); - dep_add("sys/types/dev_t/*", find_types_dev_t); - dep_add("sys/types/ino_t/*", find_types_ino_t); - dep_add("sys/types/void_ptr/*", find_types_void_ptr); - dep_add("str/strcasecmp/*", find_strcasecmp); - dep_add("str/strncasecmp/*", find_strncasecmp); - dep_add("str/stricmp/*", find_stricmp); - dep_add("str/strnicmp/*", find_strnicmp); - - dep_add("/internal/filelist/cmd", find_filelist); - dep_add("/internal/filelist/method", find_filelist); -} diff --git a/scconfig/src/default/.svn/pristine/37/376674a4fc38625bf0d57d18def4ebdb1d20c7ec.svn-base b/scconfig/src/default/.svn/pristine/37/376674a4fc38625bf0d57d18def4ebdb1d20c7ec.svn-base deleted file mode 100644 index 94424768..00000000 --- a/scconfig/src/default/.svn/pristine/37/376674a4fc38625bf0d57d18def4ebdb1d20c7ec.svn-base +++ /dev/null @@ -1,366 +0,0 @@ -/* - scconfig - detection of standard library features (processes) - Copyright (C) 2016 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_proc__spawnvp(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " const char *a[3] = {\"/c\", \"echo OK\", NULL};" - NL " _spawnvp(_P_WAIT, \"cmd\", a);" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for _spawnvp... "); - logprintf(logdepth, "find_proc__spawnvp: trying to find _spawnvp...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/proc/_spawnvp", test_c, "#include ", NULL, NULL)) return 0; - - return try_fail(logdepth, "libs/proc/_spawnvp"); -} - -int find_proc_CreateProcessA(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/proc/CreateProcessA"; - char *test_c = - NL "#include " - NL "char buf[2000];" - NL "int main() {" - NL " const char *cmd;" - NL " STARTUPINFOA si;" - NL " PROCESS_INFORMATION pi;" - NL " cmd = getenv(\"COMSPEC\");" - NL " if (cmd == NULL) { /* fallback to guessing */" - NL " UINT len = GetWindowsDirectoryA(buf, sizeof(buf));" - NL " strcpy(buf+len, \"\\\\system32\\\\cmd.exe\");" - NL " cmd = buf;" - NL " }" - NL " memset(&si, 0, sizeof(si)); si.cb = sizeof(si);" - NL " if (!CreateProcessA(cmd, \"/c \\\"echo OK\\\"\"," - NL " NULL, NULL, TRUE," - NL " 0, NULL, NULL, &si, &pi))" - NL " return 1;" - NL " if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_OBJECT_0)" - NL " abort();" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for CreateProcessA... "); - logprintf(logdepth, "find_proc_CreateProcessA: trying to find CreateProcessA...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - - return try_fail(logdepth, key); -} - - - -int find_proc_fork(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " if (fork() == 0) { return 0; }" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - - /* NOTE: can't print OK from the child process because of a possible race - with the parent immediately exiting without wait(). */ - - require("cc/cc", logdepth, fatal); - - report("Checking for fork... "); - logprintf(logdepth, "find_proc_fork: trying to find fork...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/proc/fork", test_c, "#include ", NULL, NULL)) return 0; - - return try_fail(logdepth, "libs/proc/fork"); -} - - -int find_proc_wait(const char *name, int logdepth, int fatal) -{ - char *inc; - const char *inc1; - char test_c[1024]; - char *test_c_in = - NL "%s\n" - NL "#include " - NL "#include " - NL "int main() {" - NL " int st = 0;" - NL " if (fork() == 0) {" - NL " printf(\"O\");" - NL " return 42;" - NL " }" - NL " wait(&st);" - NL " if (WIFEXITED(st) && (WEXITSTATUS(st) == 42))" - NL " printf(\"K\");" - NL " else" - NL " printf(\"%%d\", st);" - NL " printf(\"\\n\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - if (require("libs/proc/fork", logdepth, fatal)) - return try_fail(logdepth, "libs/proc/wait"); - - report("Checking for wait... "); - logprintf(logdepth, "find_proc_wait: trying to find wait...\n"); - logdepth++; - - inc1 = get("libs/proc/fork/includes"); - if (inc1 != NULL) { - char *i, *o; - inc = strclone(inc1); - for(i = o = inc; *i != '\0'; i++,o++) { - if ((i[0] == '\\') && (i[1] == 'n')) { - *o = '\n'; - i++; - } - else - *o = *i; - } - *o = '\0'; - sprintf(test_c, test_c_in, inc); - free(inc); - } - else - sprintf(test_c, test_c_in, ""); - - if (try_icl(logdepth, "libs/proc/wait", test_c, "#include \n#include ", NULL, NULL)) return 0; - - return try_fail(logdepth, "libs/proc/wait"); -} - -int find_proc__getpid(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/proc/_getpid"; - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL no_implicit(int, "_getpid", "_getpid") - NL " if (_getpid() != (-1))" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for _getpid()... "); - logprintf(logdepth, "find_proc__getpid: trying to find _getpid()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) - return 0; - - return try_fail(logdepth, key); -} - -int find_proc_getexecname(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/proc/getexecname"; - const char *test_c = - NL "void my_puts(const char *s);" - NL "int main()" - NL "{" - NL no_implicit(const char*, "getexecname", "getexecname") - NL " getexecname();" - NL " my_puts(\"OK\");" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for getexecname()... "); - logprintf(logdepth, "find_proc_getexecname: trying to find getexecname()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) - return 0; - - return try_fail(logdepth, key); -} - -int find_proc_GetModuleFileNameA(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/proc/GetModuleFileNameA"; - const char *test_c = - NL "void my_puts(const char *s);" - NL "char path_buffer[5000];" - NL "int main()" - NL "{" - NL " HMODULE hModule = GetModuleHandleA(NULL);" - NL " if (GetModuleFileNameA(hModule, path_buffer, sizeof(path_buffer)) != 0)" - NL " my_puts(\"OK\");" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for GetModuleFileNameA()... "); - logprintf(logdepth, "find_proc_GetModuleFileNameA: trying to find GetModuleFileNameA()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) - return 0; - if (try_icl(logdepth, key, test_c, "#include ", NULL, "-lkernel32")) - return 0; - - return try_fail(logdepth, key); -} - -int find_proc_shmget(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/proc/shmget"; - const char *test_c = - NL "void my_puts(const char *s);" - NL "int main()" - NL "{" - NL " int shmid;" - NL " char *addr;" - NL " shmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT|IPC_EXCL|0600);" - NL " if (shmid < 0)" - NL " return 1;" - NL " addr = (char *)shmat(shmid, (void *)0, 0);" - NL " if (addr == (char *)0) {" - NL " shmctl(shmid, IPC_RMID, (void *)0);" - NL " return 1;" - NL " }" - NL " if (shmctl(shmid, IPC_RMID, (void *)0) != 0)" - NL " return 1;" - NL " if (addr[2] != 0)" - NL " return 1;" - NL " addr[0] = 'O'; addr[1] = 'K';" - NL " my_puts(addr);" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for shmget()... "); - logprintf(logdepth, "find_proc_shmget: trying to find shmget()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include \n#include ", NULL, NULL)) - return 0; - - return try_fail(logdepth, key); -} - -int find_proc_CreateFileMappingA(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/proc/CreateFileMappingA"; - const char *test_c = - NL "void my_puts(const char *s);" - NL "#define MAP_BUF_SIZE 4096" - NL "int main()" - NL "{" - NL " char *addr;" - NL " HANDLE hMap = CreateFileMappingA(" - NL " INVALID_HANDLE_VALUE," - NL " NULL," - NL " PAGE_READWRITE," - NL " 0," - NL " MAP_BUF_SIZE," - NL " NULL);" - NL " if (hMap == NULL)" - NL " return 1;" - NL " addr = (char *)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS," - NL " 0, 0, MAP_BUF_SIZE);" - NL " if (addr == NULL) {" - NL " CloseHandle(hMap);" - NL " return 1;" - NL " }" - NL " if (addr[2] != 0) {" - NL " UnmapViewOfFile(addr);" - NL " CloseHandle(hMap);" - NL " return 1;" - NL " }" - NL " addr[0] = 'O'; addr[1] = 'K';" - NL " my_puts(addr);" - NL " UnmapViewOfFile(addr);" - NL " CloseHandle(hMap);" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for CreateFileMappingA()... "); - logprintf(logdepth, "find_proc_CreateFileMappingA: trying to find CreateFileMappingA()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) - return 0; - if (try_icl(logdepth, key, test_c, "#include ", NULL, "-lkernel32")) - return 0; - - return try_fail(logdepth, key); -} diff --git a/scconfig/src/default/.svn/pristine/39/3911f5963f6a6e2e24d22b9e3f01db85e4c42f2c.svn-base b/scconfig/src/default/.svn/pristine/39/3911f5963f6a6e2e24d22b9e3f01db85e4c42f2c.svn-base deleted file mode 100644 index a086062a..00000000 --- a/scconfig/src/default/.svn/pristine/39/3911f5963f6a6e2e24d22b9e3f01db85e4c42f2c.svn-base +++ /dev/null @@ -1,180 +0,0 @@ -/* - scconfig - dependency list of default tests - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "dep.h" -#include "find.h" - -void deps_default_init(void) -{ - dep_add("cc/cc", find_cc); - dep_add("cc/argstd/*", find_cc_argstd); - dep_add("cc/cflags", find_cc); - dep_add("cc/ldflags", find_cc); - dep_add("cc/inline", find_inline); - dep_add("cc/varargmacro", find_varargmacro); - dep_add("cc/funcmacro", find_funcmacro); - dep_add("cc/constructor", find_constructor); - dep_add("cc/destructor", find_destructor); - dep_add("cc/rdynamic", find_rdynamic); - dep_add("cc/soname", find_soname); - dep_add("cc/wlrpath", find_wlrpath); - dep_add("cc/wloutimplib", find_cc_wloutimplib); - dep_add("cc/wloutputdef", find_cc_wloutputdef); - dep_add("cc/fpic", find_fpic); - dep_add("cc/fpie/*", find_cc_fpie); - dep_add("cc/fnopie/*", find_cc_fnopie); - dep_add("cc/fnopic/*", find_cc_fnopic); - dep_add("cc/alloca/*", find_alloca); - dep_add("cc/_exit/*", find__exit); - dep_add("cc/ldflags_dynlib", find_ldflags_dynlib); - dep_add("cc/ldflags_dll", find_ldflags_dll); - dep_add("cc/ldflags_so", find_ldflags_so); - dep_add("cc/func_attr/unused/*", find_fattr_unused); - dep_add("cc/declspec/dllimport/*", find_declspec_dllimport); - dep_add("cc/declspec/dllexport/*", find_declspec_dllexport); - dep_add("cc/argmachine/*", find_cc_argmachine); - dep_add("cc/pragma_message/*", find_cc_pragma_message); - dep_add("cc/static_libgcc/*", find_cc_static_libgcc); - - dep_add("libs/ldl", find_lib_ldl); - dep_add("libs/LoadLibrary/*", find_lib_LoadLibrary); - dep_add("libs/lpthread", find_lib_lpthread); - dep_add("libs/lpthread-recursive", find_lib_lpthread); - dep_add("thread/semget/*", find_thread_semget); - dep_add("thread/pthread_create/*", find_thread_pthread_create); - dep_add("thread/CreateSemaphore/*", find_thread_CreateSemaphore); - dep_add("thread/CreateThread/*", find_thread_CreateThread); - dep_add("libs/errno/*", find_lib_errno); - dep_add("libs/printf_x", find_printf_x); - dep_add("libs/printf_ptrcast", find_printf_ptrcast); - dep_add("libs/snprintf", find_snprintf); - dep_add("libs/snprintf_safe", find_snprintf); - dep_add("libs/dprintf", find_dprintf); - dep_add("libs/vdprintf", find_vdprintf); - dep_add("libs/vsnprintf", find_vsnprintf); - dep_add("libs/proc/_spawnvp/*", find_proc__spawnvp); - dep_add("libs/proc/fork/*", find_proc_fork); - dep_add("libs/proc/wait/*", find_proc_wait); - dep_add("libs/proc/_getpid/*", find_proc__getpid); - dep_add("libs/proc/CreateProcessA/*",find_proc_CreateProcessA); - dep_add("libs/proc/getexecname/*", find_proc_getexecname); - dep_add("libs/proc/GetModuleFileNameA/*",find_proc_GetModuleFileNameA); - dep_add("libs/proc/shmget/*", find_proc_shmget); - dep_add("libs/proc/CreateFileMappingA/*",find_proc_CreateFileMappingA); - dep_add("libs/fs/realpath/*", find_fs_realpath); - dep_add("libs/fs/_fullpath/*", find_fs__fullpath); - dep_add("libs/fs/readdir/*", find_fs_readdir); - dep_add("libs/fs/findnextfile/*", find_fs_findnextfile); - dep_add("libs/fs/stat/macros/*", find_fs_stat_macros); - dep_add("libs/fs/stat/fields/*", find_fs_stat_fields); - dep_add("libs/fs/access/*", find_fs_access); - dep_add("libs/fs/access/macros/*", find_fs_access_macros); - dep_add("libs/fs/lstat/*", find_fs_lstat); - dep_add("libs/fs/statlstat/*", find_fs_statlstat); - dep_add("libs/fs/getcwd/*", find_fs_getcwd); - dep_add("libs/fs/_getcwd/*", find_fs__getcwd); - dep_add("libs/fs/getwd/*", find_fs_getwd); - dep_add("libs/fs/mkdir/*", find_fs_mkdir); - dep_add("libs/fs/_mkdir/*", find_fs__mkdir); - dep_add("libs/fs/mkdtemp/*", find_fs_mkdtemp); - dep_add("libs/fs/mmap/*", find_fs_mmap); - dep_add("libs/fsmount/next_dev/*", find_fsmount_next_dev); - dep_add("libs/fsmount/struct_fsstat/*",find_fsmount_fsstat_fields); - dep_add("libs/fsmount/struct_statfs/*",find_fsmount_statfs_fields); - dep_add("libs/fsmount/struct_statvfs/*",find_fsmount_statvfs_fields); - dep_add("libs/fs/ustat/*", find_fs_ustat); - dep_add("libs/fs/statfs/*", find_fs_statfs); - dep_add("libs/fs/statvfs/*", find_fs_statvfs); - dep_add("libs/fs/flock/*", find_fs_flock); - - dep_add("libs/io/pipe/*", find_io_pipe); - dep_add("libs/io/dup2/*", find_io_dup2); - dep_add("libs/io/fileno/*", find_io_fileno); - dep_add("libs/io/lseek/*", find_io_lseek); - dep_add("libs/io/popen/*", find_io_popen); - dep_add("libs/time/usleep/*", find_time_usleep); - dep_add("libs/types/stdint/*", find_types_stdint); - dep_add("sys/types/size/*", find_types_sizes); - dep_add("libs/time/Sleep/*", find_time_Sleep); - dep_add("libs/time/gettimeofday/*", find_time_gettimeofday); - dep_add("libs/time/ftime/*", find_time_ftime); - dep_add("libs/time/timegm/*", find_time_timegm); - dep_add("libs/time/_mkgmtime/*", find_time_mkgmtime); - dep_add("libs/time/gmtime_r/*", find_time_gmtime_r); - dep_add("libs/time/gmtime_s/*", find_time_gmtime_s); - dep_add("libs/time/localtime_r/*", find_time_localtime_r); - dep_add("libs/time/localtime_s/*", find_time_localtime_s); - dep_add("libs/env/main_3arg/*", find_main_arg3); - dep_add("libs/env/putenv/*", find_putenv); - dep_add("libs/env/setenv/*", find_setenv); - dep_add("libs/env/environ/*", find_environ); - dep_add("signal/raise/*", find_signal_raise); - dep_add("signal/names/*", find_signal_names); - dep_add("fstools/cp", find_fstools_cp); - dep_add("fstools/ln", find_fstools_ln); - dep_add("fstools/mv", find_fstools_mv); - dep_add("fstools/rm", find_fstools_rm); - dep_add("fstools/mkdir", find_fstools_mkdir); - dep_add("fstools/ar", find_fstools_ar); - dep_add("fstools/ranlib", find_fstools_ranlib); - dep_add("fstools/awk", find_fstools_awk); - dep_add("fstools/cat", find_fstools_cat); - dep_add("fstools/sed", find_fstools_sed); - dep_add("fstools/file_l", find_fstools_file_l); - dep_add("fstools/file", find_fstools_file); - dep_add("fstools/chmodx", find_fstools_chmodx); - dep_add("sys/name", find_uname); - dep_add("sys/uname", find_uname); - dep_add("sys/triplet", find_triplet); - dep_add("sys/sysid", find_sysid); - dep_add("sys/shell", find_shell); - dep_add("sys/shell_needs_quote", find_shell); - dep_add("sys/tmp", find_tmp); - dep_add("sys/shell_eats_backslash", find_tmp); - dep_add("sys/ext_exe", find_uname); - dep_add("sys/ext_dynlib", find_uname); - dep_add("sys/ext_dynlib_native", find_uname); - dep_add("sys/ext_stalib", find_uname); - dep_add("sys/class", find_uname); - dep_add("sys/path_sep", find_uname); - dep_add("sys/ptrwidth", find_sys_ptrwidth); - dep_add("sys/byte_order", find_sys_byte_order); - dep_add("sys/types/size_t/*", find_types_size_t); - dep_add("sys/types/off_t/*", find_types_off_t); - dep_add("sys/types/off64_t/*", find_types_off64_t); - dep_add("sys/types/gid_t/*", find_types_gid_t); - dep_add("sys/types/uid_t/*", find_types_uid_t); - dep_add("sys/types/pid_t/*", find_types_pid_t); - dep_add("sys/types/mode_t/*", find_types_mode_t); - dep_add("sys/types/nlink_t/*", find_types_nlink_t); - dep_add("sys/types/ptrdiff_t/*", find_types_ptrdiff_t); - dep_add("sys/types/dev_t/*", find_types_dev_t); - dep_add("sys/types/ino_t/*", find_types_ino_t); - dep_add("sys/types/void_ptr/*", find_types_void_ptr); - dep_add("str/strcasecmp/*", find_strcasecmp); - dep_add("str/strncasecmp/*", find_strncasecmp); - dep_add("str/stricmp/*", find_stricmp); - dep_add("str/strnicmp/*", find_strnicmp); - - dep_add("/internal/filelist/cmd", find_filelist); - dep_add("/internal/filelist/method", find_filelist); -} diff --git a/scconfig/src/default/.svn/pristine/3c/3c012c2d6299aeb1b00d9b44877bd14494b56949.svn-base b/scconfig/src/default/.svn/pristine/3c/3c012c2d6299aeb1b00d9b44877bd14494b56949.svn-base deleted file mode 100644 index f32d734c..00000000 --- a/scconfig/src/default/.svn/pristine/3c/3c012c2d6299aeb1b00d9b44877bd14494b56949.svn-base +++ /dev/null @@ -1,172 +0,0 @@ -/* cc */ -int find_cc(const char *name, int logdepth, int fatal); -int find_cc_argstd(const char *name, int logdepth, int fatal); -int find_cc_argmachine(const char *name, int logdepth, int fatal); -int find_cc_fpie(const char *name, int logdepth, int fatal); -int find_cc_fnopie(const char *name, int logdepth, int fatal); -int find_cc_fnopic(const char *name, int logdepth, int fatal); -int find_inline(const char *name, int logdepth, int fatal); -int find_varargmacro(const char *name, int logdepth, int fatal); -int find_funcmacro(const char *name, int logdepth, int fatal); -int find_constructor(const char *name, int logdepth, int fatal); -int find_destructor(const char *name, int logdepth, int fatal); -int find_fattr_unused(const char *name, int logdepth, int fatal); -int find_declspec_dllimport(const char *name, int logdepth, int fatal); -int find_declspec_dllexport(const char *name, int logdepth, int fatal); -int find_rdynamic(const char *name, int logdepth, int fatal); -int find_soname(const char *name, int logdepth, int fatal); -int find_so_undefined(const char *name, int logdepth, int fatal); -int find_wlrpath(const char *name, int logdepth, int fatal); -int find_cc_wloutimplib(const char *name, int logdepth, int fatal); -int find_cc_wloutputdef(const char *name, int logdepth, int fatal); -int find_fpic(const char *name, int logdepth, int fatal); -int find_ldflags_dynlib(const char *name, int logdepth, int fatal); -int find_ldflags_dll(const char *name, int logdepth, int fatal); -int find_ldflags_so(const char *name, int logdepth, int fatal); -int find_alloca(const char *name, int logdepth, int fatal); -int find__exit(const char *name, int logdepth, int fatal); -int find_cc_pragma_message(const char *name, int logdepth, int fatal); -int find_cc_static_libgcc(const char *name, int logdepth, int fatal); - -/* libs */ -int find_lib_ldl(const char *name, int logdepth, int fatal); -int find_lib_LoadLibrary(const char *name, int logdepth, int fatal); -int find_lib_errno(const char *name, int logdepth, int fatal); - -/* thread */ -int find_lib_lpthread(const char *name, int logdepth, int fatal); -int find_thread_semget(const char *name, int logdepth, int fatal); -int find_thread_pthread_create(const char *name, int logdepth, int fatal); -int find_thread_CreateSemaphore(const char *name, int logdepth, int fatal); -int find_thread_CreateThread(const char *name, int logdepth, int fatal); - -/* fscalls */ -int find_fs_realpath(const char *name, int logdepth, int fatal); -int find_fs__fullpath(const char *name, int logdepth, int fatal); -int find_fs_readdir(const char *name, int logdepth, int fatal); -int find_fs_findnextfile(const char *name, int logdepth, int fatal); -int find_fs_access(const char *name, int logdepth, int fatal); -int find_fs_access_macros(const char *name, int logdepth, int fatal); -int find_fs_stat_macros(const char *name, int logdepth, int fatal); -int find_fs_stat_fields(const char *name, int logdepth, int fatal); -int find_fs_lstat(const char *name, int logdepth, int fatal); -int find_fs_statlstat(const char *name, int logdepth, int fatal); -int find_fs_getcwd(const char *name, int logdepth, int fatal); -int find_fs__getcwd(const char *name, int logdepth, int fatal); -int find_fs_getwd(const char *name, int logdepth, int fatal); -int find_fs_mkdir(const char *name, int logdepth, int fatal); -int find_fs__mkdir(const char *name, int logdepth, int fatal); -int find_fs_mkdtemp(const char *name, int logdepth, int fatal); -int find_fs_mmap(const char *name, int logdepth, int fatal); -int find_fsmount_next_dev(const char *name, int logdepth, int fatal); -int find_fsmount_fsstat_fields(const char *name, int logdepth, int fatal); -int find_fsmount_statfs_fields(const char *name, int logdepth, int fatal); -int find_fsmount_statvfs_fields(const char *name, int logdepth, int fatal); -int find_fs_ustat(const char *name, int logdepth, int fatal); -int find_fs_statfs(const char *name, int logdepth, int fatal); -int find_fs_statvfs(const char *name, int logdepth, int fatal); -int find_fs_flock(const char *name, int logdepth, int fatal); - -/* printf */ -int find_printf_x(const char *name, int logdepth, int fatal); -int find_printf_ptrcast(const char *name, int logdepth, int fatal); -int find_snprintf(const char *name, int logdepth, int fatal); -int find_dprintf(const char *name, int logdepth, int fatal); -int find_vdprintf(const char *name, int logdepth, int fatal); -int find_vsnprintf(const char *name, int logdepth, int fatal); - -/* proc */ -int find_proc__spawnvp(const char *name, int logdepth, int fatal); -int find_proc_fork(const char *name, int logdepth, int fatal); -int find_proc_wait(const char *name, int logdepth, int fatal); -int find_proc__getpid(const char *name, int logdepth, int fatal); -int find_proc_CreateProcessA(const char *name, int logdepth, int fatal); -int find_proc_getexecname(const char *name, int logdepth, int fatal); -int find_proc_GetModuleFileNameA(const char *name, int logdepth, int fatal); -int find_proc_shmget(const char *name, int logdepth, int fatal); -int find_proc_CreateFileMappingA(const char *name, int logdepth, int fatal); - -/* fstools */ -int find_fstools_cp(const char *name, int logdepth, int fatal); -int find_fstools_ln(const char *name, int logdepth, int fatal); -int find_fstools_mv(const char *name, int logdepth, int fatal); -int find_fstools_rm(const char *name, int logdepth, int fatal); -int find_fstools_mkdir(const char *name, int logdepth, int fatal); -int find_fstools_ar(const char *name, int logdepth, int fatal); -int find_fstools_ranlib(const char *name, int logdepth, int fatal); -int find_fstools_awk(const char *name, int logdepth, int fatal); -int find_fstools_cat(const char *name, int logdepth, int fatal); -int find_fstools_sed(const char *name, int logdepth, int fatal); -int find_fstools_file(const char *name, int logdepth, int fatal); -int find_fstools_file_l(const char *name, int logdepth, int fatal); -int find_fstools_chmodx(const char *name, int logdepth, int fatal); - -/* uname */ -int find_uname(const char *name, int logdepth, int fatal); -int find_triplet(const char *name, int logdepth, int fatal); -int find_sysid(const char *name, int logdepth, int fatal); - -/* find_target */ -int find_target(const char *name, int logdepth, int fatal); - -/* filelist */ -int find_filelist(const char *name, int logdepth, int fatal); - -/* find_str.c */ -int find_strcasecmp(const char *name, int logdepth, int fatal); -int find_strncasecmp(const char *name, int logdepth, int fatal); -int find_stricmp(const char *name, int logdepth, int fatal); -int find_strnicmp(const char *name, int logdepth, int fatal); - -/* find_sys.c */ -int find_sys_ptrwidth(const char *name, int logdepth, int fatal); -int find_sys_byte_order(const char *name, int logdepth, int fatal); -int find_tmp(const char *name, int logdepth, int fatal); -int find_shell(const char *name, int logdepth, int fatal); - -/* find_io.c */ -int find_io_pipe(const char *name, int logdepth, int fatal); -int find_io_dup2(const char *name, int logdepth, int fatal); -int find_io_fileno(const char *name, int logdepth, int fatal); -int find_io_lseek(const char *name, int logdepth, int fatal); -int find_io_popen(const char *name, int logdepth, int fatal); - -/* find_time.c */ -int find_time_usleep(const char *name, int logdepth, int fatal); -int find_time_Sleep(const char *name, int logdepth, int fatal); -int find_time_gettimeofday(const char *name, int logdepth, int fatal); -int find_time_ftime(const char *name, int logdepth, int fatal); -int find_time_timegm(const char *name, int logdepth, int fatal); -int find_time_mkgmtime(const char *name, int logdepth, int fatal); -int find_time_gmtime_s(const char *name, int logdepth, int fatal); -int find_time_gmtime_r(const char *name, int logdepth, int fatal); -int find_time_localtime_s(const char *name, int logdepth, int fatal); -int find_time_localtime_r(const char *name, int logdepth, int fatal); - -/* find_types.c */ -int find_types_stdint(const char *name, int logdepth, int fatal); -int find_types_sizes(const char *name, int logdepth, int fatal); -int find_types_size_t(const char *name, int logdepth, int fatal); -int find_types_off_t(const char *name, int logdepth, int fatal); -int find_types_off64_t(const char *name, int logdepth, int fatal); -int find_types_gid_t(const char *name, int logdepth, int fatal); -int find_types_uid_t(const char *name, int logdepth, int fatal); -int find_types_pid_t(const char *name, int logdepth, int fatal); -int find_types_dev_t(const char *name, int logdepth, int fatal); -int find_types_dev_t(const char *name, int logdepth, int fatal); -int find_types_mode_t(const char *name, int logdepth, int fatal); -int find_types_nlink_t(const char *name, int logdepth, int fatal); -int find_types_ptrdiff_t(const char *name, int logdepth, int fatal); -int find_types_dev_t(const char *name, int logdepth, int fatal); -int find_types_ino_t(const char *name, int logdepth, int fatal); -int find_types_void_ptr(const char *name, int logdepth, int fatal); - -/* find_signal.c */ -int find_signal_names(const char *name, int logdepth, int fatal); -int find_signal_raise(const char *name, int logdepth, int fatal); - -/* environ.c */ -int find_main_arg3(const char *name, int logdepth, int fatal); -int find_putenv(const char *name, int logdepth, int fatal); -int find_setenv(const char *name, int logdepth, int fatal); -int find_environ(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/default/.svn/pristine/3e/3e69b4533d7d5914d0c56b45f4d6bca7870ec034.svn-base b/scconfig/src/default/.svn/pristine/3e/3e69b4533d7d5914d0c56b45f4d6bca7870ec034.svn-base deleted file mode 100644 index 0b855def..00000000 --- a/scconfig/src/default/.svn/pristine/3e/3e69b4533d7d5914d0c56b45f4d6bca7870ec034.svn-base +++ /dev/null @@ -1,181 +0,0 @@ -/* - scconfig - dependency list of default tests - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "dep.h" -#include "find.h" - -void deps_default_init(void) -{ - dep_add("cc/cc", find_cc); - dep_add("cc/argstd/*", find_cc_argstd); - dep_add("cc/cflags", find_cc); - dep_add("cc/ldflags", find_cc); - dep_add("cc/inline", find_inline); - dep_add("cc/varargmacro", find_varargmacro); - dep_add("cc/funcmacro", find_funcmacro); - dep_add("cc/constructor", find_constructor); - dep_add("cc/destructor", find_destructor); - dep_add("cc/rdynamic", find_rdynamic); - dep_add("cc/soname", find_soname); - dep_add("cc/so_undefined", find_so_undefined); - dep_add("cc/wlrpath", find_wlrpath); - dep_add("cc/wloutimplib", find_cc_wloutimplib); - dep_add("cc/wloutputdef", find_cc_wloutputdef); - dep_add("cc/fpic", find_fpic); - dep_add("cc/fpie/*", find_cc_fpie); - dep_add("cc/fnopie/*", find_cc_fnopie); - dep_add("cc/fnopic/*", find_cc_fnopic); - dep_add("cc/alloca/*", find_alloca); - dep_add("cc/_exit/*", find__exit); - dep_add("cc/ldflags_dynlib", find_ldflags_dynlib); - dep_add("cc/ldflags_dll", find_ldflags_dll); - dep_add("cc/ldflags_so", find_ldflags_so); - dep_add("cc/func_attr/unused/*", find_fattr_unused); - dep_add("cc/declspec/dllimport/*", find_declspec_dllimport); - dep_add("cc/declspec/dllexport/*", find_declspec_dllexport); - dep_add("cc/argmachine/*", find_cc_argmachine); - dep_add("cc/pragma_message/*", find_cc_pragma_message); - dep_add("cc/static_libgcc/*", find_cc_static_libgcc); - - dep_add("libs/ldl", find_lib_ldl); - dep_add("libs/LoadLibrary/*", find_lib_LoadLibrary); - dep_add("libs/lpthread", find_lib_lpthread); - dep_add("libs/lpthread-recursive", find_lib_lpthread); - dep_add("thread/semget/*", find_thread_semget); - dep_add("thread/pthread_create/*", find_thread_pthread_create); - dep_add("thread/CreateSemaphore/*", find_thread_CreateSemaphore); - dep_add("thread/CreateThread/*", find_thread_CreateThread); - dep_add("libs/errno/*", find_lib_errno); - dep_add("libs/printf_x", find_printf_x); - dep_add("libs/printf_ptrcast", find_printf_ptrcast); - dep_add("libs/snprintf", find_snprintf); - dep_add("libs/snprintf_safe", find_snprintf); - dep_add("libs/dprintf", find_dprintf); - dep_add("libs/vdprintf", find_vdprintf); - dep_add("libs/vsnprintf", find_vsnprintf); - dep_add("libs/proc/_spawnvp/*", find_proc__spawnvp); - dep_add("libs/proc/fork/*", find_proc_fork); - dep_add("libs/proc/wait/*", find_proc_wait); - dep_add("libs/proc/_getpid/*", find_proc__getpid); - dep_add("libs/proc/CreateProcessA/*",find_proc_CreateProcessA); - dep_add("libs/proc/getexecname/*", find_proc_getexecname); - dep_add("libs/proc/GetModuleFileNameA/*",find_proc_GetModuleFileNameA); - dep_add("libs/proc/shmget/*", find_proc_shmget); - dep_add("libs/proc/CreateFileMappingA/*",find_proc_CreateFileMappingA); - dep_add("libs/fs/realpath/*", find_fs_realpath); - dep_add("libs/fs/_fullpath/*", find_fs__fullpath); - dep_add("libs/fs/readdir/*", find_fs_readdir); - dep_add("libs/fs/findnextfile/*", find_fs_findnextfile); - dep_add("libs/fs/stat/macros/*", find_fs_stat_macros); - dep_add("libs/fs/stat/fields/*", find_fs_stat_fields); - dep_add("libs/fs/access/*", find_fs_access); - dep_add("libs/fs/access/macros/*", find_fs_access_macros); - dep_add("libs/fs/lstat/*", find_fs_lstat); - dep_add("libs/fs/statlstat/*", find_fs_statlstat); - dep_add("libs/fs/getcwd/*", find_fs_getcwd); - dep_add("libs/fs/_getcwd/*", find_fs__getcwd); - dep_add("libs/fs/getwd/*", find_fs_getwd); - dep_add("libs/fs/mkdir/*", find_fs_mkdir); - dep_add("libs/fs/_mkdir/*", find_fs__mkdir); - dep_add("libs/fs/mkdtemp/*", find_fs_mkdtemp); - dep_add("libs/fs/mmap/*", find_fs_mmap); - dep_add("libs/fsmount/next_dev/*", find_fsmount_next_dev); - dep_add("libs/fsmount/struct_fsstat/*",find_fsmount_fsstat_fields); - dep_add("libs/fsmount/struct_statfs/*",find_fsmount_statfs_fields); - dep_add("libs/fsmount/struct_statvfs/*",find_fsmount_statvfs_fields); - dep_add("libs/fs/ustat/*", find_fs_ustat); - dep_add("libs/fs/statfs/*", find_fs_statfs); - dep_add("libs/fs/statvfs/*", find_fs_statvfs); - dep_add("libs/fs/flock/*", find_fs_flock); - - dep_add("libs/io/pipe/*", find_io_pipe); - dep_add("libs/io/dup2/*", find_io_dup2); - dep_add("libs/io/fileno/*", find_io_fileno); - dep_add("libs/io/lseek/*", find_io_lseek); - dep_add("libs/io/popen/*", find_io_popen); - dep_add("libs/time/usleep/*", find_time_usleep); - dep_add("libs/types/stdint/*", find_types_stdint); - dep_add("sys/types/size/*", find_types_sizes); - dep_add("libs/time/Sleep/*", find_time_Sleep); - dep_add("libs/time/gettimeofday/*", find_time_gettimeofday); - dep_add("libs/time/ftime/*", find_time_ftime); - dep_add("libs/time/timegm/*", find_time_timegm); - dep_add("libs/time/_mkgmtime/*", find_time_mkgmtime); - dep_add("libs/time/gmtime_r/*", find_time_gmtime_r); - dep_add("libs/time/gmtime_s/*", find_time_gmtime_s); - dep_add("libs/time/localtime_r/*", find_time_localtime_r); - dep_add("libs/time/localtime_s/*", find_time_localtime_s); - dep_add("libs/env/main_3arg/*", find_main_arg3); - dep_add("libs/env/putenv/*", find_putenv); - dep_add("libs/env/setenv/*", find_setenv); - dep_add("libs/env/environ/*", find_environ); - dep_add("signal/raise/*", find_signal_raise); - dep_add("signal/names/*", find_signal_names); - dep_add("fstools/cp", find_fstools_cp); - dep_add("fstools/ln", find_fstools_ln); - dep_add("fstools/mv", find_fstools_mv); - dep_add("fstools/rm", find_fstools_rm); - dep_add("fstools/mkdir", find_fstools_mkdir); - dep_add("fstools/ar", find_fstools_ar); - dep_add("fstools/ranlib", find_fstools_ranlib); - dep_add("fstools/awk", find_fstools_awk); - dep_add("fstools/cat", find_fstools_cat); - dep_add("fstools/sed", find_fstools_sed); - dep_add("fstools/file_l", find_fstools_file_l); - dep_add("fstools/file", find_fstools_file); - dep_add("fstools/chmodx", find_fstools_chmodx); - dep_add("sys/name", find_uname); - dep_add("sys/uname", find_uname); - dep_add("sys/triplet", find_triplet); - dep_add("sys/sysid", find_sysid); - dep_add("sys/shell", find_shell); - dep_add("sys/shell_needs_quote", find_shell); - dep_add("sys/tmp", find_tmp); - dep_add("sys/shell_eats_backslash", find_tmp); - dep_add("sys/ext_exe", find_uname); - dep_add("sys/ext_dynlib", find_uname); - dep_add("sys/ext_dynlib_native", find_uname); - dep_add("sys/ext_stalib", find_uname); - dep_add("sys/class", find_uname); - dep_add("sys/path_sep", find_uname); - dep_add("sys/ptrwidth", find_sys_ptrwidth); - dep_add("sys/byte_order", find_sys_byte_order); - dep_add("sys/types/size_t/*", find_types_size_t); - dep_add("sys/types/off_t/*", find_types_off_t); - dep_add("sys/types/off64_t/*", find_types_off64_t); - dep_add("sys/types/gid_t/*", find_types_gid_t); - dep_add("sys/types/uid_t/*", find_types_uid_t); - dep_add("sys/types/pid_t/*", find_types_pid_t); - dep_add("sys/types/mode_t/*", find_types_mode_t); - dep_add("sys/types/nlink_t/*", find_types_nlink_t); - dep_add("sys/types/ptrdiff_t/*", find_types_ptrdiff_t); - dep_add("sys/types/dev_t/*", find_types_dev_t); - dep_add("sys/types/ino_t/*", find_types_ino_t); - dep_add("sys/types/void_ptr/*", find_types_void_ptr); - dep_add("str/strcasecmp/*", find_strcasecmp); - dep_add("str/strncasecmp/*", find_strncasecmp); - dep_add("str/stricmp/*", find_stricmp); - dep_add("str/strnicmp/*", find_strnicmp); - - dep_add("/internal/filelist/cmd", find_filelist); - dep_add("/internal/filelist/method", find_filelist); -} diff --git a/scconfig/src/default/.svn/pristine/42/427f072049a26918fd78985ae2b3f5542f56d47c.svn-base b/scconfig/src/default/.svn/pristine/42/427f072049a26918fd78985ae2b3f5542f56d47c.svn-base deleted file mode 100644 index e926a27f..00000000 --- a/scconfig/src/default/.svn/pristine/42/427f072049a26918fd78985ae2b3f5542f56d47c.svn-base +++ /dev/null @@ -1,410 +0,0 @@ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -/* Returns true if the first 2 characters of the output is OK */ -static int try_icl_accept_ok(char *stdout_str) -{ - return (strncmp(stdout_str, "OK", 2) == 0); -} - -#define is_ctrl_prefix(ch) (((ch) == '!') || ((ch) == '^')) - -static int try_icl__(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags, const char *db_includes, const char *db_cflags, const char *db_ldflags, int run, int (*accept_res)(char *stdout_str)) -{ - char *out = NULL; - char *tmp, *inc; - const char *test_c; - char c[1024]; - int l, compres; - - if (includes != NULL) { - l = strlen(includes); - memcpy(c, includes, l); - c[l] = '\n'; - l++; - strcpy(c+l, test_c_in); - test_c = c; - } - else - test_c = test_c_in; - - logprintf(logdepth, "trying '%s' and '%s' and '%s', %s\n", str_null(db_includes), str_null(db_cflags), str_null(db_ldflags), run ? "with a run" : "with no run"); - - if (run) - compres = compile_run(logdepth+1, test_c, NULL, cflags, ldflags, &out); - else { - char *fn_output = NULL; - compres = compile_code(logdepth+1, test_c, &fn_output, NULL, cflags, ldflags); - if (fn_output != NULL) { - unlink(fn_output); - free(fn_output); - } - } - - - if (compres == 0) { - if (!run || target_emu_fail(out) || accept_res(out)) { - free(out); - - /* no prefix: don't modify the database, the caller will do that */ - if (prefix == NULL) - return 1; - - tmp = malloc(strlen(prefix) + 32); - - if ((db_includes == NULL) || (*db_includes == '\0')) - inc = strclone(""); - else - inc = uniq_inc_str(db_includes, NULL, "\\n", 0, 0, NULL); - sprintf(tmp, "%s/includes", prefix); - put(tmp, inc); - - if (db_cflags == NULL) - db_cflags = ""; - - sprintf(tmp, "%s/cflags", prefix); - put(tmp, db_cflags); - - - if (db_ldflags == NULL) - db_ldflags = ""; - sprintf(tmp, "%s/ldflags", prefix); - put(tmp, db_ldflags); - - if (inc != NULL) { - report("OK ('%s', '%s' and '%s')\n", str_null(inc), str_null(db_cflags), str_null(db_ldflags)); - free(inc); - } - else - report("OK ('%s' and '%s')\n", str_null(db_cflags), str_null(db_ldflags)); - - sprintf(tmp, "%s/presents", prefix); - put(tmp, strue); - free(tmp); - return 1; - } - free(out); - } - return 0; -} - -#define LOAD(node) \ -do { \ - if (u ## node != NULL) break; \ - strcpy(apath_end, #node); \ - u ## node = get(apath); \ -} while(0) - -#define SET(dst, src, is_flag) \ -do { \ - char *__sep__ = is_flag ? " " : "\n"; \ - const char *__dst__ = dst == NULL ? "" : dst; \ - char *__out__; \ - if (is_ctrl_prefix(*__dst__)) __dst__++; \ - if (*src == '!') \ - __out__ = strclone(src+1); \ - else if (*src == '^') {\ - if (src[1] != '\0') \ - __out__ = str_concat("", src+1, __sep__, __dst__, NULL); \ - else \ - __out__ = strclone(__dst__); \ - } \ - else { \ - if (*__dst__ != '\0') \ - __out__ = str_concat("", __dst__, __sep__, src, NULL); \ - else \ - __out__ = strclone(src); \ - } \ - free(dst); \ - dst = __out__; \ - if (is_flag) { \ - char *__s__; \ - for(__s__ = dst; *__s__ != '\0'; __s__++) \ - if ((*__s__ == '\n') || (*__s__ == '\r')) \ - *__s__ = ' '; \ - } \ -} while(0) - - -/* Figure user overrides and call try_icl__() accordingly */ -int try_icl_(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags, int run, int (*accept_res)(char *stdout_str)) -{ - char apath[1024], *apath_end; - int l, res; - const char *uincludes = NULL, *ucflags = NULL, *uldflags = NULL, *uprefix = NULL; /* user specified */ - char *rincludes, *rcflags, *rldflags; /* real */ - char *dbincludes = NULL, *dbcflags = NULL, *dbldflags = NULL; /* what to add in the db at the end */ - - /* load uincludes, uclfags, uldflags and uprefix - LOAD() inserts the u */ - l = sprintf(apath, "/arg/icl/%s/", prefix); apath_end = apath+l; - LOAD(includes); - LOAD(cflags); - LOAD(ldflags); - LOAD(prefix); - l = sprintf(apath, "/arg/icl/%s/%s/", db_cwd, prefix); apath_end = apath+l; - LOAD(includes); - LOAD(cflags); - LOAD(ldflags); - LOAD(prefix); - - /* special case: all three specified by the user - ignore what the detector wanted, but run only once per node prefix */ - if ((uincludes != NULL) && (ucflags != NULL) && (uldflags != NULL)) { - const char *am; - sprintf(apath, "%s/icl/all_manual_result", prefix); - am = get(apath); - if (am != NULL) - return istrue(am); /* return cached result if available */ - res = try_icl__(logdepth, prefix, test_c_in, uincludes, ucflags, uldflags, uincludes, ucflags, uldflags, run, accept_res); - put(apath, res ? strue : sfalse); - return res; - } - - /* TODO: get default cflags here */ - rincludes = NULL; - rcflags = strclone(get("cc/cflags")); - rldflags = strclone(get("cc/ldflags")); - - /* override base/default values with detection requested ones */ - if (includes != NULL) SET(rincludes, includes, 0); - if (cflags != NULL) SET(rcflags, cflags, 1); - if (ldflags != NULL) SET(rldflags, ldflags, 1); - - if (includes != NULL) SET(dbincludes, includes, 0); - if (cflags != NULL) SET(dbcflags, cflags, 1); - if (ldflags != NULL) SET(dbldflags, ldflags, 1); - - /* override detection with user specified ICL values */ - if (uincludes != NULL) SET(rincludes, uincludes, 0); - if (ucflags != NULL) SET(rcflags, ucflags, 1); - if (uldflags != NULL) SET(rldflags, uldflags, 1); - - if (uincludes != NULL) SET(dbincludes, uincludes, 0); - if (ucflags != NULL) SET(dbcflags, ucflags, 1); - if (uldflags != NULL) SET(dbldflags, uldflags, 1); - - /* insert prefix as needed */ - if (uprefix != NULL) { - char *old, *prfx; - - old = rcflags; - if ((rcflags != NULL) && (*rcflags == '^')) { - rcflags++; - prfx = "^"; - } - else - prfx = ""; - rcflags = str_concat("", prfx, "-I", uprefix, "/include ", rcflags, NULL); - if (old != cflags) free(old); - - old = rldflags; - if ((rldflags != NULL) && (*rldflags == '^')) { - rldflags++; - prfx = "^"; - } - else - prfx = ""; - rldflags = str_concat("", prfx, "-L", uprefix, "/lib ", rldflags, NULL); - if (old != ldflags) free(old); - } - - res = try_icl__(logdepth, prefix, test_c_in, rincludes, rcflags, rldflags, dbincludes, dbcflags, dbldflags, run, accept_res); - - /* if we had to alloc, free here */ - free(rincludes); - free(rcflags); - free(rldflags); - free(dbincludes); - free(dbcflags); - free(dbldflags); - - return res; -} - -#undef LOAD -#undef SET - -int try_icl(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags) -{ - return try_icl_(logdepth, prefix, test_c_in, includes, cflags, ldflags, 1, try_icl_accept_ok); -} - -int try_icl_with_deps(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags, const char *dep_includes, const char *dep_cflags, const char *dep_ldflags, int run) -{ - int res; - - if ((dep_includes != NULL) && (*dep_includes == '\0')) dep_includes = NULL; - if ((dep_cflags != NULL) && (*dep_cflags == '\0')) dep_cflags = NULL; - if ((dep_ldflags != NULL) && (*dep_ldflags == '\0')) dep_ldflags = NULL; - - if (dep_includes != NULL) includes = str_concat(" ", dep_includes, includes, NULL); - if (dep_cflags != NULL) cflags = str_concat(" ", dep_cflags, cflags, NULL); - if (dep_ldflags != NULL) ldflags = str_concat(" ", dep_ldflags, ldflags, NULL); - - res = try_icl_(logdepth, prefix, test_c_in, includes, cflags, ldflags, run, try_icl_accept_ok); - - if (dep_includes != NULL) free((char *)includes); - if (dep_cflags != NULL) free((char *)cflags); - if (dep_ldflags != NULL) free((char *)ldflags); - - return res; -} - -int try_icl_norun(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags) -{ - return try_icl_(logdepth, prefix, test_c_in, includes, cflags, ldflags, 0, try_icl_accept_ok); -} - - -int try_fail(int logdepth, const char *prefix) -{ - char *tmp; - tmp = malloc(strlen(prefix) + 32); - sprintf(tmp, "%s/presents", prefix); - put(tmp, sfalse); - free(tmp); - report("not found\n"); - logprintf(logdepth, "NOT FOUND."); - return 1; -} - -static int try_pkg_config_(int logdepth, char *pkgname, const char *prefix, const char *test_c) -{ - char *cflags, *ldflags; - int res; - - logprintf(logdepth, "Trying pkg-config %s\n", pkgname); - if (run_pkg_config(logdepth+1, pkgname, &cflags, &ldflags) == 0) - res = try_icl(logdepth+1, prefix, test_c, NULL, cflags, ldflags); - else - res = 0; - free(cflags); - free(ldflags); - - return res; -} - -int try_icl_pkg_config(int logdepth, const char *prefix, const char *test_c, char *includes, const char *pkgpat, const char *reqver) -{ - char **pkg_ver, **s; - int num_pkg_ver; - int res = 0; - (void) includes; /* not used */ - - run_pkg_config_lst(logdepth, pkgpat, &num_pkg_ver, &pkg_ver); - if (pkg_ver == NULL) - return 0; - - if (reqver != NULL) { - /* search the list for the preferred version */ - for(s = pkg_ver; *s != NULL; s+=2) { - if (strcmp(s[1], reqver) == 0) { - if (try_pkg_config_(logdepth, s[0], prefix, test_c)) { - res = 1; - report("Found version required (%s) using pkg_config.\n", reqver); - goto out; - } - else { - report("The version required (%s) is found (via pkg_config) but does not work\n", reqver); - goto out; - } - } - } - goto out; - } - - for(s = pkg_ver; *s != NULL; s+=2) { - if (try_pkg_config_(logdepth, s[0], prefix, test_c)) { - res = 1; - goto out; - } - } - -out:; - filelist_free(&num_pkg_ver, &pkg_ver); - return res; -} - - -int import_icl(const char *key, const char *fn) -{ - char path[1024]; - - switch(*key) { - case 'l': sprintf(path, "/arg/icl/%s/ldflags", key+8); break; - case 'c': sprintf(path, "/arg/icl/%s/cflags", key+7); break; - case 'i': sprintf(path, "/arg/icl/%s/includes", key+9); break; - case 'p': sprintf(path, "/arg/icl/%s/prefix", key+7); break; - default: - return 1; - } - printf("path='%s' fn='%s'\n", path, fn); - return put(path, fn) == NULL; -} - - -static long field_accept_len; -static int field_accept_res(char *stdout_str) -{ - char *end; - field_accept_len = strtol(stdout_str, &end, 10); - if (((*end == '\0') || (*end == '\r') || (*end == '\n')) && (field_accept_len > 0)) - return 1; - return 0; -} - -int try_icl_sfield(int logdepth, const char *prefix, const char *structn, const char *fieldn, const char *includes, const char *cflags, const char *ldflags) -{ - int res; - char test_c[512]; - char ls[16]; - const char *test_c_in = - NL "#include " - NL "int main()" - NL "{" - NL " %s s;" - NL " printf(\"%%ld\\n\", (long)sizeof(s.%s));" - NL "}" - NL; - - sprintf(test_c, test_c_in, structn, fieldn); - - res = try_icl_(logdepth, prefix, test_c, includes, cflags, ldflags, 1, field_accept_res); - if (res) { - sprintf(test_c, "%s/sizeof", prefix); - sprintf(ls, "%ld", field_accept_len); - put(test_c, ls); - } - return res; -} - -int try_icl_sfields(int logdepth, const char *prefix, const char *structn, const char **fields, const char *includes, const char *cflags, const char *ldflags, int silent_exit_first_fail) -{ - int succ = 0, first = 1; - require("cc/cc", logdepth, 1); - - for(; *fields != NULL; fields++) { - report("Checking for %s.%s... ", structn, *fields); - logprintf(logdepth, "%s: checking for field %s...\n", structn, *fields); - - logdepth++; - if (try_icl_sfield(logdepth, prefix, structn, *fields, includes, cflags, ldflags)) { - succ = 1; - } - else if ((silent_exit_first_fail) && (first)) { - return 1; - } - logdepth--; - first = 0; - } - - - if (!succ) - try_fail(logdepth, "libs/fsmount/next_dev"); - - return 0; -} diff --git a/scconfig/src/default/.svn/pristine/46/46c3b30d21d29e2c96fcb71cffb3a2dbb784b796.svn-base b/scconfig/src/default/.svn/pristine/46/46c3b30d21d29e2c96fcb71cffb3a2dbb784b796.svn-base deleted file mode 100644 index ff9a61bf..00000000 --- a/scconfig/src/default/.svn/pristine/46/46c3b30d21d29e2c96fcb71cffb3a2dbb784b796.svn-base +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef STR_HT_H -#define STR_HT_H - -/* char * -> void * open addressing hashtable */ -/* keys and values are strdupped (strcloned) */ - -#define ht_deleted_key ((char *)1) -#define ht_isused(e) ((e)->key && (e)->key != ht_deleted_key) -#define ht_isempty(e) (((e)->key == NULL) || (e)->key == ht_deleted_key) -#define ht_isdeleted(e) ((e)->key == ht_deleted_key) - -typedef struct { - unsigned int hash; - char *key; - void *value; -} ht_entry_t; - -typedef struct { - unsigned int mask; - unsigned int fill; - unsigned int used; - int isstr; - ht_entry_t *table; - int refcount; -} ht_t; - -ht_t *ht_alloc(int isstr); -void ht_free(ht_t *ht); -ht_t *ht_clear(ht_t *ht); -ht_t *ht_resize(ht_t *ht, unsigned int hint); - -/* value of ht[key], NULL if key is empty or deleted */ -void *ht_get(ht_t *ht, const char *key); -/* ht[key] = value and return NULL or return ht[key] if key is already used */ -void *ht_insert(ht_t *ht, const char *key, void *value); -/* ht[key] = value and return a pointer to the strdupped key */ -const char *ht_set(ht_t *ht, const char *key, void *value); -/* delete key and return ht_deleted_key or NULL if key was not used */ -const char *ht_del(ht_t *ht, const char *key); - -/* iteration */ -#define foreach(ht, e) \ - for (e = (ht)->table; e != (ht)->table + (ht)->mask + 1; e++) \ - if (ht_isused(e)) - -/* first used (useful for iteration) NULL if empty */ -ht_entry_t *ht_first(const ht_t *ht); -/* next used (useful for iteration) NULL if there is no more used */ -ht_entry_t *ht_next(const ht_t *ht, ht_entry_t *entry); - -#endif diff --git a/scconfig/src/default/.svn/pristine/46/46cd895dbc8f7b0ea609f77c259044db0d4a0854.svn-base b/scconfig/src/default/.svn/pristine/46/46cd895dbc8f7b0ea609f77c259044db0d4a0854.svn-base deleted file mode 100644 index 591ff3f8..00000000 --- a/scconfig/src/default/.svn/pristine/46/46cd895dbc8f7b0ea609f77c259044db0d4a0854.svn-base +++ /dev/null @@ -1,355 +0,0 @@ -/* - scconfig - evaluate uname and classify the system - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "regex.h" -#include "log.h" -#include "db.h" -#include "libs.h" -#include "dep.h" - -static void sys_unix(void) -{ - put("sys/ext_exe", ""); - put("sys/ext_dynlib", ".so"); - put("sys/ext_stalib", ".a"); - put("sys/ext_dynlib_native", ".so"); -} - -static void sys_netbsd(void) -{ - sys_unix(); - put("cc/ldflags", "-Wl,-R/usr/pkg/lib -L/usr/pkg/lib"); /* TODO: is this the best way? */ -} - -static void sys_win32dlc(void) -{ - put("sys/ext_exe", ".exe"); - put("sys/ext_dynlib", ".dlc"); - put("sys/ext_stalib", ".a"); - put("sys/ext_dynlib_native", ".dll"); -} - -typedef void (*callback_t)(void); - -typedef struct { - char *uname_regex; - char *name; - char *class; - - callback_t callback; -} uname_t; - -typedef struct { - char *file_name; - char *name; - char *class; - - callback_t callback; -} magic_file_t; - -/* Guess system class by uname; class is informative, nothing important - should depend on it. - Order *does* matter */ -uname_t unames[] = { - {"[Nn]et[Bb][Ss][Dd]", "NetBSD", "UNIX", sys_netbsd}, - {"[Ll]inux", "Linux", "UNIX", sys_unix}, - {"[Bb][Ss][Dd]", "BSD", "UNIX", sys_unix}, - {"SunOS", "SunOS", "UNIX", sys_unix}, - {"OSF1", "OSF", "UNIX", sys_unix}, /* TODO: note the difference in cflags for debugging ("-ms -g") */ - {"IRIX", "IRIX", "UNIX", sys_unix}, - {"SunOS", "SunOS", "UNIX", sys_unix}, - {"[Mm]inix", "Minix", "UNIX", sys_unix}, - {"[Aa][Rr][Oo][Ss]", "Aros", "UNIX", sys_unix}, - {"^Darwin", "MacOSX", "UNIX", sys_unix}, - {"[Th]hreos", "Threos", "UNIX", sys_unix}, - {"[Cc]ygwin", "cygwin", "WIN32", sys_win32dlc}, - {"[Mm][Ii][Nn][Gg][Ww]", "mingw", "WIN32", sys_win32dlc}, - {"win32", "win32", "WIN32", sys_win32dlc}, /* vanilla windows */ - {NULL, NULL, NULL, NULL} -}; - -/* Fallback: extract machine name from uname -a if uname -m fails */ -static const char *machine_names[] = { - "i[0-9]86[^ ]*", "x86_[^ ]*", "amd[0-9]*", "armv[0-9][^ ]*", "ppc[0-9]+", - "sparc[0-9]*", "BePC", "ia64", "x86", "IP[0-9]*", "k1om", "sun4u", - "RM600", "R4000", "alpha", - NULL -}; - -/* Fallback: extract system name from uname -a if uname -s fails */ -static const char *system_names[] = { - "[Ll]inux", "sn5[0-9]*", "CYGWIN_NT[^ ]*", "GNU[^ ]*", "DragonFly", - "[^ ]*BSD[^ ]*", "Haiku", "HP-UX", "AIX", "OS4000", "Interix", - "IRIX[0-9]*", "Darwin", "Minix", "MINGW[^ ]*", "ReliantUNIX[^ ]*", - "SunOS", "OSF1", "ULTRIX", "UWIN-W7", "IS/WB", "OS/390", - "SCO[^ ]*", "QNX", - NULL -}; - -/* Fallback: if uname -a fails, guess system by looking at "magic file names" */ -magic_file_t magic_files[] = { - {"/dev/null", "UNIX", "UNIX", sys_unix}, - {"c:\\config.sys", "win32", "WIN32", sys_win32dlc}, - {"c:\\windows\\system.ini", "win32", "WIN32", sys_win32dlc}, - {"c:\\windows\\win.ini", "win32", "WIN32", sys_win32dlc}, - {"c:\\windows\\notepad.exe", "win32", "WIN32", sys_win32dlc}, - {NULL, NULL, NULL, NULL} -} ; - -static int match(const char *regex, const char *str) -{ - re_comp(regex); - return re_exec(str); -} - -/* match uname against each pattern on the list; on a match, put() the portion - of the string matched in node and return 1 */ -int uname_guess(const char *node, const char *uname, const char *list[]) -{ - const char **l; - if (uname == NULL) - return 0; - for(l = list; *l != NULL; l++) { - if (match(*l, uname)) { - char *s; - int len = eopat[0] - bopat[0]; - s = malloc(len+1); - memcpy(s, bopat[0], len); - s[len] = '\0'; - put(node, s); - return 1; - } - } - return 0; -} - -/* Don't worry about linear search or matching regexes all the time - this - function will be run at most two times */ -static callback_t lookup_uname(char **uname, const char **name, const char **class) -{ - uname_t *u; - for(u = unames; u->uname_regex != NULL; u++) { - if ( - ((*uname != NULL) && (match(u->uname_regex, *uname))) /* uname match */ - || ((*name != NULL) && ((strcmp(u->name, *name) == 0))) /* name match */ - || ((*class != NULL) && ((strcmp(u->class, *class) == 0))) /* class match */ - ) { - if (*name == NULL) *name = u->name; - if (*class == NULL) *class = u->class; - return u->callback; - } - } - return NULL; -} - -static callback_t lookup_magic_file(int logdepth, const char **name, const char **class) -{ - magic_file_t *u; - for(u = magic_files; u->file_name != NULL; u++) { - if (is_file(u->file_name)) { - logprintf(logdepth, "%s -> %s\n", u->file_name, u->class); - - if (*name == NULL) *name = u->name; - if (*class == NULL) *class = u->class; - return u->callback; - } - } - return NULL; -} - -int find_uname(const char *rname, int logdepth, int fatal) -{ - const char *name, *class, *tname, *uname_orig; - char *s, *uname, *mname, *sname; - void (*callback)(void); - - require("sys/tmp", logdepth, fatal); - - if (istarget(db_cwd)) - require("/target/sys/target", logdepth, fatal); - - report("Checking for system type... "); - logprintf(logdepth, "[find_uname] checking for sys/name\n"); - logdepth++; - - tname = get("/arg/sys/target-name"); - if (istarget(db_cwd) && (tname != NULL)) - put("sys/name", tname); - - tname = get("/arg/sys/target-uname"); - if (istarget(db_cwd) && (tname != NULL)) - put("sys/uname", tname); - - name = get("sys/name"); - uname_orig = get("sys/uname"); - - if (name == NULL) { - if (uname_orig == NULL) { - logprintf(logdepth, "not set, running\n"); - run_shell(logdepth, "uname -a", (char **)&uname); - if (uname != NULL) { - for(s = uname; *s != '\0'; s++) - if ((*s == '\n') || (*s == '\r')) *s = ' '; - put("sys/uname", uname); - } - else - put("sys/uname", ""); - - if (run_shell(logdepth, "uname -m", (char **)&mname) == 0) - put("sys/machine_name", strip(mname)); - else - put("sys/machine_name", NULL); - - if (mname != NULL) - free(mname); - - if (run_shell(logdepth, "uname -o", (char **)&sname) == 0) - put("sys/system_name", strip(sname)); - else if (run_shell(logdepth, "uname -s", (char **)&sname) == 0) - put("sys/system_name", strip(sname)); - else - put("sys/system_name", NULL); - if (sname != NULL) - free(sname); - } - - /* we have uname by now, set sys/name */ - name = NULL; - class = NULL; - callback = lookup_uname(&uname, &name, &class); - if (name == NULL) { - /* no uname or unknown system by uname - fallback: check for cross target */ - const char *target = get("/arg/sys/target"); - if ((target != NULL) && (strstr(target, "mingw") != NULL)) { - name = "WIN32"; - report("(detected mingw cross compilation to WIN32)\n"); - } - else { - report("Warning: unknown system\n"); - name = "unknown"; - } - } - put("sys/name", name); - } - else { - /* we had sys/name, that should be enough */ - uname = NULL; - class = name; - callback = lookup_uname(&uname, &name, &class); - } - - /* predefined and/or detected uname failed, try magic file method */ - if (callback == NULL) { - logprintf(logdepth, "System class is unknown by uname, running heuristics...\n"); - report("System class is unknown by uname, running heuristics... "); - - callback = lookup_magic_file(logdepth + 1, &name, &class); - } - - - if (callback == NULL) { - /* System unknown. */ - error("Unknown system '%s'\n", get("sys/uname")); - abort(); - } - - callback(); - report("OK (name: %s; class: %s)\n", name, class); - put("sys/class", class); - - /* fallbacks */ - if (get("sys/machine_name") == NULL) - uname_guess("sys/machine_name", uname, machine_names); - - if (get("sys/system_name") == NULL) - uname_guess("sys/system_name", uname, system_names); - - /* on windows, overwrite the path sep with the right amount of \ (the tmp finder may have left / in it) */ - if ((strcmp(class, "WIN32") == 0) || (strcmp(class, "win32") == 0)) { - int eats = istrue(get("sys/shell_eats_backslash")); - - if (eats) - put("sys/path_sep", "\\\\\\\\"); - else - put("sys/path_sep", "\\"); - } - - return 0; -} - -static int find_triplet_(const char *name, int logdepth, int fatal, const char *nodename, int include_vendor, char *sep, char *esc) -{ - const char *machine, *vendor, *os; - char *triplet, *s; - char fake_sep[2]; - - fake_sep[0] = 1; - fake_sep[1] = 0; - - require("sys/uname", logdepth, fatal); - - machine = get("sys/machine_name"); - if (machine == NULL) - machine = "unknown"; - - vendor = "unknown"; - - os = get("sys/system_name"); - if (os == NULL) - os = "unknown"; - - if (include_vendor) - triplet = str_concat(fake_sep, machine, vendor, os, NULL); - else - triplet = str_concat(fake_sep, machine, os, NULL); - - for(s = triplet; *s != '\0'; s++) { - if ((esc != NULL) && (*s == *sep)) - *s = *esc; - if (isalnum(*s)) - *s = tolower(*s); - else { - if (*s == *fake_sep) - *s = *sep; - else if (esc != NULL) - *s = *esc; - else - *s = '-'; - } - } - put(nodename, triplet); - free(triplet); - return 0; -} - -int find_triplet(const char *name, int logdepth, int fatal) -{ - return find_triplet_(name, logdepth, fatal, "sys/triplet", 1, "-", NULL); -} - -int find_sysid(const char *name, int logdepth, int fatal) -{ - return find_triplet_(name, logdepth, fatal, "sys/sysid", 0, "-", "_"); -} diff --git a/scconfig/src/default/.svn/pristine/48/48c8398fcdb571e7eee16fbb2cdf493f50a25ade.svn-base b/scconfig/src/default/.svn/pristine/48/48c8398fcdb571e7eee16fbb2cdf493f50a25ade.svn-base deleted file mode 100644 index 25a91a58..00000000 --- a/scconfig/src/default/.svn/pristine/48/48c8398fcdb571e7eee16fbb2cdf493f50a25ade.svn-base +++ /dev/null @@ -1,313 +0,0 @@ -/* - scconfig - detection of standard library features: time/date/sleep related calls - Copyright (C) 2011..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_time_usleep(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " if (usleep(1) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for usleep()... "); - logprintf(logdepth, "find_time_usleep: trying to find usleep...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/time/usleep", test_c, NULL, NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/time/usleep"); -} - -int find_time_Sleep(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "int main() {" - NL " Sleep(1);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for Sleep()... "); - logprintf(logdepth, "find_time_Sleep: trying to find Sleep...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/time/Sleep", test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/time/Sleep"); -} - -int find_time_gettimeofday(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " struct timeval tv;" - NL " if (gettimeofday(&tv, NULL) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for gettimeofday()... "); - logprintf(logdepth, "find_time_gettimeofday: trying to find gettimeofday...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/time/gettimeofday", test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/time/gettimeofday"); -} - - -int find_time_ftime(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "int main() {" - NL " struct timeb tb;" - NL " if (ftime(&tb) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for ftime()... "); - logprintf(logdepth, "find_time_ftime: trying to find ftime...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/time/ftime", test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/time/ftime"); -} - -static const char timegm_test_c_template[] = - NL "void my_puts(const char *s);" - NL "int main() {" - NL " struct tm tm;" - NL " tm.tm_sec = 50;" - NL " tm.tm_min = 30;" - NL " tm.tm_hour = 6;" - NL " tm.tm_mday = 1;" - NL " tm.tm_mon = 11;" - NL " tm.tm_year = 2018 - 1900;" - NL " tm.tm_wday = 0;" - NL " tm.tm_yday = 0;" - NL " if (%s(&tm) != (time_t)(-1))" - NL " my_puts(\"OK\");" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - -int find_time_timegm(const char *name, int logdepth, int fatal) -{ - char test_c[1000]; - sprintf(test_c, timegm_test_c_template, "timegm"); - - require("cc/cc", logdepth, fatal); - - report("Checking for timegm()... "); - logprintf(logdepth, "find_time_timegm: trying to find timegm...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/time/timegm", test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/time/timegm"); -} - -int find_time_mkgmtime(const char *name, int logdepth, int fatal) -{ - char test_c[1000]; - const char *ldflags[] = {"","-lmsvcr120","-lmsvcr110","-lmsvcr100","-lmsvcr90","-lmsvcr80","-lmsvcr71","-lmsvcr70",NULL}; - const char **ldf; - - sprintf(test_c, timegm_test_c_template, "_mkgmtime"); - - require("cc/cc", logdepth, fatal); - - report("Checking for _mkgmtime()... "); - logprintf(logdepth, "find_time_mkgmtime: trying to find _mkgmtime...\n"); - logdepth++; - - for (ldf = ldflags; *ldf; ++ldf) - if (try_icl(logdepth, "libs/time/_mkgmtime", test_c, "#include ", NULL, *ldf)) - return 0; - return try_fail(logdepth, "libs/time/_mkgmtime"); -} - -int find_time_gmtime_r(const char *name, int logdepth, int fatal) -{ - const char test_c[] = - NL "void my_puts(const char *s);" - NL "int main() {" - NL " time_t tim = 1543645850;" - NL " struct tm tm;" - NL " if (gmtime_r(&tim, &tm)" /* returns '&tm' */ - NL " && 50==tm.tm_sec" - NL " && 30==tm.tm_min" - NL " && 6==tm.tm_hour" - NL " && 1==tm.tm_mday" - NL " && 11==tm.tm_mon" - NL " && (2018-1900)==tm.tm_year)" - NL " my_puts(\"OK\");" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for gmtime_r()... "); - logprintf(logdepth, "find_time_gmtime_r: trying to find gmtime_r...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/time/gmtime_r", test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/time/gmtime_r"); -} - -int find_time_gmtime_s(const char *name, int logdepth, int fatal) -{ - const char test_c[] = - NL "void my_puts(const char *s);" - NL "int main() {" - NL " time_t tim = 1543645850;" - NL " struct tm tm;" - NL " if (0==gmtime_s(&tm, &tim)" /* returns errno */ - NL " && 50==tm.tm_sec" - NL " && 30==tm.tm_min" - NL " && 6==tm.tm_hour" - NL " && 1==tm.tm_mday" - NL " && 11==tm.tm_mon" - NL " && (2018-1900)==tm.tm_year)" - NL " my_puts(\"OK\");" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for gmtime_s()... "); - logprintf(logdepth, "find_time_gmtime_s: trying to find gmtime_s...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/time/gmtime_s", test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/time/gmtime_s"); -} - -int find_time_localtime_r(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/time/localtime_r"; - const char test_c[] = - NL "void my_puts(const char *s);" - NL "int main() {" - NL " time_t tim = 1543645850;" - NL " struct tm tm;" - NL " if (localtime_r(&tim, &tm)" /* returns '&tm' */ - NL " && 0!=tm.tm_sec" /* depends on TZ: sadly we can't sure in anything */ - NL " && 0!=tm.tm_min" - NL " && 0!=tm.tm_hour)" - NL " my_puts(\"OK\");" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for localtime_r()... "); - logprintf(logdepth, "find_time_localtime_r: trying to find localtime_r...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, key); -} - -int find_time_localtime_s(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/time/localtime_s"; - const char test_c[] = - NL "void my_puts(const char *s);" - NL "int main() {" - NL " time_t tim = 1543645850;" - NL " struct tm tm;" - NL " if (0==localtime_s(&tm, &tim)" /* returns errno */ - NL " && 0!=tm.tm_sec" /* depends on TZ: sadly we can't sure in anything */ - NL " && 0!=tm.tm_min" - NL " && 0!=tm.tm_hour)" - NL " my_puts(\"OK\");" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for localtime_s()... "); - logprintf(logdepth, "find_time_localtime_s: trying to find localtime_s...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, key); -} diff --git a/scconfig/src/default/.svn/pristine/51/51c782a807fbb9a9c2ee58b10657eb129de47a19.svn-base b/scconfig/src/default/.svn/pristine/51/51c782a807fbb9a9c2ee58b10657eb129de47a19.svn-base deleted file mode 100644 index c66aaf1c..00000000 --- a/scconfig/src/default/.svn/pristine/51/51c782a807fbb9a9c2ee58b10657eb129de47a19.svn-base +++ /dev/null @@ -1,324 +0,0 @@ -/* - scconfig - library for making includes on a list unique - Copyright (C) 2012, 2017 Tibor Palinkas - Copyright (C) 2017 Aron Barath - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include "libs.h" -#include "db.h" -#include "regex.h" - -#define grow \ - if (used >= alloced) { \ - alloced += 16; \ - list = realloc(list, alloced * sizeof(char *)); \ - } - -char **uniq_inc_arr(const char *includes, int indirect, const char *sep_, int *numlines) -{ - char *node, *next, *cw, *nw, *snode, *orig_node; - char *sep; - char **list; - int alloced, used, n; - - orig_node = strclone(includes); - node = orig_node; - if (sep_ == NULL) - sep = strclone("\r\n"); - else - sep = strclone(sep_); - - /* reset list */ - alloced = used = 0; - list = NULL; - /* take arguments one by one */ - while(node != NULL) { - if (indirect) { - while((*node == ' ') || (*node == '\t')) node++; - next = strpbrk(node, " \t"); - } - else { - for(;;) { - next = strpbrk(node, sep); - if ((next > node) || (next == NULL)) - break; - node = next+1; - } - } - if (next != NULL) { - *next = '\0'; - next++; - } - if (indirect) - snode = str_subsn(get(node)); - else - snode = node; - cw = snode; - /* split node value (s) by sep */ -/* fprintf(stderr, "nodename=%s snode=%s next=%s\n", node, snode, next);*/ - while(cw != NULL) { - nw = strpbrk(cw, sep); - if (nw != NULL) { - *nw = '\0'; - nw++; - } - - if (*cw != '\0') { - /* try to find cw in the existing list - this is a slow linear search for now */ - for(n = 0; n < used; n++) { - if (strcmp(list[n], cw) == 0) - goto already_on_list; - } - /* not found, append */ - grow; - list[used] = strclone(cw); - used++; - } - already_on_list:; - cw = nw; - } - if (indirect) - free(snode); - node = next; - } - grow; - list[used] = NULL; - if (numlines != NULL) - *numlines = used; - - free(orig_node); - free(sep); - - return list; -} - -void uniq_inc_free(char **arr) -{ - char **s; - for(s = arr; *s != NULL; s++) - free(*s); - free(arr); -} - -static int uniq_inc_str_cmp(const void *a_, const void *b_) -{ - char **a = (char **)a_, **b = (char **)b_; - return strcmp(*a, *b); -} - -static void uniq_inc_assemble_normal(char* const ret, int numelem, char **arr, const char *osep, const int oseplen) -{ - char *end; - int len; - - for(end = ret; 0 < numelem; ++arr, --numelem) { - if (!*arr) - continue; - - len = strlen(*arr); - memcpy(end, *arr, len); - end += len; - memcpy(end, osep, oseplen); - end += oseplen; - free(*arr); - } - - *end = '\0'; -} - -static void uniq_inc_assemble_groups(char* const ret, int numelem, char **arr, const char *osep, const int oseplen, int eren, char **eres) -{ - char *end = ret; - int erei, ndx, len; - - /* re_comp() uses a global variable to store the compiler regex! */ - - for (erei = 0; erei < eren; ++erei) { - if (re_comp(eres[erei])) - abort(); - - for (ndx = 0; ndx < numelem; ++ndx) { - if (!arr[ndx]) - continue; - - if (re_exec(arr[ndx])) { - len = strlen(arr[ndx]); - memcpy(end, arr[ndx], len); - end += len; - memcpy(end, osep, oseplen); - end += oseplen; - free(arr[ndx]); - arr[ndx] = NULL; - } - } - } - - /* collect remaining elements */ - - uniq_inc_assemble_normal(end, numelem, arr, osep, oseplen); -} - -char *uniq_inc_str(const char *includes, const char *isep, const char *osep, int sort, int eren, char **eres) -{ - char **arr, **s, *ret; - int len, numelem, oseplen; - - /* split and uniq */ - - oseplen = strlen(osep); - arr = uniq_inc_arr(includes, 0, isep, NULL); - - /* calculate the required amount of memory */ - - len = 4; /* safety margin, for terminator \0, etc. */ - numelem = 0; - for(s = arr; *s != NULL; s++) { - len += strlen(*s) + oseplen + 1; - numelem++; - } - - /* sort if needed */ - - if (sort) - qsort(arr, numelem, sizeof(char *), uniq_inc_str_cmp); - - /* allocate memory to assemble into */ - - ret = malloc(len); - - /* assemble the output */ - - if (0>=eren) - uniq_inc_assemble_normal(ret, numelem, arr, osep, oseplen); - else - uniq_inc_assemble_groups(ret, numelem, arr, osep, oseplen, eren, eres); - - /* done */ - - free(arr); - return ret; -} - -char *order_inc_str(const char *includes, const char *isep, const char *word1, int dir, const char *word2) -{ - const char *s, *next, *pre, *mid, *post; - char *out, *end; - long w1o = -1, w2o = -1; - long w1len = strlen(word1), w2len = strlen(word2), tlen; - long pre_len, mid_len, post_len; - - if (dir == 0) - return NULL; - - if ((w1len == 0) || (w2len == 0)) - return strclone(includes); - - if ((w1len == w2len) && (strcmp(word1, word2) == 0)) - return strclone(includes); - - /* search the starting offset of the first occurence of word1 and word2 */ - for(s = includes; (s != NULL) && ((w1o < 0) || (w2o < 0)); s = next) { - next = strpbrk(s, isep); - if (next == NULL) - tlen = strlen(s); - else - tlen = next-s; - - if ((w1o < 0) && (w1len == tlen) && (memcmp(s, word1, tlen) == 0)) - w1o = s - includes; - if ((w2o < 0) && (w2len == tlen) && (memcmp(s, word2, tlen) == 0)) - w2o = s - includes; - - if (next != NULL) - next += strspn(next, isep); - } - - /* one of the words is not on the list, the list is ordered */ - if ((w1o < 0) || (w2o < 0)) - return strclone(includes); - - /* both words are not on the list, but the list is ordered */ - if (((dir < 0) && (w1o < w2o)) || ((dir > 0) && (w1o > w2o))) - return strclone(includes); - - /* split up the input at word1 and word2 */ - tlen = strlen(includes); - if (dir < 0) { /* input is: 'pre w2 mid w1 post', goal is mowing w1 before w2 */ - pre = includes; - pre_len = w2o; - mid = includes + w2o + w2len + 1; - mid_len = (includes + w1o) - mid; - post = includes + w1o + w1len + 1; - post_len = (includes + tlen) - post + 1; - } - else { /* input is: 'pre w1 mid w2 post' goal is moving w1 after w2*/ - pre = includes; - pre_len = w1o; - mid = includes + w1o + w1len + 1; - mid_len = (includes + w2o) - mid; - post = includes + w2o + w2len + 1; - post_len = (includes + tlen) - post + 1; - } - - /* truncate trailing separator, if present */ - if ((pre_len > 0) && (strchr(isep, pre[pre_len-1]))) - pre_len--; - - if ((mid_len > 0) && (strchr(isep, mid[mid_len-1]))) - mid_len--; - - if ((post_len > 0) && (strchr(isep, post[mid_len-1]))) - post_len--; - - /* allocate extra space for a trailing separator and/or \0 */ - end = out = malloc(tlen+2); - - /* build the string by appending the parts */ -#define append(str, len) \ - if (len > 0) { \ - memcpy(end, str, len); \ - end += len; \ - *end = *isep; \ - end++; \ - } - - append(pre, pre_len); - if (dir < 0) { - append(word1, w1len); - append(word2, w2len); - } - append(mid, mid_len); - if (dir > 0) { - append(word2, w2len); - append(word1, w1len); - } - append(post, post_len); - -#undef append - - /* replace the last separator with \0 or just add a \0 at the end */ - if ((end > out) && (strchr(isep, end[-1]))) - end[-1] = '\0'; - else - end[0] = '\0'; - return out; -} diff --git a/scconfig/src/default/.svn/pristine/54/5466de07daabc33f7d794ac2a4d9e2d3f31fe11c.svn-base b/scconfig/src/default/.svn/pristine/54/5466de07daabc33f7d794ac2a4d9e2d3f31fe11c.svn-base deleted file mode 100644 index 6f7dca49..00000000 --- a/scconfig/src/default/.svn/pristine/54/5466de07daabc33f7d794ac2a4d9e2d3f31fe11c.svn-base +++ /dev/null @@ -1,335 +0,0 @@ -/* - scconfig - library functions for compiling and running test code - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include -#include "log.h" -#include "libs.h" -#include "db.h" -#include "dep.h" - -/* -#define KEEP_TEST_SRCS -*/ - -int cross_blind = 0; - - -static char *clone_flags(const char *input, const char *node) -{ - char *output; - const char *s; - int len; - - if (input != NULL) { - if (*input == '+') { - s = get(node); - if (s != NULL) { - len = strlen(s); - output = malloc(len + strlen(input) + 4); - memcpy(output, s, len); - output[len] = ' '; - strcpy(output + len + 1, input + 1); - } - else - output = strclone(input); - } - else - output = strclone(input); - } - else { - s = get(node); - if (s != NULL) - output = strclone(s); - else - output = strclone(""); - } - return output; -} - -int compile_file_raw(int logdepth, const char *fn_input, char **fn_output, const char *cc, const char *cflags, const char *ldflags) -{ - char *cmdline; - char *cc_esc, *fn_input_esc, *fn_output_esc, *temp_out_esc, *temp_out; - int ret; - - temp_out = tempfile_new(".out"); - - if (*fn_output == NULL) - *fn_output = tempfile_new(get("sys/ext_exe")); - else - *fn_output = tempfile_new(*fn_output); - unlink(*fn_output); - - cc_esc = shell_escape_dup(cc == NULL ? get("cc/cc") : cc); - fn_input_esc = shell_escape_dup(fn_input); - fn_output_esc = shell_escape_dup(*fn_output); - temp_out_esc = shell_escape_dup(temp_out); - - cmdline = str_concat("", - get("/host/sys/shell"), " \"", cc_esc, " ", cflags, " ", fn_input_esc, " ", \ - ldflags, " -o ", fn_output_esc, " 2>&1\" >", temp_out_esc, NULL); - - free(cc_esc); - free(fn_input_esc); - free(fn_output_esc); - free(temp_out_esc); - - logprintf(logdepth, "compile: '%s'\n", cmdline); - ret = system(cmdline); - free(cmdline); - log_merge(logdepth + 1, temp_out); -#ifndef KEEP_TEST_SRCS - unlink(temp_out); -#endif - free(temp_out); - logprintf(logdepth, "compile result: %d\n", ret); - - return ret; -} - -int compile_file(int logdepth, const char *fn_input, char **fn_output, const char *cc, const char *cflags, const char *ldflags) -{ - int ret; - char *ldflags_, *cflags_; - - cflags_ = clone_flags(cflags, "cc/cflags"); - ldflags_ = clone_flags(ldflags, "cc/ldflags"); - - ret = compile_file_raw(logdepth, fn_input, fn_output, cc, cflags_, ldflags_); - - free(cflags_); - free(ldflags_); - - return ret; -} - -int compile_code(int logdepth, const char *testcode, char **fn_output, const char *cc, const char *cflags, const char *ldflags) -{ - char *temp_in; - int ret; - - require("sys/ext_exe", logdepth, 1); - - assert(testcode != NULL); - assert(fn_output != NULL); - - temp_in = tempfile_dump(testcode, ".c"); - ret = compile_file(logdepth, temp_in, fn_output, cc, cflags, ldflags); -#ifndef KEEP_TEST_SRCS - unlink(temp_in); -#endif - free(temp_in); - - return ret; -} - -int compile_code_raw(int logdepth, const char *testcode, char **fn_output, const char *cc, const char *cflags, const char *ldflags) -{ - char *temp_in; - int ret; - - require("sys/ext_exe", logdepth, 1); - - assert(testcode != NULL); - assert(fn_output != NULL); - - temp_in = tempfile_dump(testcode, ".c"); - ret = compile_file_raw(logdepth, temp_in, fn_output, cc, cflags, ldflags); -#ifndef KEEP_TEST_SRCS - unlink(temp_in); -#endif - free(temp_in); - - return ret; -} - -char *shell_escape_dup(const char *in) -{ - char *o, *out; - const char *i; - const char *esc = get("sys/shell_escape_char"); - - /* in the early phase, before detecting the shell, this happens */ - if (esc == NULL) - return strclone(in); - - out = malloc(strlen(in)*2+1); - for(i = in, o = out; *i != '\0'; i++) { - if (*i == *esc) { - *o++ = *esc; - } - else if (!isalnum(*i)) { - switch(*i) { - case '/': - case '_': - case '-': - case '.': - break; - default: - *o++ = *esc; - } - } - *o++ = *i; - } - *o = '\0'; - return out; -} - -int run(int logdepth, const char *cmd_, char **stdout_saved) -{ - char *cmd; - char *fn_out, *temp_out; - char *fn_out_esc, *temp_out_esc; - int ret; - const char *emu; - - assert(cmd_ != NULL); - - /* blind cross compiling mode means we always assume success */ - if (cross_blind) { - if (stdout_saved != NULL) - *stdout_saved = NULL; - return 0; - } - - emu = get("sys/emu"); - - /* emu == NULL means we need an emulator but we don't have one and - we should pretend everything went well (and of course can't provide - output.) */ - if (emu == NULL) { - if (stdout_saved != NULL) - *stdout_saved = NULL; - return 0; - } - - /* emu == false means we need an emulator and we don't want to pretend -> fatal */ - if (strcmp(emu, sfalse) == 0) { - error("Trying to run unavailable emulator (db_cwd='%s')\n", db_cwd); - abort(); - } - - temp_out = tempfile_new(".out"); - fn_out = tempfile_new(""); - - temp_out_esc = shell_escape_dup(temp_out); - fn_out_esc = shell_escape_dup(fn_out); - cmd = malloc(strlen(emu) + strlen(cmd_) + strlen(fn_out_esc) + strlen(temp_out_esc) + 32); - sprintf(cmd, "%s %s >%s 2>>%s", emu, cmd_, fn_out_esc, temp_out_esc); - free(temp_out_esc); - free(fn_out_esc); - - logprintf(logdepth, "run: '%s'\n", cmd); - ret = system(cmd); - log_merge(logdepth + 1, temp_out); - unlink(temp_out); - free(temp_out); - logprintf(logdepth, "run result: %d\n", ret); - free(cmd); - - if (stdout_saved != NULL) { - if (ret == 0) { - *stdout_saved = load_file(fn_out); - logprintf(logdepth, "stdout: '%s'\n", *stdout_saved); - } - else - *stdout_saved = NULL; - } - - unlink(fn_out); - free(fn_out); - return ret; -} - -int run_shell(int logdepth, const char *cmd_, char **stdout_saved) -{ - int ret; - char *cmd, *cmd_esc; - const char *emu; - const char *shell; - - emu = get("sys/emulator"); - if (emu == NULL) - emu = ""; - - shell = get("sys/shell"); - if (shell == NULL) { - error("No shell was specified (db_cwd='%s')\n", db_cwd); - abort(); - } - - cmd_esc = shell_escape_dup(cmd_); - cmd = malloc(strlen(emu) + strlen(shell) + strlen(cmd_esc) + 16); - if (istrue(get("sys/shell_needs_quote"))) - sprintf(cmd, "%s %s \"%s\"", emu, shell, cmd_); - else - sprintf(cmd, "%s %s %s", emu, shell, cmd_); - free(cmd_esc); - - ret = run(logdepth, cmd, stdout_saved); - free(cmd); - return ret; -} - - -int compile_run(int logdepth, const char *testcode, const char *cc, const char *cflags, const char *ldflags, char **stdout_saved) -{ - int ret; - char *fn_output = NULL; - - ret = compile_code(logdepth+1, testcode, &fn_output, cc, cflags, ldflags); - - if (ret == 0) { - char *fn_output_esc = shell_escape_dup(fn_output); - ret = run(logdepth+1, fn_output_esc, stdout_saved); - free(fn_output_esc); - } - - if (fn_output != NULL) { - unlink(fn_output); - free(fn_output); - } - return ret; -} - -int run_script(int logdepth, const char *interpreter, const char *script, const char *suffix, char **out) -{ - char *temp, *cmd; - int res; - - temp = tempfile_dump(script, suffix); - cmd = malloc(strlen(temp) + strlen(interpreter) + 4); - sprintf(cmd, "%s %s", interpreter, temp); - - res = run(logdepth, cmd, out); - - unlink(temp); - free(temp); - free(cmd); - return res; -} - diff --git a/scconfig/src/default/.svn/pristine/59/593d7d511965ba9ae40492c8ed34c132c975107d.svn-base b/scconfig/src/default/.svn/pristine/59/593d7d511965ba9ae40492c8ed34c132c975107d.svn-base deleted file mode 100644 index 9634fe93..00000000 --- a/scconfig/src/default/.svn/pristine/59/593d7d511965ba9ae40492c8ed34c132c975107d.svn-base +++ /dev/null @@ -1,153 +0,0 @@ -/* - scconfig - command line argument processing - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include "db.h" -#include "arg.h" -#include "dep.h" -#include "log.h" -#include "libs.h" - -argtbl_t main_argument_table[] = { - {"import", NULL, import_args, "Import saved config (sub)tree"}, - {"target", "/arg/sys/target", NULL, "set cross compilation target (prefix)"}, - {"target-name", "/arg/sys/target-name", NULL, "set cross compilation target (system name)"}, - {"target-shell","/arg/sys/target-shell",NULL, "set the shell on cross compilation target"}, - {"emu", "/arg/sys/emu", NULL, "emulator for testing cross compiled executables with"}, - {"pkg-config", "/arg/sys/pkg-config", NULL, "path to pkg-config to use"}, - {"pkg-config-zap","/arg/sys/pkg-config-zap",NULL, "ignore pkg-config results by this regex pattern"}, - -/* wildcard rules for icl() control */ - {"^ldflags/", NULL, import_icl, "force LDFLAGS for a node"}, - {"^cflags/", NULL, import_icl, "force CFLAGS for a node"}, - {"^includes/", NULL, import_icl, "force #includes for a node"}, - {"^prefix/", NULL, import_icl, "force using prefix path for detecting the node"}, - -/* the followings are autoconf compatibility translations */ - {"CC", "/arg/cc/cc", NULL, "Force using a C compiler (command line)"}, - {"CFLAGS", "/arg/cc/cflags", NULL, "Force using a CFLAGS for C compilation"}, - {"LDFLAGS", "/arg/cc/ldflags", NULL, "Force using a LDFLAGS for linking"}, - {"LDL", "/arg/libs/ldl", NULL, "Force using -ldl string"}, - - {"gpmi-prefix", "/arg/gpmi/prefix", NULL, NULL}, - {NULL, NULL, NULL, NULL} -}; - -void process_args(int argc, char *argv[]) -{ - int n; - char *key, *value; - argtbl_t *a; - int found, tainted = 0; - - db_mkdir("/arg"); - - logprintf(0, "CLI arg 0: '%s'\n", argv[0]); - for(n = 1; n < argc; n++) { - key = argv[n]; - logprintf(0, "CLI arg %d: '%s'\n", n, key); - while(*key == '-') key++; - value = str_chr(key, '='); - found = 0; - - if (value != NULL) { - *value = '\0'; - value++; - - if (strcmp(key, "without") == 0) { - char *tmp; - if (*value != '/') { - const char **r, *roots[] = {"target", "host", "runtime", NULL}; - for(r = roots; *r != NULL; r++) { - tmp = str_concat("/", "/arg/without", *r, value, NULL); - put(tmp, strue); - free(tmp); - } - } - else { - tmp = str_concat("/", "/arg/without", value+1, NULL); - put(tmp, strue); - free(tmp); - } - found = 1; - } - else { - /* Look in the argument translate table */ - for(a = main_argument_table; a->arg != NULL; a++) { - if (((a->arg[0] == '^') && (strncmp(a->arg+1, key, strlen(a->arg+1)) == 0)) || (strcmp(a->arg, key) == 0)) { - found = 1; - if (a->callback != NULL) { - if (a->callback(key, value) != 0) { - error("Processing argument '%s' failed in the callback\n", argv[n]); - abort(); - } - } - if (a->path != NULL) - put(a->path, value); - } - } - } - - /* Look in known deps table or /arg */ - if (found == 0) { - if ((is_dep_known(key)) || (strncmp(key, "/arg/", 5) == 0)) { - put(key, value); - found = 1; - } - } - } - - if (found == 0) { - if (custom_arg(key, value) == 0) { - error("Unknown argument '%s'\n", key); - tainted++; - } - } - } - if (tainted) - exit(1); -} - -void help_default_args(FILE *f, const char *prefix) -{ - argtbl_t *a; - - if (prefix == NULL) - prefix = ""; - - fprintf(f, "%sscconfig generic command line arguments:\n", prefix); - for(a = main_argument_table; a->arg != NULL; a++) { - char *tmp; - if (a->help == NULL) - continue; - if (*a->arg == '^') { - tmp = str_concat("", a->arg+1, "...=...", NULL); - fprintf(f, "%s --%-22s %s\n", prefix, tmp, a->help); - } - else { - tmp = str_concat("", a->arg, "=...", NULL); - fprintf(f, "%s --%-22s %s\n", prefix, tmp, a->help); - } - free(tmp); - } -} diff --git a/scconfig/src/default/.svn/pristine/5a/5a8cc5aaf0475eaecd997b7ad6266f2d8417b7e7.svn-base b/scconfig/src/default/.svn/pristine/5a/5a8cc5aaf0475eaecd997b7ad6266f2d8417b7e7.svn-base deleted file mode 100644 index b02a2cfc..00000000 --- a/scconfig/src/default/.svn/pristine/5a/5a8cc5aaf0475eaecd997b7ad6266f2d8417b7e7.svn-base +++ /dev/null @@ -1,187 +0,0 @@ -/* - scconfig - non-standard string manipulation routines - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include - -char *strclone(const char *str) -{ - int l; - char *ret; - - if (str == NULL) - return NULL; - - l = strlen(str)+1; - ret = malloc(l); - memcpy(ret, str, l); - return ret; -} - -#define SPACE(c) (((c) == '\r') || ((c) == '\n') || ((c) == '\t') || ((c) == ' ')) - -char *trim_left(char *str) -{ - while(SPACE(*str)) str++; - return str; -} - -char *trim_right(char *str) -{ - char *end; - - end = str + strlen(str) - 1; - while((end >= str) && SPACE(*end)) { *end = '\0'; end--; } - return str; -} - -char *strip(char *str) -{ - return trim_left(trim_right(str)); -} - -char *str_chr(char *str, char c) -{ - char *s; - - for(s = str; *s != '\0'; s++) - if (*s == c) - return s; - return NULL; -} - -char *str_rchr(char *str, char c) -{ - char *s, *last; - - last = NULL; - for(s = str; *s != '\0'; s++) - if (*s == c) - last = s; - return last; -} - -char *str_subsn(const char *str) -{ - char *out, *o; - const char *i; - if (str == NULL) - return strclone(""); - o = out = malloc(strlen(str)+1); - for(i = str; *i != '\0'; i++, o++) { - if ((i[0] == '\\') && (i[1] == 'n')) { - i++; - *o = '\n'; - } - else - *o = *i; - } - *o = '\0'; - return out; -} - -char *str_concat(const char *sep, ...) -{ -# define CONCAT_MAX 64 - int len[CONCAT_MAX]; - const char *str[CONCAT_MAX]; - int n, v, sum, sl; - char *out, *o; - va_list ap; - va_start(ap, sep); - - if (sep == NULL) - sep = ""; - - /* load all strings into an array, measure their lengths */ - sum = 0; - for(v = 0; ;v++) { - if (v >= CONCAT_MAX) { - fprintf(stderr, "Internal error: str_concat got more strings than CONCAT_MAX\n"); - abort(); - } - str[v] = va_arg(ap, const char *); - if (str[v] == NULL) { - len[v] = 0; - break; - } - len[v] = strlen(str[v]); - sum += len[v]; - } - - /* first string is NULL; return a new allocation that is a simple \0, empty string to avoid a nasty corner case */ - if (sum == 0) - return calloc(1, 1); - - sl = strlen(sep); - sum += (v-1) * sl + 1; /* + a sep between each two strings and a terminator at the end */ - o = out = malloc(sum); - for(n = 0; n < v; n++) { - if ((n > 0) && (sl > 0)) { - memcpy(o, sep, sl); - o += sl; - } - if (len[n] > 0) { - memcpy(o, str[n], len[n]); - o += len[n]; - } - } - *o = '\0'; - va_end(ap); - return out; -} - -char *esc_interpret(const char *str) -{ - char *out, *si, *so; - - out = strclone(str); - /* replace (interpret) \ sequences in seq */ - for(si = so = out; *si != '\0'; si++,so++) { - if (si[0] == '\\') { - switch(si[1]) { - case 'n': *so = '\n'; break; - case 't': *so = '\t'; break; - case 's': *so = ' '; break; - case '\\': *so = '\\'; break; - } - si++; - } - else - *so = *si; - } - *so = '\0'; - return out; -} - -int chr_inset(char c, const char *set) -{ - while (*set != '\0') { - if (c == *set) - return 1; - set++; - } - return 0; -} - diff --git a/scconfig/src/default/.svn/pristine/61/61817943ad2f956efca5195cd0b850f1668dec27.svn-base b/scconfig/src/default/.svn/pristine/61/61817943ad2f956efca5195cd0b850f1668dec27.svn-base deleted file mode 100644 index a0e16774..00000000 --- a/scconfig/src/default/.svn/pristine/61/61817943ad2f956efca5195cd0b850f1668dec27.svn-base +++ /dev/null @@ -1,37 +0,0 @@ -#include "ht.h" - - -#define strue "true" -#define sfalse "false" -#define istrue(s) ((s != NULL) && (*s == 't')) -#define isfalse(s) ((s != NULL) && (*s == 'f')) -/* the 3rd option is "unknown" */ - -/* accessors */ -const char *get(const char *key); -const char *put(const char *key, const char *data); -void append(const char *key, const char *value); -char *concat_nodes(const char *prefix, ...); -int node_istrue(const char *key); - - -/* init/uninit */ -void db_init(void); -void db_uninit(void); - -/* export/import */ -int export(const char *fn, int export_empty, const char *root); -int import(const char *fn); -int import_args(const char *key, const char *fn); - -/* file system features */ -extern char *db_cwd; -void db_cd(const char *path); -void db_mkdir(const char *path); -void db_link(const char *existing, const char *new); -void db_rmdir(const char *path); - -extern ht_t *DBs; -#define iscross (ht_get(DBs, "target") != ht_get(DBs, "host")) -#define in_cross_target (iscross && (strcmp(db_cwd, "/target") == 0)) -#define in_cross_host (iscross && (strcmp(db_cwd, "/host") == 0)) diff --git a/scconfig/src/default/.svn/pristine/62/6297d94e20d705f315542b34e21c31ad327a56b8.svn-base b/scconfig/src/default/.svn/pristine/62/6297d94e20d705f315542b34e21c31ad327a56b8.svn-base deleted file mode 100644 index 7e990d2b..00000000 --- a/scconfig/src/default/.svn/pristine/62/6297d94e20d705f315542b34e21c31ad327a56b8.svn-base +++ /dev/null @@ -1,808 +0,0 @@ -/* - scconfig - detection of standard library features: file system specific calls - Copyright (C) 2010 Tibor Palinkas - Copyright (C) 2018 Aron Barath - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_fs_realpath(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "#ifdef PATH_MAX" - NL "char out_buf[PATH_MAX];" - NL "#else" - NL "char out_buf[32768];" - NL "#endif" - NL "int main() {" - NL " if (realpath(\".\", out_buf) == out_buf)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for realpath()... "); - logprintf(logdepth, "find_fs_realpath: trying to find realpath...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/realpath", test_c, NULL, NULL, NULL)) return 0; - if (try_icl(logdepth, "libs/fs/realpath", test_c, "#define _DEFAULT_SOURCE", NULL, NULL)) return 0; - if (try_icl(logdepth, "libs/fs/realpath", test_c, "#define _BSD_SOURCE", NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/realpath"); -} - - -int find_fs__fullpath(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "#include " - NL "int main() {" - NL " char full[_MAX_PATH];" - NL " if (_fullpath(full, \".\", _MAX_PATH) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for _fullpath()... "); - logprintf(logdepth, "find_fs__fullpath: trying to find _fullpath...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/_fullpath", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/_fullpath"); -} - - -int find_fs_readdir(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " DIR *dirp;" - NL " struct dirent *dp;" - NL " int found = 0;" - NL " if ((dirp = opendir(\".\")) == 0)" - NL " return -1;" - NL " while ((dp = readdir(dirp)) != 0)" - NL " if (strcmp(dp->d_name, \"configure\") == 0)" - NL " found++;" - NL " closedir(dirp);" - NL " if (found == 1)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - char *includes[] = { - "#include ", - "#include ", /* 4.2BSD */ - NULL - }; - char **i; - - require("cc/cc", logdepth, fatal); - - report("Checking for readdir()... "); - logprintf(logdepth, "find_fs_readdir: trying to find readdir...\n"); - logdepth++; - - for (i = includes; *i != NULL; i++) - if (try_icl(logdepth, "libs/fs/readdir", test_c, *i, NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/fs/readdir"); -} - - -int find_fs_findnextfile(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "int main(int argc, char *argv[]) {" - NL " WIN32_FIND_DATA fd;" - NL " HANDLE h;" - NL " int found=0;" - NL " h = FindFirstFile(argv[0], &fd);" - NL " if (h == INVALID_HANDLE_VALUE)" - NL " return -1;" - NL " while (FindNextFile(h, &fd) != 0);" - NL " found++;" - NL " FindClose(h);" - NL " if (found > 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for FindNextFile()... "); - logprintf(logdepth, "find_fs_findnextfile: trying to find FindNextFile...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/findnextfile", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/findnextfile"); -} - -int find_fs_access(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "int my_test() { return access(\".\", 0); }" - NL "#include " - NL "int main() {" - NL " if (my_test() == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char* includes[] = { "#include ", "#include \n#include ", "#include ", NULL }; - const char** inc; - - require("cc/cc", logdepth, fatal); - - report("Checking for access()... "); - logprintf(logdepth, "find_fs_access: trying to find access...\n"); - logdepth++; - - for (inc=includes; *inc; ++inc) - if (try_icl(logdepth, "libs/fs/access", test_c, *inc, NULL, NULL)) return 0; - - return try_fail(logdepth, "libs/fs/access"); -} - -int find_fs_access_macros(const char *rname, int logdepth, int fatal) -{ - char *test_c_templ = - NL "%s" - NL "void my_test() { int a = %s; }" - NL "#include " - NL "int main() {" - NL " my_test();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - char test_c[256]; - - char *names[][3] = { - {"F_OK", "F_OK", NULL}, - {"R_OK", "R_OK", NULL}, - {"W_OK", "W_OK", NULL}, - {"X_OK", "X_OK", NULL}, - {NULL, NULL, NULL} - }; - char **n; - const char* access_includes; - int name, pr; - char nodename[128]; - - require("cc/cc", logdepth, fatal); - if (require("libs/fs/access/*", logdepth, fatal)!=0 || - !istrue(get("libs/fs/access/presents"))) { - put("libs/fs/access/macros/presents", sfalse); - return 1; - } - access_includes = get("libs/fs/access/includes"); - - report("Checking for access macros:\n"); - logprintf(logdepth, "find_fs_access_macros: trying to find access macros...\n"); - logdepth++; - - pr = 0; - for(name = 0; *names[name] != NULL; name++) { - report(" %s...\t", names[name][0]); - for(n = &names[name][0]; *n != NULL; n++) { - sprintf(test_c, test_c_templ, access_includes, *n); - if (try_icl(logdepth, NULL, test_c, NULL, NULL, NULL)) { - sprintf(nodename, "libs/fs/access/macros/%s", names[name][0]); - put(nodename, *n); - report("found as %s\n", *n); - pr++; - goto found; - } - } - report("not found\n"); - found:; - } - - put("libs/fs/access/macros/presents", ((pr > 0) ? (strue) : (sfalse))); - return (pr == 0); -} - -int find_fs_stat_macros(const char *rname, int logdepth, int fatal) -{ - char *test_c_templ = - NL "#include " - NL "#include " - NL "void my_test() { int a = %s(0); }" - NL "#include " - NL "int main() {" - NL " my_test();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - char test_c[256]; - - char *names[][3] = { - {"S_ISREG", "S_IFREG", NULL}, - {"S_ISDIR", "S_IFDIR", NULL}, - {"S_ISCHR", "S_IFCHR", NULL}, - {"S_ISBLK", "S_IFBLK", NULL}, - {"S_ISFIFO", "S_IFFIFO", NULL}, - {"S_ISLNK", "S_IFLNK", NULL}, - {"S_ISCHR", "S_IFCHR", NULL}, - {"S_ISSOCK", "S_IFSOCK", NULL}, - {NULL, NULL, NULL} - }; - char **n; - int name, pr; - char nodename[128]; - - require("cc/cc", logdepth, fatal); - - report("Checking for stat macros:\n"); - logprintf(logdepth, "find_fs_stat_macros: trying to find stat macros...\n"); - logdepth++; - - pr = 0; - for(name = 0; *names[name] != NULL; name++) { - report(" %s...\t", names[name][0]); - for(n = &names[name][0]; *n != NULL; n++) { - sprintf(test_c, test_c_templ, *n); - if (try_icl(logdepth, NULL, test_c, NULL, NULL, NULL)) { - sprintf(nodename, "libs/fs/stat/macros/%s", names[name][0]); - put(nodename, *n); - report("found as %s\n", *n); - pr++; - goto found; - } - } - report("not found\n"); - found:; - } - - put("libs/fs/stat/macros/presents", ((pr > 0) ? (strue) : (sfalse))); - return (pr == 0); -} - -int find_fs_stat_fields(const char *rname, int logdepth, int fatal) -{ - char *test_c_templ = - NL "#include " - NL "#include " - NL "#include " - NL "int main() {" - NL " struct stat st;" - NL " (void)st.%s;" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - char test_c[256]; - - char *names[] = {"st_blksize", "st_blocks", "st_rdev", "st_mtim", "st_mtime", "st_birthtim", "st_birthtime", NULL }; - int name, pr; - char nodename[128]; - - require("cc/cc", logdepth, fatal); - - report("Checking for stat macros:\n"); - logprintf(logdepth, "find_fs_stat_fields: trying to find stat macros...\n"); - logdepth++; - - pr = 0; - for(name = 0; names[name] != NULL; name++) { - report(" %s...\t", names[name]); - sprintf(test_c, test_c_templ, names[name]); - sprintf(nodename, "libs/fs/stat/fields/%s/presents", names[name]); - if (try_icl(logdepth, NULL, test_c, NULL, NULL, NULL)) { - put(nodename, strue); - report("found\n"); - pr++; - } - else { - report("not found\n"); - put(nodename, sfalse); - } - } - return (pr == 0); -} - -static int find_fs_any_lstat(const char *name, int logdepth, int fatal, char *fn) -{ - /* make sure does not affect our lstat() detection */ - const char *test_c_in = - NL "void my_puts(const char *s);" - NL "int main() {" - NL " struct stat buf;" - NL " if (%s(\".\", &buf) == 0)" - NL " my_puts(\"OK\");" - NL " return 0;" - NL "}" - NL "#include " - NL "void my_puts(const char *s)" - NL "{" - NL " puts(s);" - NL "}" - NL; - char test_c[384], node[64]; - const char *incs[] = {"#include ", "#include ", "#include \n#include \n#include ", NULL}; - const char **inc; - - require("cc/cc", logdepth, fatal); - - sprintf(node, "libs/fs/%s", fn); - sprintf(test_c, test_c_in, fn); - - report("Checking for %s... ", fn); - logprintf(logdepth, "find_fs_%s: trying to find lstat()...\n", fn); - logdepth++; - - for (inc = incs; *inc; ++inc) { - if (try_icl(logdepth, node, test_c, *inc, NULL, NULL)) - return 0; - } - - return try_fail(logdepth, node); -} - -int find_fs_lstat(const char *name, int logdepth, int fatal) -{ - return find_fs_any_lstat(name, logdepth, fatal, "lstat"); -} - -int find_fs_statlstat(const char *name, int logdepth, int fatal) -{ - return find_fs_any_lstat(name, logdepth, fatal, "statlstat"); -} - - -int find_fs_getcwd(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " char b[1024];" - NL " if (getcwd(b, sizeof(b)) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for getcwd... "); - logprintf(logdepth, "find_fs_getcwd: trying to find getcwd()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/getcwd", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/getcwd"); -} - -int find_fs__getcwd(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " char b[1024];" - NL " if (_getcwd(b, sizeof(b)) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for _getcwd... "); - logprintf(logdepth, "find_fs__getcwd: trying to find _getcwd()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/_getcwd", test_c, "#include ", NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/_getcwd"); -} - - -int find_fs_getwd(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " char b[8192];" - NL " if (getwd(b) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for getwd... "); - logprintf(logdepth, "find_fs_getwd: trying to find getwd()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/getwd", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/getwd"); -} - -int find_fs_mkdir(const char *name, int logdepth, int fatal) -{ - char *dir; - char test_c[1024]; - char *test_c_in = - NL "#include " - NL "int main() {" - NL no_implicit(int, "mkdir", "mkdir") - NL " if (mkdir(\"%s\"%s) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - dir = tempfile_new(""); - unlink(dir); - - report("Checking for mkdir... "); - logprintf(logdepth, "find_fs_mkdir: trying to find mkdir()...\n"); - logdepth++; - - /* POSIX, 2 arguments, standard includes */ - sprintf(test_c, test_c_in, dir, ", 0755"); - if (try_icl(logdepth, "libs/fs/mkdir", test_c, "#include \n#include \n", NULL, NULL)) { - if (!is_dir(dir)) - goto oops1; - put("libs/fs/mkdir/num_args", "2"); - rmdir(dir); - return 0; - } - - /* POSIX, 2 arguments, no includes */ - oops1:; - sprintf(test_c, test_c_in, dir, ", 0755"); - if (try_icl(logdepth, "libs/fs/mkdir", test_c, NULL, NULL, NULL)) { - if (!is_dir(dir)) - goto oops2; - put("libs/fs/mkdir/num_args", "2"); - rmdir(dir); - return 0; - } - - /* win32, 1 argument, with */ - oops2:; - sprintf(test_c, test_c_in, dir, ""); - if (try_icl(logdepth, "libs/fs/mkdir", test_c, "#include \n", NULL, NULL)) { - if (!is_dir(dir)) - goto oops3; - put("libs/fs/mkdir/num_args", "1"); - rmdir(dir); - return 0; - } - - oops3:; - put("libs/fs/mkdir/includes", ""); - put("libs/fs/mkdir/ldflags", ""); - put("libs/fs/mkdir/cdflags", ""); - - rmdir(dir); - return try_fail(logdepth, "libs/fs/mkdir"); -} - -int find_fs__mkdir(const char *name, int logdepth, int fatal) -{ - char *dir; - char test_c[1024]; - char *test_c_in = - NL "#include " - NL "int main() {" - NL " if (_mkdir(\"%s\"%s) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - dir = tempfile_new(""); - unlink(dir); - - report("Checking for _mkdir... "); - logprintf(logdepth, "find_fs__mkdir: trying to find _mkdir()...\n"); - logdepth++; - - /* win32, 2 arguments, standard includes */ - sprintf(test_c, test_c_in, dir, ", 0755"); - if (try_icl(logdepth, "libs/fs/_mkdir", test_c, "#include \n", NULL, NULL)) { - if (!is_dir(dir)) - goto oops1; - put("libs/fs/_mkdir/num_args", "2"); - rmdir(dir); - return 0; - } - - oops1:; - /* win32, 1 argument, standard includes */ - sprintf(test_c, test_c_in, dir, ""); - if (try_icl(logdepth, "libs/fs/_mkdir", test_c, "#include \n", NULL, NULL)) { - if (!is_dir(dir)) - goto oops2; - put("libs/fs/_mkdir/num_args", "1"); - rmdir(dir); - return 0; - } - - oops2:; - put("libs/fs/_mkdir/includes", ""); - put("libs/fs/_mkdir/ldflags", ""); - put("libs/fs/_mkdir/cdflags", ""); - - rmdir(dir); - return try_fail(logdepth, "libs/fs/_mkdir"); -} - -int find_fs_mkdtemp(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "int main() {" - NL " char fn[32], *o;" - NL " strcpy(fn, \"scc.XXXXXX\");" - NL " o = mkdtemp(fn);" - NL " if ((o != NULL) && (strstr(o, \"scc.\") != NULL)) {" - NL " remove(o);" - NL " puts(\"OK\");" - NL " }" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for mkdtemp... "); - logprintf(logdepth, "find_fs_mkdtemp: trying to find mkdtemp()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/mkdtemp", test_c, "#include \n", NULL, NULL)) return 0; - if (try_icl(logdepth, "libs/fs/mkdtemp", test_c, "#define _BSD_SOURCE\n#include \n", NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fs/mkdtemp"); -} - -int find_fs_mmap(const char *name, int logdepth, int fatal) -{ - char test_c[1024]; - char *tmp; - FILE *f; - char *test_c_in = - NL "#include " - NL "#include " - NL "#include " - NL "#include " - NL "#include " - NL "#include " - NL "int main() {" - NL " int fd, size = 11;" - NL " void *p;" - NL " fd = open(\"%s\", O_RDONLY);" - NL " p = mmap(0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0);" - NL " if (p == NULL) {" - NL " puts(\"mmap fail\");" - NL " return 0;" - NL " }" - NL " if (strcmp(p, \"hello world\") != 0) {" - NL " puts(\"strcmp fail\");" - NL " return 0;" - NL " }" - NL " if (munmap(p, size) != 0) {" - NL " puts(\"munmap fail\");" - NL " return 0;" - NL " }" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - tmp = tempfile_new(""); - f = fopen(tmp, "w"); - fprintf(f, "hello world"); - fclose(f); - sprintf(test_c, test_c_in, tmp); - - report("Checking for mmap... "); - logprintf(logdepth, "find_fs_mmap: trying to find mmap()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fs/mmap", test_c, "#include \n", NULL, NULL)) { - unlink(tmp); - free(tmp); - return 0; - } - - unlink(tmp); - free(tmp); - return try_fail(logdepth, "libs/fs/mmap"); -} - -/* Haiku/BeOS next_dev */ -int find_fsmount_next_dev(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " int32 pos = 0;" - NL " dev_t res = next_dev(&pos);" - NL " if (res >= 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for next_dev... "); - logprintf(logdepth, "find_fsmount_next_dev: trying to find next_dev()...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/fsmount/next_dev", test_c, "#include \n", NULL, NULL)) return 0; - return try_fail(logdepth, "libs/fsmount/next_dev"); -} - -int find_fsmount_fsstat_fields(const char *name, int logdepth, int fatal) -{ - const char *fields[] = {"f_fstypename", NULL}; - return try_icl_sfields(logdepth, "libs/fsmount/struct_fsstat", "struct fsstat", fields, "#include ", NULL, NULL, 0); -} - -int find_fsmount_statfs_fields(const char *name, int logdepth, int fatal) -{ - const char *fields[] = {"f_fstypename", "f_type", NULL}; - return try_icl_sfields(logdepth, "libs/fsmount/struct_statfs", "struct statfs", fields, "#include ", NULL, NULL, 0); -} - -int find_fsmount_statvfs_fields(const char *name, int logdepth, int fatal) -{ - const char *fields[] = {"f_fstypename", "f_type", "f_basetype", NULL}; - return try_icl_sfields(logdepth, "libs/fsmount/struct_statvfs", "struct statvfs", fields, "#include ", NULL, NULL, 0); -} - -int find_fs_ustat(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/fs/ustat"; - const char *test_c = - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " struct stat stat_buf;" - NL " struct ustat ustat_buf;" - NL " if (stat(\".\", &stat_buf) == 0 &&" - NL " ustat(stat_buf.st_dev, &ustat_buf) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for ustat... "); - logprintf(logdepth, "find_fs_ustat: trying to find ustat()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - if (try_icl(logdepth, key, test_c, "#include \n#include ", NULL, NULL)) return 0; - if (try_icl(logdepth, key, test_c, "#include \n#include \n#include ", NULL, NULL)) return 0; - return try_fail(logdepth, key); -} - -int find_fs_statfs(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/fs/statfs"; - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " struct statfs statfs_buf;" - NL " if (statfs(\".\", &statfs_buf) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for statfs... "); - logprintf(logdepth, "find_fs_statfs: trying to find statfs()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - return try_fail(logdepth, key); -} - -int find_fs_statvfs(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/fs/statvfs"; - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " struct statvfs statvfs_buf;" - NL " if (statvfs(\".\", &statvfs_buf) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for statvfs... "); - logprintf(logdepth, "find_fs_statvfs: trying to find statvfs()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - return try_fail(logdepth, key); -} - -int find_fs_flock(const char *name, int logdepth, int fatal) -{ - const char *key = "libs/fs/flock"; - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " if (flock(1, LOCK_UN) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for flock... "); - logprintf(logdepth, "find_fs_flock: trying to find flock()...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, "#include ", NULL, NULL)) return 0; - return try_fail(logdepth, key); -} diff --git a/scconfig/src/default/.svn/pristine/63/63df6ceeaf370f97450395c6fbe40349a7016e92.svn-base b/scconfig/src/default/.svn/pristine/63/63df6ceeaf370f97450395c6fbe40349a7016e92.svn-base deleted file mode 100644 index 1c148285..00000000 --- a/scconfig/src/default/.svn/pristine/63/63df6ceeaf370f97450395c6fbe40349a7016e92.svn-base +++ /dev/null @@ -1,357 +0,0 @@ -/* - scconfig - evaluate uname and classify the system - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "regex.h" -#include "log.h" -#include "db.h" -#include "libs.h" -#include "dep.h" - -static void sys_unix(void) -{ - put("sys/ext_exe", ""); - put("sys/ext_dynlib", ".so"); - put("sys/ext_stalib", ".a"); - put("sys/ext_dynlib_native", ".so"); -} - -static void sys_netbsd(void) -{ - sys_unix(); - put("cc/ldflags", "-Wl,-R/usr/pkg/lib -L/usr/pkg/lib"); /* TODO: is this the best way? */ -} - -static void sys_win32dlc(void) -{ - put("sys/ext_exe", ".exe"); - put("sys/ext_dynlib", ".dlc"); - put("sys/ext_stalib", ".a"); - put("sys/ext_dynlib_native", ".dll"); -} - -typedef void (*callback_t)(void); - -typedef struct { - char *uname_regex; - char *name; - char *class; - - callback_t callback; -} uname_t; - -typedef struct { - char *file_name; - char *name; - char *class; - - callback_t callback; -} magic_file_t; - -/* Guess system class by uname; class is informative, nothing important - should depend on it. - Order *does* matter */ -uname_t unames[] = { - {"[Nn]et[Bb][Ss][Dd]", "NetBSD", "UNIX", sys_netbsd}, - {"[Ll]inux", "Linux", "UNIX", sys_unix}, - {"[Bb][Ss][Dd]", "BSD", "UNIX", sys_unix}, - {"SunOS", "SunOS", "UNIX", sys_unix}, - {"OSF1", "OSF", "UNIX", sys_unix}, /* TODO: note the difference in cflags for debugging ("-ms -g") */ - {"IRIX", "IRIX", "UNIX", sys_unix}, - {"SunOS", "SunOS", "UNIX", sys_unix}, - {"[Mm]inix", "Minix", "UNIX", sys_unix}, - {"[Aa][Rr][Oo][Ss]", "Aros", "UNIX", sys_unix}, - {"^Darwin", "MacOSX", "UNIX", sys_unix}, - {"[Th]hreos", "Threos", "UNIX", sys_unix}, - {"[Cc]ygwin", "cygwin", "WIN32", sys_win32dlc}, - {"[Mm][Ii][Nn][Gg][Ww]", "mingw", "WIN32", sys_win32dlc}, - {"win32", "win32", "WIN32", sys_win32dlc}, /* vanilla windows */ - {NULL, NULL, NULL, NULL} -}; - -/* Fallback: extract machine name from uname -a if uname -m fails */ -static const char *machine_names[] = { - "i[0-9]86[^ ]*", "x86_[^ ]*", "amd[0-9]*", "armv[0-9][^ ]*", "ppc[0-9]+", - "sparc[0-9]*", "BePC", "ia64", "x86", "IP[0-9]*", "k1om", "sun4u", - "RM600", "R4000", "alpha", - NULL -}; - -/* Fallback: extract system name from uname -a if uname -s fails */ -static const char *system_names[] = { - "[Ll]inux", "sn5[0-9]*", "CYGWIN_NT[^ ]*", "GNU[^ ]*", "DragonFly", - "[^ ]*BSD[^ ]*", "Haiku", "HP-UX", "AIX", "OS4000", "Interix", - "IRIX[0-9]*", "Darwin", "Minix", "MINGW[^ ]*", "ReliantUNIX[^ ]*", - "SunOS", "OSF1", "ULTRIX", "UWIN-W7", "IS/WB", "OS/390", - "SCO[^ ]*", "QNX", - NULL -}; - -/* Fallback: if uname -a fails, guess system by looking at "magic file names" */ -magic_file_t magic_files[] = { - {"/dev/null", "UNIX", "UNIX", sys_unix}, - {"c:\\config.sys", "win32", "WIN32", sys_win32dlc}, - {"c:\\windows\\system.ini", "win32", "WIN32", sys_win32dlc}, - {"c:\\windows\\win.ini", "win32", "WIN32", sys_win32dlc}, - {"c:\\windows\\notepad.exe", "win32", "WIN32", sys_win32dlc}, - {NULL, NULL, NULL, NULL} -} ; - -static int match(const char *regex, const char *str) -{ - re_comp(regex); - return re_exec(str); -} - -/* match uname against each pattern on the list; on a match, put() the portion - of the string matched in node and return 1 */ -int uname_guess(const char *node, const char *uname, const char *list[]) -{ - const char **l; - if (uname == NULL) - return 0; - for(l = list; *l != NULL; l++) { - if (match(*l, uname)) { - char *s; - int len = eopat[0] - bopat[0]; - s = malloc(len+1); - memcpy(s, bopat[0], len); - s[len] = '\0'; - put(node, s); - return 1; - } - } - return 0; -} - -/* Don't worry about linear search or matching regexes all the time - this - function will be run at most two times */ -static callback_t lookup_uname(char **uname, const char **name, const char **class) -{ - uname_t *u; - for(u = unames; u->uname_regex != NULL; u++) { - if ( - ((*uname != NULL) && (match(u->uname_regex, *uname))) /* uname match */ - || ((*name != NULL) && ((strcmp(u->name, *name) == 0))) /* name match */ - || ((*class != NULL) && ((strcmp(u->class, *class) == 0))) /* class match */ - ) { - if (*name == NULL) *name = u->name; - if (*class == NULL) *class = u->class; - return u->callback; - } - } - return NULL; -} - -static callback_t lookup_magic_file(int logdepth, const char **name, const char **class) -{ - magic_file_t *u; - for(u = magic_files; u->file_name != NULL; u++) { - if (is_file(u->file_name)) { - logprintf(logdepth, "%s -> %s\n", u->file_name, u->class); - - if (*name == NULL) *name = u->name; - if (*class == NULL) *class = u->class; - return u->callback; - } - } - return NULL; -} - -int find_uname(const char *rname, int logdepth, int fatal) -{ - const char *name, *class, *tname, *uname_orig; - char *s, *uname, *mname, *sname; - void (*callback)(void); - - require("sys/tmp", logdepth, fatal); - - if (istarget(db_cwd)) - require("/target/sys/target", logdepth, fatal); - - report("Checking for system type... "); - logprintf(logdepth, "[find_uname] checking for sys/name\n"); - logdepth++; - - tname = get("/arg/sys/target-name"); - if (istarget(db_cwd) && (tname != NULL)) - put("sys/name", tname); - - tname = get("/arg/sys/target-uname"); - if (istarget(db_cwd) && (tname != NULL)) - put("sys/uname", tname); - - name = get("sys/name"); - uname_orig = get("sys/uname"); - - if (name == NULL) { - if (uname_orig == NULL) { - logprintf(logdepth, "not set, running\n"); - run_shell(logdepth, "uname -a", (char **)&uname); - if (uname != NULL) { - for(s = uname; *s != '\0'; s++) - if ((*s == '\n') || (*s == '\r')) *s = ' '; - put("sys/uname", uname); - } - else - put("sys/uname", ""); - - if (run_shell(logdepth, "uname -m", (char **)&mname) == 0) - put("sys/machine_name", strip(mname)); - else - put("sys/machine_name", NULL); - - if (mname != NULL) - free(mname); - - if (run_shell(logdepth, "uname -o", (char **)&sname) == 0) - put("sys/system_name", strip(sname)); - else if (run_shell(logdepth, "uname -s", (char **)&sname) == 0) - put("sys/system_name", strip(sname)); - else - put("sys/system_name", NULL); - if (sname != NULL) - free(sname); - } - - /* we have uname by now, set sys/name */ - name = NULL; - class = NULL; - callback = lookup_uname(&uname, &name, &class); - if (name == NULL) { - /* no uname or unknown system by uname - fallback: check for cross target */ - const char *target = get("/arg/sys/target"); - if ((target != NULL) && (strstr(target, "mingw") != NULL)) { - name = "WIN32"; - report("(detected mingw cross compilation to WIN32)\n"); - } - else { - report("Warning: unknown system\n"); - name = "unknown"; - } - } - put("sys/name", name); - } - else { - /* we had sys/name, that should be enough */ - uname = NULL; - class = name; - callback = lookup_uname(&uname, &name, &class); - } - - /* predefined and/or detected uname failed, try magic file method */ - if (callback == NULL) { - logprintf(logdepth, "System class is unknown by uname, running heuristics...\n"); - report("System class is unknown by uname, running heuristics... "); - - callback = lookup_magic_file(logdepth + 1, &name, &class); - } - - - if (callback == NULL) { - /* System unknown. */ - error("Unknown system '%s'\n", get("sys/uname")); - abort(); - } - - callback(); - report("OK (name: %s; class: %s)\n", name, class); - put("sys/class", class); - - /* fallbacks */ - if (get("sys/machine_name") == NULL) - uname_guess("sys/machine_name", uname, machine_names); - - if (get("sys/system_name") == NULL) - uname_guess("sys/system_name", uname, system_names); - - /* on windows, overwrite the path sep with the right amount of \ (the tmp finder may have left / in it) */ - if ((strcmp(class, "WIN32") == 0) || (strcmp(class, "win32") == 0)) { - int eats = istrue(get("sys/shell_eats_backslash")); - - if (eats) - put("sys/path_sep", "\\\\\\\\"); - else - put("sys/path_sep", "\\"); - - put("sys/path_sep_escaped", "\\\\"); - } - - return 0; -} - -static int find_triplet_(const char *name, int logdepth, int fatal, const char *nodename, int include_vendor, char *sep, char *esc) -{ - const char *machine, *vendor, *os; - char *triplet, *s; - char fake_sep[2]; - - fake_sep[0] = 1; - fake_sep[1] = 0; - - require("sys/uname", logdepth, fatal); - - machine = get("sys/machine_name"); - if (machine == NULL) - machine = "unknown"; - - vendor = "unknown"; - - os = get("sys/system_name"); - if (os == NULL) - os = "unknown"; - - if (include_vendor) - triplet = str_concat(fake_sep, machine, vendor, os, NULL); - else - triplet = str_concat(fake_sep, machine, os, NULL); - - for(s = triplet; *s != '\0'; s++) { - if ((esc != NULL) && (*s == *sep)) - *s = *esc; - if (isalnum(*s)) - *s = tolower(*s); - else { - if (*s == *fake_sep) - *s = *sep; - else if (esc != NULL) - *s = *esc; - else - *s = '-'; - } - } - put(nodename, triplet); - free(triplet); - return 0; -} - -int find_triplet(const char *name, int logdepth, int fatal) -{ - return find_triplet_(name, logdepth, fatal, "sys/triplet", 1, "-", NULL); -} - -int find_sysid(const char *name, int logdepth, int fatal) -{ - return find_triplet_(name, logdepth, fatal, "sys/sysid", 0, "-", "_"); -} diff --git a/scconfig/src/default/.svn/pristine/68/68a7e367d90f6d6fa7f291aea14ddb0531bbc4f1.svn-base b/scconfig/src/default/.svn/pristine/68/68a7e367d90f6d6fa7f291aea14ddb0531bbc4f1.svn-base deleted file mode 100644 index 4004e4d1..00000000 --- a/scconfig/src/default/.svn/pristine/68/68a7e367d90f6d6fa7f291aea14ddb0531bbc4f1.svn-base +++ /dev/null @@ -1,166 +0,0 @@ -/* - scconfig - detection of environmental variable access features - Copyright (C) 2014 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_main_arg3(const char *name, int logdepth, int fatal) -{ - char *out; - char *test_c = - NL "#include " - NL "#include " - NL "int main(int argc, char *argv[], char *env[])" - NL "{" - NL " char **e;" - NL " int cnt;" - NL " for(e = env, cnt = 0; *e != NULL; e++, cnt++) ;" - NL " printf(\"%d\\n\", cnt);" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for main() with 3 arguments... "); - logprintf(logdepth, "find_main_3args: checking for main() with 3 arguments\n"); - if (compile_run(logdepth+1, test_c, NULL, NULL, NULL, &out) == 0) { - if (atoi(out) > 1) { - put("libs/env/main_3arg", strue); - report("OK\n"); - free(out); - return 0; - } - free(out); - report("not found (broken output).\n"); - } - else { - report("not found (no output).\n"); - } - put("libs/env/main_3arg", sfalse); - return 1; -} - -int find_environ(const char *name, int logdepth, int fatal) -{ - char *out; - char *test_c = - NL "#include " - NL "#include " - NL "extern char **environ;" - NL "int main(int argc, char *argv[])" - NL "{" - NL " char **e;" - NL " int cnt;" - NL " for(e = environ, cnt = 0; *e != NULL; e++, cnt++) ;" - NL " printf(\"%d\\n\", cnt);" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for extern environ... "); - logprintf(logdepth, "find_environ: checking for extern environ\n"); - if (compile_run(logdepth+1, test_c, NULL, NULL, NULL, &out) == 0) { - if (atoi(out) > 1) { - put("libs/env/environ", strue); - report("OK\n"); - free(out); - return 0; - } - free(out); - report("not found (broken output).\n"); - } - else { - report("not found (no output).\n"); - } - put("libs/env/environ", sfalse); - return 1; -} - -int find_putenv(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "int main(int argc, char *argv[])" - NL "{" - NL " putenv(\"SCCONFIG_TEST=bad\");" - NL " putenv(\"SCCONFIG_TEST=OK\");" - NL " printf(\"%s\\n\", getenv(\"SCCONFIG_TEST\"));" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for putenv()... "); - logprintf(logdepth, "find_putenv: trying to find putenv...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/env/putenv", test_c, "", NULL, NULL)) - return 0; - if (try_icl(logdepth, "libs/env/putenv", test_c, "#define _XOPEN_SOURCE", NULL, NULL)) - return 0; - if (try_icl(logdepth, "libs/env/putenv", test_c, "#define _SVID_SOURCE", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/env/putenv"); -} - - -int find_setenv(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "int main(int argc, char *argv[])" - NL "{" - NL " setenv(\"SCCONFIG_TEST\", \"bad\", 1);" - NL " setenv(\"SCCONFIG_TEST\", \"OK\", 1);" - NL " printf(\"%s\\n\", getenv(\"SCCONFIG_TEST\"));" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for setenv()... "); - logprintf(logdepth, "find_setenv: trying to find setenv...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/env/setenv", test_c, "", NULL, NULL)) - return 0; - if (try_icl(logdepth, "libs/env/setenv", test_c, "#define _BSD_SOURCE", NULL, NULL)) - return 0; - if (try_icl(logdepth, "libs/env/setenv", test_c, "#define _POSIX_C_SOURCE 200112L", NULL, NULL)) - return 0; - if (try_icl(logdepth, "libs/env/setenv", test_c, "#define _XOPEN_SOURCE 600", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/env/setenv"); -} - diff --git a/scconfig/src/default/.svn/pristine/6c/6ce2d66e5ceb25609e3341be59bfbb97920623be.svn-base b/scconfig/src/default/.svn/pristine/6c/6ce2d66e5ceb25609e3341be59bfbb97920623be.svn-base deleted file mode 100644 index f69f59d4..00000000 --- a/scconfig/src/default/.svn/pristine/6c/6ce2d66e5ceb25609e3341be59bfbb97920623be.svn-base +++ /dev/null @@ -1,1134 +0,0 @@ -/* - scconfig - detection of cc and compiler features - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - - - -static int try_flags(int logdepth, const char *cc, const char *test_c, const char *cflags, const char *ldflags, const char *expected) -{ - char *out; - - logprintf(logdepth, "trying cc:try_flags with cc='%s' cflags='%s' ldflags='%s'\n", (cc == NULL ? get("cc/cc") : cc), cflags == NULL ? "" : cflags, ldflags == NULL ? "" : ldflags); - - if (compile_run(logdepth+1, test_c, cc, cflags, ldflags, &out) == 0) { - if (((out == NULL) && (iscross)) || (strncmp(out, expected, strlen(expected)) == 0)) { - free(out); - return 1; - } - free(out); - } - return 0; -} - -static int try_flags_inv(int logdepth, const char *cc, const char *test_c, const char *cflags, const char *ldflags, const char *expected_bad) -{ - char *out; - - logprintf(logdepth, "trying cc:try_flags with cc='%s' cflags='%s' ldflags='%s'\n", (cc == NULL ? get("cc/cc") : cc), cflags == NULL ? "" : cflags, ldflags == NULL ? "" : ldflags); - - if (compile_run(logdepth+1, test_c, cc, cflags, ldflags, &out) == 0) { - if (((out == NULL) && (iscross)) || (strncmp(out, expected_bad, strlen(expected_bad)) != 0)) { - free(out); - return 1; - } - free(out); - } - return 0; -} - -static int try(int logdepth, const char *cc, const char *test_c, const char *expected) -{ - return try_flags(logdepth, cc, test_c, NULL, NULL, expected); -} - - -static int trycc(int logdepth, const char *cc, const char *test_c) -{ - int ret; - - if (cc == NULL) - return 0; - - ret = try(logdepth, cc, test_c, "OK"); - if (ret) - put("cc/cc", cc); - return ret; -} - -int find_cc(const char *name, int logdepth, int fatal) -{ - char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL, *targetcc; - const char *cc, *cflags, *ldflags, *target, *sys; - int len; - - require("sys/name", logdepth, fatal); - - sys = istarget(db_cwd) ? "target" : "host"; - report("Checking for cc (%s)... ", sys); - logprintf(logdepth, "find_cc: trying to find cc (%s)...\n", sys); - logdepth++; - - /* cflags */ - cflags = get("/arg/cc/cflags"); - if (cflags != NULL) { - logprintf(logdepth+1, "using user supplied cflags '%s'\n", cflags); - put("cc/cflags", cflags); - } - - /* ldflags */ - ldflags = get("/arg/cc/ldflags"); - if (ldflags != NULL) { - logprintf(logdepth+1, "using user supplied ldflags '%s'\n", ldflags); - put("cc/ldflags", ldflags); - } - - cc = get("/arg/cc/cc"); - if (cc == NULL) { - target = get("sys/target"); - if (target != NULL) { - logprintf(logdepth+1, "find_cc: crosscompiling for '%s', looking for target cc\n", target); - len = strlen(target); - targetcc = malloc(len + 8); - memcpy(targetcc, target, len); - strcpy(targetcc + len, "-gcc"); - if (!trycc(logdepth+1, targetcc, test_c)) { - strcpy(targetcc + len, "-cc"); - if (!trycc(logdepth+1, targetcc, test_c)) { - report("FAILED: failed to find crosscompiler for target '%s'\n", target); - logprintf(logdepth, "find_cc: FAILED to find a crosscompiler for target '%s'\n", target); - return 1; - } - } - put("cc/cc", targetcc); - } - else { - cc = getenv("CC"); - logprintf(logdepth, "find_cc: Detecting cc (host)\n"); - /* Find a working cc (no arguments) */ - if (!(((cc != NULL) && (trycc(logdepth+1, cc, test_c))) || trycc(logdepth+1, "gcc", test_c) || trycc(logdepth+1, "cc", test_c))) { - report("FAILED to find a compiler\n"); - logprintf(logdepth, "find_cc: FAILED to find a compiler\n"); - return 1; - } - } - } - else { - put("cc/cc", cc); - logprintf(logdepth+1, "using user supplied '%s' (will test later)\n", cc); - } - - /* cflags (again) */ - if (cflags == NULL) { - logprintf(logdepth, "find_cc: Detecting -pipe\n"); - - if (compile_run(logdepth+1, test_c, NULL, "-pipe", "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - append("cc/cflags", " -pipe"); - } - free(out); - } - } - if (get("cc/cflags") == NULL) - put("cc/cflags", ""); - - /* ldflags (again) */ - if (get("cc/ldflags") == NULL) - put("cc/ldflags", ""); - - /* Final test of all arguments together */ - logprintf(logdepth, "find_cc: final test on cc and all flags \n"); - if (compile_run(logdepth+1, test_c, NULL, NULL, NULL, &out) != 0) { - report("FAILED to get the compiler and all flags to work together\n"); - logprintf(logdepth, "find_cc: the compiler and all the flags don't work well together, aborting\n"); - if (out != NULL) - free(out); - return 1; - } - - report("OK ('%s', '%s', '%s')\n", get("cc/cc"), get("cc/cflags"), get("cc/ldflags")); - logprintf(logdepth, "find_cc: conclusion: cc='%s' cflags='%s' ldflags='%s'\n", get("cc/cc"), get("cc/cflags"), get("cc/ldflags")); - if (out != NULL) - free(out); - return 0; -} - -int find_cc_argstd(const char *det_name, int logdepth, int fatal) -{ - char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL; - char **flg, *flags[] = {"-ansi", "-pedantic", "-Wall", "-std=c89", "-std=c99", "-Werror", "-Wextra", "-W", "-pg", "-no-pie", "-static-pie", NULL}; - const char *det_target = det_list_target(det_name); - - require("cc/cc", logdepth, fatal); - - logprintf(logdepth, "find_cc: Detecting CC args %s\n", det_target); - report("Checking for cc args for std %s... ", det_target); - - for(flg = flags; *flg != NULL; flg++) { - char name[128], *end; - const char *found = ""; - sprintf(name, "cc/argstd/%s", (*flg)+1); - end = strchr(name, '='); - if (end != NULL) - *end = '_'; - if (!asked_for(name, det_name)) - continue; - if (compile_run(logdepth+1, test_c, NULL, *flg, "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - found = *flg; - report(" "); - report(found); - } - free(out); - } - put(name, found); - } - - if (is_dep_wild(det_name)) - put("cc/argstd/presents", strue); /* to avoid re-detection*/ - - report("\n"); - return 0; -} - -int find_cc_argmachine(const char *name, int logdepth, int fatal) -{ -#define ARGM(flag) "-m" #flag , "-mno-" #flag - const char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL; - const char **flg, *flags[] = { ARGM(mmx), ARGM(sse), ARGM(sse2), ARGM(sse3), ARGM(ssse3), ARGM(sse4), ARGM(sse4.1), ARGM(sse4.2), ARGM(avx), ARGM(avx2), NULL}; - - require("cc/cc", logdepth, fatal); - - logprintf(logdepth, "find_cc: Detecting CC machine args\n"); - report("Checking for cc args for machine... "); - - for(flg = flags; *flg != NULL; flg++) { - char name[128], *end; - const char *found = ""; - { - const char* ptr = (*flg) + 1; - strcpy(name, "cc/argmachine/"); - end = name + strlen(name); - while(*ptr) { - if('.'!=*ptr && '-'!=*ptr) *end++ = *ptr; - ++ptr; - } - *end = '\0'; - } - end = strchr(name, '='); - if (end != NULL) - *end = '_'; - if (compile_run(logdepth+1, test_c, NULL, *flg, "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - found = *flg; - report(" "); - report(found); - } - free(out); - } - put(name, found); - } - - report("\n"); - return 0; -#undef ARGM -} - -int find_inline(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "static inline void test_inl()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test_inl();" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for inline... "); - logprintf(logdepth, "find_inline: trying to find inline...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/inline", strue); - report("Found.\n"); - return 0; - } - put("cc/inline", sfalse); - report("Not found.\n"); - return 1; -} - -int find_varargmacro(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#define pr(fmt, x...) {printf(\"PR \"); printf(fmt, x); }" - NL "int main() {" - NL " pr(\"%d %d %s\", 42, 8192, \"test\");" - NL " puts(\"\");" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for vararg macro... "); - logprintf(logdepth, "find_varargmacro: trying to find vararg macro...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "PR 42 8192 test")) { - put("cc/varargmacro", strue); - report("Found.\n"); - return 0; - } - put("cc/varargmacro", sfalse); - report("Not found.\n"); - return 1; -} - -int find_funcmacro(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " printf(\"%s\\n\", __func__);" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for __func__ macro... "); - logprintf(logdepth, "find_funcmacro: trying to find __func__ macro...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "main")) { - put("cc/funcmacro", strue); - report("Found.\n"); - return 0; - } - put("cc/funcmacro", sfalse); - report("Not found.\n"); - return 1; -} - -int find_constructor(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "void startup() __attribute__ ((constructor));" - NL "void startup()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for constructor... "); - logprintf(logdepth, "find_constructor: trying to find constructor...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/constructor", strue); - report("Found.\n"); - return 0; - } - put("cc/constructor", sfalse); - report("Not found.\n"); - return 1; -} - -int find_destructor(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "void startup() __attribute__ ((destructor));" - NL "void startup()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for destructor... "); - logprintf(logdepth, "find_destructor: trying to find destructor...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/destructor", strue); - report("Found.\n"); - return 0; - } - put("cc/destructor", sfalse); - report("Not found.\n"); - return 1; -} - -static int test_fattr(const char *name, int logdepth, int fatal, const char *fattr) -{ - char path[64]; - char test_c[256]; - const char *test_c_tmp = - NL "#include " - NL "static void test1() __attribute__ ((%s));" - NL "static void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - sprintf(test_c, test_c_tmp, fattr); - sprintf(path, "cc/func_attr/%s/presents", fattr); - - report("Checking for function attribute %s... ", fattr); - logprintf(logdepth, "test_fattr: trying to find %s...\n", fattr); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put(path, strue); - report("Found.\n"); - return 0; - } - put(path, sfalse); - report("Not found.\n"); - return 1; -} - -int find_fattr_unused(const char *name, int logdepth, int fatal) -{ - return test_fattr(name, logdepth, fatal, "unused"); -} - -static int test_declspec(const char *name, int logdepth, int fatal, const char *dspec) -{ - char path[64]; - char test_c[256]; - const char *test_c_tmp = - NL "#include " - NL "void __declspec (%s) test1();" - NL "void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test1();" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - sprintf(test_c, test_c_tmp, dspec); - sprintf(path, "cc/declspec/%s/presents", dspec); - - report("Checking for declspec %s... ", dspec); - logprintf(logdepth, "test_declspec: trying to find %s...\n", dspec); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put(path, strue); - report("Found.\n"); - return 0; - } - put(path, sfalse); - report("Not found.\n"); - return 1; -} - -int find_declspec_dllimport(const char *name, int logdepth, int fatal) -{ - return test_declspec(name, logdepth, fatal, "dllimport"); -} - -int find_declspec_dllexport(const char *name, int logdepth, int fatal) -{ - return test_declspec(name, logdepth, fatal, "dllexport"); -} - -static int test_dll_auxfile(const char *name, int logdepth, int fatal, const char *path, const char *ldflag, const char *filename) -{ - char *ldflags; - char test_c[256]; - const char *test_c_template = - NL "#include " - NL "void %s test1();" - NL "void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test1();" - NL " return 0;" - NL "}" - NL ; - const char *dspec; - - require("cc/cc", logdepth, fatal); - require("cc/declspec/dllexport/*", logdepth, 0); - - if (istrue("cc/declspec/dllexport/presents")) - dspec = " __declspec(dllexport) "; - else - dspec = ""; - - sprintf(test_c, test_c_template, dspec); - - report("Checking for DLL flag %s... ", ldflag); - logprintf(logdepth, "test_dll_auxfile: trying to find %s...\n", ldflag); - logdepth++; - ldflags = str_concat("", ldflag, ",", filename, " ", get("cc/ldflags"), NULL); - if (try_flags(logdepth, NULL, test_c, NULL, ldflags, "OK")) { - unlink(filename); - put(path, ldflag); - free(ldflags); - report("Found.\n"); - return 0; - } - unlink(filename); - free(ldflags); - report("Not found.\n"); - return 1; -} - -int find_cc_wloutimplib(const char *name, int logdepth, int fatal) -{ - return test_dll_auxfile(name, logdepth, fatal, "cc/wloutimplib", "-Wl,--out-implib", "libscconfig_0.a"); -} - -int find_cc_wloutputdef(const char *name, int logdepth, int fatal) -{ - return test_dll_auxfile(name, logdepth, fatal, "cc/wloutputdef", "-Wl,--output-def", "libscconfig_0.def"); -} - -/* Hello world program to test compiler flags */ -static const char *test_hello_world = - NL "#include " - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -static int try_hello(int logdepth, const char *cflags, const char *ldflags, const char *name, const char *value) -{ - if (try_flags(logdepth, NULL, test_hello_world, cflags, ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - return 1; - } - return 0; -} - -int find_rdynamic(const char *name, int logdepth, int fatal) -{ - const char *node = "cc/rdynamic"; - - require("cc/cc", logdepth, fatal); - - report("Checking for rdynamic... "); - logprintf(logdepth, "find_rdynamic: trying to find rdynamic...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-rdynamic", node, "-rdynamic")) return 0; - if (try_hello(logdepth, NULL, "-Wl,-export-dynamic", node, "-Wl,-export-dynamic")) return 0; - if (try_hello(logdepth, NULL, NULL, node, "")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_cc_fpie(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - /* TODO: what about -fpic? */ - - report("Checking for -fpie... "); - logprintf(logdepth, "find_cc_fpie: trying to find -fpie...\n"); - logdepth++; - - /* NOTE: some gcc configuration might not pass the -pie flag to the linker, so */ - /* try to detect whether we can force it to the linker */ - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fpie", "-pie -Wl,-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fPIE", "-pie -Wl,-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fpie", "-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fPIE", "-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fpie"); -} - -int find_cc_fnopie(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - - report("Checking for -fno-pie... "); - logprintf(logdepth, "find_cc_fnopie: trying to find -fno-pie...\n"); - logdepth++; - - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, "-fno-pie", NULL)) return 0; - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, "-fno-pie", "-static")) return 0; - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fnopie"); -} - -int find_cc_fnopic(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - - report("Checking for -fno-pic... "); - logprintf(logdepth, "find_cc_fnopic: trying to find -fno-pic...\n"); - logdepth++; - - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, "-fno-pic", NULL)) return 0; - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, "-fno-pic", "-static")) return 0; - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fnopic"); -} - -int find_soname(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for soname... "); - logprintf(logdepth, "find_soname: trying to find soname...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-Wl,-soname,libscconfig.0", "cc/soname", "-Wl,-soname,")) return 0; - if (try_hello(logdepth, NULL, NULL, "cc/soname", "")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_so_undefined(const char *name, int logdepth, int fatal) -{ - static const char *test_c = - NL "#include " - NL "void intentionally_undefined_symbol(void);" - NL "int main() {" - NL " intentionally_undefined_symbol();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - const char **t, *try_ldflags[] = { - "", - "-undefined dynamic_lookup", /* OSX + clang */ - NULL - }; - - require("cc/cc", logdepth, fatal); - require("cc/ldflags_dynlib", logdepth, fatal); - - report("Checking for so_undefined... "); - logprintf(logdepth, "find_so_undefined: trying to find so_undefined...\n"); - logdepth++; - - for(t = try_ldflags; *t != NULL; t++) { - const char *fpic; - char *ldf, *oname = ".o", *libname_dyn, *cflags_c; - int res1, res2; - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - cflags_c = str_concat(" ", "-c", fpic, NULL); - - libname_dyn = (char *)get("sys/ext_dynlib"); - ldf = str_concat(" ", get("cc/ldflags_dynlib"), *t, NULL); - res1 = compile_code(logdepth, test_c, &oname, NULL, cflags_c, NULL); - res2 = compile_file(logdepth, oname, &libname_dyn, NULL, NULL, ldf); - unlink(libname_dyn); - unlink(oname); - free(libname_dyn); - free(oname); - free(cflags_c); - - if ((res1 == 0) && (res2 == 0)) { - put(name, *t); - report("OK (%s)\n", *t); - return 0; - } - } - - report("Not found.\n"); - return 1; -} - - -int find_wlrpath(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for rpath... "); - logprintf(logdepth, "find_wlrpath: trying to find rpath...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-Wl,-rpath=.", "cc/wlrpath", "-Wl,-rpath=")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_fpic(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for -fpic... "); - logprintf(logdepth, "find_fpic: trying to find -fpic...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-fPIC", "cc/fpic", "-fPIC")) return 0; - if (try_hello(logdepth, NULL, "-fpic", "cc/fpic", "-fpic")) return 0; - if (try_hello(logdepth, NULL, NULL, "cc/fpic", "")) return 0; - - report("Not found.\n"); - return 1; -} - -/* Hello world lib... */ -static const char *test_lib = - NL "#include " - NL "int hello() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -/* ...and the corresponding host application */ -static const char *test_host = - NL "#include " - NL "#include " - NL "#include %s" - NL "int main() {" - NL " void *handle = NULL;" - NL " void (*func)() = NULL;" - NL " char *error;" - NL - NL " handle = dlopen(\"%s\", RTLD_NOW);" - NL " if (handle == NULL) {" - NL " printf(\"dlopen fails: \", dlerror());" - NL " return 1;" - NL " }" - NL " func = dlsym(handle, \"hello\");" - NL " if (func == NULL) {" - NL " printf(\"dlsym fails: \", dlerror());" - NL " return 1;" - NL " }" - NL " func();" - NL " return 0;" - NL "}" - NL ; - -static int try_dynlib(int logdepth, const char *cflags, char *concated_ldflags, const char *name, const char *value, const char *host_app_cflags, const char *host_app_ldflags) -{ - char test_host_app[1024]; - const char *fpic; - const char *ld_include; - const char *dlc; - char *libname, *libname_dyn; - char *cflags_c; - char *oname = ".o"; - int ret = 0; - - - dlc = get("libs/dl-compat"); - if ((dlc != NULL) && (strcmp(dlc, strue) == 0)) - ld_include = ""; - else - ld_include = ""; - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - if (cflags == NULL) - cflags=""; - - cflags_c = malloc(strlen(cflags) + 8 + strlen(fpic)); - sprintf(cflags_c, "%s -c %s", cflags, fpic); - - - libname_dyn = libname = (char *)get("sys/ext_dynlib"); - if ((compile_code(logdepth, test_lib, &oname, NULL, cflags_c, NULL) != 0) || - (compile_file(logdepth, oname, &libname_dyn, NULL, NULL, concated_ldflags) != 0)) { - report("FAILED (compiling dynlib)\n"); - } - else { - sprintf(test_host_app, test_host, ld_include, libname_dyn); - if (try_flags(logdepth, NULL, test_host_app, host_app_cflags, host_app_ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - ret = 1; - } - } - unlink(libname_dyn); - unlink(oname); - if (libname != libname_dyn) - free(libname_dyn); - free(oname); - free(concated_ldflags); - free(cflags_c); - return ret; -} - - -int find_ldflags_dynlib(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - require("cc/rdynamic", logdepth, fatal); - require("cc/fpic", logdepth, fatal); - require("libs/ldl", logdepth, fatal); - - report("Checking for dynamic library ldflags... "); - logprintf(logdepth, "find_ldflags_dynlib: trying to find dynamic library ldflags...\n"); - logdepth++; - - if (try_dynlib(logdepth, NULL, concat_nodes("-dynamic -shared", "cc/rdynamic", "libs/ldl", NULL), "cc/ldflags_dynlib", "-dynamic -shared", NULL, get("libs/ldl"))) return 0; - if (try_dynlib(logdepth, NULL, concat_nodes("-shared", "cc/rdynamic", "libs/ldl", NULL), "cc/ldflags_dynlib", "-shared", NULL, get("libs/ldl"))) return 0; - report("Not found.\n"); - return 1; -} - -static int try_dll_or_so(int logdepth, int is_dll, const char *lib_ldflags, const char *name, const char *value, - const char *dspec_dllexport, const char *dspec_dllimport, - const char *app_cflags, const char *app_ldflags) -{ - static const char *test_lib_template = - NL "#include " - NL "%s void hello();" - NL "void hello() {" - NL " puts(\"OK\");" - NL "}" - NL ; - static const char *test_app_template = - NL "%s void hello();" - NL "int main() {" - NL " hello();" - NL " return 0;" - NL "}" - NL ; - char test_lib[1024]; - char test_app[1024]; - const char *fpic; - char *cflags_c; - char *oname, *oname_ext; - char *libname, *libname_ext; - char *appname = NULL, *appname_ext = NULL; - char *lib_filename = NULL, *lib_dirname = NULL; - char *lib_ldflags_new = NULL; - char *app_ldflags_new = NULL; - size_t len, ii; - int ret = 0; - - ++logdepth; - - require("cc/cc", logdepth, 0); - require("cc/cflags", logdepth, 0); - require("cc/ldflags", logdepth, 0); - require("cc/fpic", logdepth, 0); - require("sys/ext_exe", logdepth, 0); - require("sys/ext_dynlib_native", logdepth, 0); - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - if (app_cflags == NULL) - app_cflags = ""; - - if (app_ldflags == NULL) - app_ldflags = ""; - - cflags_c = str_concat(" ", get("cc/cflags"), "-c", fpic, NULL); - - oname = oname_ext = ".o"; - libname = libname_ext = (char *)get("sys/ext_dynlib_native"); - sprintf(test_lib, test_lib_template, dspec_dllexport); - lib_ldflags_new = str_concat(" ", get("cc/ldflags"), lib_ldflags, NULL); - if ((compile_code(logdepth, test_lib, &oname, NULL, cflags_c, NULL) != 0) || - (compile_file(logdepth, oname, &libname, NULL, NULL, lib_ldflags_new) != 0)) { - report("FAILED (compiling %s)\n", (is_dll?"DLL":"SO")); - } - else { - lib_filename = file_name(libname); - lib_dirname = dir_name(libname); - - if (!is_dll) { - len = strlen(lib_filename) - strlen(libname_ext); - for (ii=3; ii" - NL "int main() {" - NL " char *s;" - NL " s = alloca(128);" - NL " if (s != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -static int try_alloca(int logdepth, const char *cflags, const char *ldflags, const char *name, const char *value) -{ - if (try_flags(logdepth, NULL, test_alloca, cflags, ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - return 1; - } - return 0; -} - -int find_alloca(const char *name, int logdepth, int fatal) -{ - require("cc/cc", logdepth, fatal); - - report("Checking for alloca()... "); - logprintf(logdepth, "find_alloca: trying to find alloca()...\n"); - logdepth++; - - if (try_alloca(logdepth, NULL, NULL, "cc/alloca/presents", "true")) return 0; - - put("cc/alloca/presents", "false"); - report("Not found.\n"); - return 1; -} - - -int find__exit(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " _exit(0);" - NL " puts(\"BAD\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for _exit()... "); - logprintf(logdepth, "find__exit: trying to find _exit()...\n"); - logdepth++; - - if (try_flags_inv(logdepth, NULL, test_c, NULL, NULL, "BAD")) { - put("cc/_exit/presents", strue); - report("found\n"); - return 0; - } - - put("cc/_exit/presents", sfalse); - report("Not found.\n"); - return 1; -} - -int find_cc_pragma_message(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#define DO_PRAGMA(arg) _Pragma(#arg)" - NL "#define TODO(x) DO_PRAGMA(message(\"TODO: \" #x))" - NL "TODO(test)" - NL "int main()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for _Pragma(message)... "); - logprintf(logdepth, "find_cc_pragma_message: trying to find pragma_message...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/pragma_message", strue); - report("Found.\n"); - return 0; - } - put("cc/pragma_message", sfalse); - report("Not found.\n"); - return 1; -} - -int find_cc_static_libgcc(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - const char *key = "cc/static_libgcc"; - - require("cc/cc", logdepth, fatal); - - report("Checking for -static-libgcc... "); - logprintf(logdepth, "find_cc_static_libgcc: trying to find -static-libgcc...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, NULL, NULL, "-static-libgcc")) return 0; - return try_fail(logdepth, key); -} diff --git a/scconfig/src/default/.svn/pristine/6e/6ee0101dbcb67d12be2ec8ad8ae36b617af56fcf.svn-base b/scconfig/src/default/.svn/pristine/6e/6ee0101dbcb67d12be2ec8ad8ae36b617af56fcf.svn-base deleted file mode 100644 index ae0bb93a..00000000 --- a/scconfig/src/default/.svn/pristine/6e/6ee0101dbcb67d12be2ec8ad8ae36b617af56fcf.svn-base +++ /dev/null @@ -1,171 +0,0 @@ -/* cc */ -int find_cc(const char *name, int logdepth, int fatal); -int find_cc_argstd(const char *name, int logdepth, int fatal); -int find_cc_argmachine(const char *name, int logdepth, int fatal); -int find_cc_fpie(const char *name, int logdepth, int fatal); -int find_cc_fnopie(const char *name, int logdepth, int fatal); -int find_cc_fnopic(const char *name, int logdepth, int fatal); -int find_inline(const char *name, int logdepth, int fatal); -int find_varargmacro(const char *name, int logdepth, int fatal); -int find_funcmacro(const char *name, int logdepth, int fatal); -int find_constructor(const char *name, int logdepth, int fatal); -int find_destructor(const char *name, int logdepth, int fatal); -int find_fattr_unused(const char *name, int logdepth, int fatal); -int find_declspec_dllimport(const char *name, int logdepth, int fatal); -int find_declspec_dllexport(const char *name, int logdepth, int fatal); -int find_rdynamic(const char *name, int logdepth, int fatal); -int find_soname(const char *name, int logdepth, int fatal); -int find_wlrpath(const char *name, int logdepth, int fatal); -int find_cc_wloutimplib(const char *name, int logdepth, int fatal); -int find_cc_wloutputdef(const char *name, int logdepth, int fatal); -int find_fpic(const char *name, int logdepth, int fatal); -int find_ldflags_dynlib(const char *name, int logdepth, int fatal); -int find_ldflags_dll(const char *name, int logdepth, int fatal); -int find_ldflags_so(const char *name, int logdepth, int fatal); -int find_alloca(const char *name, int logdepth, int fatal); -int find__exit(const char *name, int logdepth, int fatal); -int find_cc_pragma_message(const char *name, int logdepth, int fatal); -int find_cc_static_libgcc(const char *name, int logdepth, int fatal); - -/* libs */ -int find_lib_ldl(const char *name, int logdepth, int fatal); -int find_lib_LoadLibrary(const char *name, int logdepth, int fatal); -int find_lib_errno(const char *name, int logdepth, int fatal); - -/* thread */ -int find_lib_lpthread(const char *name, int logdepth, int fatal); -int find_thread_semget(const char *name, int logdepth, int fatal); -int find_thread_pthread_create(const char *name, int logdepth, int fatal); -int find_thread_CreateSemaphore(const char *name, int logdepth, int fatal); -int find_thread_CreateThread(const char *name, int logdepth, int fatal); - -/* fscalls */ -int find_fs_realpath(const char *name, int logdepth, int fatal); -int find_fs__fullpath(const char *name, int logdepth, int fatal); -int find_fs_readdir(const char *name, int logdepth, int fatal); -int find_fs_findnextfile(const char *name, int logdepth, int fatal); -int find_fs_access(const char *name, int logdepth, int fatal); -int find_fs_access_macros(const char *name, int logdepth, int fatal); -int find_fs_stat_macros(const char *name, int logdepth, int fatal); -int find_fs_stat_fields(const char *name, int logdepth, int fatal); -int find_fs_lstat(const char *name, int logdepth, int fatal); -int find_fs_statlstat(const char *name, int logdepth, int fatal); -int find_fs_getcwd(const char *name, int logdepth, int fatal); -int find_fs__getcwd(const char *name, int logdepth, int fatal); -int find_fs_getwd(const char *name, int logdepth, int fatal); -int find_fs_mkdir(const char *name, int logdepth, int fatal); -int find_fs__mkdir(const char *name, int logdepth, int fatal); -int find_fs_mkdtemp(const char *name, int logdepth, int fatal); -int find_fs_mmap(const char *name, int logdepth, int fatal); -int find_fsmount_next_dev(const char *name, int logdepth, int fatal); -int find_fsmount_fsstat_fields(const char *name, int logdepth, int fatal); -int find_fsmount_statfs_fields(const char *name, int logdepth, int fatal); -int find_fsmount_statvfs_fields(const char *name, int logdepth, int fatal); -int find_fs_ustat(const char *name, int logdepth, int fatal); -int find_fs_statfs(const char *name, int logdepth, int fatal); -int find_fs_statvfs(const char *name, int logdepth, int fatal); -int find_fs_flock(const char *name, int logdepth, int fatal); - -/* printf */ -int find_printf_x(const char *name, int logdepth, int fatal); -int find_printf_ptrcast(const char *name, int logdepth, int fatal); -int find_snprintf(const char *name, int logdepth, int fatal); -int find_dprintf(const char *name, int logdepth, int fatal); -int find_vdprintf(const char *name, int logdepth, int fatal); -int find_vsnprintf(const char *name, int logdepth, int fatal); - -/* proc */ -int find_proc__spawnvp(const char *name, int logdepth, int fatal); -int find_proc_fork(const char *name, int logdepth, int fatal); -int find_proc_wait(const char *name, int logdepth, int fatal); -int find_proc__getpid(const char *name, int logdepth, int fatal); -int find_proc_CreateProcessA(const char *name, int logdepth, int fatal); -int find_proc_getexecname(const char *name, int logdepth, int fatal); -int find_proc_GetModuleFileNameA(const char *name, int logdepth, int fatal); -int find_proc_shmget(const char *name, int logdepth, int fatal); -int find_proc_CreateFileMappingA(const char *name, int logdepth, int fatal); - -/* fstools */ -int find_fstools_cp(const char *name, int logdepth, int fatal); -int find_fstools_ln(const char *name, int logdepth, int fatal); -int find_fstools_mv(const char *name, int logdepth, int fatal); -int find_fstools_rm(const char *name, int logdepth, int fatal); -int find_fstools_mkdir(const char *name, int logdepth, int fatal); -int find_fstools_ar(const char *name, int logdepth, int fatal); -int find_fstools_ranlib(const char *name, int logdepth, int fatal); -int find_fstools_awk(const char *name, int logdepth, int fatal); -int find_fstools_cat(const char *name, int logdepth, int fatal); -int find_fstools_sed(const char *name, int logdepth, int fatal); -int find_fstools_file(const char *name, int logdepth, int fatal); -int find_fstools_file_l(const char *name, int logdepth, int fatal); -int find_fstools_chmodx(const char *name, int logdepth, int fatal); - -/* uname */ -int find_uname(const char *name, int logdepth, int fatal); -int find_triplet(const char *name, int logdepth, int fatal); -int find_sysid(const char *name, int logdepth, int fatal); - -/* find_target */ -int find_target(const char *name, int logdepth, int fatal); - -/* filelist */ -int find_filelist(const char *name, int logdepth, int fatal); - -/* find_str.c */ -int find_strcasecmp(const char *name, int logdepth, int fatal); -int find_strncasecmp(const char *name, int logdepth, int fatal); -int find_stricmp(const char *name, int logdepth, int fatal); -int find_strnicmp(const char *name, int logdepth, int fatal); - -/* find_sys.c */ -int find_sys_ptrwidth(const char *name, int logdepth, int fatal); -int find_sys_byte_order(const char *name, int logdepth, int fatal); -int find_tmp(const char *name, int logdepth, int fatal); -int find_shell(const char *name, int logdepth, int fatal); - -/* find_io.c */ -int find_io_pipe(const char *name, int logdepth, int fatal); -int find_io_dup2(const char *name, int logdepth, int fatal); -int find_io_fileno(const char *name, int logdepth, int fatal); -int find_io_lseek(const char *name, int logdepth, int fatal); -int find_io_popen(const char *name, int logdepth, int fatal); - -/* find_time.c */ -int find_time_usleep(const char *name, int logdepth, int fatal); -int find_time_Sleep(const char *name, int logdepth, int fatal); -int find_time_gettimeofday(const char *name, int logdepth, int fatal); -int find_time_ftime(const char *name, int logdepth, int fatal); -int find_time_timegm(const char *name, int logdepth, int fatal); -int find_time_mkgmtime(const char *name, int logdepth, int fatal); -int find_time_gmtime_s(const char *name, int logdepth, int fatal); -int find_time_gmtime_r(const char *name, int logdepth, int fatal); -int find_time_localtime_s(const char *name, int logdepth, int fatal); -int find_time_localtime_r(const char *name, int logdepth, int fatal); - -/* find_types.c */ -int find_types_stdint(const char *name, int logdepth, int fatal); -int find_types_sizes(const char *name, int logdepth, int fatal); -int find_types_size_t(const char *name, int logdepth, int fatal); -int find_types_off_t(const char *name, int logdepth, int fatal); -int find_types_off64_t(const char *name, int logdepth, int fatal); -int find_types_gid_t(const char *name, int logdepth, int fatal); -int find_types_uid_t(const char *name, int logdepth, int fatal); -int find_types_pid_t(const char *name, int logdepth, int fatal); -int find_types_dev_t(const char *name, int logdepth, int fatal); -int find_types_dev_t(const char *name, int logdepth, int fatal); -int find_types_mode_t(const char *name, int logdepth, int fatal); -int find_types_nlink_t(const char *name, int logdepth, int fatal); -int find_types_ptrdiff_t(const char *name, int logdepth, int fatal); -int find_types_dev_t(const char *name, int logdepth, int fatal); -int find_types_ino_t(const char *name, int logdepth, int fatal); -int find_types_void_ptr(const char *name, int logdepth, int fatal); - -/* find_signal.c */ -int find_signal_names(const char *name, int logdepth, int fatal); -int find_signal_raise(const char *name, int logdepth, int fatal); - -/* environ.c */ -int find_main_arg3(const char *name, int logdepth, int fatal); -int find_putenv(const char *name, int logdepth, int fatal); -int find_setenv(const char *name, int logdepth, int fatal); -int find_environ(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/default/.svn/pristine/72/72871299763ccb21fcd0034592711800e7399d44.svn-base b/scconfig/src/default/.svn/pristine/72/72871299763ccb21fcd0034592711800e7399d44.svn-base deleted file mode 100644 index 03830a07..00000000 --- a/scconfig/src/default/.svn/pristine/72/72871299763ccb21fcd0034592711800e7399d44.svn-base +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef REGEX_H -#define REGEX_H - -extern const char *bopat[]; -extern const char *eopat[]; - - -extern char *re_comp(const char *); -extern int re_exec(const char *); -extern void re_modw(char *); -char *re_subs_dup(char *sub); - - -#endif /* REGEX_H */ diff --git a/scconfig/src/default/.svn/pristine/7b/7be570151ca1394caab18314ffed013788a6b3fb.svn-base b/scconfig/src/default/.svn/pristine/7b/7be570151ca1394caab18314ffed013788a6b3fb.svn-base deleted file mode 100644 index e2d55c92..00000000 --- a/scconfig/src/default/.svn/pristine/7b/7be570151ca1394caab18314ffed013788a6b3fb.svn-base +++ /dev/null @@ -1,194 +0,0 @@ -/* - scconfig - detect I/O features of the system - Copyright (C) 2010 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_io_pipe(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " int fd[2];" - NL " if (pipe(fd) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for pipe(2)... "); - logprintf(logdepth, "find_io_pipe: trying to find pipe(2)...\n"); - logdepth++; - - - if (try_icl(logdepth, "libs/io/pipe", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/io/pipe"); -} - -int find_io_dup2(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " int fd;" - NL " if (dup2(1, 4) == 4)" - NL " write(4, \"OK\\n\", 3); " - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for dup2(2)... "); - logprintf(logdepth, "find_io_dup2: trying to find dup2(2)...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/io/dup2", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/io/dup2"); -} - - -int find_io_fileno(const char *name, int logdepth, int fatal) -{ - char test_c[256]; - char *test_c_ = - NL "#include " - NL "int main() {" - NL no_implicit(int, "%s", "%s") - NL " if (%s(stdout) >= 0)" - NL " puts(\"OK\"); " - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for fileno(3)... "); - logprintf(logdepth, "find_io_fileno: trying to find fileno(3)...\n"); - logdepth++; - - /* UNIX */ - sprintf(test_c, test_c_, "fileno", "fileno", "fileno"); - if (try_icl(logdepth, "libs/io/fileno", test_c, "#include \n", NULL, NULL)) { - put("libs/io/fileno/call", "fileno"); - return 0; - } - - sprintf(test_c, test_c_, "fileno", "fileno", "fileno"); - if (try_icl(logdepth, "libs/io/fileno", test_c, "#define _XOPEN_SOURCE\n#include \n", NULL, NULL)) { - put("libs/io/fileno/call", "fileno"); - return 0; - } - - /* windows */ - sprintf(test_c, test_c_, "_fileno", "_fileno", "_fileno"); - if (try_icl(logdepth, "libs/io/fileno", test_c, "#include \n", NULL, NULL)) { - put("libs/io/fileno/call", "_fileno"); - return 0; - } - - return try_fail(logdepth, "libs/io/fileno"); -} - -int find_io_lseek(const char *name, int logdepth, int fatal) -{ -#define NODE "libs/io/lseek" - - char test_c[3256]; - const char *test_c_template = - NL "#include " - NL "#include " - NL "int main() {" - NL " const char *filename = \"%s\";" - NL no_implicit(int, "%s", "%s") - NL " int fd = open(filename, O_WRONLY);" - NL " if (write(fd, \"abc\", 3) == 3 && %s(fd, 1, SEEK_SET) == 1)" - NL " puts(\"OK\"); " - NL " return 0;" - NL "}" - NL; - char *tmpf; - const char *incs[] = {"#include ","#include ",NULL}; - const char *fns[] = {"lseek", "_lseek", NULL}; - const char **inc; - const char **fn; - - require("cc/cc", logdepth, fatal); - - report("Checking for lseek(2)... "); - logprintf(logdepth, "find_io_lseek: trying to find lseek(2)...\n"); - logdepth++; - - tmpf = tempfile_new(".psx"); - - for (inc = incs, fn = fns; *fn; ++inc, ++fn) { - sprintf(test_c, test_c_template, tmpf, *fn, *fn, *fn); - if (try_icl(logdepth, NODE, test_c, *inc, NULL, NULL)) { - unlink(tmpf); - free(tmpf); - put(NODE "/call", *fn); - return 0; - } - } - - unlink(tmpf); - free(tmpf); - return try_fail(logdepth, NODE); -#undef NODE -} - -int find_io_popen(const char *name, int logdepth, int fatal) -{ - const char **i, *incs[] = {"#define _XOPEN_SOURCE", "#define _BSD_SOURCE", "#define _POSIX_C_SOURCE 2", NULL}; - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " FILE *f = popen(\"echo OK\", \"r\");" - NL " char line[16];" - NL " if (f == NULL) return 0;" - NL " if (fgets(line, sizeof(line)-1, f) == NULL) return 0;" - NL " puts(line);" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for popen(3)... "); - logprintf(logdepth, "find_io_popen: trying to find popen(3)...\n"); - logdepth++; - - for(i = incs; *i != NULL; i++) - if (try_icl(logdepth, "libs/io/popen", test_c, *i, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/io/popen"); -} - diff --git a/scconfig/src/default/.svn/pristine/7c/7c5dcdc5627aa79ed32e6d521bc9d64879f3bae9.svn-base b/scconfig/src/default/.svn/pristine/7c/7c5dcdc5627aa79ed32e6d521bc9d64879f3bae9.svn-base deleted file mode 100644 index 9d7ab725..00000000 --- a/scconfig/src/default/.svn/pristine/7c/7c5dcdc5627aa79ed32e6d521bc9d64879f3bae9.svn-base +++ /dev/null @@ -1,161 +0,0 @@ -#define NL "\n" - -/* main.c */ -extern int no_autodetect_sys; /* set this to 1 to suppress system and cross detection */ -extern int no_save_cache; /* set this to 1 to avoid saving config.cache */ - -/* lib_try.c: try to compile and run a test code; save results under prefix, if worked */ -/* include, compile-flags, link-flags; - NULL includes, cflags, *ldflags means don't put anything in the db; cflags - and ldflags may be prefixed with "+" to include standard flags; - the test code has to print "OK" if it worked. If prefix is NULL, do not - modify the db or announce the output, silently return 0 or 1. - Returns 1 if worked, 0 if not */ -int try_icl(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, - const char *ldflags); - -/* same as try_icl(), but does not execute the code, only compiles. Useful - for test programs with undesirable side effects (e.g. gtk: would open a window) */ -int try_icl_norun(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, - const char *ldflags); - -/* same as try_icl, but also insert flags picked up from deps (if not NULL); - useful for detecting features that depend on other detected features. - If run is 0, do not run the test program, compile only */ -int try_icl_with_deps(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags, const char *dep_includes, const char *dep_cflags, const char *dep_ldflags, int run); - -/* Low level function for the same, giving more control to the caller */ -int try_icl_(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags, int run, int (*accept_res)(char *stdout_str)); - -/* use try_icl() on a list of packages found by pkg-config. Stick to the version - required if reqver is non-NULL, else try them in the order pkg-config returned - them. */ -int try_icl_pkg_config(int logdepth, const char *prefix, const char *test_c, char *includes, const char *pkgpat, - const char *reqver); - -/* call this when failed to find the feature (after multiple try_*() calls); - always returns 1 (so that return try_fail() does the Right Thing) */ -int try_fail(int logdepth, const char *prefix); - -/* Import an argument for controlling try_icl() */ -int import_icl(const char *key, const char *fn); - -/* Determine the sizeof() of a struct field; works the same way as icl() but - also sets prefix/sizeof */ -int try_icl_sfield(int logdepth, const char *prefix, const char *structn, const char *fieldn, const char *includes, const char *cflags, const char *ldflags); -int try_icl_sfields(int logdepth, const char *prefix, const char *structn, const char **fields, const char *includes, const char *cflags, const char *ldflags, int silent_exit_first_fail); - - -/* lib_compile.c */ -extern int cross_blind; /* 1 if crosscompiling is blind (no emulator to test with) */ - -char *shell_escape_dup(const char *in); /* strdup in and escape any special char for the shell */ - -int compile_file(int logdepth, const char *fn_input, char **fn_output, const char *cc, const char *cflags, const char *ldflags); -int compile_code(int logdepth, const char *testcode, char **fn_output, const char *cc, const char *cflags, const char *ldflags); - -/* same as above, but do not add cc/cflags and cc/ldfags */ -int compile_file_raw(int logdepth, const char *fn_input, char **fn_output, const char *cc, const char *cflags, const char *ldflags); -int compile_code_raw(int logdepth, const char *testcode, char **fn_output, const char *cc, const char *cflags, const char *ldflags); - -int run(int logdepth, const char *cmd_, char **stdout_saved); -int run_shell(int logdepth, const char *cmd_, char **stdout_saved); -int compile_run(int logdepth, const char *testcode, const char *cc, const char *cflags, const char *ldflags, - char **stdout_saved); -int run_script(int logdepth, const char *interpreter, const char *script, const char *suffix, char **out); - -/* lib_file.c */ -int file_size(const char *name); -char *tempdir_new(int logdepth, const char *suffix); -char *tempfile_new(const char *suffix); -char *tempfile_dump(const char *testcode, const char *suffix); -char *load_file(const char *name); -int is_dir(const char *path); -int is_file(const char *path); -int exists(const char *path); -int exists_in(const char *dir, const char *file); -char *file_name(const char *path); /* returns malloc'd buffer */ -char *dir_name(const char *path); /* returns malloc'd buffer */ -char *tempfile_new_noabort(const char *suffix); /* for internal use - returns NULL instead of aborting when temp file can not be created */ -int touch_file(const char *path); - -/* lib_filelist.c */ -void filelist(int logdepth, const char *dir, int *argc, char ***argv); -void filelist_free(int *argc, char ***argv); - -/* lib_pkg_config.c */ - -/** run pkg config on @pkgname: - - with `--cflags` if cflags is not NULL, storing the result in cflags (malloc()'d) - - with `--libs` if ldflags is not NULL, storing the result in ldflags (malloc()'d) - Returns 0 on success. -*/ -int run_pkg_config(int logdepth, const char *pkgname, char **cflags, char **ldflags); - -/** same as run_pkg_config(), but runs a generic config tool (e.g. gdconfig) - passed in confname */ -int run_gen_config(int logdepth, const char *confname, const char *pkgname, char **cflags, char **ldflags); - -int run_pkg_config_modversion(int logdepth, const char *pkgname, char **modversion); -int run_pkg_config_modversion_db(int logdepth, const char *node, const char *pkgname); - -/** run pkg-config --list-all and keep lines matching regex pkgpat. - - argc/argv is a filelist output, each item pair is package name returned by - pkg_config (odd items are full package names, even items are suffixes: - pkgpath match removed) -*/ -void run_pkg_config_lst(int logdepth, const char *pkgpat, int *argc, char ***argv); - - -/* lib_uniqinc.c */ -char **uniq_inc_arr(const char *includes, int indirect, const char *sep, int *numlines); /* split includes by sep; includes is a list of nodes to get() if indirect is non-zero; return a NULL-terminated array of unique include strings and set *numlines if numlines is not NULL */ -void uniq_inc_free(char **arr); /* free an array returned by uniq_inc_arr() */ -char *uniq_inc_str(const char *includes, const char *isep, const char *osep, int sort, int eren, char **eres); /* take a long list of includes separated by isep and emit an uniq list separated by osep */ -char *order_inc_str(const char *includes, const char *isep, const char *word1, int dir, const char *word2); /* take a long list of includes separated by isep and emit a new list where word1 is moved before/after of word2 if dir < 0 or dir > 0 */ - -/* find_types.c */ -int find_types_something_t(const char *name, int logdepth, int fatal, const char* prefix, const char *typ, const char* define, const char *try_include); - -/* str.c */ -char *strclone(const char *str); -char *trim_left(char *str); -char *trim_right(char *str); -char *strip(char *str); -char *str_chr(char *str, char c); -char *str_rchr(char *str, char c); -char *str_subsn(const char *str); /* advanced strdup that also interprets \n */ -char *str_concat(const char *sep, ...); /* concat a list of strings into a newly allocated buffer, putting sep between them */ -char *esc_interpret(const char *str); -int chr_inset(char c, const char *set); /* returns whether c is in set */ - -/* srctree.c */ - -/* Run svn info on dir and extract the value for key; - key is case sensitive. The first match is returned or NULL if not found - or on error. */ -char *svn_info(int logdepth, const char *dir, const char *key); - -#define isblind(root) ((strncmp((root), "/target", 7) == 0) && cross_blind) -#define istarget(root) (strncmp((root), "/target", 7) == 0) - -#define target_emu_fail(out) ((isblind(db_cwd)) && (out == NULL)) - -#define safeNULL(s) ((s) == NULL ? "(NULL)" : (s)) -#define str_null(s) ((s) == NULL ? "" : (s)) - -/* Test program helper: generate code that ensures a given FUNCT exists - and is a function; can be turned off by defining SCCONFIG_ACCEPT_IMPLICIT - on scconfig compilation time */ -/* Both FUNCT1 and FUNCT2 argument *must* be used exactly once! In some - cases FUNCT1 and FUNCT2 is a format string parameter. We expect, however, - both arguments will substituted to the same value. */ -#ifdef SCCONFIG_ACCEPT_IMPLICIT -# define no_implicit(RET_TYPE, FUNCT1, FUNCT2) \ - "/* accept implicit (" FUNCT1 ", " FUNCT2 ") */\n" -#else -# define no_implicit(RET_TYPE, FUNCT1, FUNCT2) \ - "#ifndef " FUNCT1 "\n" \ - "{ " #RET_TYPE " (*tmp)() = " FUNCT2 "; if (tmp) {}}\n" \ - "#endif\n" -#endif diff --git a/scconfig/src/default/.svn/pristine/84/84638559fd0affc7f4bf66c213e7b8880278e648.svn-base b/scconfig/src/default/.svn/pristine/84/84638559fd0affc7f4bf66c213e7b8880278e648.svn-base deleted file mode 100644 index 17fdbc36..00000000 --- a/scconfig/src/default/.svn/pristine/84/84638559fd0affc7f4bf66c213e7b8880278e648.svn-base +++ /dev/null @@ -1,496 +0,0 @@ -/* - scconfig - detect features of the system or the host/target computer - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_sys_ptrwidth(const char *name, int logdepth, int fatal) -{ - char *end, W[32]; - char *out = NULL; - int w; - - char *test_c = - NL "#include " - NL "int main() {" - NL " void *ptr;" - NL " printf(\"%d\\n\", sizeof(ptr));" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for pointer width... "); - logprintf(logdepth, "find_sys_ptrwidth: trying to find pointer width...\n"); - logdepth++; - - if (compile_run(logdepth, test_c, NULL, NULL, NULL, &out) == 0) { - w = strtol(out, &end, 10); - if ((*end != '\0') && (*end != '\n') && (*end != '\r')) { - report("FAILED (test code failed)\n"); - logprintf(logdepth+1, "FAILED: returned '%s' which is not a valid decimal number (at '%s')\n", out, end); - return 1; - } - sprintf(W, "%d", w * 8); - report("OK (%s bits)\n", W); - put("sys/ptrwidth", W); - logprintf(logdepth+1, "OK (%s bits)\n", W); - } - return 0; -} - -int find_sys_byte_order(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " long int i = 8;" - NL " char *s = (char *)&i;" - NL " printf(\"%d\\n\", s[0]);" - NL " return 0;" - NL "}" - NL; - const char* test_c_blind_template = - NL "#include " - NL "#include " - NL "#ifndef __BYTE_ORDER" - NL "#error \"ERROR 1\"" - NL "void void *;" - NL "#endif" - NL "#ifndef __%s_ENDIAN" - NL "#error \"ERROR 2\"" - NL "char char *;" - NL "#endif" - NL "#if __BYTE_ORDER != __%s_ENDIAN" - NL "#error \"ERROR 3\"" - NL "int int *;" - NL "#endif" - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *key = "sys/byte_order"; - const char *endians1[] = { "LITTLE", "BIG", NULL }; - const char *endians2[] = { "LSB", "MSB", NULL }; - int index; - char test_c_blind[1024]; - char *end; - const char *W; - char *out = NULL; - int w; - - require("cc/cc", logdepth, fatal); - - report("Checking for byte order... "); - logprintf(logdepth, "find_sys_byte_order: trying to find byte order...\n"); - logdepth++; - - if ((!isblind(db_cwd)) && compile_run(logdepth, test_c, NULL, NULL, NULL, &out) == 0) { - w = strtol(out, &end, 10); - if (((*end != '\0') && (*end != '\n') && (*end != '\r')) || ((w != 0) && (w != 8))) { - report("FAILED (test code failed)\n"); - logprintf(logdepth+1, "FAILED: returned '%s' which is not a valid decimal number (at '%s')\n", out, end); - return 1; - } - if (w == 0) - W = "MSB"; - else - W = "LSB"; - - report("OK (%s first)\n", W); - put("sys/byte_order", W); - logprintf(logdepth+1, "OK (%s first)\n", W); - return 0; - } - - for (index=0; endians1[index]!=NULL; ++index) - { - sprintf(test_c_blind, test_c_blind_template, endians1[index], endians1[index]); - - if (compile_run(logdepth, test_c_blind, NULL, NULL, NULL, NULL) == 0) - { - W = endians2[index]; - report("OK (%s first)\n", W); - put(key, W); - return 0; - } - } - - report("FAILED (cannot determine byte order, you must supply it)\n"); - return try_fail(logdepth, key); -} - -static int test_shell_eats_backslash(int logdepth) -{ - char *test = "echo c:\\n"; - char *out; - - - logprintf(logdepth, "testing if shell eats \\...\n"); - run_shell(logdepth+1, test, &out); - if (out == NULL) { - logprintf(logdepth+1, "oops, couldn't run shell?! (returned NULL)\n"); - report("ERROR: shell fails."); - abort(); - } - if (out[2] == '\\') { - logprintf(logdepth, "shell does NOT eat \\...\n"); - put("sys/shell_eats_backslash", sfalse); - free(out); - return 0; - } - - free(out); - logprintf(logdepth, "shell eats \\...\n"); - put("sys/shell_eats_backslash", strue); - return 1; -} - - -static int try_get_cwd(int logdepth, const char *cmd) -{ - char *cwd, *end; - run_shell(logdepth+1, cmd, &cwd); - if (cwd != NULL) { - end = strpbrk(cwd, "\r\n"); - if (end != NULL) - *end = '\0'; - if (*cwd != '\0') { - end = cwd + strlen(cwd) - 1; - while((*end == ' ') || (*end == '\t')) { *end = '\0'; end--; } - put("sys/tmp", cwd); - /* ugly hack for win32: paths there start as c:\ */ - if ((cwd[1] == ':') && (cwd[2] == '\\')) - append("sys/tmp", "\\"); - else - append("sys/tmp", "/"); - logprintf(logdepth, "cwd is '%s'\n", get("sys/tmp")); - free(cwd); - return 1; - } - else - free(cwd); - } - return 0; -} - -static int try_tmp(int logdepth) -{ - char *fn; - - logprintf(logdepth, "validating temp dir '%s'\n", get("sys/tmp")); - fn = tempfile_new_noabort(""); - if (fn != NULL) { - unlink(fn); - free(fn); - logprintf(logdepth, "temp dir works!\n"); - return 1; - } - - logprintf(logdepth, "temp dir fails\n"); - return 0; -} - -/* test temp dir with all sort of workarounds */ -static int try_tmp_all(int logdepth) -{ - const char *tmp, *si; - char c; - char *t, *so, *old_tmp; - int eats, n; - - tmp = get("sys/tmp"); - - /* path must end in path separator */ - c = tmp[strlen(tmp)-1]; - if ((c != '/') && (c != '\\')) { - append("sys/tmp", "/"); - tmp = get("sys/tmp"); - } - - logprintf(logdepth, "trying detected temp dir '%s'\n", tmp); - if (try_tmp(logdepth+1)) return 1; - - /* try msys-on-windows hack: if path starts with /d/something, try d:/ instead */ - if ((tmp[0] == '/') && (isalpha(tmp[1])) && (tmp[2] == '/')) { - /* for the next test we shouldn't use our half-detected tmp path but go with . */ - old_tmp = strclone(tmp); - put("sys/tmp", ""); - eats = istrue(get("sys/shell_eats_backslash")); - tmp = old_tmp; - logprintf(logdepth, "tmp2='%s' eats=%d\n", tmp, eats); - t = malloc(strlen(tmp) * 2); - t[0] = tmp[1]; - t[1] = ':'; - for(si = tmp + 2, so = t + 2; *si != '\0'; si++, so++) { - if (*si == '/') { - *so = '\\'; - if (eats) { - for(n = 0; n < 3; n++) { - so++; - *so = '\\'; - } - } - } - else - *so = *si; - } - *so = '\0'; - free(old_tmp); - - logprintf(logdepth, "trying windows fix: '%s'\n", t); - put("sys/tmp", t); - free(t); - if (try_tmp(logdepth+1)) { - if (eats) - put("sys/path_sep", "\\\\\\\\"); - else - put("sys/path_sep", "\\"); - put("sys/path_sep_escaped", "\\\\"); - return 1; - } - tmp = get("sys/tmp"); - } - - /* fail. Set back tmp to empty so next command has a chance to run */ - put("sys/tmp", ""); - return 0; -} - -int find_tmp(const char *name, int logdepth, int fatal) -{ - const char *usertmp; - - if (in_cross_target) { - report("Temp dir for cross compilation target is the same as for host..."); - logprintf(logdepth, "Copying temp dir from host to target\n"); - require("/host/sys/tmp", logdepth, fatal); - usertmp = get("/host/sys/tmp"); - if (usertmp == NULL) { - report("Host temp dir not found.\n"); - logprintf(logdepth, "Host temp dir not found.\n"); - return 1; - } - put("sys/tmp", usertmp); - return 0; - } - - /* we need shell for later tests; do this detection in . */ - put("sys/tmp", ""); - require("sys/shell", logdepth, fatal); - - put("sys/path_sep", "/"); - put("sys/path_sep_escaped", "/"); - - report("Detecting temp dir..."); - logprintf(logdepth, "Finding temp dir (current working directory)...\n"); - - usertmp = get("/arg/sys/tmp"); - - /* . as tmp would fail for commands including a "cd" - this would cause - temporary files left in the target dir. We start out with empty - string (which is ., but on windows ./ would fail), and run - pwd (without cd) to find out the current directory (as getcwd() is not - portable). If pwd fails, we stay with ./ */ - put("sys/tmp", ""); - - /* we need to know about shell backslash problem regardless of how - we end up with tmp - currently tmp is ., where the test could run - safely */ - test_shell_eats_backslash(logdepth+1); - - /* Special case: cross-compilation with emulator; we can not assume - the emulator uses the same paths as the host system, while we mix - accessing files from host and emu. If we stay in ., both emulator - and host system should be (more or less) happy. */ - if (istarget(db_cwd) && iscross) { - if (usertmp == NULL) { - report("using temp dir . for cross-compilation\n"); - logprintf(logdepth, "staying with . for cross-compilation\n"); - } - else { - put("sys/tmp", usertmp); - report("using user supplied temp dir '%s' for cross-compilation\n", usertmp); - logprintf(logdepth, "using user supplied temp dir '%s' for cross-compilation\n", usertmp); - logprintf(logdepth, "Path sep: '%s'\n", get("sys/path_sep")); - } - return 0; - } - - if ((usertmp != NULL)) - put("sys/tmp", usertmp); - - if ( - ((usertmp != NULL) && (try_tmp_all(logdepth+2))) || /* try user supplied temp dir */ - ((try_get_cwd(logdepth+1, "pwd")) && (try_tmp_all(logdepth+2))) || /* try pwd for finding out cwd */ - ((try_get_cwd(logdepth+1, "echo %cd%") && (try_tmp_all(logdepth+2))))) { /* try windows-specific way for finding out cwd */ - - report(" validated %s\n", get("sys/tmp")); - logprintf(logdepth, "Detected temp dir '%s'\n", get("sys/tmp")); - logprintf(logdepth, "Path sep: '%s'\n", get("sys/path_sep")); - return 0; - } - - put("sys/tmp", ""); - report("using temp dir fallback .\n"); - logprintf(logdepth, "all temp directories failed, using . as tmp\n"); - logprintf(logdepth, "Path sep: '%s'\n", get("sys/path_sep")); - return 0; -} - -int test_shell(const char *shell, int logdepth, int quote) -{ - char *test = "echo hello"; - char *cmd; - char *out; - char *q; - - if (quote) - q = "\""; - else - q = ""; - - logprintf(logdepth, "testing '%s' as shell\n", shell); - cmd = malloc(strlen(test) + strlen(shell) + 8); - sprintf(cmd, "%s %s%s%s", shell, q, test, q); - - run(logdepth+1, cmd, &out); - - free(cmd); - - if ((out != NULL) && (strncmp(out, "hello", 5) == 0)) { - put("sys/shell", shell); - if (quote) - put("sys/shell_needs_quote", strue); - else - put("sys/shell_needs_quote", sfalse); - logprintf(logdepth, "accepted.\n"); - free(out); - return 1; - } - - logprintf(logdepth, "refused.\n"); - free(out); - return 0; -} - -static int find_shell_escape(const char *name, int logdepth, int fatal, const char *shell) -{ - char cmdline[256]; - char **t; - char *tests[] = { - "\\", "\\ {}&;|", - "^", "^ &", - NULL, NULL - }; - (void) fatal; /* not used */ - (void) shell; /* not used */ - - report("Looking for a shell escape character... "); - logprintf(logdepth, "finding shell escape character...\n"); - - for(t = tests; *t != NULL; t += 2) { - char *s, *end, *out, *start; - strcpy(cmdline, "echo "); - end = cmdline+5; - for(s = t[1]; *s != '\0'; s++) { - *end++ = *t[0]; - *end++ = *s; - } - *end = '\0'; - run(logdepth+1, cmdline, &out); - if (out != NULL) { - int res; - if (*out == '\"') /* wine likes to wrap the output in quotes for some reason */ - start = out+1; - else - start = out; - - res = strncmp(start, t[1], strlen(t[1])); - free(out); - if (res == 0) { - report("found: '%s'\n", t[0]); - logprintf(logdepth, "found shell escape char '%s'\n", t[0]); - put("sys/shell_escape_char", t[0]); - return 0; - } - } - } - report("NOT FOUND\n"); - logprintf(logdepth, "shell escape character not found\n"); - - return 1; -} - -int find_shell(const char *name, int logdepth, int fatal) -{ - const char *shells[] = { - "/bin/sh -c", - "/bin/bash -c", - "bash -c", - "cmd.exe /c", - "sh -c", - "/bin/dash -c", - "dash -c", - "/bin/ksh -c", - "ksh -c", - NULL - }; - const char **s; - - if (cross_blind) { - const char *shell = get("/arg/sys/target-shell"); - if (shell == NULL) { - report("Need to specify sys/target-shell in blind cross compiling mode, because the shell cannot be detected (note: scconfig will not attempt to run the target shell)\n"); - exit(1); - } - - put("sys/shell", shell); - report("Blind cross compiling: accepting '%s' as shell\n", shell); - logprintf(logdepth, "Blind cross compiling: accepting '%s' as shell\n", shell); - return 0; - } - - report("Looking for a shell... "); - logprintf(logdepth, "finding a shell\n"); - - for(s = shells; *s != NULL; s++) { - if ((test_shell(*s, logdepth+1, 0)) || (test_shell(*s, logdepth+1, 1))) { - report("%s\n", *s); - logprintf(logdepth, "found a shell '%s', need quote: %s\n", *s, get("sys/shell_needs_quote")); - return find_shell_escape(name, logdepth, fatal, *s); - } - } - - report("NOT FOUND\n"); - logprintf(logdepth, "shell not found\n"); - return 1; -} diff --git a/scconfig/src/default/.svn/pristine/88/8833081aebd64e048d9a8349d92166f967e596d0.svn-base b/scconfig/src/default/.svn/pristine/88/8833081aebd64e048d9a8349d92166f967e596d0.svn-base deleted file mode 100644 index 86af971d..00000000 --- a/scconfig/src/default/.svn/pristine/88/8833081aebd64e048d9a8349d92166f967e596d0.svn-base +++ /dev/null @@ -1,240 +0,0 @@ -/* - scconfig - library to query files and directories - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include "db.h" -#include "libs.h" -#include "log.h" -#include "dep.h" - -int file_size(const char *name) -{ - struct stat buf; - if (stat(name, &buf) != 0) - return -1; - return buf.st_size; -} - -char *tempdir_new(int logdepth, const char *suffix) -{ - char s[1024]; - char *cmd; - const char *tmp; - const char *mkdir, *emu; - unsigned int rn, n; - - require("sys/tmp", logdepth+1, 1); - tmp = get("sys/tmp"); - - if (strlen(suffix) > sizeof(s) - strlen(tmp) - 32) { - fprintf(stderr, "Not enough room for creating temporary file name\n"); - abort(); - } - - require("fstools/mkdir", logdepth+1, 1); - mkdir = get("fstools/mkdir"); - - emu = get("sys/emu"); - if (emu == NULL) - emu = ""; - - for(n = 0; n < 128; n++) { - rn = rand() % 100000; - sprintf(s, "%sscc_%u%s", tmp, rn, suffix); - if (!exists(s)) { - char *s_esc = shell_escape_dup(s); - cmd = malloc(strlen(s_esc) + strlen(mkdir) + 16); - sprintf(cmd, "%s %s", mkdir, s_esc); - run_shell(logdepth+1, cmd, NULL); - free(s_esc); - free(cmd); - if (is_dir(s)) - return strclone(s); - } - } - error("Couldn't find a suitable temp dir name\n"); - abort(); -} - -char *tempfile_new_noabort(const char *suffix) -{ - char s[1024]; - const char *tmp; - unsigned int rn, n; - FILE *f; - - - require("/host/sys/tmp", 0, 1); - tmp = get("/host/sys/tmp"); - if (strlen(suffix) > sizeof(s) - strlen(tmp) - 32) { - fprintf(stderr, "tempfile_new_noabort(): not enough room for creating temporary file name\n"); - abort(); - } - - for(n = 0; n < 128; n++) { - rn = rand() % 100000; - sprintf(s, "%sscc_%u%s", tmp, rn, suffix); - if (!is_file(s)) { /* can not test for exists() because that would recurse is_dir */ - f = fopen(s, "w"); - if (f != NULL) { - fclose(f); - return strclone(s); - } - } - } - return NULL; -} - -char *tempfile_new(const char *suffix) -{ - char *tmp; - - tmp = tempfile_new_noabort(suffix); - if (tmp == NULL) { - error("Couldn't find a suitable temp file name\n"); - abort(); - } - return tmp; -} - -char *tempfile_dump(const char *testcode, const char *suffix) -{ - char *fn; - FILE *f; - - fn = tempfile_new(suffix); - f = fopen(fn, "w"); - fprintf(f, "%s", testcode); - fclose(f); - return fn; -} - -char *load_file(const char *name) -{ - int size; - char *content; - FILE *f; - - size = file_size(name); - if (size > 0) { - content = malloc(size+1); - *content = '\0'; - f = fopen(name, "r"); - if (f != NULL) { - int len = fread(content, 1, size, f); - if (len < 0) - len = 0; - content[len] = '\0'; - fclose(f); - } - } - else { - content = malloc(1); - *content = '\0'; - } - return content; -} - -int is_dir(const char *path) -{ - char *tmp, *path_esc; - int ret; - - require("sys/shell", 0, 1); - - path_esc = shell_escape_dup(path); - tmp = malloc(strlen(path_esc) + 16); - sprintf(tmp, "cd %s", path_esc); - ret = run_shell(0, tmp, NULL); - free(tmp); - free(path_esc); - return !ret; -} - -int is_file(const char *path) -{ - return file_size(path) >= 0; -} - -int exists(const char *path) -{ - return is_file(path) || is_dir(path); -} - - -int exists_in(const char *dir, const char *file) -{ - char *path; - int ret; - - path = malloc(strlen(dir) + strlen(file) + 5); - sprintf(path, "%s/%s", dir, file); - ret = is_file(path) || is_dir(path); - free(path); - return ret; -} - -const char *file_name_ptr(const char *path) -{ - const char *s; - s = str_rchr((char *)path, '/'); - if (s == NULL) - s = str_rchr((char *)path, '\\'); - return s; -} - -char *file_name(const char *path) -{ - const char *s; - s = file_name_ptr(path); - if (s == NULL) - return strclone(path); - s++; - return strclone(s); -} - -char *dir_name(const char *path) -{ - char *s, *r; - s = strclone(path); - r = (char *)file_name_ptr(s); - if (r == NULL) { - free(s); - return strclone(""); - } - *r = '\0'; - return s; -} - -int touch_file(const char *path) -{ - FILE *f; - f = fopen(path, "a"); - if (f == NULL) - return -1; - fclose(f); - return 0; -} diff --git a/scconfig/src/default/.svn/pristine/88/88f29d7f81d3a39384f553d581a83898ca6b853c.svn-base b/scconfig/src/default/.svn/pristine/88/88f29d7f81d3a39384f553d581a83898ca6b853c.svn-base deleted file mode 100644 index b7955cf1..00000000 --- a/scconfig/src/default/.svn/pristine/88/88f29d7f81d3a39384f553d581a83898ca6b853c.svn-base +++ /dev/null @@ -1,257 +0,0 @@ -/* - scconfig - hash tables - Copyright (C) 2007, 2008, 2009 by Szabolcs Nagy - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include "libs.h" -#include "ht.h" - -#define HT_MINSIZE 8 -#define HT_MAXSIZE ((UINT_MAX >> 1U) + 1U) - -#define JUMP(i, j) i += j++ -#define JUMP_FIRST(i, j) j = 1, i += j++ - -/* portable str hash */ -#define HASH_INIT 0xbabeface -static unsigned int keyhash(const char *key) { - unsigned int a = HASH_INIT; - - while (*key) - a += (a << 5) + *key++; - return a; -} - -/* fill threshold = 3/4 */ -#define HT_LOG_THRES 2 -static void checkfill(ht_t *ht) -{ - if (ht->fill > ht->mask - (ht->mask >> HT_LOG_THRES) || ht->fill > ht->used << 2) - ht_resize(ht, ht->used << (ht->used > 1U << 15 ? 1 : 2)); -} - -static ht_t *ht_init(ht_t *ht, int isstr) -{ - ht->mask = HT_MINSIZE - 1; - ht->fill = 0; - ht->used = 0; - ht->isstr = isstr; - ht->table = calloc(ht->mask + 1, sizeof(ht_entry_t)); - ht->refcount = 1; - return ht; -} - -static ht_t *ht_uninit(ht_t *ht) -{ - ht_entry_t *entry; - - for (entry = ht->table; entry != ht->table + ht->mask + 1; entry++) - if (ht_isused(entry)) { - if (ht->isstr) - free(entry->value); - free(entry->key); - } - free(ht->table); - return ht; -} - -ht_t *ht_alloc(int isstr) -{ - ht_t *ht; - - ht = malloc(sizeof(ht_t)); - return ht_init(ht, isstr); -} - -void ht_free(ht_t *ht) -{ - ht_uninit(ht); - free(ht); -} - -ht_t *ht_clear(ht_t *ht) -{ - ht_uninit(ht); - return ht_init(ht, ht->isstr); -} - -/* one lookup function to rule them all */ -static ht_entry_t *ht_lookup(ht_t *ht, const char *key, unsigned int hash) -{ - unsigned int mask; - unsigned int i; - unsigned int j; - ht_entry_t *table; - ht_entry_t *entry; - ht_entry_t *free_entry; - - mask = ht->mask; - i = hash; - table = ht->table; - assert(ht->table); - entry = table + (i & mask); - if (ht_isempty(entry) || !strcmp(entry->key, key)) - return entry; - /* free_entry: first deleted entry for insert */ - free_entry = ht_isdeleted(entry) ? entry : NULL; - assert(ht->fill <= ht->mask); - for (JUMP_FIRST(i, j); ; JUMP(i, j)) { - entry = table + (i & mask); - if (ht_isempty(entry)) - return (free_entry == NULL) ? entry : free_entry; - if (entry->hash == hash && !strcmp(entry->key, key)) - return entry; - if (ht_isdeleted(entry) && free_entry == NULL) - free_entry = entry; - } -} - -/* for resize: no deleted entries in ht, entry->key is not in ht, no strdup */ -static void cleaninsert(ht_t *ht, const ht_entry_t *entry) -{ - unsigned int i; - unsigned int j; - ht_entry_t *newentry; - - i = entry->hash; - newentry = ht->table + (i & ht->mask); - if (!ht_isempty(newentry)) - for (JUMP_FIRST(i, j); !ht_isempty(newentry); JUMP(i, j)) - newentry = ht->table + (i & ht->mask); - ++ht->fill; - ++ht->used; - memcpy(newentry, entry, sizeof(ht_entry_t)); -} - -ht_t *ht_resize(ht_t *ht, unsigned int hint) -{ - unsigned int newsize; - unsigned int oldused; - ht_entry_t *oldtable, *newtable, *entry; - - oldused = ht->used; - if (hint < oldused << 1) - hint = oldused << 1; - assert(hint <= HT_MAXSIZE && hint > oldused); - for (newsize = HT_MINSIZE; newsize < hint; newsize <<= 1); - newtable = calloc(newsize, sizeof(ht_entry_t)); - oldtable = ht->table; - ht->mask = newsize - 1; - ht->fill = 0; - ht->used = 0; - ht->table = newtable; - for (entry = oldtable; oldused > 0; ++entry) - if (ht_isused(entry)) { - --oldused; - cleaninsert(ht, entry); - } - free(oldtable); - return ht; -} - -void *ht_get(ht_t *ht, const char *key) -{ - ht_entry_t *entry; - - entry = ht_lookup(ht, key, keyhash(key)); - return ht_isused(entry) ? entry->value : NULL; -} - -void *ht_insert(ht_t *ht, const char *key, void *value) -{ - unsigned int hash; - ht_entry_t *entry; - - hash = keyhash(key); - entry = ht_lookup(ht, key, hash); - if (ht_isused(entry)) - return entry->value; - if (ht_isempty(entry)) - ++ht->fill; - ++ht->used; - entry->hash = hash; - entry->key = strclone(key); - entry->value = ht->isstr ? strclone(value) : value; - checkfill(ht); - return NULL; -} - -const char *ht_set(ht_t *ht, const char *key, void *value) -{ - unsigned int hash; - ht_entry_t *entry; - char *k; - - hash = keyhash(key); - entry = ht_lookup(ht, key, hash); - if (ht_isused(entry)) { - if (ht->isstr) { - free(entry->value); - entry->value = strclone(value); - } else - entry->value = value; - return entry->key; - } - if (ht_isempty(entry)) - ++ht->fill; - ++ht->used; - entry->hash = hash; - entry->key = k = strclone(key); - entry->value = ht->isstr ? strclone(value) : value; - checkfill(ht); - return k; -} - -const char *ht_del(ht_t *ht, const char *key) -{ - ht_entry_t *entry; - - entry = ht_lookup(ht, key, keyhash(key)); - if (!ht_isused(entry)) - return NULL; - --ht->used; - free(entry->key); - if (ht->isstr) - free(entry->value); - entry->key = ht_deleted_key; - return ht_deleted_key; -} - -ht_entry_t *ht_first(const ht_t *ht) -{ - ht_entry_t *entry = 0; - - if (ht->used) - for (entry = ht->table; !ht_isused(entry); ++entry); - return entry; -} - -ht_entry_t *ht_next(const ht_t *ht, ht_entry_t *entry) -{ - while (++entry != ht->table + ht->mask + 1) - if (ht_isused(entry)) - return entry; - return 0; -} diff --git a/scconfig/src/default/.svn/pristine/8f/8fc4b12feea1e169cbe06caff7e609a91ccadc43.svn-base b/scconfig/src/default/.svn/pristine/8f/8fc4b12feea1e169cbe06caff7e609a91ccadc43.svn-base deleted file mode 100644 index 05c0d842..00000000 --- a/scconfig/src/default/.svn/pristine/8f/8fc4b12feea1e169cbe06caff7e609a91ccadc43.svn-base +++ /dev/null @@ -1,404 +0,0 @@ -/* - scconfig - detection of types and type sizes - Copyright (C) 2012 Tibor Palinkas - Copyright (C) 2017-2018 Aron Barath - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -/* assume there is no integer that is at least this wide, in bytes */ -#define MAX_INT_WIDTH 9 -/* ('long double' can be 16 bytes; see https://en.wikipedia.org/wiki/Long_double) */ -#define MAX_FLT_WIDTH 17 - -static int try_size(int logdepth, char *cflags, char *ldflags, const char *type, int use_stdint, const char *path, const char **sizearr, unsigned char *inc_stdint, const int max_width) -{ - char *out = NULL; - const char *test_c_template = - NL "#include " - NL "int main() {" - NL " printf(\"OK %%d\\n\", sizeof(%s));" - NL " return 0;" - NL "}" - NL; - char test_c[512], *start; - const char *inc = "#include \n"; - int size; - - if (use_stdint) { - strcpy(test_c, inc); - start = test_c + strlen(inc); - } - else - start = test_c; - sprintf(start, test_c_template, type); - - report("Testing size of type %25s... ", type); - - logprintf(logdepth, "trying size with ldflags '%s'\n", ldflags == NULL ? get("cc/ldflags") : ldflags); - if (compile_run(logdepth+1, test_c, NULL, cflags, ldflags, &out) == 0) { - if (target_emu_fail(out)) { - report(" FAIL (emulator)\n"); - free(out); - return -1; - } - - if (strncmp(out, "OK", 2) == 0) { - size = atoi(out+3); - if ((size > 0) && (size < max_width)) { - sprintf(test_c, "%d", size); - put(path, test_c); - sizearr[size] = type; - if (inc_stdint != NULL) - inc_stdint[size] = use_stdint; - report(" OK, size %d byte%s\n", size, (size > 1) ? "s" : ""); - } - else { - report(" FAIL, size %d bytes\n", size); - size = -1; - } - free(out); - return size; - } - free(out); - } - report(" FAIL (compile)\n"); - return -1; -} - -int find_types_stdint(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " if (sizeof(uint8_t) == 1)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for stdint.h... "); - logprintf(logdepth, "find_types_stdint: trying to find stdint.h...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/types/stdint", test_c, NULL, NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/types/stdint"); -} - -int find_types_sizes(const char *name, int logdepth, int fatal) -{ - const char *stdint; - const char *sizearr_u[MAX_INT_WIDTH]; - const char *sizearr_s[MAX_INT_WIDTH]; - const char *sizearr_f[MAX_FLT_WIDTH]; - unsigned char inc_stdint_u[MAX_INT_WIDTH]; - unsigned char inc_stdint_s[MAX_INT_WIDTH]; - int n; - const char *includes = ""; - const char *path_template = "sys/types/size/%d_%c_int"; - const char *path_template_f = "sys/types/size/%d_float"; - char path[64]; - - require("cc/cc", logdepth, fatal); - require("libs/types/stdint/presents", logdepth, 0); - stdint = get("libs/types/stdint/presents"); - - for(n = 0; n < MAX_INT_WIDTH; n++) { - sizearr_u[n] = NULL; - sizearr_s[n] = NULL; - inc_stdint_u[n] = 0; - inc_stdint_s[n] = 0; - } - for(n = 0; n < MAX_FLT_WIDTH; n++) - sizearr_f[n] = NULL; - - try_size(logdepth+1, NULL, NULL, "unsigned long long int", 0, "sys/types/size/unsigned_long_long_int", sizearr_u, NULL, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "unsigned char", 0, "sys/types/size/unsigned_char", sizearr_u, NULL, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "unsigned short int", 0, "sys/types/size/unsigned_short_int", sizearr_u, NULL, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "unsigned int", 0, "sys/types/size/unsigned_int", sizearr_u, NULL, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "unsigned long int", 0, "sys/types/size/unsigned_long_int", sizearr_u, NULL, MAX_INT_WIDTH); - - try_size(logdepth+1, NULL, NULL, "signed long long int", 0, "sys/types/size/signed_long_long_int", sizearr_s, NULL, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "signed char", 0, "sys/types/size/signed_char", sizearr_s, NULL, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "signed short int", 0, "sys/types/size/signed_short_int", sizearr_s, NULL, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "signed int", 0, "sys/types/size/signed_int", sizearr_s, NULL, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "signed long int", 0, "sys/types/size/signed_long_int", sizearr_s, NULL, MAX_INT_WIDTH); - - if ((stdint != NULL) && (istrue(stdint))) { - try_size(logdepth+1, NULL, NULL, "uint8_t", 1, "sys/types/size/uint8_t", sizearr_u, inc_stdint_u, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "uint16_t", 1, "sys/types/size/uint16_t", sizearr_u, inc_stdint_u, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "uint32_t", 1, "sys/types/size/uint32_t", sizearr_u, inc_stdint_u, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "uint64_t", 1, "sys/types/size/uint64_t", sizearr_u, inc_stdint_u, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "int8_t", 1, "sys/types/size/int8_t", sizearr_s, inc_stdint_s, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "int16_t", 1, "sys/types/size/int16_t", sizearr_s, inc_stdint_s, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "int32_t", 1, "sys/types/size/int32_t", sizearr_s, inc_stdint_s, MAX_INT_WIDTH); - try_size(logdepth+1, NULL, NULL, "int64_t", 1, "sys/types/size/int64_t", sizearr_s, inc_stdint_s, MAX_INT_WIDTH); - } - - try_size(logdepth+1, NULL, NULL, "float", 0, "sys/types/size/float", sizearr_f, NULL, MAX_FLT_WIDTH); - try_size(logdepth+1, NULL, NULL, "double", 0, "sys/types/size/double", sizearr_f, NULL, MAX_FLT_WIDTH); - try_size(logdepth+1, NULL, NULL, "long double", 0, "sys/types/size/long_double", sizearr_f, NULL, MAX_FLT_WIDTH); - - for(n = 0; n < MAX_INT_WIDTH; n++) { - if (sizearr_u[n] != NULL) { - report("Found best fit %d bytes wide uint: %s\n", n, sizearr_u[n]); - sprintf(path, path_template, n, 'u'); - put(path, sizearr_u[n]); - if (inc_stdint_u[n]) - includes = "#include "; - } - if (sizearr_s[n] != NULL) { - report("Found best fit %d bytes wide sint: %s\n", n, sizearr_s[n]); - sprintf(path, path_template, n, 's'); - put(path, sizearr_s[n]); - if (inc_stdint_s[n]) - includes = "#include "; - } - } - for(n = 0; n < MAX_FLT_WIDTH; n++) { - if (sizearr_f[n] != NULL) { - report("Found best fit %d bytes wide float: %s\n", n, sizearr_f[n]); - sprintf(path, path_template_f, n); - put(path, sizearr_f[n]); - } - } - - put("sys/types/size/presents", strue); /* to avoid redetection */ - put("sys/types/size/includes", includes); - - return 0; -} - - -int find_types_something_t(const char *name, int logdepth, int fatal, const char *prefix, const char *typ, const char *define, const char *try_include) -{ - char *out = NULL; - int res; - char test_c[512]; - char node[256], *nodeend; - const char **include, *includes[] = {"", "#include ", "#include ", "#include ", "#include ", "#include ", "#include ", NULL}; - const char ** const first_include = (try_include && *try_include) ? includes : (includes+1); - - char *test_c_include = - NL "%s" - NL "int my_puts(const char *s);" - NL "%s" - NL "int main() {" - NL " %s s;" - NL " my_puts(\"OK\");" - NL " return 0;" - NL "}" - NL "#include " - NL "int my_puts(const char *s)" - NL "{" - NL " return puts(s);" - NL "}" - NL; - - char *test_c_size = - NL "%s" - NL "#include " - NL "%s" - NL "int main() {" - NL " printf(\"%%d\", sizeof(%s));" - NL " return 0;" - NL "}" - NL; - - char *test_c_broken = - NL "%s" - NL "int my_puts(const char *s);" - NL "%s" - NL "int main() {" - NL " %s s;" - NL " void *v;" - NL " if (sizeof(v) != sizeof(s)) my_puts(\"yes\");" - NL " else my_puts(\"no\");" - NL " return 0;" - NL "}" - NL "#include " - NL "int my_puts(const char *s)" - NL "{" - NL " return puts(s);" - NL "}" - NL; - - includes[0] = try_include; - - require("cc/cc", logdepth, fatal); - - report("Checking for type %s... ", typ); - logprintf(logdepth, "find_types_something_t: Checking for %s...\n", typ); - logdepth++; - - sprintf(node, "%s/%s", prefix, typ); - nodeend = node + strlen(node); - - /* replace '*' at the end of the node path with _ptr so it can be saved in the tree */ - if (nodeend[-1] == '*') { - nodeend--; - while((nodeend > node) && (*nodeend == ' ')) nodeend--; - strcpy(nodeend-1, "_ptr"); - nodeend+=4; - } - - nodeend[0] = '/'; - nodeend[1] = '\0'; - nodeend++; - - if (define == NULL) - define = ""; - - for(include = first_include; *include != NULL; include++) { - sprintf(test_c, test_c_include, define, *include, typ); - if ((compile_run(logdepth, test_c, NULL, NULL, NULL, &out) == 0) && (strncmp(out, "OK", 2) == 0)) { - report("Found; "); - logprintf(logdepth+1, "include %s works\n", *include); - sprintf(nodeend, "includes"); - if (define) { - put(node, define); - append(node, "\\n"); - append(node, *include); - } else - put(node, *include); - break; - } - logprintf(logdepth+1, "include %s fails\n", *include); - if (out != NULL) - free(out); - } - if (*include == NULL) { - report("Not found\n"); - return 1; - } - - sprintf(nodeend, "presents"); - put(node, strue); - - /* check if typ is broken (smaller than void *) */ - sprintf(test_c, test_c_broken, define, *include, typ); - if (compile_run(logdepth, test_c, NULL, NULL, NULL, &out) == 0) { - if ((out != NULL) && (strncmp(out, "yes", 3) == 0)) { - report("(%s is narrower than void *)\n", typ); - sprintf(nodeend, "broken"); - put(node, strue); - res = 0; - } - else if ((out != NULL) && (strncmp(out, "no", 2) == 0)) { - report("(%s is not narrower than void *)\n", typ); - sprintf(nodeend, "broken"); - put(node, sfalse); - res = 0; - } - else { - report("ERROR: test failed (%s)\n", out); - res = 1; - } - } - if (out != NULL) - free(out); - - if (res == 0) { - report("Checking for size of %s... ", typ); - sprintf(test_c, test_c_size, define, *include, typ); - if (compile_run(logdepth, test_c, NULL, NULL, NULL, &out) == 0) { - if (out != NULL) { - report("(sizeof %s is %s)\n", typ, out); - sprintf(nodeend, "size"); - put(node, out); - } - } - if (out != NULL) - free(out); - } - - return res; -} - - -int find_types_size_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "size_t", NULL, NULL); -} - -int find_types_off_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "off_t", NULL, NULL); -} - -int find_types_off64_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "off64_t", NULL, NULL) && - find_types_something_t(name, logdepth, fatal, "sys/types", "off64_t", "#define _LARGEFILE64_SOURCE", NULL); -} - -int find_types_gid_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "gid_t", NULL, NULL); -} - -int find_types_uid_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "uid_t", NULL, NULL); -} - -int find_types_pid_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "pid_t", NULL, NULL); -} - -int find_types_mode_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "mode_t", NULL, NULL); -} - -int find_types_nlink_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "nlink_t", NULL, NULL); -} - -int find_types_ptrdiff_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "ptrdiff_t", NULL, NULL); -} - -int find_types_dev_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "dev_t", NULL, NULL); -} - -int find_types_ino_t(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "ino_t", NULL, NULL); -} - -int find_types_void_ptr(const char *name, int logdepth, int fatal) -{ - return find_types_something_t(name, logdepth, fatal, "sys/types", "void *", NULL, NULL); -} diff --git a/scconfig/src/default/.svn/pristine/91/91ba746c9b2db5f5422464cb24bd97409caaacee.svn-base b/scconfig/src/default/.svn/pristine/91/91ba746c9b2db5f5422464cb24bd97409caaacee.svn-base deleted file mode 100644 index 8f81220c..00000000 --- a/scconfig/src/default/.svn/pristine/91/91ba746c9b2db5f5422464cb24bd97409caaacee.svn-base +++ /dev/null @@ -1,188 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "log.h" -#include "libs.h" -#include "db.h" -#include "dep.h" -#include "regex.h" - -static void zap(char **str) -{ - const char *pat = get("/arg/sys/pkg-config-zap"); - char *n; - - if (pat == NULL) - return; - if (re_comp(pat) != NULL) - return; - while (re_exec(*str)) { - n = re_subs_dup(""); - free(*str); - *str = n; - } -} - -int run_gen_config(int logdepth, const char *confname, const char *pkgname, char **cflags, char **ldflags) -{ - char cmd[256]; - - assert(strlen(pkgname) < sizeof(cmd) - 64); - - if (cflags != NULL) { - sprintf(cmd, "%s --cflags %s", confname, pkgname); - if (run(logdepth, cmd, cflags) != 0) { - report("not found: %s --cflags failed.", confname); - logprintf(logdepth, "not found: %s --cflags failed.\n", confname); - return -1; - } - if (*cflags != NULL) { - zap(cflags); - strip(*cflags); - } - } - - if (ldflags != NULL) { - sprintf(cmd, "%s --libs %s", confname, pkgname); - if (run(logdepth, cmd, ldflags) != 0) { - report("not found: %s --libs failed.", confname); - logprintf(logdepth, "not found: %s --libs failed.\n", confname); - if (cflags != NULL) - free(*cflags); - return -1; - } - if (*ldflags != NULL) { - zap(ldflags); - strip(*ldflags); - } - } - - return 0; -} - -const char *pkg_config_name() -{ - const char *name; - name = get("/arg/sys/pkg-config"); - if (name != NULL) - return name; - return "pkg-config"; /* fallback */ -} - -/** run_pkg_config_modversion: - run `pkg-config` on @pkgname: - - with `--modversion` if @modversion is not NULL, storing the result in @modversion (malloc()'d) - Returns 0 on success. -*/ -int run_pkg_config_modversion(int logdepth, const char *pkgname, char **modversion) -{ - char cmd[256]; - const char *confname = pkg_config_name(); - - assert(strlen(pkgname) < sizeof(cmd) - 64); - - if (modversion != NULL) { - sprintf(cmd, "%s --modversion %s", confname, pkgname); - if (run(logdepth, cmd, modversion) != 0) { - /*report("Module version not found: %s --modversion %s failed.", confname, pkgname); - logprintf(logdepth, "Module version not found: %s --modversion %s failed.\n", confname, pkgname); */ - return -1; - } - zap(modversion); - strip(*modversion); - } - - return 0; -} - -/** run_pkg_config_modversion_db: - run `pkg-config --modversion` on @pkgname to find module (or package) version - and store the result in @node/modversion - Returns 0 on success. -*/ -int run_pkg_config_modversion_db(int logdepth, const char *node, const char *pkgname /*, char **modversion */ ) -{ - char *modversion; - char *tmp; - - if (run_pkg_config_modversion(logdepth, pkgname, &modversion) != 0) { - return -1; - } - /* Store the module version in node */ - tmp = str_concat("/", node, "modversion", NULL); - put(tmp, modversion); - free(tmp); - free(modversion); - - return 0; -} - -int run_pkg_config(int logdepth, const char *pkgname, char **cflags, char **ldflags) -{ - - return run_gen_config(logdepth, pkg_config_name(), pkgname, cflags, ldflags); -} - -void run_pkg_config_lst(int logdepth, const char *pkgpat, int *argc, char ***argv) -{ - char *end, *s, *next; - int n = 0, a = 0; - char **sf = NULL; - static const char *pkg_cfg_cache = NULL; - static char no_pkg_cfg; - char *list; - - if (pkg_cfg_cache == &no_pkg_cfg) - goto error; - - if (pkg_cfg_cache == NULL) { - char *cmd = str_concat(" ", pkg_config_name(), "--list-all", NULL); - run(logdepth, cmd, (char **) &pkg_cfg_cache); - free(cmd); - if (pkg_cfg_cache == NULL) { - pkg_cfg_cache = &no_pkg_cfg; - goto error; - } - } - - if (re_comp(pkgpat) != NULL) - goto error; - - s = list = strclone(pkg_cfg_cache); - for (;;) { - while (isspace(*s)) - s++; - if (*s == '\0') - break; - next = strpbrk(s, "\r\n"); - if (next != NULL) - *next = '\0'; - if (re_exec(s)) { - if ((n + 2) >= a) { /* n+2: make sure there's always room for the NULL at the end */ - a += 16; - sf = realloc(sf, sizeof(char *) * a); - } - end = strpbrk(s, " \t"); - if (end != NULL) - *end = '\0'; - - sf[n] = strclone(s); - sf[n + 1] = re_subs_dup(""); -/* report("\ns='%s' sf='%s'\n", s, sf[n]);*/ - n += 2; - } - s = next + 1; - } - - if (sf != NULL) - sf[n] = NULL; - - free(list); -error:; - *argc = n; - *argv = sf; - return; -} diff --git a/scconfig/src/default/.svn/pristine/95/9553ec35d7199749d799182f6b8427eea302227e.svn-base b/scconfig/src/default/.svn/pristine/95/9553ec35d7199749d799182f6b8427eea302227e.svn-base deleted file mode 100644 index d2d230ea..00000000 --- a/scconfig/src/default/.svn/pristine/95/9553ec35d7199749d799182f6b8427eea302227e.svn-base +++ /dev/null @@ -1,835 +0,0 @@ -/* - scconfig - detection of file system tools - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" -#include "dep.h" - -static int test_cp_ln(int logdepth, const char *command, int link) -{ - char *src, *dst, *src_esc, *dst_esc; - char *cmd, *result; - char *test_string = "works."; - int ret; - - logprintf(logdepth, "trying '%s'\n", command); - - src = tempfile_dump(test_string, ""); - dst = tempfile_new(""); - if (link) - unlink(dst); - - src_esc = shell_escape_dup(src); - dst_esc = shell_escape_dup(dst); - cmd = malloc(strlen(command) + strlen(src_esc) + strlen(dst_esc) + 32); - sprintf(cmd, "%s %s %s", command, src_esc, dst_esc); - run_shell(logdepth, cmd, NULL); - free(cmd); - free(src_esc); - free(dst_esc); - - result = load_file(dst); - ret = !strcmp(result, test_string); - logprintf(logdepth+1, "result: '%s' == '%s' (%d)\n", result, test_string, ret); - free(result); - - unlink(src); - free(src); - - result = load_file(dst); - if (link) { - if (strcmp(result, test_string) == 0) { - report("Warning: link is copy (or hard link). "); - logprintf(logdepth+1, "Warning: link is copy (or hard link).\n"); - } - } - else { - if (strcmp(result, test_string) != 0) { - report("Warning: copy is symlink. "); - logprintf(logdepth+1, "Warning: copy is symlink.\n"); - } - } - free(result); - - if (ret) { - if (link) - put("fstools/ln", command); - else - put("fstools/cp", command); - - report("OK (%s)\n", command); - } - - unlink(dst); - free(dst); - return ret; -} - -static int test_mv(int logdepth, const char *command) -{ - char *src, *dst, *src_esc, *dst_esc; - char *cmd, *result; - char *test_string = "works."; - int ret; - - logprintf(logdepth, "trying '%s'\n", command); - - src = tempfile_dump(test_string, ""); - dst = tempfile_new(""); - unlink(dst); - - src_esc = shell_escape_dup(src); - dst_esc = shell_escape_dup(dst); - cmd = malloc(strlen(command) + strlen(src_esc) + strlen(dst_esc) + 32); - sprintf(cmd, "%s %s %s", command, src_esc, dst_esc); - run_shell(logdepth, cmd, NULL); - free(cmd); - free(src_esc); - free(dst_esc); - - result = load_file(dst); - ret = !strcmp(result, test_string); - logprintf(logdepth+1, "result: '%s' == '%s' (%d)\n", result, test_string, ret); - free(result); - - if (file_size(src) > 0) { - report("Warning: mv is copy. "); - logprintf(logdepth+1, "Warning: mv is copy.\n"); - } - - if (ret) { - put("fstools/mv", command); - report("OK (%s)\n", command); - } - - unlink(dst); - unlink(src); - free(dst); - free(src); - return ret; -} - -static int test_mkdir(int logdepth, const char *command) -{ - char *dir, *file; - char *dir_esc; - char *cmd, *result; - char *test_string = "works."; - int ret = 0, had_p; - FILE *f; - - logprintf(logdepth, "trying '%s'\n", command); - dir = tempfile_new(""); - dir_esc = shell_escape_dup(dir); - unlink(dir); - - had_p = is_dir("-p"); - - cmd = malloc(strlen(command) + strlen(dir_esc) + 32); - sprintf(cmd, "%s %s", command, dir_esc); - run_shell(logdepth, cmd, NULL); - free(cmd); - - file = malloc(strlen(dir) + 32); - sprintf(file, "%s/test", dir); - f = fopen(file, "w"); - if (f != NULL) { - fputs(test_string, f); - fclose(f); - result = load_file(file); - if (strcmp(result, test_string) == 0) - ret = 1; - free(result); - } - - unlink(file); - unlink(dir); - - cmd = malloc(strlen(dir) + 32); - sprintf(cmd, "rmdir %s", dir_esc); - run_shell(logdepth, cmd, NULL); - free(cmd); - - free(file); - free(dir); - free(dir_esc); - - /* This is a bit ugly, but on win32 or other systems where mkdir works - but -p doesn't have an effect, a directory called -p may be left over... */ - if ((!had_p) && (is_dir("-p"))) { - unlink("-p"); - return 0; - } - - if (ret != 0) { - put("fstools/mkdir", command); - report("OK (%s)\n", command); - } - - return ret; -} - -static int test_rm(int logdepth, const char *command) -{ - char *src, *src_esc, *cmd, *test_string = "works."; - int ret; - - logprintf(logdepth, "trying '%s'\n", command); - - src = tempfile_dump(test_string, ""); - - if (file_size(src) < 0) { - report("error: can't create temp file\n"); - free(src); - return 0; - } - - - src_esc = shell_escape_dup(src); - cmd = malloc(strlen(command) + strlen(src_esc) + 32); - sprintf(cmd, "%s %s", command, src_esc); - run_shell(logdepth, cmd, NULL); - free(cmd); - free(src_esc); - - ret = file_size(src) < 0; - - if (ret) { - put("fstools/rm", command); - report("OK (%s)\n", command); - } - else - unlink(src); - - free(src); - return ret; -} - -static int test_ar(int logdepth, const char *command) -{ - char *src, *dst, *src_esc, *dst_esc; - char *cmd, *result, *expected; - char *test_string = "works."; - const char *path_sep; - int ret = 0; - - logprintf(logdepth, "trying '%s'\n", command); - path_sep = get("sys/path_sep"); - - src = tempfile_dump(test_string, ""); - dst = tempfile_new(""); - unlink(dst); - - src_esc = shell_escape_dup(src); - dst_esc = shell_escape_dup(dst); - cmd = malloc(strlen(command) + strlen(src_esc) + strlen(dst_esc) + 32); - sprintf(cmd, "%s ru %s %s", command, dst_esc, src_esc); - run_shell(logdepth, cmd, NULL); - sprintf(cmd, "%s t %s", command, dst_esc); - run_shell(logdepth, cmd, &result); - free(cmd); - free(dst_esc); - free(src_esc); - - if (result != NULL) { - expected = str_rchr(src, *path_sep); - if (expected == NULL) - expected = src; - else - expected++; - - logprintf(logdepth, "test_ar path_sep='%s' expected='%s' result='%s'\n", path_sep, expected, result); - - ret = strncmp(expected, result, strlen(expected)) == 0; - if (ret) { - put("fstools/ar", command); - report("OK (%s)\n", command); - } - free(result); - } - - unlink(src); - unlink(dst); - free(src); - free(dst); - return ret; -} - -static int test_ranlib(int logdepth, const char *command, const char *obj) -{ - char *cmd, *archive, *archive_esc, *obj_esc; - const char *ar; - int ret; - ar = get("fstools/ar"); - logprintf(logdepth, "trying '%s'\n", command); - - archive = tempfile_new(".a"); - archive_esc = shell_escape_dup(archive); - obj_esc = shell_escape_dup(obj); - cmd = malloc(strlen(command) + strlen(obj_esc) + strlen(archive_esc) + 64); - - sprintf(cmd, "%s r %s %s", ar, archive_esc, obj_esc); - unlink(archive); - ret = run_shell(logdepth, cmd, NULL) == 0; - if (!ret) - goto fin; - - sprintf(cmd, "%s %s", command, archive_esc); - ret = run_shell(logdepth, cmd, NULL) == 0; - - if (ret) { - put("fstools/ranlib", command); - report("OK (%s)\n", command); - } - -fin:; - unlink(archive); - free(archive); - free(cmd); - free(archive_esc); - free(obj_esc); - return ret; -} - -static int test_awk(int logdepth, const char *command) -{ - char cmd[1024]; - char *out; - int ret = 0; - char *script, *script_esc; - - /* For some reason windows awk doesn't like the code with NLs */ - char *test_awk = - "BEGIN {" - " gsub(\"b\", \"B\", t);" - " print t;" - "}"; - - logprintf(logdepth, "trying '%s'\n", command); - script = tempfile_dump(test_awk, ".awk"); - script_esc = shell_escape_dup(script); - sprintf(cmd, "%s -v \"t=blobb\" -f %s", command, script_esc); - free(script_esc); - run_shell(logdepth, cmd, &out); - unlink(script); - free(script); - - if ((out != NULL) && (strncmp(out, "BloBB", 5) == 0)) { - put("fstools/awk", command); - report("OK (%s)\n", command); - ret = 1; - } - - free(out); - return ret; -} - -static int test_cat(int logdepth, const char *command) -{ - char cmd[1024]; - char *out; - int ret = 0; - char *fn, *fn_esc; - const char *test_str = "hello world"; - - logprintf(logdepth, "trying '%s'\n", command); - fn = tempfile_dump(test_str, ".txt"); - fn_esc = shell_escape_dup(fn); - sprintf(cmd, "%s %s", command, fn_esc); - run_shell(logdepth, cmd, &out); - unlink(fn); - free(fn); - free(fn_esc); - - if ((out != NULL) && (strncmp(out, test_str, strlen(test_str)) == 0)) { - put("fstools/cat", command); - report("OK (%s)\n", command); - ret = 1; - } - - free(out); - return ret; -} - -static int test_sed(int logdepth, const char *command) -{ - char cmd[1024]; - char *out; - int ret = 0; - char *fn, *fn_esc; - const char *test_str_in = "hello world"; - const char *test_str_out = "he11o wor1d"; - - logprintf(logdepth, "trying '%s'\n", command); - fn = tempfile_dump(test_str_in, ".txt"); - fn_esc = shell_escape_dup(fn); - sprintf(cmd, "%s \"s/l/1/g\" < %s", command, fn_esc); - run_shell(logdepth, cmd, &out); - unlink(fn); - free(fn); - free(fn_esc); - - if ((out != NULL) && (strncmp(out, test_str_out, strlen(test_str_out)) == 0)) { - put("fstools/sed", command); - report("OK (%s)\n", command); - ret = 1; - } - - free(out); - return ret; -} - -static int test_chmodx(int logdepth, const char *command) -{ - char *cmd, *tmp, *tmp_esc, *out, *s; - int ret; - - logprintf(logdepth, "trying '%s'\n", command); - tmp = tempfile_dump("#!/bin/sh\necho OK\n", ".bat"); - - tmp_esc = shell_escape_dup(tmp); - cmd = malloc(strlen(command) + strlen(tmp_esc) + 16); - sprintf(cmd, "%s %s", command, tmp_esc); - ret = run_shell(logdepth, cmd, NULL) == 0; - free(cmd); - if (!ret) { - free(tmp_esc); - return ret; - } - - ret = run(logdepth+1, tmp_esc, &out); - free(tmp_esc); - - if (ret == 0) { - for(s = out; s != NULL; s = str_chr(s, '\n')) { - logprintf(logdepth+1, "chmod line to test: '%s'\n", s); - if ((s[0] == 'O') && (s[1] == 'K')) { - logprintf(logdepth+2, "(OK)\n"); - ret = 1; - break; - } - s++; - } - } - else - ret = 0; - - free(out); - if (ret) { - put("fstools/chmodx", command); - logprintf(logdepth, "chmodx command validated: '%s'\n", command); - report("OK (%s)\n", command); - } - unlink(tmp); - return ret; -} - -static int test_file(int logdepth, const char *node, const char *command) -{ - char cmd[1024]; - char *out; - int ret = 0; - char *fn, *fn_esc; - - logprintf(logdepth, "trying '%s'\n", command); - fn = tempfile_dump("plain text file\r\n", ".txt"); - fn_esc = shell_escape_dup(fn); - sprintf(cmd, "%s %s", command, fn_esc); - run_shell(logdepth, cmd, &out); - unlink(fn); - free(fn); - free(fn_esc); - - if ((out != NULL) && (strstr(out, "text") != NULL)) { - put(node, command); - report("OK (%s)\n", command); - ret = 1; - } - - free(out); - return ret; -} - -int find_fstools_cp(const char *name, int logdepth, int fatal) -{ - const char *cp; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for cp... "); - logprintf(logdepth, "find_fstools_cp: trying to find cp...\n"); - logdepth++; - - cp = get("/arg/fstools/cp"); - if (cp == NULL) { - if (test_cp_ln(logdepth, "cp -rp", 0)) return 0; - if (test_cp_ln(logdepth, "cp -r", 0)) return 0; - if (test_cp_ln(logdepth, "copy /r", 0)) return 0; /* wine */ - } - else { - report(" user provided (%s)...", cp); - if (test_cp_ln(logdepth, cp, 0)) return 0; - } - return 1; -} - -int find_fstools_ln(const char *name, int logdepth, int fatal) -{ - const char *ln; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for ln... "); - logprintf(logdepth, "find_fstools_ln: trying to find ln...\n"); - logdepth++; - - ln = get("/arg/fstools/ln"); - if (ln == NULL) { - if (test_cp_ln(logdepth, "ln -sf",1 )) return 0; - if (test_cp_ln(logdepth, "ln -s",1 )) return 0; - if (test_cp_ln(logdepth, "ln", 1)) return 0; - /* "mklink /H" -> win32 equivalent to "ln" */ - /* "cp -s" -> same as "ln -s" */ - /* "cp -l" -> same as "ln" */ - if (test_cp_ln(logdepth, "cp", 1)) return 0; - } - else { - report(" user provided (%s)...", ln); - if (test_cp_ln(logdepth, ln, 1)) return 0; - } - return 1; -} - -int find_fstools_mv(const char *name, int logdepth, int fatal) -{ - const char *mv; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for mv... "); - logprintf(logdepth, "find_fstools_mv: trying to find mv...\n"); - logdepth++; - - mv = get("/arg/fstools/mv"); - if (mv == NULL) { - if (test_mv(logdepth, "mv")) return 0; - if (test_mv(logdepth, "move")) return 0; /* win32 */ - if (test_mv(logdepth, "cp")) return 0; - } - else { - report(" user provided (%s)...", mv); - if (test_mv(logdepth, mv)) return 0; - } - return 1; -} - -int find_fstools_rm(const char *name, int logdepth, int fatal) -{ - const char *rm; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for rm... "); - logprintf(logdepth, "find_fstools_rm: trying to find rm...\n"); - logdepth++; - - rm = get("/arg/fstools/rm"); - if (rm == NULL) { - if (test_rm(logdepth, "rm -rf")) return 0; - if (test_rm(logdepth, "rm -f")) return 0; - if (test_rm(logdepth, "rm")) return 0; - if (test_rm(logdepth, "del")) return 0; /* for win32 */ - } - else { - report(" user provided (%s)...", rm); - if (test_rm(logdepth, rm)) return 0; - } - return 1; -} - -int find_fstools_mkdir(const char *name, int logdepth, int fatal) -{ - const char *mkdir; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for mkdir... "); - logprintf(logdepth, "find_fstools_mkdir: trying to find mkdir...\n"); - logdepth++; - - mkdir = get("/arg/fstools/mkdir"); - if (mkdir == NULL) { - if (test_mkdir(logdepth, "mkdir -p")) return 0; - if (test_mkdir(logdepth, "md")) return 0; /* for win32 */ - } - else { - report(" user provided (%s)...", mkdir); - if (test_mkdir(logdepth, mkdir)) return 0; - } - return 1; -} - -int find_fstools_ar(const char *name, int logdepth, int fatal) -{ - const char *ar, *target; - char *targetar; - int len; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - require("sys/path_sep", logdepth, fatal); - - - report("Checking for ar... "); - logprintf(logdepth, "find_fstools_ar: trying to find ar...\n"); - logdepth++; - - ar = get("/arg/fstools/ar"); - if (ar == NULL) { - target = get("/arg/sys/target"); - if (target != NULL) { - logprintf(logdepth+1, "find_ar: crosscompiling for '%s', looking for target ar\n", target); - len = strlen(target); - targetar = malloc(len + 8); - memcpy(targetar, target, len); - strcpy(targetar + len, "-ar"); - if (test_ar(logdepth, targetar)) { - free(targetar); - return 0; - } - free(targetar); - } - if (test_ar(logdepth, "ar")) return 0; - if (test_ar(logdepth, "/usr/bin/ar")) return 0; - } - else { - report(" user provided (%s)...", ar); - if (test_ar(logdepth, ar)) return 0; - } - return 1; -} - -int find_fstools_ranlib(const char *name, int logdepth, int fatal) -{ - const char *ranlib, *target; - char *targetranlib; - int len; - char *test_code = NL "int zero() { return 0; }" NL; - char *obj = ".o"; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - require("fstools/ar", logdepth, fatal); - require("cc/cc", logdepth, fatal); - - report("Checking for ranlib... "); - logprintf(logdepth, "find_fstools_ranlib: trying to find ranlib...\n"); - logdepth++; - - logprintf(logdepth, "compiling test object...\n"); - if (compile_code(logdepth+1, test_code, &obj, NULL, "-c", NULL) != 0) { - logprintf(logdepth, "ERROR: Can't compile test object\n"); - report("ERROR: Can't compile test object\n"); - abort(); - } - - ranlib = get("/arg/fstools/ranlib"); - if (ranlib == NULL) { - target = get("/arg/sys/target"); - if (target != NULL) { - logprintf(logdepth+1, "find_ranlib: crosscompiling for '%s', looking for target ranlib\n", target); - len = strlen(target); - targetranlib = malloc(len + 16); - memcpy(targetranlib, target, len); - strcpy(targetranlib + len, "-ranlib"); - if (test_ranlib(logdepth, targetranlib, obj)) { - free(targetranlib); - return 0; - } - free(targetranlib); - } - if (test_ranlib(logdepth, "ranlib", obj)) goto found; - if (test_ranlib(logdepth, "/usr/bin/ranlib", obj)) goto found; - if (test_ranlib(logdepth, "ar -s", obj)) goto found; - if (test_ranlib(logdepth, "/usr/bin/ar -s", obj)) goto found; - - /* some systems (for example IRIX) can't run s without doing - something else; t is harmless */ - if (test_ranlib(logdepth, "ar ts", obj)) goto found; - if (test_ranlib(logdepth, "/usr/bin/ar ts", obj)) goto found; - - /* final fallback: some systems (for example minix3) simply - do not have ranlib or ar equivalent; it's easier to detect - a dummy command than to force conditions into Makefiles */ - if (test_ranlib(logdepth, "true", obj)) goto found; - } - else { - report(" user provided (%s)...", ranlib); - if (test_ranlib(logdepth, ranlib, obj)) goto found; - } - unlink(obj); - free(obj); - return 1; -found:; - unlink(obj); - free(obj); - return 0; -} - -int find_fstools_awk(const char *name, int logdepth, int fatal) -{ - const char *awk; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for awk... "); - logprintf(logdepth, "find_fstools_awk: trying to find awk...\n"); - logdepth++; - - awk = get("/arg/fstools/awk"); - if (awk == NULL) { - if (test_awk(logdepth, "awk")) return 0; - if (test_awk(logdepth, "gawk")) return 0; - if (test_awk(logdepth, "mawk")) return 0; - if (test_awk(logdepth, "nawk")) return 0; - } - else { - report(" user provided (%s)...", awk); - if (test_awk(logdepth, awk)) return 0; - } - return 1; -} - -int find_fstools_chmodx(const char *name, int logdepth, int fatal) -{ - const char *chmod; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for chmod to executable... "); - logprintf(logdepth, "find_fstools_awk: trying to find chmod to executable...\n"); - logdepth++; - - chmod = get("/arg/fstools/chmodx"); - if (chmod == NULL) { - if (test_chmodx(logdepth, "chmod +x")) return 0; - if (test_chmodx(logdepth, "chmod 755")) return 0; - if (test_chmodx(logdepth, "")) return 0; /* on some systems we don't need to do anything */ - } - else { - report(" user provided (%s)...", chmod); - if (test_chmodx(logdepth, chmod)) return 0; - } - return 1; -} - -int find_fstools_cat(const char *name, int logdepth, int fatal) -{ - const char *cat; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for cat... "); - logprintf(logdepth, "find_fstools_cat: trying to find cat...\n"); - logdepth++; - - cat = get("/arg/fstools/cat"); - if (cat == NULL) { - if (test_cat(logdepth, "cat")) return 0; - if (test_cat(logdepth, "type")) return 0; - } - else { - report(" user provided (%s)...", cat); - if (test_cat(logdepth, cat)) return 0; - } - return 1; -} - -int find_fstools_sed(const char *name, int logdepth, int fatal) -{ - const char *sed; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for sed... "); - logprintf(logdepth, "find_fstools_sed: trying to find sed...\n"); - logdepth++; - - sed = get("/arg/fstools/sed"); - if (sed == NULL) { - if (test_sed(logdepth, "sed")) return 0; - } - else { - report(" user provided (%s)...", sed); - if (test_sed(logdepth, sed)) return 0; - } - return 1; -} - -int find_fstools_file_l(const char *name, int logdepth, int fatal) -{ - const char *file; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for file... "); - logprintf(logdepth, "find_fstools_file_l: trying to find file -L...\n"); - logdepth++; - - file = get("/arg/fstools/file_l"); - if (file == NULL) { - if (test_file(logdepth, "fstools/file_l", "file -L")) return 0; - if (test_file(logdepth, "fstools/file_l", "file")) return 0; - } - else { - report(" user provided (%s)...", file); - if (test_file(logdepth, "fstools/file_l", file)) return 0; - } - return 1; -} - -int find_fstools_file(const char *name, int logdepth, int fatal) -{ - const char *file; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for file... "); - logprintf(logdepth, "find_fstools_file: trying to find file...\n"); - logdepth++; - - file = get("/arg/fstools/file"); - if (file == NULL) { - if (test_file(logdepth, "fstools/file", "file")) return 0; - } - else { - report(" user provided (%s)...", file); - if (test_file(logdepth, "fstools/file", file)) return 0; - } - return 1; -} diff --git a/scconfig/src/default/.svn/pristine/95/956d2e9d771346da5dce5fc1f161c07daafd7d7f.svn-base b/scconfig/src/default/.svn/pristine/95/956d2e9d771346da5dce5fc1f161c07daafd7d7f.svn-base deleted file mode 100644 index cbb8cc0a..00000000 --- a/scconfig/src/default/.svn/pristine/95/956d2e9d771346da5dce5fc1f161c07daafd7d7f.svn-base +++ /dev/null @@ -1,1079 +0,0 @@ -/* - scconfig - detection of cc and compiler features - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - - - -static int try_flags(int logdepth, const char *cc, const char *test_c, const char *cflags, const char *ldflags, const char *expected) -{ - char *out; - - logprintf(logdepth, "trying cc:try_flags with cc='%s' cflags='%s' ldflags='%s'\n", (cc == NULL ? get("cc/cc") : cc), cflags == NULL ? "" : cflags, ldflags == NULL ? "" : ldflags); - - if (compile_run(logdepth+1, test_c, cc, cflags, ldflags, &out) == 0) { - if (((out == NULL) && (iscross)) || (strncmp(out, expected, strlen(expected)) == 0)) { - free(out); - return 1; - } - free(out); - } - return 0; -} - -static int try_flags_inv(int logdepth, const char *cc, const char *test_c, const char *cflags, const char *ldflags, const char *expected_bad) -{ - char *out; - - logprintf(logdepth, "trying cc:try_flags with cc='%s' cflags='%s' ldflags='%s'\n", (cc == NULL ? get("cc/cc") : cc), cflags == NULL ? "" : cflags, ldflags == NULL ? "" : ldflags); - - if (compile_run(logdepth+1, test_c, cc, cflags, ldflags, &out) == 0) { - if (((out == NULL) && (iscross)) || (strncmp(out, expected_bad, strlen(expected_bad)) != 0)) { - free(out); - return 1; - } - free(out); - } - return 0; -} - -static int try(int logdepth, const char *cc, const char *test_c, const char *expected) -{ - return try_flags(logdepth, cc, test_c, NULL, NULL, expected); -} - - -static int trycc(int logdepth, const char *cc, const char *test_c) -{ - int ret; - - if (cc == NULL) - return 0; - - ret = try(logdepth, cc, test_c, "OK"); - if (ret) - put("cc/cc", cc); - return ret; -} - -int find_cc(const char *name, int logdepth, int fatal) -{ - char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL, *targetcc; - const char *cc, *cflags, *ldflags, *target, *sys; - int len; - - require("sys/name", logdepth, fatal); - - sys = istarget(db_cwd) ? "target" : "host"; - report("Checking for cc (%s)... ", sys); - logprintf(logdepth, "find_cc: trying to find cc (%s)...\n", sys); - logdepth++; - - /* cflags */ - cflags = get("/arg/cc/cflags"); - if (cflags != NULL) { - logprintf(logdepth+1, "using user supplied cflags '%s'\n", cflags); - put("cc/cflags", cflags); - } - - /* ldflags */ - ldflags = get("/arg/cc/ldflags"); - if (ldflags != NULL) { - logprintf(logdepth+1, "using user supplied ldflags '%s'\n", ldflags); - put("cc/ldflags", ldflags); - } - - cc = get("/arg/cc/cc"); - if (cc == NULL) { - target = get("sys/target"); - if (target != NULL) { - logprintf(logdepth+1, "find_cc: crosscompiling for '%s', looking for target cc\n", target); - len = strlen(target); - targetcc = malloc(len + 8); - memcpy(targetcc, target, len); - strcpy(targetcc + len, "-gcc"); - if (!trycc(logdepth+1, targetcc, test_c)) { - strcpy(targetcc + len, "-cc"); - if (!trycc(logdepth+1, targetcc, test_c)) { - report("FAILED: failed to find crosscompiler for target '%s'\n", target); - logprintf(logdepth, "find_cc: FAILED to find a crosscompiler for target '%s'\n", target); - return 1; - } - } - put("cc/cc", targetcc); - } - else { - cc = getenv("CC"); - logprintf(logdepth, "find_cc: Detecting cc (host)\n"); - /* Find a working cc (no arguments) */ - if (!(((cc != NULL) && (trycc(logdepth+1, cc, test_c))) || trycc(logdepth+1, "gcc", test_c) || trycc(logdepth+1, "cc", test_c))) { - report("FAILED to find a compiler\n"); - logprintf(logdepth, "find_cc: FAILED to find a compiler\n"); - return 1; - } - } - } - else { - put("cc/cc", cc); - logprintf(logdepth+1, "using user supplied '%s' (will test later)\n", cc); - } - - /* cflags (again) */ - if (cflags == NULL) { - logprintf(logdepth, "find_cc: Detecting -pipe\n"); - - if (compile_run(logdepth+1, test_c, NULL, "-pipe", "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - append("cc/cflags", " -pipe"); - } - free(out); - } - } - if (get("cc/cflags") == NULL) - put("cc/cflags", ""); - - /* ldflags (again) */ - if (get("cc/ldflags") == NULL) - put("cc/ldflags", ""); - - /* Final test of all arguments together */ - logprintf(logdepth, "find_cc: final test on cc and all flags \n"); - if (compile_run(logdepth+1, test_c, NULL, NULL, NULL, &out) != 0) { - report("FAILED to get the compiler and all flags to work together\n"); - logprintf(logdepth, "find_cc: the compiler and all the flags don't work well together, aborting\n"); - if (out != NULL) - free(out); - return 1; - } - - report("OK ('%s', '%s', '%s')\n", get("cc/cc"), get("cc/cflags"), get("cc/ldflags")); - logprintf(logdepth, "find_cc: conclusion: cc='%s' cflags='%s' ldflags='%s'\n", get("cc/cc"), get("cc/cflags"), get("cc/ldflags")); - if (out != NULL) - free(out); - return 0; -} - -int find_cc_argstd(const char *det_name, int logdepth, int fatal) -{ - char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL; - char **flg, *flags[] = {"-ansi", "-pedantic", "-Wall", "-std=c89", "-std=c99", "-Werror", "-Wextra", "-W", "-pg", "-no-pie", "-static-pie", NULL}; - const char *det_target = det_list_target(det_name); - - require("cc/cc", logdepth, fatal); - - logprintf(logdepth, "find_cc: Detecting CC args %s\n", det_target); - report("Checking for cc args for std %s... ", det_target); - - for(flg = flags; *flg != NULL; flg++) { - char name[128], *end; - const char *found = ""; - sprintf(name, "cc/argstd/%s", (*flg)+1); - end = strchr(name, '='); - if (end != NULL) - *end = '_'; - if (!asked_for(name, det_name)) - continue; - if (compile_run(logdepth+1, test_c, NULL, *flg, "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - found = *flg; - report(" "); - report(found); - } - free(out); - } - put(name, found); - } - - if (is_dep_wild(det_name)) - put("cc/argstd/presents", strue); /* to avoid re-detection*/ - - report("\n"); - return 0; -} - -int find_cc_argmachine(const char *name, int logdepth, int fatal) -{ -#define ARGM(flag) "-m" #flag , "-mno-" #flag - const char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL; - const char **flg, *flags[] = { ARGM(mmx), ARGM(sse), ARGM(sse2), ARGM(sse3), ARGM(ssse3), ARGM(sse4), ARGM(sse4.1), ARGM(sse4.2), ARGM(avx), ARGM(avx2), NULL}; - - require("cc/cc", logdepth, fatal); - - logprintf(logdepth, "find_cc: Detecting CC machine args\n"); - report("Checking for cc args for machine... "); - - for(flg = flags; *flg != NULL; flg++) { - char name[128], *end; - const char *found = ""; - { - const char* ptr = (*flg) + 1; - strcpy(name, "cc/argmachine/"); - end = name + strlen(name); - while(*ptr) { - if('.'!=*ptr && '-'!=*ptr) *end++ = *ptr; - ++ptr; - } - *end = '\0'; - } - end = strchr(name, '='); - if (end != NULL) - *end = '_'; - if (compile_run(logdepth+1, test_c, NULL, *flg, "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - found = *flg; - report(" "); - report(found); - } - free(out); - } - put(name, found); - } - - report("\n"); - return 0; -#undef ARGM -} - -int find_inline(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "static inline void test_inl()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test_inl();" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for inline... "); - logprintf(logdepth, "find_inline: trying to find inline...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/inline", strue); - report("Found.\n"); - return 0; - } - put("cc/inline", sfalse); - report("Not found.\n"); - return 1; -} - -int find_varargmacro(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#define pr(fmt, x...) {printf(\"PR \"); printf(fmt, x); }" - NL "int main() {" - NL " pr(\"%d %d %s\", 42, 8192, \"test\");" - NL " puts(\"\");" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for vararg macro... "); - logprintf(logdepth, "find_varargmacro: trying to find vararg macro...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "PR 42 8192 test")) { - put("cc/varargmacro", strue); - report("Found.\n"); - return 0; - } - put("cc/varargmacro", sfalse); - report("Not found.\n"); - return 1; -} - -int find_funcmacro(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " printf(\"%s\\n\", __func__);" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for __func__ macro... "); - logprintf(logdepth, "find_funcmacro: trying to find __func__ macro...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "main")) { - put("cc/funcmacro", strue); - report("Found.\n"); - return 0; - } - put("cc/funcmacro", sfalse); - report("Not found.\n"); - return 1; -} - -int find_constructor(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "void startup() __attribute__ ((constructor));" - NL "void startup()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for constructor... "); - logprintf(logdepth, "find_constructor: trying to find constructor...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/constructor", strue); - report("Found.\n"); - return 0; - } - put("cc/constructor", sfalse); - report("Not found.\n"); - return 1; -} - -int find_destructor(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "void startup() __attribute__ ((destructor));" - NL "void startup()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for destructor... "); - logprintf(logdepth, "find_destructor: trying to find destructor...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/destructor", strue); - report("Found.\n"); - return 0; - } - put("cc/destructor", sfalse); - report("Not found.\n"); - return 1; -} - -static int test_fattr(const char *name, int logdepth, int fatal, const char *fattr) -{ - char path[64]; - char test_c[256]; - const char *test_c_tmp = - NL "#include " - NL "static void test1() __attribute__ ((%s));" - NL "static void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - sprintf(test_c, test_c_tmp, fattr); - sprintf(path, "cc/func_attr/%s/presents", fattr); - - report("Checking for function attribute %s... ", fattr); - logprintf(logdepth, "test_fattr: trying to find %s...\n", fattr); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put(path, strue); - report("Found.\n"); - return 0; - } - put(path, sfalse); - report("Not found.\n"); - return 1; -} - -int find_fattr_unused(const char *name, int logdepth, int fatal) -{ - return test_fattr(name, logdepth, fatal, "unused"); -} - -static int test_declspec(const char *name, int logdepth, int fatal, const char *dspec) -{ - char path[64]; - char test_c[256]; - const char *test_c_tmp = - NL "#include " - NL "void __declspec (%s) test1();" - NL "void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test1();" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - sprintf(test_c, test_c_tmp, dspec); - sprintf(path, "cc/declspec/%s/presents", dspec); - - report("Checking for declspec %s... ", dspec); - logprintf(logdepth, "test_declspec: trying to find %s...\n", dspec); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put(path, strue); - report("Found.\n"); - return 0; - } - put(path, sfalse); - report("Not found.\n"); - return 1; -} - -int find_declspec_dllimport(const char *name, int logdepth, int fatal) -{ - return test_declspec(name, logdepth, fatal, "dllimport"); -} - -int find_declspec_dllexport(const char *name, int logdepth, int fatal) -{ - return test_declspec(name, logdepth, fatal, "dllexport"); -} - -static int test_dll_auxfile(const char *name, int logdepth, int fatal, const char *path, const char *ldflag, const char *filename) -{ - char *ldflags; - char test_c[256]; - const char *test_c_template = - NL "#include " - NL "void %s test1();" - NL "void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test1();" - NL " return 0;" - NL "}" - NL ; - const char *dspec; - - require("cc/cc", logdepth, fatal); - require("cc/declspec/dllexport/*", logdepth, 0); - - if (istrue("cc/declspec/dllexport/presents")) - dspec = " __declspec(dllexport) "; - else - dspec = ""; - - sprintf(test_c, test_c_template, dspec); - - report("Checking for DLL flag %s... ", ldflag); - logprintf(logdepth, "test_dll_auxfile: trying to find %s...\n", ldflag); - logdepth++; - ldflags = str_concat("", ldflag, ",", filename, " ", get("cc/ldflags"), NULL); - if (try_flags(logdepth, NULL, test_c, NULL, ldflags, "OK")) { - unlink(filename); - put(path, ldflag); - free(ldflags); - report("Found.\n"); - return 0; - } - unlink(filename); - free(ldflags); - report("Not found.\n"); - return 1; -} - -int find_cc_wloutimplib(const char *name, int logdepth, int fatal) -{ - return test_dll_auxfile(name, logdepth, fatal, "cc/wloutimplib", "-Wl,--out-implib", "libscconfig_0.a"); -} - -int find_cc_wloutputdef(const char *name, int logdepth, int fatal) -{ - return test_dll_auxfile(name, logdepth, fatal, "cc/wloutputdef", "-Wl,--output-def", "libscconfig_0.def"); -} - -/* Hello world program to test compiler flags */ -static const char *test_hello_world = - NL "#include " - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -static int try_hello(int logdepth, const char *cflags, const char *ldflags, const char *name, const char *value) -{ - if (try_flags(logdepth, NULL, test_hello_world, cflags, ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - return 1; - } - return 0; -} - -int find_rdynamic(const char *name, int logdepth, int fatal) -{ - const char *node = "cc/rdynamic"; - - require("cc/cc", logdepth, fatal); - - report("Checking for rdynamic... "); - logprintf(logdepth, "find_rdynamic: trying to find rdynamic...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-rdynamic", node, "-rdynamic")) return 0; - if (try_hello(logdepth, NULL, "-Wl,-export-dynamic", node, "-Wl,-export-dynamic")) return 0; - if (try_hello(logdepth, NULL, NULL, node, "")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_cc_fpie(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - /* TODO: what about -fpic? */ - - report("Checking for -fpie... "); - logprintf(logdepth, "find_cc_fpie: trying to find -fpie...\n"); - logdepth++; - - /* NOTE: some gcc configuration might not pass the -pie flag to the linker, so */ - /* try to detect whether we can force it to the linker */ - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fpie", "-pie -Wl,-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fPIE", "-pie -Wl,-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fpie", "-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fPIE", "-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fpie"); -} - -int find_cc_fnopie(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - - report("Checking for -fno-pie... "); - logprintf(logdepth, "find_cc_fnopie: trying to find -fno-pie...\n"); - logdepth++; - - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, "-fno-pie", NULL)) return 0; - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, "-fno-pie", "-static")) return 0; - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fnopie"); -} - -int find_cc_fnopic(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - - report("Checking for -fno-pic... "); - logprintf(logdepth, "find_cc_fnopic: trying to find -fno-pic...\n"); - logdepth++; - - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, "-fno-pic", NULL)) return 0; - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, "-fno-pic", "-static")) return 0; - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fnopic"); -} - -int find_soname(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for soname... "); - logprintf(logdepth, "find_soname: trying to find soname...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-Wl,-soname,libscconfig.0", "cc/soname", "-Wl,-soname,")) return 0; - if (try_hello(logdepth, NULL, NULL, "cc/soname", "")) return 0; - - report("Not found.\n"); - return 1; -} - - -int find_wlrpath(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for rpath... "); - logprintf(logdepth, "find_wlrpath: trying to find rpath...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-Wl,-rpath=.", "cc/wlrpath", "-Wl,-rpath=")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_fpic(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for -fpic... "); - logprintf(logdepth, "find_fpic: trying to find -fpic...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-fPIC", "cc/fpic", "-fPIC")) return 0; - if (try_hello(logdepth, NULL, "-fpic", "cc/fpic", "-fpic")) return 0; - if (try_hello(logdepth, NULL, NULL, "cc/fpic", "")) return 0; - - report("Not found.\n"); - return 1; -} - -/* Hello world lib... */ -static const char *test_lib = - NL "#include " - NL "int hello() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -/* ...and the corresponding host application */ -static const char *test_host = - NL "#include " - NL "#include " - NL "#include %s" - NL "int main() {" - NL " void *handle = NULL;" - NL " void (*func)() = NULL;" - NL " char *error;" - NL - NL " handle = dlopen(\"%s\", RTLD_NOW);" - NL " if (handle == NULL) {" - NL " printf(\"dlopen fails: \", dlerror());" - NL " return 1;" - NL " }" - NL " func = dlsym(handle, \"hello\");" - NL " if (func == NULL) {" - NL " printf(\"dlsym fails: \", dlerror());" - NL " return 1;" - NL " }" - NL " func();" - NL " return 0;" - NL "}" - NL ; - -static int try_dynlib(int logdepth, const char *cflags, char *concated_ldflags, const char *name, const char *value, const char *host_app_cflags, const char *host_app_ldflags) -{ - char test_host_app[1024]; - const char *fpic; - const char *ld_include; - const char *dlc; - char *libname, *libname_dyn; - char *cflags_c; - char *oname = ".o"; - int ret = 0; - - - dlc = get("libs/dl-compat"); - if ((dlc != NULL) && (strcmp(dlc, strue) == 0)) - ld_include = ""; - else - ld_include = ""; - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - if (cflags == NULL) - cflags=""; - - cflags_c = malloc(strlen(cflags) + 8 + strlen(fpic)); - sprintf(cflags_c, "%s -c %s", cflags, fpic); - - - libname_dyn = libname = (char *)get("sys/ext_dynlib"); - if ((compile_code(logdepth, test_lib, &oname, NULL, cflags_c, NULL) != 0) || - (compile_file(logdepth, oname, &libname_dyn, NULL, NULL, concated_ldflags) != 0)) { - report("FAILED (compiling dynlib)\n"); - } - else { - sprintf(test_host_app, test_host, ld_include, libname_dyn); - if (try_flags(logdepth, NULL, test_host_app, host_app_cflags, host_app_ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - ret = 1; - } - } - unlink(libname_dyn); - unlink(oname); - if (libname != libname_dyn) - free(libname_dyn); - free(oname); - free(concated_ldflags); - free(cflags_c); - return ret; -} - - -int find_ldflags_dynlib(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - require("cc/rdynamic", logdepth, fatal); - require("cc/fpic", logdepth, fatal); - require("libs/ldl", logdepth, fatal); - - report("Checking for dynamic library ldflags... "); - logprintf(logdepth, "find_ldflags_dynlib: trying to find dynamic library ldflags...\n"); - logdepth++; - - if (try_dynlib(logdepth, NULL, concat_nodes("-dynamic -shared", "cc/rdynamic", "libs/ldl", NULL), "cc/ldflags_dynlib", "-dynamic -shared", NULL, get("libs/ldl"))) return 0; - if (try_dynlib(logdepth, NULL, concat_nodes("-shared", "cc/rdynamic", "libs/ldl", NULL), "cc/ldflags_dynlib", "-shared", NULL, get("libs/ldl"))) return 0; - report("Not found.\n"); - return 1; -} - -static int try_dll_or_so(int logdepth, int is_dll, const char *lib_ldflags, const char *name, const char *value, - const char *dspec_dllexport, const char *dspec_dllimport, - const char *app_cflags, const char *app_ldflags) -{ - static const char *test_lib_template = - NL "#include " - NL "%s void hello();" - NL "void hello() {" - NL " puts(\"OK\");" - NL "}" - NL ; - static const char *test_app_template = - NL "%s void hello();" - NL "int main() {" - NL " hello();" - NL " return 0;" - NL "}" - NL ; - char test_lib[1024]; - char test_app[1024]; - const char *fpic; - char *cflags_c; - char *oname, *oname_ext; - char *libname, *libname_ext; - char *appname = NULL, *appname_ext = NULL; - char *lib_filename = NULL, *lib_dirname = NULL; - char *lib_ldflags_new = NULL; - char *app_ldflags_new = NULL; - size_t len, ii; - int ret = 0; - - ++logdepth; - - require("cc/cc", logdepth, 0); - require("cc/cflags", logdepth, 0); - require("cc/ldflags", logdepth, 0); - require("cc/fpic", logdepth, 0); - require("sys/ext_exe", logdepth, 0); - require("sys/ext_dynlib_native", logdepth, 0); - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - if (app_cflags == NULL) - app_cflags = ""; - - if (app_ldflags == NULL) - app_ldflags = ""; - - cflags_c = str_concat(" ", get("cc/cflags"), "-c", fpic, NULL); - - oname = oname_ext = ".o"; - libname = libname_ext = (char *)get("sys/ext_dynlib_native"); - sprintf(test_lib, test_lib_template, dspec_dllexport); - lib_ldflags_new = str_concat(" ", get("cc/ldflags"), lib_ldflags, NULL); - if ((compile_code(logdepth, test_lib, &oname, NULL, cflags_c, NULL) != 0) || - (compile_file(logdepth, oname, &libname, NULL, NULL, lib_ldflags_new) != 0)) { - report("FAILED (compiling %s)\n", (is_dll?"DLL":"SO")); - } - else { - lib_filename = file_name(libname); - lib_dirname = dir_name(libname); - - if (!is_dll) { - len = strlen(lib_filename) - strlen(libname_ext); - for (ii=3; ii" - NL "int main() {" - NL " char *s;" - NL " s = alloca(128);" - NL " if (s != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -static int try_alloca(int logdepth, const char *cflags, const char *ldflags, const char *name, const char *value) -{ - if (try_flags(logdepth, NULL, test_alloca, cflags, ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - return 1; - } - return 0; -} - -int find_alloca(const char *name, int logdepth, int fatal) -{ - require("cc/cc", logdepth, fatal); - - report("Checking for alloca()... "); - logprintf(logdepth, "find_alloca: trying to find alloca()...\n"); - logdepth++; - - if (try_alloca(logdepth, NULL, NULL, "cc/alloca/presents", "true")) return 0; - - put("cc/alloca/presents", "false"); - report("Not found.\n"); - return 1; -} - - -int find__exit(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " _exit(0);" - NL " puts(\"BAD\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for _exit()... "); - logprintf(logdepth, "find__exit: trying to find _exit()...\n"); - logdepth++; - - if (try_flags_inv(logdepth, NULL, test_c, NULL, NULL, "BAD")) { - put("cc/_exit/presents", strue); - report("found\n"); - return 0; - } - - put("cc/_exit/presents", sfalse); - report("Not found.\n"); - return 1; -} - -int find_cc_pragma_message(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#define DO_PRAGMA(arg) _Pragma(#arg)" - NL "#define TODO(x) DO_PRAGMA(message(\"TODO: \" #x))" - NL "TODO(test)" - NL "int main()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for _Pragma(message)... "); - logprintf(logdepth, "find_cc_pragma_message: trying to find pragma_message...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/pragma_message", strue); - report("Found.\n"); - return 0; - } - put("cc/pragma_message", sfalse); - report("Not found.\n"); - return 1; -} - -int find_cc_static_libgcc(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - const char *key = "cc/static_libgcc"; - - require("cc/cc", logdepth, fatal); - - report("Checking for -static-libgcc... "); - logprintf(logdepth, "find_cc_static_libgcc: trying to find -static-libgcc...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, NULL, NULL, "-static-libgcc")) return 0; - return try_fail(logdepth, key); -} diff --git a/scconfig/src/default/.svn/pristine/98/982bfc24f40acedb8fb83eb7552c2d5f8adfb059.svn-base b/scconfig/src/default/.svn/pristine/98/982bfc24f40acedb8fb83eb7552c2d5f8adfb059.svn-base deleted file mode 100644 index 0d60fe79..00000000 --- a/scconfig/src/default/.svn/pristine/98/982bfc24f40acedb8fb83eb7552c2d5f8adfb059.svn-base +++ /dev/null @@ -1,204 +0,0 @@ -/* - scconfig - helpers for a main() - Copyright (C) 2009..2016 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "db.h" -#include "find.h" -#include "log.h" -#include "arg.h" -#include "dep.h" -#include "deps_default.h" -#include "libs.h" -#include "hooks.h" -#include "regex.h" -#include "main_custom_args.h" - -#ifdef PLUGIN_SCRIPTS -#include "../scripts/INIT.h" -#endif - -#ifdef PLUGIN_PARSER -#include "../parser/INIT.h" -#endif - -#ifdef PLUGIN_C99 -#include "../c99/INIT.h" -#endif - -#ifdef PLUGIN_PARSGEN -#include "../parsgen/INIT.h" -#endif - -#ifdef PLUGIN_MATH -#include "../math/INIT.h" -#endif - -#ifdef PLUGIN_SOCKET -#include "../socket/INIT.h" -#endif - -#ifdef PLUGIN_USERPASS -#include "../userpass/INIT.h" -#endif - -#ifdef PLUGIN_GUI -#include "../gui/INIT.h" -#endif - -#ifdef PLUGIN_TTY -#include "../tty/INIT.h" -#endif - -#ifdef PLUGIN_SUL -#include "../sul/INIT.h" -#endif - -#ifdef PLUGIN_POSIX -#include "../posix/INIT.h" -#endif - -#ifdef PLUGIN_GENERATOR -#include "generator.h" -#endif - - -void init(void) -{ - db_init(); - log_init(); - dep_init(); - deps_default_init(); - - /* common internal directory */ - db_mkdir("/internal"); - - /* We have a host system for sure - also make it the default */ - db_mkdir("/host"); - db_cd("/host"); - - /* emulator for the host system is empty string */ - put("sys/emu", ""); - -#ifdef PLUGIN_SCRIPTS -#include "../scripts/INIT.c" -#endif - -#ifdef PLUGIN_PARSER -#include "../parser/INIT.c" -#endif - -#ifdef PLUGIN_C99 -#include "../c99/INIT.c" -#endif - -#ifdef PLUGIN_PARSGEN -#include "../parsgen/INIT.c" -#endif - -#ifdef PLUGIN_MATH -#include "../math/INIT.c" -#endif - -#ifdef PLUGIN_SOCKET -#include "../socket/INIT.c" -#endif - -#ifdef PLUGIN_USERPASS -#include "../userpass/INIT.c" -#endif - -#ifdef PLUGIN_GUI -#include "../gui/INIT.c" -#endif - -#ifdef PLUGIN_TTY -#include "../tty/INIT.c" -#endif - -#ifdef PLUGIN_SUL -#include "../sul/INIT.c" -#endif - -#ifdef PLUGIN_POSIX -#include "../posix/INIT.c" -#endif - -#ifdef PLUGIN_GENERATOR -#include "../generator/INIT.c" -#endif -} - -void uninit(void) -{ - log_uninit(); - dep_uninit(); - db_uninit(); -} - -void run_custom_reqs(void) -{ - int n; - if (num_custom_reqs > 0) { - printf("Running custom requirements\n"); - for(n = 0; n < num_custom_reqs; n++) { - if (custom_reqs[n] == NULL) { - fprintf(stderr, "Error: requested detection of empty string - please check your command line, syntax is --detect=node\n"); - exit(1); - } - require(custom_reqs[n], 1, 1); - } - } -} - -int main_init(void) -{ - re_modw("./\\"); - if (hook_preinit()) { - fprintf(stderr, "hook_preinit failed, exiting\n"); - return 1; - } - init(); - if (hook_postinit()) { - fprintf(stderr, "hook_postinit failed, exiting\n"); - return 1; - } - return 0; -} - -int main_process_args(int argc, char *argv[]) -{ - process_args(argc, argv); - if (hook_postarg()) { - fprintf(stderr, "hook_postarg failed, exiting\n"); - return 1; - } - return 0; -} - -void main_uninit(void) -{ - hook_preuninit(); - uninit(); - hook_postuninit(); -} diff --git a/scconfig/src/default/.svn/pristine/98/98a84ee5f5df6a0c2c8681ecbe8f2f2ff7b388f9.svn-base b/scconfig/src/default/.svn/pristine/98/98a84ee5f5df6a0c2c8681ecbe8f2f2ff7b388f9.svn-base deleted file mode 100644 index 4ba66f14..00000000 --- a/scconfig/src/default/.svn/pristine/98/98a84ee5f5df6a0c2c8681ecbe8f2f2ff7b388f9.svn-base +++ /dev/null @@ -1,194 +0,0 @@ -/* - scconfig - detection of standard library features - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -static int trydlc(int logdepth, const char *test_c_dlc, const char *cflagsf, const char *ldflagsf, const char *dlc) -{ - char *cflags, *ldflags; - - cflags = malloc(strlen(dlc) + 64); - ldflags = malloc(strlen(dlc)*2 + 256); - sprintf(cflags, cflagsf, dlc); - sprintf(ldflags, ldflagsf, dlc, dlc); - if (try_icl(logdepth, NULL, test_c_dlc, NULL, cflags, ldflags)) { - *cflags = ' '; - append("cc/cflags", cflags); - put("libs/ldl", ldflags); - put("libs/dl-compat", strue); - report("OK (%s and %s)\n", cflags, ldflags); - free(cflags); - free(ldflags); - return 1; - } - free(cflags); - free(ldflags); - return 0; -} - -int find_lib_ldl(const char *name, int logdepth, int fatal) -{ - const char *ldl, *dlc; - char *s; - - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " void *handle;" - NL " handle = dlopen(\"/this file does not exist.\", RTLD_NOW);" - NL " if (handle == NULL) printf(\"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - char *test_c_dlc = - NL "#include " - NL "#include " - NL "int main() {" - NL " void *handle;" - NL " handle = dlopen(\"/this file does not exist.\", RTLD_NOW);" - NL " if (handle == NULL) printf(\"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for -ldl... "); - logprintf(logdepth, "find_lib_ldl: trying to find ldl...\n"); - logdepth++; - - ldl = get("/arg/libs/ldl"); - if (ldl == NULL) { - dlc = get("/arg/libs/dl-compat"); - - if (dlc == NULL) { - /* If dlc is not explicitly requested by the user, try standard - dl (see whether we need -ldl for dlopen()) */ - if (try_icl(logdepth, NULL, test_c, NULL, NULL, NULL)) { - put("libs/ldl", ""); - put("libs/ldl/includes", "#include \\n"); - report("OK ()\n"); - return 0; - } - if (try_icl(logdepth, NULL, test_c, NULL, NULL, "-ldl")) { - put("libs/ldl", "-ldl"); - put("libs/ldl/includes", "#include \\n"); - report("OK (-ldl)\n"); - return 0; - } - } - /* try dl-compat (dl compatibility lib) */ - if (dlc != NULL) { - /* test at user supplied dlc prefix: - - first assume the linker will find it - - next assume gcc and pass rpath to the linker - - finally try static linking */ - if (trydlc(logdepth, test_c_dlc, "-I%s/include", "-L%s/lib -ldl-compat\000%s", dlc)) { - put("libs/ldl/includes", "#include \\n"); - return 0; - } - if (trydlc(logdepth, test_c_dlc, "-I%s/include", "-L%s/lib -Wl,-rpath=%s/lib -ldl-compat", dlc)) { - put("libs/ldl/includes", "#include \\n"); - return 0; - } - if (trydlc(logdepth, test_c_dlc, "-I%s/include", "%s/lib/libdl-compat.a\000%s", dlc)) { - put("libs/ldl/includes", "#include \\n"); - return 0; - } - } - else if (try_icl(logdepth, NULL, test_c_dlc, NULL, NULL, "-ldl-compat")) { - /* check at normal system installation */ - put("libs/ldl", "-ldl-compat"); - put("libs/ldl/includes", "#include \\n"); - report("OK (-ldl-compat)\n"); - return 0; - } - } - else { - report("User provided... "); - s = strclone(ldl); - if (try_icl(logdepth, NULL, test_c, NULL, NULL, s)) { - put("libs/ldl", ldl); - put("libs/ldl/includes", "#include \\n"); - report("OK (%s)\n", ldl); - free(s); - return 0; - } - free(s); - } - report("Not found\n"); - return 1; -} - -int find_lib_LoadLibrary(const char *name, int logdepth, int fatal) -{ - /*char *s;*/ - - char *test_c = - NL "#include " - NL "int main() {" - NL " void *handle;" - NL " handle = LoadLibrary(\"/this file does not exist.\");" - NL " if (handle == NULL) printf(\"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for LoadLibrary... "); - logprintf(logdepth, "find_lib_LoadLibrary: trying to find LoadLibrary...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/LoadLibrary", test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/LoadLibrary"); -} - -int find_lib_errno(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " errno = 0;" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for errno.h... "); - logprintf(logdepth, "find_lib_errno: trying to find errno...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/errno", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/errno"); -} diff --git a/scconfig/src/default/.svn/pristine/99/99a4dc7f656fca861f22aede638e5f1ac3661555.svn-base b/scconfig/src/default/.svn/pristine/99/99a4dc7f656fca861f22aede638e5f1ac3661555.svn-base deleted file mode 100644 index c94a3d6e..00000000 --- a/scconfig/src/default/.svn/pristine/99/99a4dc7f656fca861f22aede638e5f1ac3661555.svn-base +++ /dev/null @@ -1,189 +0,0 @@ -/* - scconfig - detect I/O features of the system - Copyright (C) 2010 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_io_pipe(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " int fd[2];" - NL " if (pipe(fd) == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for pipe(2)... "); - logprintf(logdepth, "find_io_pipe: trying to find pipe(2)...\n"); - logdepth++; - - - if (try_icl(logdepth, "libs/io/pipe", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/io/pipe"); -} - -int find_io_dup2(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " int fd;" - NL " if (dup2(1, 4) == 4)" - NL " write(4, \"OK\\n\", 3); " - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for dup2(2)... "); - logprintf(logdepth, "find_io_dup2: trying to find dup2(2)...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/io/dup2", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/io/dup2"); -} - - -int find_io_fileno(const char *name, int logdepth, int fatal) -{ - char test_c[256]; - char *test_c_ = - NL "#include " - NL "int main() {" - NL no_implicit(int, "%s", "%s") - NL " if (%s(stdout) >= 0)" - NL " puts(\"OK\"); " - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for fileno(3)... "); - logprintf(logdepth, "find_io_fileno: trying to find fileno(3)...\n"); - logdepth++; - - /* UNIX */ - sprintf(test_c, test_c_, "fileno", "fileno", "fileno"); - if (try_icl(logdepth, "libs/io/fileno", test_c, "#include \n", NULL, NULL)) { - put("libs/io/fileno/call", "fileno"); - return 0; - } - - sprintf(test_c, test_c_, "fileno", "fileno", "fileno"); - if (try_icl(logdepth, "libs/io/fileno", test_c, "#define _XOPEN_SOURCE\n#include \n", NULL, NULL)) { - put("libs/io/fileno/call", "fileno"); - return 0; - } - - /* windows */ - sprintf(test_c, test_c_, "_fileno", "_fileno", "_fileno"); - if (try_icl(logdepth, "libs/io/fileno", test_c, "#include \n", NULL, NULL)) { - put("libs/io/fileno/call", "_fileno"); - return 0; - } - - return try_fail(logdepth, "libs/io/fileno"); -} - -int find_io_lseek(const char *name, int logdepth, int fatal) -{ -#define NODE "libs/io/lseek" - - char test_c[3256]; - const char *test_c_template = - NL "#include " - NL "#include " - NL "int main() {" - NL " const char *filename = \"%s\";" - NL no_implicit(int, "%s", "%s") - NL " int fd = open(filename, O_WRONLY);" - NL " if (write(fd, \"abc\", 3) == 3 && %s(fd, 1, SEEK_SET) == 1)" - NL " puts(\"OK\"); " - NL " return 0;" - NL "}" - NL; - char *tmpf; - const char *incs[] = {"#include ","#include ",NULL}; - const char *fns[] = {"lseek", "_lseek", NULL}; - const char **inc; - const char **fn; - - require("cc/cc", logdepth, fatal); - - report("Checking for lseek(2)... "); - logprintf(logdepth, "find_io_lseek: trying to find lseek(2)...\n"); - logdepth++; - - tmpf = tempfile_new(".psx"); - - for (inc = incs, fn = fns; *fn; ++inc, ++fn) { - sprintf(test_c, test_c_template, tmpf, *fn, *fn, *fn); - if (try_icl(logdepth, NODE, test_c, *inc, NULL, NULL)) { - put(NODE "/call", *fn); - return 0; - } - } - - return try_fail(logdepth, NODE); -#undef NODE -} - -int find_io_popen(const char *name, int logdepth, int fatal) -{ - const char **i, *incs[] = {"#define _XOPEN_SOURCE", "#define _BSD_SOURCE", "#define _POSIX_C_SOURCE 2", NULL}; - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " FILE *f = popen(\"echo OK\", \"r\");" - NL " char line[16];" - NL " if (f == NULL) return 0;" - NL " if (fgets(line, sizeof(line)-1, f) == NULL) return 0;" - NL " puts(line);" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for popen(3)... "); - logprintf(logdepth, "find_io_popen: trying to find popen(3)...\n"); - logdepth++; - - for(i = incs; *i != NULL; i++) - if (try_icl(logdepth, "libs/io/popen", test_c, *i, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/io/popen"); -} - diff --git a/scconfig/src/default/.svn/pristine/9b/9b6eb0b7777e5360a2ca7e76eeede0b5c3585e9c.svn-base b/scconfig/src/default/.svn/pristine/9b/9b6eb0b7777e5360a2ca7e76eeede0b5c3585e9c.svn-base deleted file mode 100644 index 54134055..00000000 --- a/scconfig/src/default/.svn/pristine/9b/9b6eb0b7777e5360a2ca7e76eeede0b5c3585e9c.svn-base +++ /dev/null @@ -1,424 +0,0 @@ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -/* Returns true if the first 2 characters of the output is OK */ -static int try_icl_accept_ok(char *stdout_str) -{ - return (strncmp(stdout_str, "OK", 2) == 0); -} - -#define is_ctrl_prefix(ch) (((ch) == '!') || ((ch) == '^')) - -static int try_icl__(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags, const char *db_includes, const char *db_cflags, const char *db_ldflags, int run, int (*accept_res)(char *stdout_str)) -{ - char *out = NULL; - char *tmp, *inc; - const char *test_c; - char c[1024]; - int l, compres; - - if (includes != NULL) { - l = strlen(includes); - memcpy(c, includes, l); - c[l] = '\n'; - l++; - strcpy(c+l, test_c_in); - test_c = c; - } - else - test_c = test_c_in; - - logprintf(logdepth, "trying '%s' and '%s' and '%s', %s\n", str_null(db_includes), str_null(db_cflags), str_null(db_ldflags), run ? "with a run" : "with no run"); - - if (run) - compres = compile_run(logdepth+1, test_c, NULL, cflags, ldflags, &out); - else { - char *fn_output = NULL; - compres = compile_code(logdepth+1, test_c, &fn_output, NULL, cflags, ldflags); - if (fn_output != NULL) { - unlink(fn_output); - free(fn_output); - } - } - - - if (compres == 0) { - if (!run || target_emu_fail(out) || accept_res(out)) { - free(out); - - /* no prefix: don't modify the database, the caller will do that */ - if (prefix == NULL) - return 1; - - tmp = malloc(strlen(prefix) + 32); - - if ((db_includes == NULL) || (*db_includes == '\0')) - inc = strclone(""); - else - inc = uniq_inc_str(db_includes, NULL, "\\n", 0, 0, NULL); - sprintf(tmp, "%s/includes", prefix); - put(tmp, inc); - - if (db_cflags == NULL) - db_cflags = ""; - - sprintf(tmp, "%s/cflags", prefix); - put(tmp, db_cflags); - - - if (db_ldflags == NULL) - db_ldflags = ""; - sprintf(tmp, "%s/ldflags", prefix); - put(tmp, db_ldflags); - - if (inc != NULL) { - report("OK ('%s', '%s' and '%s')\n", str_null(inc), str_null(db_cflags), str_null(db_ldflags)); - free(inc); - } - else - report("OK ('%s' and '%s')\n", str_null(db_cflags), str_null(db_ldflags)); - - sprintf(tmp, "%s/presents", prefix); - put(tmp, strue); - free(tmp); - return 1; - } - free(out); - } - return 0; -} - -#define LOAD(node) \ -do { \ - if (u ## node != NULL) break; \ - strcpy(apath_end, #node); \ - u ## node = get(apath); \ -} while(0) - -#define SET(dst, src, is_flag) \ -do { \ - char *__sep__ = is_flag ? " " : "\n"; \ - const char *__dst__ = dst == NULL ? "" : dst; \ - char *__out__; \ - if (is_ctrl_prefix(*__dst__)) __dst__++; \ - if (*src == '!') \ - __out__ = strclone(src+1); \ - else if (*src == '^') {\ - if (src[1] != '\0') \ - __out__ = str_concat("", src+1, __sep__, __dst__, NULL); \ - else \ - __out__ = strclone(__dst__); \ - } \ - else { \ - if (*__dst__ != '\0') \ - __out__ = str_concat("", __dst__, __sep__, src, NULL); \ - else \ - __out__ = strclone(src); \ - } \ - free(dst); \ - dst = __out__; \ - if (is_flag) { \ - char *__s__; \ - for(__s__ = dst; *__s__ != '\0'; __s__++) \ - if ((*__s__ == '\n') || (*__s__ == '\r')) \ - *__s__ = ' '; \ - } \ -} while(0) - - -/* Figure user overrides and call try_icl__() accordingly */ -int try_icl_(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags, int run, int (*accept_res)(char *stdout_str)) -{ - char apath[1024], *apath_end; - int l, res; - const char *uincludes = NULL, *ucflags = NULL, *uldflags = NULL, *uprefix = NULL; /* user specified */ - char *rincludes, *rcflags, *rldflags; /* real */ - char *dbincludes = NULL, *dbcflags = NULL, *dbldflags = NULL; /* what to add in the db at the end */ - - if ((prefix == NULL) ? 0 : strlen(prefix) + strlen(db_cwd) > sizeof(apath)-32) { - report("ERROR: no room for try_icl_() - prefix is probably too long.\n"); - return -1; - } - - /* load uincludes, uclfags, uldflags and uprefix - LOAD() inserts the u */ - l = sprintf(apath, "/arg/icl/%s/", prefix); apath_end = apath+l; - LOAD(includes); - LOAD(cflags); - LOAD(ldflags); - LOAD(prefix); - l = sprintf(apath, "/arg/icl/%s/%s/", db_cwd, prefix); apath_end = apath+l; - LOAD(includes); - LOAD(cflags); - LOAD(ldflags); - LOAD(prefix); - - /* special case: all three specified by the user - ignore what the detector wanted, but run only once per node prefix */ - if ((uincludes != NULL) && (ucflags != NULL) && (uldflags != NULL)) { - const char *am; - sprintf(apath, "%s/icl/all_manual_result", prefix); - am = get(apath); - if (am != NULL) - return istrue(am); /* return cached result if available */ - res = try_icl__(logdepth, prefix, test_c_in, uincludes, ucflags, uldflags, uincludes, ucflags, uldflags, run, accept_res); - put(apath, res ? strue : sfalse); - return res; - } - - /* TODO: get default cflags here */ - rincludes = NULL; - rcflags = strclone(get("cc/cflags")); - rldflags = strclone(get("cc/ldflags")); - - /* override base/default values with detection requested ones */ - if (includes != NULL) SET(rincludes, includes, 0); - if (cflags != NULL) SET(rcflags, cflags, 1); - if (ldflags != NULL) SET(rldflags, ldflags, 1); - - if (includes != NULL) SET(dbincludes, includes, 0); - if (cflags != NULL) SET(dbcflags, cflags, 1); - if (ldflags != NULL) SET(dbldflags, ldflags, 1); - - /* override detection with user specified ICL values */ - if (uincludes != NULL) SET(rincludes, uincludes, 0); - if (ucflags != NULL) SET(rcflags, ucflags, 1); - if (uldflags != NULL) SET(rldflags, uldflags, 1); - - if (uincludes != NULL) SET(dbincludes, uincludes, 0); - if (ucflags != NULL) SET(dbcflags, ucflags, 1); - if (uldflags != NULL) SET(dbldflags, uldflags, 1); - - /* insert prefix as needed */ - if (uprefix != NULL) { - char *old, *prfx; - - old = rcflags; - if ((rcflags != NULL) && (*rcflags == '^')) { - rcflags++; - prfx = "^"; - } - else - prfx = ""; - rcflags = str_concat("", prfx, "-I", uprefix, "/include ", rcflags, NULL); - if (old != cflags) free(old); - - old = rldflags; - if ((rldflags != NULL) && (*rldflags == '^')) { - rldflags++; - prfx = "^"; - } - else - prfx = ""; - rldflags = str_concat("", prfx, "-L", uprefix, "/lib ", rldflags, NULL); - if (old != ldflags) free(old); - } - - res = try_icl__(logdepth, prefix, test_c_in, rincludes, rcflags, rldflags, dbincludes, dbcflags, dbldflags, run, accept_res); - - /* if we had to alloc, free here */ - free(rincludes); - free(rcflags); - free(rldflags); - free(dbincludes); - free(dbcflags); - free(dbldflags); - - return res; -} - -#undef LOAD -#undef SET - -int try_icl(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags) -{ - return try_icl_(logdepth, prefix, test_c_in, includes, cflags, ldflags, 1, try_icl_accept_ok); -} - -int try_icl_with_deps(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags, const char *dep_includes, const char *dep_cflags, const char *dep_ldflags, int run) -{ - int res; - - if ((dep_includes != NULL) && (*dep_includes == '\0')) dep_includes = NULL; - if ((dep_cflags != NULL) && (*dep_cflags == '\0')) dep_cflags = NULL; - if ((dep_ldflags != NULL) && (*dep_ldflags == '\0')) dep_ldflags = NULL; - - if (dep_includes != NULL) includes = str_concat(" ", dep_includes, includes, NULL); - if (dep_cflags != NULL) cflags = str_concat(" ", dep_cflags, cflags, NULL); - if (dep_ldflags != NULL) ldflags = str_concat(" ", dep_ldflags, ldflags, NULL); - - res = try_icl_(logdepth, prefix, test_c_in, includes, cflags, ldflags, run, try_icl_accept_ok); - - if (dep_includes != NULL) free((char *)includes); - if (dep_cflags != NULL) free((char *)cflags); - if (dep_ldflags != NULL) free((char *)ldflags); - - return res; -} - -int try_icl_norun(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags) -{ - return try_icl_(logdepth, prefix, test_c_in, includes, cflags, ldflags, 0, try_icl_accept_ok); -} - - -int try_fail(int logdepth, const char *prefix) -{ - char *tmp; - tmp = malloc(strlen(prefix) + 32); - sprintf(tmp, "%s/presents", prefix); - put(tmp, sfalse); - free(tmp); - report("not found\n"); - logprintf(logdepth, "NOT FOUND."); - return 1; -} - -static int try_pkg_config_(int logdepth, char *pkgname, const char *prefix, const char *test_c) -{ - char *cflags, *ldflags; - int res; - - logprintf(logdepth, "Trying pkg-config %s\n", pkgname); - if (run_pkg_config(logdepth+1, pkgname, &cflags, &ldflags) == 0) - res = try_icl(logdepth+1, prefix, test_c, NULL, cflags, ldflags); - else - res = 0; - free(cflags); - free(ldflags); - - return res; -} - -int try_icl_pkg_config(int logdepth, const char *prefix, const char *test_c, char *includes, const char *pkgpat, const char *reqver) -{ - char **pkg_ver, **s; - int num_pkg_ver; - int res = 0; - (void) includes; /* not used */ - - run_pkg_config_lst(logdepth, pkgpat, &num_pkg_ver, &pkg_ver); - if (pkg_ver == NULL) - return 0; - - if (reqver != NULL) { - /* search the list for the preferred version */ - for(s = pkg_ver; *s != NULL; s+=2) { - if (strcmp(s[1], reqver) == 0) { - if (try_pkg_config_(logdepth, s[0], prefix, test_c)) { - res = 1; - report("Found version required (%s) using pkg_config.\n", reqver); - goto out; - } - else { - report("The version required (%s) is found (via pkg_config) but does not work\n", reqver); - goto out; - } - } - } - goto out; - } - - for(s = pkg_ver; *s != NULL; s+=2) { - if (try_pkg_config_(logdepth, s[0], prefix, test_c)) { - res = 1; - goto out; - } - } - -out:; - filelist_free(&num_pkg_ver, &pkg_ver); - return res; -} - - -int import_icl(const char *key, const char *fn) -{ - char path[1024]; - - if (strlen(key) > sizeof(path)-32) { - report("ERROR: no room for import_icl() - key is probably too long.\n"); - return -1; - } - - switch(*key) { - case 'l': sprintf(path, "/arg/icl/%s/ldflags", key+8); break; - case 'c': sprintf(path, "/arg/icl/%s/cflags", key+7); break; - case 'i': sprintf(path, "/arg/icl/%s/includes", key+9); break; - case 'p': sprintf(path, "/arg/icl/%s/prefix", key+7); break; - default: - return 1; - } - return put(path, fn) == NULL; -} - - -static long field_accept_len; -static int field_accept_res(char *stdout_str) -{ - char *end; - field_accept_len = strtol(stdout_str, &end, 10); - if (((*end == '\0') || (*end == '\r') || (*end == '\n')) && (field_accept_len > 0)) - return 1; - return 0; -} - -int try_icl_sfield(int logdepth, const char *prefix, const char *structn, const char *fieldn, const char *includes, const char *cflags, const char *ldflags) -{ - int res; - char test_c[512]; - char ls[16]; - const char *test_c_in = - NL "#include " - NL "int main()" - NL "{" - NL " %s s;" - NL " printf(\"%%ld\\n\", (long)sizeof(s.%s));" - NL "}" - NL; - - if (strlen(fieldn) + strlen(structn) + strlen(test_c_in) + 32 >= sizeof(test_c)) { - report("ERROR: no room for try_icl_sfield() - struct or field name is probably too long.\n"); - return -1; - } - - sprintf(test_c, test_c_in, structn, fieldn); - - res = try_icl_(logdepth, prefix, test_c, includes, cflags, ldflags, 1, field_accept_res); - if (res) { - sprintf(test_c, "%s/sizeof", prefix); - sprintf(ls, "%ld", field_accept_len); - put(test_c, ls); - } - return res; -} - -int try_icl_sfields(int logdepth, const char *prefix, const char *structn, const char **fields, const char *includes, const char *cflags, const char *ldflags, int silent_exit_first_fail) -{ - int succ = 0, first = 1; - require("cc/cc", logdepth, 1); - - for(; *fields != NULL; fields++) { - report("Checking for %s.%s... ", structn, *fields); - logprintf(logdepth, "%s: checking for field %s...\n", structn, *fields); - - logdepth++; - if (try_icl_sfield(logdepth, prefix, structn, *fields, includes, cflags, ldflags)) { - succ = 1; - } - else if ((silent_exit_first_fail) && (first)) { - return 1; - } - logdepth--; - first = 0; - } - - - if (!succ) - try_fail(logdepth, "libs/fsmount/next_dev"); - - return 0; -} diff --git a/scconfig/src/default/.svn/pristine/9b/9bee1bda286c34c511f80bc2f557aab2793b82ce.svn-base b/scconfig/src/default/.svn/pristine/9b/9bee1bda286c34c511f80bc2f557aab2793b82ce.svn-base deleted file mode 100644 index 6f7d32c7..00000000 --- a/scconfig/src/default/.svn/pristine/9b/9bee1bda286c34c511f80bc2f557aab2793b82ce.svn-base +++ /dev/null @@ -1,203 +0,0 @@ -/* - scconfig - detection of standard library features - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -static int trydlc(int logdepth, const char *test_c_dlc, const char *cflagsf, const char *ldflagsf, const char *dlc) -{ - char *cflags, *ldflags; - - cflags = malloc(strlen(dlc) + 64); - ldflags = malloc(strlen(dlc)*2 + 256); - sprintf(cflags, cflagsf, dlc); - sprintf(ldflags, ldflagsf, dlc, dlc); - if (try_icl(logdepth, NULL, test_c_dlc, NULL, cflags, ldflags)) { - *cflags = ' '; - append("cc/cflags", cflags); - put("libs/ldl", ldflags); - put("libs/dl-compat", strue); - report("OK (%s and %s)\n", cflags, ldflags); - free(cflags); - free(ldflags); - return 1; - } - free(cflags); - free(ldflags); - return 0; -} - -int find_lib_ldl(const char *name, int logdepth, int fatal) -{ - const char *ldl, *dlc; - char *s; - - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " void *handle;" - NL " handle = dlopen(\"/this file does not exist.\", RTLD_NOW);" - NL " if (handle == NULL) printf(\"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - char *test_c_dlc = - NL "#include " - NL "#include " - NL "int main() {" - NL " void *handle;" - NL " handle = dlopen(\"/this file does not exist.\", RTLD_NOW);" - NL " if (handle == NULL) printf(\"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - s = (char *)get("libs/ldl/presents"); - if (s != NULL) - return !istrue(s); - - require("cc/cc", logdepth, fatal); - - report("Checking for -ldl... "); - logprintf(logdepth, "find_lib_ldl: trying to find ldl...\n"); - logdepth++; - - ldl = get("/arg/libs/ldl"); - if (ldl == NULL) { - dlc = get("/arg/libs/dl-compat"); - - if (dlc == NULL) { - /* If dlc is not explicitly requested by the user, try standard - dl (see whether we need -ldl for dlopen()) */ - if (try_icl(logdepth, NULL, test_c, NULL, NULL, NULL)) { - put("libs/ldl", ""); - put("libs/ldl/includes", "#include \\n"); - put("libs/ldl/presents", strue); - report("OK ()\n"); - return 0; - } - if (try_icl(logdepth, NULL, test_c, NULL, NULL, "-ldl")) { - put("libs/ldl", "-ldl"); - put("libs/ldl/includes", "#include \\n"); - put("libs/ldl/presents", strue); - report("OK (-ldl)\n"); - return 0; - } - } - /* try dl-compat (dl compatibility lib) */ - if (dlc != NULL) { - /* test at user supplied dlc prefix: - - first assume the linker will find it - - next assume gcc and pass rpath to the linker - - finally try static linking */ - if (trydlc(logdepth, test_c_dlc, "-I%s/include", "-L%s/lib -ldl-compat\000%s", dlc)) { - put("libs/ldl/includes", "#include \\n"); - return 0; - } - if (trydlc(logdepth, test_c_dlc, "-I%s/include", "-L%s/lib -Wl,-rpath=%s/lib -ldl-compat", dlc)) { - put("libs/ldl/includes", "#include \\n"); - return 0; - } - if (trydlc(logdepth, test_c_dlc, "-I%s/include", "%s/lib/libdl-compat.a\000%s", dlc)) { - put("libs/ldl/includes", "#include \\n"); - return 0; - } - } - else if (try_icl(logdepth, NULL, test_c_dlc, NULL, NULL, "-ldl-compat")) { - /* check at normal system installation */ - put("libs/ldl", "-ldl-compat"); - put("libs/ldl/includes", "#include \\n"); - put("libs/ldl/presents", strue); - report("OK (-ldl-compat)\n"); - return 0; - } - } - else { - report("User provided... "); - s = strclone(ldl); - if (try_icl(logdepth, NULL, test_c, NULL, NULL, s)) { - put("libs/ldl", ldl); - put("libs/ldl/includes", "#include \\n"); - put("libs/ldl/presents", strue); - report("OK (%s)\n", ldl); - free(s); - return 0; - } - free(s); - } - put("libs/ldl/presents", sfalse); - report("Not found\n"); - return 1; -} - -int find_lib_LoadLibrary(const char *name, int logdepth, int fatal) -{ - /*char *s;*/ - - char *test_c = - NL "#include " - NL "int main() {" - NL " void *handle;" - NL " handle = LoadLibrary(\"/this file does not exist.\");" - NL " if (handle == NULL) printf(\"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for LoadLibrary... "); - logprintf(logdepth, "find_lib_LoadLibrary: trying to find LoadLibrary...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/LoadLibrary", test_c, "#include ", NULL, NULL)) - return 0; - return try_fail(logdepth, "libs/LoadLibrary"); -} - -int find_lib_errno(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " errno = 0;" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for errno.h... "); - logprintf(logdepth, "find_lib_errno: trying to find errno...\n"); - logdepth++; - - if (try_icl(logdepth, "libs/errno", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "libs/errno"); -} diff --git a/scconfig/src/default/.svn/pristine/a9/a9d0ee8a97028d44044ff633fd584a9af4264afe.svn-base b/scconfig/src/default/.svn/pristine/a9/a9d0ee8a97028d44044ff633fd584a9af4264afe.svn-base deleted file mode 100644 index b8f15588..00000000 --- a/scconfig/src/default/.svn/pristine/a9/a9d0ee8a97028d44044ff633fd584a9af4264afe.svn-base +++ /dev/null @@ -1,153 +0,0 @@ -/* - scconfig - command line argument processing - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include "db.h" -#include "arg.h" -#include "dep.h" -#include "log.h" -#include "libs.h" - -argtbl_t main_argument_table[] = { - {"import", NULL, import_args, "Import saved config (sub)tree"}, - {"target", "/arg/sys/target", NULL, "set cross compilation target (prefix)"}, - {"target-name", "/arg/sys/target-name", NULL, "set cross compilation target (system name)"}, - {"target-shell","/arg/sys/target-shell",NULL, "set the shell on cross compilation target"}, - {"emu", "/arg/sys/emu", NULL, "emulator for testing cross compiled executables with"}, - {"pkg-config", "/arg/sys/pkg-config", NULL, "path to pkg-config to use"}, - {"pkg-config-zap","/arg/sys/pkg-config-zap",NULL, "ignore pkg-config results by this regex pattern"}, - -/* wildcard rules for icl() control */ - {"^ldflags/", NULL, import_icl, "force LDFLAGS for a node"}, - {"^cflags/", NULL, import_icl, "force CFLAGS for a node"}, - {"^includes/", NULL, import_icl, "force #includes for a node"}, - {"^prefix/", NULL, import_icl, "force using prefix path for detecting the node"}, - -/* the followings are autoconf compatibility translations */ - {"CC", "/arg/cc/cc", NULL, "Force using a C compiler (command line)"}, - {"CFLAGS", "/arg/cc/cflags", NULL, "Force using a CFLAGS for C compilation"}, - {"LDFLAGS", "/arg/cc/ldflags", NULL, "Force using a LDFLAGS for linking"}, - {"LDL", "/arg/libs/ldl", NULL, "Force using -ldl string"}, - - {"gpmi-prefix", "/arg/gpmi/prefix", NULL, NULL}, - {NULL, NULL, NULL, NULL} -}; - -void process_args(int argc, char *argv[]) -{ - int n; - char *key, *value; - argtbl_t *a; - int found, tainted = 0; - - db_mkdir("/arg"); - - logprintf(0, "CLI arg 0: '%s'\n", argv[0]); - for(n = 1; n < argc; n++) { - key = argv[n]; - logprintf(0, "CLI arg %d: '%s'\n", n, key); - while(*key == '-') key++; - value = str_chr(key, '='); - found = 0; - - if (value != NULL) { - *value = '\0'; - value++; - - if (strcmp(key, "without") == 0) { - char *tmp, *end; - if (*value != '/') { - const char **r, *roots[] = {"target", "host", "runtime", NULL}; - for(r = roots; *r != NULL; r++) { - tmp = str_concat("/", "/arg/without", *r, value, NULL); - put(tmp, strue); - free(tmp); - } - } - else { - tmp = str_concat("/", "/arg/without", value+1, NULL); - put(tmp, strue); - free(tmp); - } - found = 1; - } - else { - /* Look in the argument translate table */ - for(a = main_argument_table; a->arg != NULL; a++) { - if (((a->arg[0] == '^') && (strncmp(a->arg+1, key, strlen(a->arg+1)) == 0)) || (strcmp(a->arg, key) == 0)) { - found = 1; - if (a->callback != NULL) { - if (a->callback(key, value) != 0) { - error("Processing argument '%s' failed in the callback\n", argv[n]); - abort(); - } - } - if (a->path != NULL) - put(a->path, value); - } - } - } - - /* Look in known deps table or /arg */ - if (found == 0) { - if ((is_dep_known(key)) || (strncmp(key, "/arg/", 5) == 0)) { - put(key, value); - found = 1; - } - } - } - - if (found == 0) { - if (custom_arg(key, value) == 0) { - error("Unknown argument '%s'\n", key); - tainted++; - } - } - } - if (tainted) - exit(1); -} - -void help_default_args(FILE *f, const char *prefix) -{ - argtbl_t *a; - - if (prefix == NULL) - prefix = ""; - - fprintf(f, "%sscconfig generic command line arguments:\n", prefix); - for(a = main_argument_table; a->arg != NULL; a++) { - char *tmp; - if (a->help == NULL) - continue; - if (*a->arg == '^') { - tmp = str_concat("", a->arg+1, "...=...", NULL); - fprintf(f, "%s --%-22s %s\n", prefix, tmp, a->help); - } - else { - tmp = str_concat("", a->arg, "=...", NULL); - fprintf(f, "%s --%-22s %s\n", prefix, tmp, a->help); - } - free(tmp); - } -} diff --git a/scconfig/src/default/.svn/pristine/a9/a9e020f40b5b180c4633dae3856a50261bb01caf.svn-base b/scconfig/src/default/.svn/pristine/a9/a9e020f40b5b180c4633dae3856a50261bb01caf.svn-base deleted file mode 100644 index 77ebf1f7..00000000 --- a/scconfig/src/default/.svn/pristine/a9/a9e020f40b5b180c4633dae3856a50261bb01caf.svn-base +++ /dev/null @@ -1 +0,0 @@ -void deps_default_init(void); diff --git a/scconfig/src/default/.svn/pristine/ac/ac1ad49e7dc16c56210cf8707c3b483be87ba7cd.svn-base b/scconfig/src/default/.svn/pristine/ac/ac1ad49e7dc16c56210cf8707c3b483be87ba7cd.svn-base deleted file mode 100644 index 54eccb9b..00000000 --- a/scconfig/src/default/.svn/pristine/ac/ac1ad49e7dc16c56210cf8707c3b483be87ba7cd.svn-base +++ /dev/null @@ -1,49 +0,0 @@ -/* - scconfig - default way to handle custom args (save them in an array) - Copyright (C) 2016 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "hooks.h" -#include "main_custom_args.h" - -char *custom_reqs[MAX_CUSTOM_REQS]; -int num_custom_reqs = 0; - -int custom_arg(const char *key, const char *value) -{ - if (hook_custom_arg(key, value)) - return 1; - if (strcmp(key, "detect") == 0) { - printf("Will detect: %s\n", value); - if (num_custom_reqs >= MAX_CUSTOM_REQS) { - report("Too many custom reqs from the command line, exiting\n"); - exit(1); - } - custom_reqs[num_custom_reqs] = strclone(value); - num_custom_reqs++; - return 1; - } - return 0; -} diff --git a/scconfig/src/default/.svn/pristine/b9/b920be843d0aa9d41ecf2ba5f509d7b9b7c3787f.svn-base b/scconfig/src/default/.svn/pristine/b9/b920be843d0aa9d41ecf2ba5f509d7b9b7c3787f.svn-base deleted file mode 100644 index cafc36ff..00000000 --- a/scconfig/src/default/.svn/pristine/b9/b920be843d0aa9d41ecf2ba5f509d7b9b7c3787f.svn-base +++ /dev/null @@ -1,132 +0,0 @@ -/* - scconfig - logging - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "log.h" -#include -#include -#include -#include - -char *spaces = " "; -FILE *logfile = NULL; -char *fn_log = "config.log"; - -void log_init(void) -{ - if (fn_log != NULL) { - /* double open for truncate - for extreme portability, please do not "fix" */ - logfile = fopen(fn_log, "w"); - assert(logfile != NULL); - fclose(logfile); - logfile = fopen(fn_log, "a"); - assert(logfile != NULL); - } -} - -void log_uninit(void) -{ - if (logfile != NULL) - fclose(logfile); -} - -void logprintf(int depth, const char *format, ...) -{ - va_list ap; - va_start(ap, format); - - if (logfile != NULL) { - fprintf(logfile, "%s", logprefix(depth)); - vfprintf(logfile, format, ap); - fflush(logfile); - } - - va_end(ap); -} - -void error(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); - - va_start(ap, format); - if (logfile != NULL) { - fprintf(logfile, "###error### "); - vfprintf(logfile, format, ap); - fflush(logfile); - } - va_end(ap); - -} - -void report(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - vprintf(format, ap); - fflush(stdout); - va_end(ap); - - va_start(ap, format); - if (logfile != NULL) { - fprintf(logfile, "###report### "); - vfprintf(logfile, format, ap); - fflush(logfile); - } - va_end(ap); -} - -void log_merge(int logdepth, const char *fn) -{ - FILE *f; - char line[2048]; - int lines; - - if (logfile == NULL) - return; - - f = fopen(fn, "r"); - if (f == NULL) { - logprintf(logdepth, "scconfig error: couldn't open %s for merging.\n", fn); - return; - } - lines = 0; - while(!(feof(f))) { - *line = '\0'; - fgets(line, sizeof(line), f); - if (*line != '\0') { - if (lines == 0) - logprintf(logdepth, "========= output dump start ============\n"); - lines++; - logprintf(logdepth, "%s", line); - /* Make sure we have newline at the end of each line */ - if (line[strlen(line)-1] != '\n') - logprintf(0, "\n"); - } - } - if (lines == 0) - logprintf(logdepth, "========= empty stderr =================\n"); - else - logprintf(logdepth, "========= output dump end ==============\n"); - fclose(f); -} diff --git a/scconfig/src/default/.svn/pristine/bb/bbac4df25f24efcf5daa2f38486551a16b7e9d80.svn-base b/scconfig/src/default/.svn/pristine/bb/bbac4df25f24efcf5daa2f38486551a16b7e9d80.svn-base deleted file mode 100644 index 12664fc9..00000000 --- a/scconfig/src/default/.svn/pristine/bb/bbac4df25f24efcf5daa2f38486551a16b7e9d80.svn-base +++ /dev/null @@ -1,332 +0,0 @@ -/* - scconfig - library functions for compiling and running test code - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include -#include "log.h" -#include "libs.h" -#include "db.h" -#include "dep.h" - -/* -#define KEEP_TEST_SRCS -*/ - -int cross_blind = 0; - - -static char *clone_flags(const char *input, const char *node) -{ - char *output; - const char *s; - int len; - - if (input != NULL) { - if (*input == '+') { - s = get(node); - if (s != NULL) { - len = strlen(s); - output = malloc(len + strlen(input) + 4); - memcpy(output, s, len); - output[len] = ' '; - strcpy(output + len + 1, input + 1); - } - else - output = strclone(input); - } - else - output = strclone(input); - } - else { - s = get(node); - if (s != NULL) - output = strclone(s); - else - output = strclone(""); - } - return output; -} - -int compile_file_raw(int logdepth, const char *fn_input, char **fn_output, const char *cc, const char *cflags, const char *ldflags) -{ - char cmd[2048]; - char *cc_esc, *fn_input_esc, *fn_output_esc, *temp_out_esc, *temp_out; - int ret; - - temp_out = tempfile_new(".out"); - - if (*fn_output == NULL) - *fn_output = tempfile_new(get("sys/ext_exe")); - else - *fn_output = tempfile_new(*fn_output); - unlink(*fn_output); - - cc_esc = shell_escape_dup(cc == NULL ? get("cc/cc") : cc); - fn_input_esc = shell_escape_dup(fn_input); - fn_output_esc = shell_escape_dup(*fn_output); - temp_out_esc = shell_escape_dup(temp_out); - - sprintf(cmd, "%s \"%s %s %s %s -o %s 2>&1\" >%s", get("/host/sys/shell"), cc_esc, cflags, fn_input_esc, ldflags, fn_output_esc, temp_out_esc); - - free(cc_esc); - free(fn_input_esc); - free(fn_output_esc); - free(temp_out_esc); - - logprintf(logdepth, "compile: '%s'\n", cmd); - ret = system(cmd); - log_merge(logdepth + 1, temp_out); -#ifndef KEEP_TEST_SRCS - unlink(temp_out); -#endif - free(temp_out); - logprintf(logdepth, "compile result: %d\n", ret); - - return ret; -} - -int compile_file(int logdepth, const char *fn_input, char **fn_output, const char *cc, const char *cflags, const char *ldflags) -{ - int ret; - char *ldflags_, *cflags_; - - cflags_ = clone_flags(cflags, "cc/cflags"); - ldflags_ = clone_flags(ldflags, "cc/ldflags"); - - ret = compile_file_raw(logdepth, fn_input, fn_output, cc, cflags_, ldflags_); - - free(cflags_); - free(ldflags_); - - return ret; -} - -int compile_code(int logdepth, const char *testcode, char **fn_output, const char *cc, const char *cflags, const char *ldflags) -{ - char *temp_in; - int ret; - - require("sys/ext_exe", logdepth, 1); - - assert(testcode != NULL); - assert(fn_output != NULL); - - temp_in = tempfile_dump(testcode, ".c"); - ret = compile_file(logdepth, temp_in, fn_output, cc, cflags, ldflags); -#ifndef KEEP_TEST_SRCS - unlink(temp_in); -#endif - free(temp_in); - - return ret; -} - -int compile_code_raw(int logdepth, const char *testcode, char **fn_output, const char *cc, const char *cflags, const char *ldflags) -{ - char *temp_in; - int ret; - - require("sys/ext_exe", logdepth, 1); - - assert(testcode != NULL); - assert(fn_output != NULL); - - temp_in = tempfile_dump(testcode, ".c"); - ret = compile_file_raw(logdepth, temp_in, fn_output, cc, cflags, ldflags); -#ifndef KEEP_TEST_SRCS - unlink(temp_in); -#endif - free(temp_in); - - return ret; -} - -char *shell_escape_dup(const char *in) -{ - char *o, *out; - const char *i; - const char *esc = get("sys/shell_escape_char"); - - /* in the early phase, before detecting the shell, this happens */ - if (esc == NULL) - return strclone(in); - - out = malloc(strlen(in)*2+1); - for(i = in, o = out; *i != '\0'; i++) { - if (*i == *esc) { - *o++ = *esc; - } - else if (!isalnum(*i)) { - switch(*i) { - case '/': - case '_': - case '-': - case '.': - break; - default: - *o++ = *esc; - } - } - *o++ = *i; - } - *o = '\0'; - return out; -} - -int run(int logdepth, const char *cmd_, char **stdout_saved) -{ - char *cmd; - char *fn_out, *temp_out; - char *fn_out_esc, *temp_out_esc; - int ret; - const char *emu; - - assert(cmd_ != NULL); - - /* blind cross compiling mode means we always assume success */ - if (cross_blind) { - if (stdout_saved != NULL) - *stdout_saved = NULL; - return 0; - } - - emu = get("sys/emu"); - - /* emu == NULL means we need an emulator but we don't have one and - we should pretend everything went well (and of course can't provide - output.) */ - if (emu == NULL) { - if (stdout_saved != NULL) - *stdout_saved = NULL; - return 0; - } - - /* emu == false means we need an emulator and we don't want to pretend -> fatal */ - if (strcmp(emu, sfalse) == 0) { - error("Trying to run unavailable emulator (db_cwd='%s')\n", db_cwd); - abort(); - } - - temp_out = tempfile_new(".out"); - fn_out = tempfile_new(""); - - temp_out_esc = shell_escape_dup(temp_out); - fn_out_esc = shell_escape_dup(fn_out); - cmd = malloc(strlen(emu) + strlen(cmd_) + strlen(fn_out_esc) + strlen(temp_out_esc) + 32); - sprintf(cmd, "%s %s >%s 2>>%s", emu, cmd_, fn_out_esc, temp_out_esc); - free(temp_out_esc); - free(fn_out_esc); - - logprintf(logdepth, "run: '%s'\n", cmd); - ret = system(cmd); - log_merge(logdepth + 1, temp_out); - unlink(temp_out); - free(temp_out); - logprintf(logdepth, "run result: %d\n", ret); - free(cmd); - - if (stdout_saved != NULL) { - if (ret == 0) { - *stdout_saved = load_file(fn_out); - logprintf(logdepth, "stdout: '%s'\n", *stdout_saved); - } - else - *stdout_saved = NULL; - } - - unlink(fn_out); - free(fn_out); - return ret; -} - -int run_shell(int logdepth, const char *cmd_, char **stdout_saved) -{ - int ret; - char *cmd, *cmd_esc; - const char *emu; - const char *shell; - - emu = get("sys/emulator"); - if (emu == NULL) - emu = ""; - - shell = get("sys/shell"); - if (shell == NULL) { - error("No shell was specified (db_cwd='%s')\n", db_cwd); - abort(); - } - - cmd_esc = shell_escape_dup(cmd_); - cmd = malloc(strlen(emu) + strlen(shell) + strlen(cmd_esc) + 16); - if (istrue(get("sys/shell_needs_quote"))) - sprintf(cmd, "%s %s \"%s\"", emu, shell, cmd_); - else - sprintf(cmd, "%s %s %s", emu, shell, cmd_); - free(cmd_esc); - - ret = run(logdepth, cmd, stdout_saved); - free(cmd); - return ret; -} - - -int compile_run(int logdepth, const char *testcode, const char *cc, const char *cflags, const char *ldflags, char **stdout_saved) -{ - int ret; - char *fn_output = NULL; - - ret = compile_code(logdepth+1, testcode, &fn_output, cc, cflags, ldflags); - - if (ret == 0) { - char *fn_output_esc = shell_escape_dup(fn_output); - ret = run(logdepth+1, fn_output_esc, stdout_saved); - free(fn_output_esc); - } - - if (fn_output != NULL) { - unlink(fn_output); - free(fn_output); - } - return ret; -} - -int run_script(int logdepth, const char *interpreter, const char *script, const char *suffix, char **out) -{ - char *temp, *cmd; - int res; - - temp = tempfile_dump(script, suffix); - cmd = malloc(strlen(temp) + strlen(interpreter) + 4); - sprintf(cmd, "%s %s", interpreter, temp); - - res = run(logdepth, cmd, out); - - unlink(temp); - free(temp); - free(cmd); - return res; -} - diff --git a/scconfig/src/default/.svn/pristine/be/be815a673c7fbf3870d8ea4ec2e8fcfa09a678ae.svn-base b/scconfig/src/default/.svn/pristine/be/be815a673c7fbf3870d8ea4ec2e8fcfa09a678ae.svn-base deleted file mode 100644 index 879b59c6..00000000 --- a/scconfig/src/default/.svn/pristine/be/be815a673c7fbf3870d8ea4ec2e8fcfa09a678ae.svn-base +++ /dev/null @@ -1,173 +0,0 @@ -/* cc */ -int find_cc(const char *name, int logdepth, int fatal); -int find_cc_argstd(const char *name, int logdepth, int fatal); -int find_cc_argmachine(const char *name, int logdepth, int fatal); -int find_cc_fpie(const char *name, int logdepth, int fatal); -int find_cc_fnopie(const char *name, int logdepth, int fatal); -int find_cc_fnopic(const char *name, int logdepth, int fatal); -int find_inline(const char *name, int logdepth, int fatal); -int find_varargmacro(const char *name, int logdepth, int fatal); -int find_funcmacro(const char *name, int logdepth, int fatal); -int find_constructor(const char *name, int logdepth, int fatal); -int find_destructor(const char *name, int logdepth, int fatal); -int find_fattr_unused(const char *name, int logdepth, int fatal); -int find_declspec_dllimport(const char *name, int logdepth, int fatal); -int find_declspec_dllexport(const char *name, int logdepth, int fatal); -int find_rdynamic(const char *name, int logdepth, int fatal); -int find_soname(const char *name, int logdepth, int fatal); -int find_so_undefined(const char *name, int logdepth, int fatal); -int find_wlrpath(const char *name, int logdepth, int fatal); -int find_cc_wloutimplib(const char *name, int logdepth, int fatal); -int find_cc_wloutputdef(const char *name, int logdepth, int fatal); -int find_fpic(const char *name, int logdepth, int fatal); -int find_ldflags_dynlib(const char *name, int logdepth, int fatal); -int find_ldflags_dll(const char *name, int logdepth, int fatal); -int find_ldflags_so(const char *name, int logdepth, int fatal); -int find_alloca(const char *name, int logdepth, int fatal); -int find__exit(const char *name, int logdepth, int fatal); -int find_cc_pragma_message(const char *name, int logdepth, int fatal); -int find_cc_static_libgcc(const char *name, int logdepth, int fatal); - -/* libs */ -int find_lib_ldl(const char *name, int logdepth, int fatal); -int find_lib_LoadLibrary(const char *name, int logdepth, int fatal); -int find_lib_errno(const char *name, int logdepth, int fatal); - -/* thread */ -int find_lib_lpthread(const char *name, int logdepth, int fatal); -int find_thread_semget(const char *name, int logdepth, int fatal); -int find_thread_pthread_create(const char *name, int logdepth, int fatal); -int find_thread_CreateSemaphore(const char *name, int logdepth, int fatal); -int find_thread_CreateThread(const char *name, int logdepth, int fatal); - -/* fscalls */ -int find_fs_realpath(const char *name, int logdepth, int fatal); -int find_fs__fullpath(const char *name, int logdepth, int fatal); -int find_fs_readdir(const char *name, int logdepth, int fatal); -int find_fs_findnextfile(const char *name, int logdepth, int fatal); -int find_fs_access(const char *name, int logdepth, int fatal); -int find_fs_access_macros(const char *name, int logdepth, int fatal); -int find_fs_stat_macros(const char *name, int logdepth, int fatal); -int find_fs_stat_fields(const char *name, int logdepth, int fatal); -int find_fs_lstat(const char *name, int logdepth, int fatal); -int find_fs_statlstat(const char *name, int logdepth, int fatal); -int find_fs_getcwd(const char *name, int logdepth, int fatal); -int find_fs__getcwd(const char *name, int logdepth, int fatal); -int find_fs_getwd(const char *name, int logdepth, int fatal); -int find_fs_mkdir(const char *name, int logdepth, int fatal); -int find_fs__mkdir(const char *name, int logdepth, int fatal); -int find_fs_mkdtemp(const char *name, int logdepth, int fatal); -int find_fs_mmap(const char *name, int logdepth, int fatal); -int find_fsmount_next_dev(const char *name, int logdepth, int fatal); -int find_fsmount_fsstat_fields(const char *name, int logdepth, int fatal); -int find_fsmount_statfs_fields(const char *name, int logdepth, int fatal); -int find_fsmount_statvfs_fields(const char *name, int logdepth, int fatal); -int find_fs_ustat(const char *name, int logdepth, int fatal); -int find_fs_statfs(const char *name, int logdepth, int fatal); -int find_fs_statvfs(const char *name, int logdepth, int fatal); -int find_fs_flock(const char *name, int logdepth, int fatal); -int find_fs_makedev(const char *name, int logdepth, int fatal); - -/* printf */ -int find_printf_x(const char *name, int logdepth, int fatal); -int find_printf_ptrcast(const char *name, int logdepth, int fatal); -int find_snprintf(const char *name, int logdepth, int fatal); -int find_dprintf(const char *name, int logdepth, int fatal); -int find_vdprintf(const char *name, int logdepth, int fatal); -int find_vsnprintf(const char *name, int logdepth, int fatal); - -/* proc */ -int find_proc__spawnvp(const char *name, int logdepth, int fatal); -int find_proc_fork(const char *name, int logdepth, int fatal); -int find_proc_wait(const char *name, int logdepth, int fatal); -int find_proc__getpid(const char *name, int logdepth, int fatal); -int find_proc_CreateProcessA(const char *name, int logdepth, int fatal); -int find_proc_getexecname(const char *name, int logdepth, int fatal); -int find_proc_GetModuleFileNameA(const char *name, int logdepth, int fatal); -int find_proc_shmget(const char *name, int logdepth, int fatal); -int find_proc_CreateFileMappingA(const char *name, int logdepth, int fatal); - -/* fstools */ -int find_fstools_cp(const char *name, int logdepth, int fatal); -int find_fstools_ln(const char *name, int logdepth, int fatal); -int find_fstools_mv(const char *name, int logdepth, int fatal); -int find_fstools_rm(const char *name, int logdepth, int fatal); -int find_fstools_mkdir(const char *name, int logdepth, int fatal); -int find_fstools_ar(const char *name, int logdepth, int fatal); -int find_fstools_ranlib(const char *name, int logdepth, int fatal); -int find_fstools_awk(const char *name, int logdepth, int fatal); -int find_fstools_cat(const char *name, int logdepth, int fatal); -int find_fstools_sed(const char *name, int logdepth, int fatal); -int find_fstools_file(const char *name, int logdepth, int fatal); -int find_fstools_file_l(const char *name, int logdepth, int fatal); -int find_fstools_chmodx(const char *name, int logdepth, int fatal); - -/* uname */ -int find_uname(const char *name, int logdepth, int fatal); -int find_triplet(const char *name, int logdepth, int fatal); -int find_sysid(const char *name, int logdepth, int fatal); - -/* find_target */ -int find_target(const char *name, int logdepth, int fatal); - -/* filelist */ -int find_filelist(const char *name, int logdepth, int fatal); - -/* find_str.c */ -int find_strcasecmp(const char *name, int logdepth, int fatal); -int find_strncasecmp(const char *name, int logdepth, int fatal); -int find_stricmp(const char *name, int logdepth, int fatal); -int find_strnicmp(const char *name, int logdepth, int fatal); - -/* find_sys.c */ -int find_sys_ptrwidth(const char *name, int logdepth, int fatal); -int find_sys_byte_order(const char *name, int logdepth, int fatal); -int find_tmp(const char *name, int logdepth, int fatal); -int find_shell(const char *name, int logdepth, int fatal); - -/* find_io.c */ -int find_io_pipe(const char *name, int logdepth, int fatal); -int find_io_dup2(const char *name, int logdepth, int fatal); -int find_io_fileno(const char *name, int logdepth, int fatal); -int find_io_lseek(const char *name, int logdepth, int fatal); -int find_io_popen(const char *name, int logdepth, int fatal); - -/* find_time.c */ -int find_time_usleep(const char *name, int logdepth, int fatal); -int find_time_Sleep(const char *name, int logdepth, int fatal); -int find_time_gettimeofday(const char *name, int logdepth, int fatal); -int find_time_ftime(const char *name, int logdepth, int fatal); -int find_time_timegm(const char *name, int logdepth, int fatal); -int find_time_mkgmtime(const char *name, int logdepth, int fatal); -int find_time_gmtime_s(const char *name, int logdepth, int fatal); -int find_time_gmtime_r(const char *name, int logdepth, int fatal); -int find_time_localtime_s(const char *name, int logdepth, int fatal); -int find_time_localtime_r(const char *name, int logdepth, int fatal); - -/* find_types.c */ -int find_types_stdint(const char *name, int logdepth, int fatal); -int find_types_sizes(const char *name, int logdepth, int fatal); -int find_types_size_t(const char *name, int logdepth, int fatal); -int find_types_off_t(const char *name, int logdepth, int fatal); -int find_types_off64_t(const char *name, int logdepth, int fatal); -int find_types_gid_t(const char *name, int logdepth, int fatal); -int find_types_uid_t(const char *name, int logdepth, int fatal); -int find_types_pid_t(const char *name, int logdepth, int fatal); -int find_types_dev_t(const char *name, int logdepth, int fatal); -int find_types_dev_t(const char *name, int logdepth, int fatal); -int find_types_mode_t(const char *name, int logdepth, int fatal); -int find_types_nlink_t(const char *name, int logdepth, int fatal); -int find_types_ptrdiff_t(const char *name, int logdepth, int fatal); -int find_types_dev_t(const char *name, int logdepth, int fatal); -int find_types_ino_t(const char *name, int logdepth, int fatal); -int find_types_void_ptr(const char *name, int logdepth, int fatal); - -/* find_signal.c */ -int find_signal_names(const char *name, int logdepth, int fatal); -int find_signal_raise(const char *name, int logdepth, int fatal); - -/* environ.c */ -int find_main_arg3(const char *name, int logdepth, int fatal); -int find_putenv(const char *name, int logdepth, int fatal); -int find_setenv(const char *name, int logdepth, int fatal); -int find_environ(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/default/.svn/pristine/c0/c00231df84c4932716a328201f1bedcaadbd308d.svn-base b/scconfig/src/default/.svn/pristine/c0/c00231df84c4932716a328201f1bedcaadbd308d.svn-base deleted file mode 100644 index 2a6993d2..00000000 --- a/scconfig/src/default/.svn/pristine/c0/c00231df84c4932716a328201f1bedcaadbd308d.svn-base +++ /dev/null @@ -1,58 +0,0 @@ -/* - scconfig - glue layer for proper crosscompiling to target - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include "db.h" -#include "libs.h" - -int find_target(const char *name, int logdepth, int fatal) -{ - const char *target = get("/arg/sys/target"); - const char *emu = get("/arg/sys/emu"); - - (void) logdepth; /* to suppress compiler warnings about not using logdepth */ - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - /* Does target differ from host? */ - if (target == NULL) { - db_link("/host", "/target"); -#ifdef RUNTIME - db_link("/host", "/runtime"); -#endif - put("/target/sys/cross", sfalse); - put("/target/sys/cross_blind", sfalse); - return 0; - } - else - db_mkdir("/target"); - - put("/target/sys/target", target); - put("/target/sys/cross", strue); - if (emu != NULL) - put("/target/sys/emu", emu); - - /* If so, check if emulator is provided */ - cross_blind = ((emu == NULL) || (*emu == '\0')); - put("/target/sys/cross_blind", cross_blind ? strue : sfalse); - - return 0; -} diff --git a/scconfig/src/default/.svn/pristine/cb/cb2a7c706d66573c8facacdbdcfa514d5bb054e3.svn-base b/scconfig/src/default/.svn/pristine/cb/cb2a7c706d66573c8facacdbdcfa514d5bb054e3.svn-base deleted file mode 100644 index 6bf1d826..00000000 --- a/scconfig/src/default/.svn/pristine/cb/cb2a7c706d66573c8facacdbdcfa514d5bb054e3.svn-base +++ /dev/null @@ -1,355 +0,0 @@ -/* - scconfig - evaluate uname and classify the system - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "regex.h" -#include "log.h" -#include "db.h" -#include "libs.h" -#include "dep.h" - -static void sys_unix(void) -{ - put("sys/ext_exe", ""); - put("sys/ext_dynlib", ".so"); - put("sys/ext_stalib", ".a"); - put("sys/ext_dynlib_native", ".so"); -} - -static void sys_netbsd(void) -{ - sys_unix(); - put("cc/ldflags", "-Wl,-R/usr/pkg/lib -L/usr/pkg/lib"); /* TODO: is this the best way? */ -} - -static void sys_win32dlc(void) -{ - put("sys/ext_exe", ".exe"); - put("sys/ext_dynlib", ".dlc"); - put("sys/ext_stalib", ".a"); - put("sys/ext_dynlib_native", ".dll"); -} - -typedef void (*callback_t)(void); - -typedef struct { - char *uname_regex; - char *name; - char *class; - - callback_t callback; -} uname_t; - -typedef struct { - char *file_name; - char *name; - char *class; - - callback_t callback; -} magic_file_t; - -/* Guess system class by uname; class is informative, nothing important - should depend on it. - Order *does* matter */ -uname_t unames[] = { - {"[Nn]et[Bb][Ss][Dd]", "NetBSD", "UNIX", sys_netbsd}, - {"[Ll]inux", "Linux", "UNIX", sys_unix}, - {"[Bb][Ss][Dd]", "BSD", "UNIX", sys_unix}, - {"SunOS", "SunOS", "UNIX", sys_unix}, - {"OSF1", "OSF", "UNIX", sys_unix}, /* TODO: note the difference in cflags for debugging ("-ms -g") */ - {"IRIX", "IRIX", "UNIX", sys_unix}, - {"SunOS", "SunOS", "UNIX", sys_unix}, - {"[Mm]inix", "Minix", "UNIX", sys_unix}, - {"[Aa][Rr][Oo][Ss]", "Aros", "UNIX", sys_unix}, - {"^Darwin", "MacOSX", "UNIX", sys_unix}, - {"[Th]hreos", "Threos", "UNIX", sys_unix}, - {"[Cc]ygwin", "cygwin", "WIN32", sys_win32dlc}, - {"[Mm][Ii][Nn][Gg][Ww]", "mingw", "WIN32", sys_win32dlc}, - {"win32", "win32", "WIN32", sys_win32dlc}, /* vanilla windows */ - {NULL, NULL, NULL, NULL} -}; - -/* Fallback: extract machine name from uname -a if uname -m fails */ -static const char *machine_names[] = { - "i[0-9]86[^ ]*", "x86_[^ ]*", "amd[0-9]*", "armv[0-9][^ ]*", "ppc[0-9]+", - "sparc[0-9]*", "BePC", "ia64", "x86", "IP[0-9]*", "k1om", "sun4u", - "RM600", "R4000", "alpha", - NULL -}; - -/* Fallback: extract system name from uname -a if uname -s fails */ -static const char *system_names[] = { - "[Ll]inux", "sn5[0-9]*", "CYGWIN_NT[^ ]*", "GNU[^ ]*", "DragonFly", - "[^ ]*BSD[^ ]*", "Haiku", "HP-UX", "AIX", "OS4000", "Interix", - "IRIX[0-9]*", "Darwin", "Minix", "MINGW[^ ]*", "ReliantUNIX[^ ]*", - "SunOS", "OSF1", "ULTRIX", "UWIN-W7", "IS/WB", "OS/390", - "SCO[^ ]*", "QNX", - NULL -}; - -/* Fallback: if uname -a fails, guess system by looking at "magic file names" */ -magic_file_t magic_files[] = { - {"/dev/null", "UNIX", "UNIX", sys_unix}, - {"c:\\config.sys", "win32", "WIN32", sys_win32dlc}, - {"c:\\windows\\system.ini", "win32", "WIN32", sys_win32dlc}, - {"c:\\windows\\win.ini", "win32", "WIN32", sys_win32dlc}, - {"c:\\windows\\notepad.exe", "win32", "WIN32", sys_win32dlc}, - {NULL, NULL, NULL, NULL} -} ; - -static int match(const char *regex, const char *str) -{ - re_comp(regex); - return re_exec(str); -} - -/* match uname against each pattern on the list; on a match, put() the portion - of the string matched in node and return 1 */ -int uname_guess(const char *node, const char *uname, const char *list[]) -{ - const char **l; - if (uname == NULL) - return 0; - for(l = list; *l != NULL; l++) { - if (match(*l, uname)) { - char *s; - int len = eopat[0] - bopat[0]; - s = malloc(len+1); - memcpy(s, bopat[0], len); - s[len] = '\0'; - put(node, s); - return 1; - } - } - return 0; -} - -/* Don't worry about linear search or matching regexes all the time - this - function will be run at most two times */ -static callback_t lookup_uname(char **uname, const char **name, const char **class) -{ - uname_t *u; - for(u = unames; u->uname_regex != NULL; u++) { - if ( - ((*uname != NULL) && (match(u->uname_regex, *uname))) /* uname match */ - || ((*name != NULL) && ((strcmp(u->name, *name) == 0))) /* name match */ - || ((*class != NULL) && ((strcmp(u->class, *class) == 0))) /* class match */ - ) { - if (*name == NULL) *name = u->name; - if (*class == NULL) *class = u->class; - return u->callback; - } - } - return NULL; -} - -static callback_t lookup_magic_file(int logdepth, const char **name, const char **class) -{ - magic_file_t *u; - for(u = magic_files; u->file_name != NULL; u++) { - if (is_file(u->file_name)) { - logprintf(logdepth, "%s -> %s\n", u->file_name, u->class); - - if (*name == NULL) *name = u->name; - if (*class == NULL) *class = u->class; - return u->callback; - } - } - return NULL; -} - -int find_uname(const char *rname, int logdepth, int fatal) -{ - const char *name, *class, *tname, *uname_orig; - char *s, *uname, *mname, *sname; - void (*callback)(void); - - require("sys/tmp", logdepth, fatal); - - if (istarget(db_cwd)) - require("/target/sys/target", logdepth, fatal); - - report("Checking for system type... "); - logprintf(logdepth, "[find_uname] checking for sys/name\n"); - logdepth++; - - tname = get("/arg/sys/target-name"); - if (istarget(db_cwd) && (tname != NULL)) - put("sys/name", tname); - - tname = get("/arg/sys/target-uname"); - if (istarget(db_cwd) && (tname != NULL)) - put("sys/uname", tname); - - name = get("sys/name"); - uname_orig = get("sys/uname"); - - if (name == NULL) { - if (uname_orig == NULL) { - logprintf(logdepth, "not set, running\n"); - run_shell(logdepth, "uname -a", (char **)&uname); - if (uname != NULL) { - for(s = uname; *s != '\0'; s++) - if ((*s == '\n') || (*s == '\r')) *s = ' '; - put("sys/uname", uname); - } - else - put("sys/uname", ""); - - if (run_shell(logdepth, "uname -m", (char **)&mname) == 0) - put("sys/machine_name", strip(mname)); - else - put("sys/machine_name", NULL); - - if (mname != NULL) - free(mname); - - if (run_shell(logdepth, "uname -o", (char **)&sname) == 0) - put("sys/system_name", strip(sname)); - else if (run_shell(logdepth, "uname -s", (char **)&sname) == 0) - put("sys/system_name", strip(sname)); - else - put("sys/system_name", NULL); - if (sname != NULL) - free(sname); - } - - /* we have uname by now, set sys/name */ - name = NULL; - class = NULL; - callback = lookup_uname(&uname, &name, &class); - if (name == NULL) { - /* no uname or unknown system by uname - fallback: check for cross target */ - const char *target = get("/arg/sys/target"); - if ((target != NULL) && (strstr(target, "mingw") != NULL)) { - name = "WIN32"; - report("(detected mingw cross compilation to WIN32)\n"); - } - else { - report("Warning: unknown system\n"); - name = "unknown"; - } - } - put("sys/name", name); - } - else { - /* we had sys/name, that should be enough */ - uname = NULL; - class = name; - callback = lookup_uname(&uname, &name, &class); - } - - /* predefined and/or detected uname failed, try magic file method */ - if (callback == NULL) { - logprintf(logdepth, "System class is unknown by uname, running heuristics...\n"); - report("System class is unknown by uname, running heuristics... "); - - callback = lookup_magic_file(logdepth + 1, &name, &class); - } - - - if (callback == NULL) { - /* System unknown. */ - error("Unknown system '%s'\n", get("sys/uname")); - abort(); - } - - callback(); - report("OK (name: %s; class: %s)\n", name, class); - put("sys/class", class); - - /* fallbacks */ - if (get("sys/machine_name") == NULL) - uname_guess("sys/machine_name", uname, machine_names); - - if (get("sys/system_name") == NULL) - uname_guess("sys/system_name", uname, system_names); - - /* on windows, overwrite the path sep with the right amount of \ (the tmp finder may have left / in it) */ - if (strcmp(class, "WIN32") == 0) { - int eats = istrue(get("sys/shell_eats_backslash")); - - if (eats) - put("sys/path_sep", "\\\\\\\\"); - else - put("sys/path_sep", "\\"); - } - - return 0; -} - -static int find_triplet_(const char *name, int logdepth, int fatal, const char *nodename, int include_vendor, char *sep, char *esc) -{ - const char *machine, *vendor, *os; - char *triplet, *s; - char fake_sep[2]; - - fake_sep[0] = 1; - fake_sep[1] = 0; - - require("sys/uname", logdepth, fatal); - - machine = get("sys/machine_name"); - if (machine == NULL) - machine = "unknown"; - - vendor = "unknown"; - - os = get("sys/system_name"); - if (os == NULL) - os = "unknown"; - - if (include_vendor) - triplet = str_concat(fake_sep, machine, vendor, os, NULL); - else - triplet = str_concat(fake_sep, machine, os, NULL); - - for(s = triplet; *s != '\0'; s++) { - if ((esc != NULL) && (*s == *sep)) - *s = *esc; - if (isalnum(*s)) - *s = tolower(*s); - else { - if (*s == *fake_sep) - *s = *sep; - else if (esc != NULL) - *s = *esc; - else - *s = '-'; - } - } - put(nodename, triplet); - free(triplet); - return 0; -} - -int find_triplet(const char *name, int logdepth, int fatal) -{ - return find_triplet_(name, logdepth, fatal, "sys/triplet", 1, "-", NULL); -} - -int find_sysid(const char *name, int logdepth, int fatal) -{ - return find_triplet_(name, logdepth, fatal, "sys/sysid", 0, "-", "_"); -} diff --git a/scconfig/src/default/.svn/pristine/cc/cc2cc22b97db928b05ae83e1b83ab9aa0d04f561.svn-base b/scconfig/src/default/.svn/pristine/cc/cc2cc22b97db928b05ae83e1b83ab9aa0d04f561.svn-base deleted file mode 100644 index 96d826de..00000000 --- a/scconfig/src/default/.svn/pristine/cc/cc2cc22b97db928b05ae83e1b83ab9aa0d04f561.svn-base +++ /dev/null @@ -1,33 +0,0 @@ -/* Runs when a custom command line argument is found - returns true if no further argument processing should be done */ -int hook_custom_arg(const char *key, const char *value); - -/* If any of the int hooks return non-zero, that means failure and stops - the whole process */ - -/* Runs before anything else */ -int hook_preinit(void); - -/* Runs after initialization */ -int hook_postinit(void); - -/* Runs after all arguments are read and parsed */ -int hook_postarg(void); - -/* Runs when things should be detected for the host system (tools compiled for and/or run on compilation host) */ -int hook_detect_host(void); - -/* Runs when things should be detected for the target system (tools compiled on the compilation host but running on the target)*/ -int hook_detect_target(void); - -/* Runs when things should be detected for the runtime system (tools that will run only on the target, production runtime, not during compilation or installation) */ -int hook_detect_runtime(void); - -/* Runs after detection hooks, should generate the output (Makefiles, etc.) */ -int hook_generate(void); - -/* Runs before everything is uninitialized */ -void hook_preuninit(void); - -/* Runs at the very end, when everything is already uninitialized */ -void hook_postuninit(void); diff --git a/scconfig/src/default/.svn/pristine/cd/cd6dfcf85e7ef1f23d97a27997080de8dce354c9.svn-base b/scconfig/src/default/.svn/pristine/cd/cd6dfcf85e7ef1f23d97a27997080de8dce354c9.svn-base deleted file mode 100644 index 4d5e97fe..00000000 --- a/scconfig/src/default/.svn/pristine/cd/cd6dfcf85e7ef1f23d97a27997080de8dce354c9.svn-base +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -#define max_spaces 64 -extern char *spaces; - -#define logprefix(n) (((n) > max_spaces) ? spaces : (spaces+max_spaces-(n))) - -void logprintf(int depth, const char *format, ...); -void error(const char *format, ...); -void report(const char *format, ...); - -void log_merge(int logdepth, const char *fn); - -extern FILE *logfile; -extern void log_init(void); -void log_uninit(void); - -extern char *fn_log; diff --git a/scconfig/src/default/.svn/pristine/cd/cdfe161ff62e86603e9e943ba0a3699a6d004b20.svn-base b/scconfig/src/default/.svn/pristine/cd/cdfe161ff62e86603e9e943ba0a3699a6d004b20.svn-base deleted file mode 100644 index 4df90631..00000000 --- a/scconfig/src/default/.svn/pristine/cd/cdfe161ff62e86603e9e943ba0a3699a6d004b20.svn-base +++ /dev/null @@ -1,24 +0,0 @@ -#include "ht.h" - -int is_dep_known(const char *name); -int require(const char *name, int logdepth, int fatal); -const char *dep_add(const char *name, int (*finder)(const char *name, int logdepth, int fatal)); -void require_all(int fatal); - -/* Returns if dependency is a wildcard one (ending in / *) */ -int is_dep_wild(const char *path); - -/* Almost 'basename': returns the last portion of the path, which may - be '*'. Returns "" on error. */ -const char *det_list_target(const char *path); - -/* Returns 1 if the user asked for detecting a feature; needtodo is - the first argument passed to the detection function (the target the caller - wants to get detected), cando is the output path of the test that the - detector could do next. */ -int asked_for(const char *cando, const char *needtodo); - -/* for internal use */ -void dep_init(void); -void dep_uninit(void); - diff --git a/scconfig/src/default/.svn/pristine/cf/cfceccbaafb51bb4ad0eedddbd4000ebfb4f8d72.svn-base b/scconfig/src/default/.svn/pristine/cf/cfceccbaafb51bb4ad0eedddbd4000ebfb4f8d72.svn-base deleted file mode 100644 index a249c090..00000000 --- a/scconfig/src/default/.svn/pristine/cf/cfceccbaafb51bb4ad0eedddbd4000ebfb4f8d72.svn-base +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SCC_ARG_H -#define SCC_ARG_H - -#include - -typedef struct { - char *arg; - char *path; - int (*callback)(const char *key, const char *value); - char *help; -} argtbl_t; - -extern argtbl_t main_argument_table[]; - - - -void process_args(int argc, char *argv[]); -void help_default_args(FILE *f, const char *prefix); - - -/* main.c: */ -extern int custom_arg(const char *key, const char *value); -extern int num_custom_reqs; - -#endif diff --git a/scconfig/src/default/.svn/pristine/d1/d13e3d536c5517eb1f9924804d3c9129b392ee91.svn-base b/scconfig/src/default/.svn/pristine/d1/d13e3d536c5517eb1f9924804d3c9129b392ee91.svn-base deleted file mode 100644 index f94eb311..00000000 --- a/scconfig/src/default/.svn/pristine/d1/d13e3d536c5517eb1f9924804d3c9129b392ee91.svn-base +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef SCC_ARG_H -#define SCC_ARG_H - -typedef struct { - char *arg; - char *path; - int (*callback)(const char *key, const char *value); - char *help; -} argtbl_t; - -extern argtbl_t main_argument_table[]; - - - -void process_args(int argc, char *argv[]); - - -/* main.c: */ -extern int custom_arg(const char *key, const char *value); -extern int num_custom_reqs; - -#endif diff --git a/scconfig/src/default/.svn/pristine/d4/d4792c3c26ef93ba62e9d274e5198ff7120e39e8.svn-base b/scconfig/src/default/.svn/pristine/d4/d4792c3c26ef93ba62e9d274e5198ff7120e39e8.svn-base deleted file mode 100644 index 17809f44..00000000 --- a/scconfig/src/default/.svn/pristine/d4/d4792c3c26ef93ba62e9d274e5198ff7120e39e8.svn-base +++ /dev/null @@ -1,77 +0,0 @@ -/* - scconfig - library to explore the source tree - Copyright (C) 2015 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "db.h" -#include "libs.h" -#include "log.h" -#include "dep.h" - - -char *svn_info(int logdepth, const char *dir, const char *key) -{ - char *cmd, *stdo = NULL; - char *res = NULL; - int keylen = strlen(key); - - cmd = str_concat(" ", "svn info", dir, NULL); - if (run_shell(logdepth, cmd, &stdo) == 0) { - char *line, *nline; - - /* check key against each line */ - for(line = stdo; line != NULL; line = nline) { - /* split line */ - nline = strpbrk(line, "\r\n"); - if (nline != NULL) { - *nline = '\0'; - nline++; - while((*nline == '\n') || (*nline == '\r')) nline++; - } - - /* compare key */ - if (strncmp(line, key, keylen) == 0) { - char *val; - - /* extract value */ - val = strchr(line, ':'); - if (val != NULL) { - val++; - while((*val == ' ') || (*val == '\t')) val++; - } - else - val = line; - - /* produce output */ - res = strclone(val); - goto found; - } - } - } - - found:; - if (stdo != NULL) - free(stdo); - free(cmd); - return res; -} diff --git a/scconfig/src/default/.svn/pristine/d5/d52333501e6c867fdaf9dacaa4c3c1a7306a903f.svn-base b/scconfig/src/default/.svn/pristine/d5/d52333501e6c867fdaf9dacaa4c3c1a7306a903f.svn-base deleted file mode 100644 index 79803cfa..00000000 --- a/scconfig/src/default/.svn/pristine/d5/d52333501e6c867fdaf9dacaa4c3c1a7306a903f.svn-base +++ /dev/null @@ -1,491 +0,0 @@ -/* - scconfig - detect features of the system or the host/target computer - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_sys_ptrwidth(const char *name, int logdepth, int fatal) -{ - char *end, W[32]; - char *out = NULL; - int w; - - char *test_c = - NL "#include " - NL "int main() {" - NL " void *ptr;" - NL " printf(\"%d\\n\", sizeof(ptr));" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for pointer width... "); - logprintf(logdepth, "find_sys_ptrwidth: trying to find pointer width...\n"); - logdepth++; - - if (compile_run(logdepth, test_c, NULL, NULL, NULL, &out) == 0) { - w = strtol(out, &end, 10); - if ((*end != '\0') && (*end != '\n') && (*end != '\r')) { - report("FAILED (test code failed)\n"); - logprintf(logdepth+1, "FAILED: returned '%s' which is not a valid decimal number (at '%s')\n", out, end); - return 1; - } - sprintf(W, "%d", w * 8); - report("OK (%s bits)\n", W); - put("sys/ptrwidth", W); - logprintf(logdepth+1, "OK (%s bits)\n", W); - } - return 0; -} - -int find_sys_byte_order(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " long int i = 8;" - NL " char *s = (char *)&i;" - NL " printf(\"%d\\n\", s[0]);" - NL " return 0;" - NL "}" - NL; - const char* test_c_blind_template = - NL "#include " - NL "#include " - NL "#ifndef __BYTE_ORDER" - NL "#error \"ERROR 1\"" - NL "void void *;" - NL "#endif" - NL "#ifndef __%s_ENDIAN" - NL "#error \"ERROR 2\"" - NL "char char *;" - NL "#endif" - NL "#if __BYTE_ORDER != __%s_ENDIAN" - NL "#error \"ERROR 3\"" - NL "int int *;" - NL "#endif" - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *key = "sys/byte_order"; - const char *endians1[] = { "LITTLE", "BIG", NULL }; - const char *endians2[] = { "LSB", "MSB", NULL }; - int index; - char test_c_blind[1024]; - char *end; - const char *W; - char *out = NULL; - int w; - - require("cc/cc", logdepth, fatal); - - report("Checking for byte order... "); - logprintf(logdepth, "find_sys_byte_order: trying to find byte order...\n"); - logdepth++; - - if ((!isblind(db_cwd)) && compile_run(logdepth, test_c, NULL, NULL, NULL, &out) == 0) { - w = strtol(out, &end, 10); - if (((*end != '\0') && (*end != '\n') && (*end != '\r')) || ((w != 0) && (w != 8))) { - report("FAILED (test code failed)\n"); - logprintf(logdepth+1, "FAILED: returned '%s' which is not a valid decimal number (at '%s')\n", out, end); - return 1; - } - if (w == 0) - W = "MSB"; - else - W = "LSB"; - - report("OK (%s first)\n", W); - put("sys/byte_order", W); - logprintf(logdepth+1, "OK (%s first)\n", W); - return 0; - } - - for (index=0; endians1[index]!=NULL; ++index) - { - sprintf(test_c_blind, test_c_blind_template, endians1[index], endians1[index]); - - if (compile_run(logdepth, test_c_blind, NULL, NULL, NULL, NULL) == 0) - { - W = endians2[index]; - report("OK (%s first)\n", W); - put(key, W); - return 0; - } - } - - report("FAILED (cannot determine byte order, you must supply it)\n"); - return try_fail(logdepth, key); -} - -static int test_shell_eats_backslash(int logdepth) -{ - char *test = "echo c:\\n"; - char *out; - - - logprintf(logdepth, "testing if shell eats \\...\n"); - run_shell(logdepth+1, test, &out); - if (out == NULL) { - logprintf(logdepth+1, "oops, couldn't run shell?! (returned NULL)\n"); - report("ERROR: shell fails."); - abort(); - } - if (out[2] == '\\') { - logprintf(logdepth, "shell does NOT eat \\...\n"); - put("sys/shell_eats_backslash", sfalse); - free(out); - return 0; - } - - free(out); - logprintf(logdepth, "shell eats \\...\n"); - put("sys/shell_eats_backslash", strue); - return 1; -} - - -static int try_get_cwd(int logdepth, const char *cmd) -{ - char *cwd, *end; - run_shell(logdepth+1, cmd, &cwd); - if (cwd != NULL) { - end = strpbrk(cwd, "\r\n"); - if (end != NULL) - *end = '\0'; - if (*cwd != '\0') { - end = cwd + strlen(cwd) - 1; - while((*end == ' ') || (*end == '\t')) { *end = '\0'; end--; } - put("sys/tmp", cwd); - /* ugly hack for win32: paths there start as c:\ */ - if ((cwd[1] == ':') && (cwd[2] == '\\')) - append("sys/tmp", "\\"); - else - append("sys/tmp", "/"); - logprintf(logdepth, "cwd is '%s'\n", get("sys/tmp")); - free(cwd); - return 1; - } - else - free(cwd); - } - return 0; -} - -static int try_tmp(int logdepth) -{ - char *fn; - - logprintf(logdepth, "validating temp dir '%s'\n", get("sys/tmp")); - fn = tempfile_new_noabort(""); - if (fn != NULL) { - unlink(fn); - free(fn); - logprintf(logdepth, "temp dir works!\n"); - return 1; - } - - logprintf(logdepth, "temp dir fails\n"); - return 0; -} - -/* test temp dir with all sort of workarounds */ -static int try_tmp_all(int logdepth) -{ - const char *tmp, *si; - char c; - char *t, *so, *old_tmp; - int eats, n; - - tmp = get("sys/tmp"); - - /* path must end in path separator */ - c = tmp[strlen(tmp)-1]; - if ((c != '/') && (c != '\\')) { - append("sys/tmp", "/"); - tmp = get("sys/tmp"); - } - - logprintf(logdepth, "trying detected temp dir '%s'\n", tmp); - if (try_tmp(logdepth+1)) return 1; - - /* try msys-on-windows hack: if path starts with /d/something, try d:/ instead */ - if ((tmp[0] == '/') && (isalpha(tmp[1])) && (tmp[2] == '/')) { - /* for the next test we shouldn't use our half-detected tmp path but go with . */ - old_tmp = strclone(tmp); - put("sys/tmp", ""); - eats = istrue(get("sys/shell_eats_backslash")); - tmp = old_tmp; - logprintf(logdepth, "tmp2='%s' eats=%d\n", tmp, eats); - t = malloc(strlen(tmp) * 2); - t[0] = tmp[1]; - t[1] = ':'; - for(si = tmp + 2, so = t + 2; *si != '\0'; si++, so++) { - if (*si == '/') { - *so = '\\'; - if (eats) { - for(n = 0; n < 3; n++) { - so++; - *so = '\\'; - } - } - } - else - *so = *si; - } - *so = '\0'; - free(old_tmp); - - logprintf(logdepth, "trying windows fix: '%s'\n", t); - put("sys/tmp", t); - free(t); - if (try_tmp(logdepth+1)) { - if (eats) - put("sys/path_sep", "\\\\\\\\"); - else - put("sys/path_sep", "\\"); - return 1; - } - tmp = get("sys/tmp"); - } - - /* fail. Set back tmp to empty so next command has a chance to run */ - put("sys/tmp", ""); - return 0; -} - -int find_tmp(const char *name, int logdepth, int fatal) -{ - const char *usertmp; - - if (in_cross_target) { - report("Temp dir for cross compilation target is the same as for host..."); - logprintf(logdepth, "Copying temp dir from host to target\n"); - require("/host/sys/tmp", logdepth, fatal); - usertmp = get("/host/sys/tmp"); - if (usertmp == NULL) { - report("Host temp dir not found.\n"); - logprintf(logdepth, "Host temp dir not found.\n"); - return 1; - } - put("sys/tmp", usertmp); - return 0; - } - - /* we need shell for later tests; do this detection in . */ - put("sys/tmp", ""); - require("sys/shell", logdepth, fatal); - - put("sys/path_sep", "/"); - - report("Detecting temp dir..."); - logprintf(logdepth, "Finding temp dir (current working directory)...\n"); - - usertmp = get("/arg/sys/tmp"); - - /* . as tmp would fail for commands including a "cd" - this would cause - temporary files left in the target dir. We start out with empty - string (which is ., but on windows ./ would fail), and run - pwd (without cd) to find out the current directory (as getcwd() is not - portable). If pwd fails, we stay with ./ */ - put("sys/tmp", ""); - - /* we need to know about shell backslash problem regardless of how - we end up with tmp - currently tmp is ., where the test could run - safely */ - test_shell_eats_backslash(logdepth+1); - - /* Special case: cross-compilation with emulator; we can not assume - the emulator uses the same paths as the host system, while we mix - accessing files from host and emu. If we stay in ., both emulator - and host system should be (more or less) happy. */ - if (istarget(db_cwd) && iscross) { - if (usertmp == NULL) { - report("using temp dir . for cross-compilation\n"); - logprintf(logdepth, "staying with . for cross-compilation\n"); - } - else { - put("sys/tmp", usertmp); - report("using user supplied temp dir '%s' for cross-compilation\n", usertmp); - logprintf(logdepth, "using user supplied temp dir '%s' for cross-compilation\n", usertmp); - } - return 0; - } - - if ((usertmp != NULL)) - put("sys/tmp", usertmp); - - if ( - ((usertmp != NULL) && (try_tmp_all(logdepth+2))) || /* try user supplied temp dir */ - ((try_get_cwd(logdepth+1, "pwd")) && (try_tmp_all(logdepth+2))) || /* try pwd for finding out cwd */ - ((try_get_cwd(logdepth+1, "echo %cd%") && (try_tmp_all(logdepth+2))))) { /* try windows-specific way for finding out cwd */ - - report(" validated %s\n", get("sys/tmp")); - logprintf(logdepth, "Detected temp dir '%s'\n", get("sys/tmp")); - return 0; - } - - put("sys/tmp", ""); - report("using temp dir fallback .\n"); - logprintf(logdepth, "all temp directories failed, using . as tmp\n"); - return 0; -} - -int test_shell(const char *shell, int logdepth, int quote) -{ - char *test = "echo hello"; - char *cmd; - char *out; - char *q; - - if (quote) - q = "\""; - else - q = ""; - - logprintf(logdepth, "testing '%s' as shell\n", shell); - cmd = malloc(strlen(test) + strlen(shell) + 8); - sprintf(cmd, "%s %s%s%s", shell, q, test, q); - - run(logdepth+1, cmd, &out); - - free(cmd); - - if ((out != NULL) && (strncmp(out, "hello", 5) == 0)) { - put("sys/shell", shell); - if (quote) - put("sys/shell_needs_quote", strue); - else - put("sys/shell_needs_quote", sfalse); - logprintf(logdepth, "accepted.\n"); - free(out); - return 1; - } - - logprintf(logdepth, "refused.\n"); - free(out); - return 0; -} - -static int find_shell_escape(const char *name, int logdepth, int fatal, const char *shell) -{ - char cmdline[256]; - char **t; - char *tests[] = { - "\\", "\\ {}&;|", - "^", "^ &", - NULL, NULL - }; - (void) fatal; /* not used */ - (void) shell; /* not used */ - - report("Looking for a shell escape character... "); - logprintf(logdepth, "finding shell escape character...\n"); - - for(t = tests; *t != NULL; t += 2) { - char *s, *end, *out, *start; - strcpy(cmdline, "echo "); - end = cmdline+5; - for(s = t[1]; *s != '\0'; s++) { - *end++ = *t[0]; - *end++ = *s; - } - *end = '\0'; - run(logdepth+1, cmdline, &out); - if (out != NULL) { - int res; - if (*out == '\"') /* wine likes to wrap the output in quotes for some reason */ - start = out+1; - else - start = out; - - res = strncmp(start, t[1], strlen(t[1])); - free(out); - if (res == 0) { - report("found: '%s'\n", t[0]); - logprintf(logdepth, "found shell escape char '%s'\n", t[0]); - put("sys/shell_escape_char", t[0]); - return 0; - } - } - } - report("NOT FOUND\n"); - logprintf(logdepth, "shell escape character not found\n"); - - return 1; -} - -int find_shell(const char *name, int logdepth, int fatal) -{ - const char *shells[] = { - "/bin/sh -c", - "/bin/bash -c", - "bash -c", - "cmd.exe /c", - "sh -c", - "/bin/dash -c", - "dash -c", - "/bin/ksh -c", - "ksh -c", - NULL - }; - const char **s; - - if (cross_blind) { - const char *shell = get("/arg/sys/target-shell"); - if (shell == NULL) { - report("Need to specify sys/target-shell in blind cross compiling mode, because the shell cannot be detected (note: scconfig will not attempt to run the target shell)\n"); - exit(1); - } - - put("sys/shell", shell); - report("Blind cross compiling: accepting '%s' as shell\n", shell); - logprintf(logdepth, "Blind cross compiling: accepting '%s' as shell\n", shell); - return 0; - } - - report("Looking for a shell... "); - logprintf(logdepth, "finding a shell\n"); - - for(s = shells; *s != NULL; s++) { - if ((test_shell(*s, logdepth+1, 0)) || (test_shell(*s, logdepth+1, 1))) { - report("%s\n", *s); - logprintf(logdepth, "found a shell '%s', need quote: %s\n", *s, get("sys/shell_needs_quote")); - return find_shell_escape(name, logdepth, fatal, *s); - } - } - - report("NOT FOUND\n"); - logprintf(logdepth, "shell not found\n"); - return 1; -} diff --git a/scconfig/src/default/.svn/pristine/d6/d601cd96dc16b045dbe85a0623475dd87f07d488.svn-base b/scconfig/src/default/.svn/pristine/d6/d601cd96dc16b045dbe85a0623475dd87f07d488.svn-base deleted file mode 100644 index f1028a8e..00000000 --- a/scconfig/src/default/.svn/pristine/d6/d601cd96dc16b045dbe85a0623475dd87f07d488.svn-base +++ /dev/null @@ -1,227 +0,0 @@ -/* - scconfig - dependencies - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include "dep.h" -#include "db.h" -#include "log.h" -#include "libs.h" - -typedef struct { - int (*fn)(const char *name, int logdepth, int fatal); -} fn_wrap_t; - - -static ht_t *deps = NULL; - - -/* find name_ and decide if it was a wildcard request; - NOTE: there are requests and servers, both can be wildcard independently. - - if a request ends with a / *, it is an explicit wildcard request (*wild=1) - - if a request names a "directory" that is wildcard-server, that's a wildcard request (*wild=1) - - else the request is a normal request (*wild=0). - For normal requests, a required node was explicitly named; if that node is - not created by the detection function, that's a failure. For wildcard - requests we don't look for any specific node to be created. - TODO: we may still check if at least the directory is created - */ -fn_wrap_t *get_wrap(const char *name_, int *wild, int *missing) -{ - fn_wrap_t *w; - char *name, *sep; - int len; - - len = strlen(name_); - *wild = name_[len-1] == '*'; - - if (*wild) { - char *pres; - pres = malloc(len+16); - memcpy(pres, name_, len-1); - strcpy(pres+len-1, "presents"); - *missing = get(pres) == NULL; - if (*missing) { /* if there's no /presents, it may be a non-directory node with an actual non-empty string value */ - const char *val; - pres[len-2] = '\0'; - val = get(pres); - if (val != NULL) - *missing = !strlen(val); - } - free(pres); - if (!(*missing)) /* already detected, won't be detected again */ - return NULL; - } - *missing = 1; - - /* try full match first */ - w = ht_get(deps, name_); - if (w != NULL) - return w; - - - /* try substituting the last part of the path with * for wildcard matches */ - name = malloc(len+3); /* worst case: ends in a / and we need to append *\0; allocate a bit more */ - memcpy(name, name_, len+1); /* make a copy we can modify */ - if (name[len-1] != '/') { - name[len] = '/'; /* append a / - if name_ was a "directory", this will result in name/ * */ - name[len+1] = '\0'; - } - - *wild = 1; /* if we append a / *, then it's a wildcard request */ - for(;;) { - sep = str_rchr(name, '/'); - if (sep == NULL) - goto error; - sep[1] = '*'; - sep[2] = '\0'; - w = ht_get(deps, name); - if (w != NULL) { - free(name); - return w; - } - *sep = '\0'; - *wild = 0; /* cutting back the second layer - not wildcard request anymore, but a request to a specific node served by a wildcard */ - } - - /* no match, exit with error */ - error:; - *wild = 0; - free(name); - return NULL; -} - - -int require(const char *name, int logdepth, int fatal) -{ - fn_wrap_t *w; - int wild, missing; - - if (get(name) == NULL) { - w = get_wrap(name, &wild, &missing); - if (!missing) - return 0; - if ((w == NULL) || (w->fn == NULL)) { - error("Node %s is required but I don't know how to detect it.\n", name); - abort(); - } - - logprintf(logdepth, "(Required node: '%s')\n", name); - if (w->fn(name, logdepth+1, fatal) != 0) { - if (fatal) { - error("Node %s is required but provided detection callback fails to find that feature on that system.\n", name); - abort(); - } - else { - logprintf(logdepth, "(Feature not found, but it is not fatal)"); - return 1; - } - } - if ((!wild) && (get(name) == NULL)) { - error("Node %s is required but provided detection callback didn't create it (looks like an internal error in scconfig). (db_cwd='%s')\n", name, db_cwd); - abort(); - } - } - return 0; -} - -const char *dep_add(const char *name, int (*finder)(const char *name, int logdepth, int fatal)) -{ - fn_wrap_t *w; - w = malloc(sizeof(fn_wrap_t)); - w->fn = finder; - return ht_set(deps, name, w); -} - -int asked_for(const char *cando, const char *needtodo) -{ - int len; - - /* foo/bar/baz matches /foo/bar/baz */ - if (strcmp(cando, needtodo) == 0) - goto yes; - - len = strlen(needtodo); - if (len == 0) - return 0; - - /* foo/bar/baz matches /foo/bar/ * */ - if ((needtodo[len-1] == '*') && (strncmp(cando, needtodo, len-1) == 0)) - goto yes; - - return 0; - - - yes:; /* asked for it, but have to see if it's already detected */ - if (get(cando) != NULL) - return 0; - - return 1; -} - -int is_dep_wild(const char *path) -{ - int len = strlen(path); - if (len == 0) - return 0; - return (path[len-1] == '*'); -} - -const char *det_list_target(const char *path) -{ - const char *res; - - if (path == NULL) - goto unk; - - res = strrchr(path, '/'); - if (res == NULL) - goto unk; - - return res + 1; -unk:; - return ""; -} - - -void dep_init(void) -{ - deps = ht_resize(ht_alloc(0), 128); -} - -void dep_uninit(void) -{ - ht_free(deps); -} - -int is_dep_known(const char *name) -{ - return (ht_get(deps, name) != NULL); -} - -void require_all(int fatal) -{ - ht_entry_t *h; - - for(h = ht_first(deps); h != NULL; h = ht_next(deps, h)) - require(h->key, 0, fatal); -} diff --git a/scconfig/src/default/.svn/pristine/de/deca79672ca296d74fb373d1824179163df52167.svn-base b/scconfig/src/default/.svn/pristine/de/deca79672ca296d74fb373d1824179163df52167.svn-base deleted file mode 100644 index 1aeb782c..00000000 --- a/scconfig/src/default/.svn/pristine/de/deca79672ca296d74fb373d1824179163df52167.svn-base +++ /dev/null @@ -1,318 +0,0 @@ -/* - scconfig - detection of printf-related features - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -static int tryx(int logdepth, const char *test_c, const char *trying, const char *expected) -{ - char *out = NULL; - char buff[512]; - - logprintf(logdepth, "trying '%s'\n", trying); - sprintf(buff, test_c, trying, trying); - if (compile_run(logdepth+1, buff, NULL, NULL, NULL, &out) == 0) { - if (strncmp(out, expected, strlen(expected)) == 0) { - free(out); - return 1; - } - free(out); - } - return 0; -} - -static int tryc(int logdepth, const char *test_c, const char *trying) -{ - char *out = NULL; - char buff[512]; - char *spc, *end; - - logprintf(logdepth, "trying '%s'\n", trying); - sprintf(buff, test_c, trying); - if (compile_run(logdepth+1, buff, NULL, NULL, NULL, &out) == 0) { - spc = str_chr(out, ' '); - if (spc == NULL) - return 0; - *spc = '\0'; - spc++; - end = str_chr(spc, ' '); - if (end == NULL) - return 0; - *end = '\0'; - if (strcmp(out, spc) == 0) { - free(out); - put("libs/printf_ptrcast", trying); - report("OK (%s)\n", trying); - return 1; - } - free(out); - } - return 0; -} - -int find_printf_x(const char *name, int logdepth, int fatal) -{ - const char *pfx; - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " printf(\"'%s%%x'/'%s%%x'\\n\", (size_t)0x1234, NULL);" - NL " return 0;" - NL "}" - NL; - char *expected = "'0x1234'/'0x0'"; - - require("cc/cc", logdepth, fatal); - - report("Checking for printf %%x prefix... "); - logprintf(logdepth, "find_printf_x: trying to find printf %%x prefix...\n"); - logdepth++; - - pfx = get("/arg/libs/printf_x"); - if (pfx == NULL) { - - if (tryx(logdepth, test_c, "", expected)) { - put("libs/printf_x", ""); - report("OK ()\n"); - return 0; - } - if (tryx(logdepth, test_c, "0x", expected)) { - put("libs/printf_x", "0x"); - report("OK (0x)\n"); - return 0; - } - } - else { - report("User provided... "); - if (tryx(logdepth, test_c, pfx, expected)) { - put("libs/printf_x", pfx); - report("OK (%s)\n", pfx); - return 0; - } - } - return 1; -} - -int find_printf_ptrcast(const char *name, int logdepth, int fatal) -{ - const char *cast; - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " printf(\"%%d %%d \\n\", sizeof(void *), sizeof(%s));" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for printf %%x pointer cast... "); - logprintf(logdepth, "find_printf_ptrcast: trying to find printf %%x pointer cast...\n"); - logdepth++; - - cast = get("/arg/libs/printf_ptrcast"); - if (cast == NULL) { - if (tryc(logdepth, test_c, "unsigned int")) return 0; - if (tryc(logdepth, test_c, "unsigned long")) return 0; - if (tryc(logdepth, test_c, "unsigned long long")) return 0; - } - else { - report("User provided... "); - if (tryc(logdepth, test_c, cast)) return 0; - } - return 1; -} - -int find_snprintf(const char *name, int logdepth, int fatal) -{ - char *out; - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " char buff[9];" - NL " char *s = buff+2;" - NL - NL " /* build a fence */" - NL " buff[0] = 0;" - NL " buff[1] = 65;" - NL " buff[7] = 66;" - NL " buff[8] = 0;" - NL - NL " snprintf(s, 4, \"%d\", 123456);" - NL " if ((buff[0] == 0) && (buff[1] == 65) && (buff[7] == 65) && (buff[8] == 0))" - NL " printf(\"%s\\n\", s);" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for snprintf... "); - logprintf(logdepth, "find_snprintf_works: trying to find snprintf...\n"); - logdepth++; - logprintf(logdepth, "trying snprintf...\n"); - - if (compile_run(logdepth+1, test_c, NULL, NULL, NULL, &out) == 0) { - if (cross_blind) { - put("libs/snprintf", strue); - report("OK (can't check if safe)\n"); - free(out); - return 0; - } - if (strcmp(out, "123")) { - put("libs/snprintf", strue); - put("libs/snprintf_safe", strue); - report("OK (safe)\n"); - free(out); - return 0; - } - if (strcmp(out, "1234")) { - put("libs/snprintf", strue); - put("libs/snprintf_safe", sfalse); - report("OK (UNSAFE)\n"); - free(out); - return 0; - } - free(out); - report("not found (broken output).\n"); - } - else { - report("not found (no output).\n"); - } - put("libs/snprintf", sfalse); - return 1; -} - -int find_dprintf(const char *name, int logdepth, int fatal) -{ - char *out; - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " dprintf(1, \"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for dprintf... "); - logprintf(logdepth, "find_dprintf: trying to find dprintf...\n"); - logdepth++; - logprintf(logdepth, "trying dprintf...\n"); - - if ((compile_run(logdepth+1, test_c, NULL, NULL, NULL, &out) == 0) && (strcmp(out, "OK"))) { - put("libs/dprintf", strue); - report("found\n"); - free(out); - return 0; - } - put("libs/dprintf", sfalse); - report("not found\n"); - return 1; -} - -int find_vdprintf(const char *name, int logdepth, int fatal) -{ - char *out; - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "void local_dprintf(int fd, const char *fmt, ...)" - NL "{" - NL " va_list ap;" - NL " va_start(ap, fmt);" - NL " vdprintf(fd, fmt, ap);" - NL "}" - NL "int main() {" - NL " local_dprintf(1, \"OK\\n\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for vdprintf... "); - logprintf(logdepth, "find_vdprintf: trying to find vdprintf...\n"); - logdepth++; - logprintf(logdepth, "trying vdprintf...\n"); - - if ((compile_run(logdepth+1, test_c, NULL, NULL, NULL, &out) == 0) && (strcmp(out, "OK"))) { - put("libs/vdprintf", strue); - report("found\n"); - free(out); - return 0; - } - put("libs/vdprintf", sfalse); - report("not found\n"); - return 1; -} - -int find_vsnprintf(const char *name, int logdepth, int fatal) -{ - char *out; - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "void local_vsnprintf(char *s, int len, const char *fmt, ...)" - NL "{" - NL " va_list ap;" - NL " va_start(ap, fmt);" - NL " vsnprintf(s, len, fmt, ap);" - NL "}" - NL "int main() {" - NL " char s[16];" - NL " *s = '\\0';" - NL " local_vsnprintf(s, 14, \"OK\\n\");" - NL " printf(\"%s\", s);" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for vsnprintf... "); - logprintf(logdepth, "find_vsnprintf: trying to find vsnprintf...\n"); - logdepth++; - logprintf(logdepth, "trying vsnprintf...\n"); - - if ((compile_run(logdepth+1, test_c, NULL, NULL, NULL, &out) == 0) && (strcmp(out, "OK"))) { - put("libs/vsnprintf", strue); - report("found\n"); - free(out); - return 0; - } - put("libs/vsnprintf", sfalse); - report("not found\n"); - return 1; -} diff --git a/scconfig/src/default/.svn/pristine/e0/e0c917ecbc06b89251fe23dba939fcaa3113cad0.svn-base b/scconfig/src/default/.svn/pristine/e0/e0c917ecbc06b89251fe23dba939fcaa3113cad0.svn-base deleted file mode 100644 index 1cc8aa90..00000000 --- a/scconfig/src/default/.svn/pristine/e0/e0c917ecbc06b89251fe23dba939fcaa3113cad0.svn-base +++ /dev/null @@ -1,255 +0,0 @@ -/* - scconfig - dependencies - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include "dep.h" -#include "db.h" -#include "log.h" -#include "libs.h" - -typedef struct { - int (*fn)(const char *name, int logdepth, int fatal); -} fn_wrap_t; - - -static ht_t *deps = NULL; - -static const char *USER_WITHOUT = ""; - -/* find name_ and decide if it was a wildcard request; - NOTE: there are requests and servers, both can be wildcard independently. - - if a request ends with a / *, it is an explicit wildcard request (*wild=1) - - if a request names a "directory" that is wildcard-server, that's a wildcard request (*wild=1) - - else the request is a normal request (*wild=0). - For normal requests, a required node was explicitly named; if that node is - not created by the detection function, that's a failure. For wildcard - requests we don't look for any specific node to be created. - TODO: we may still check if at least the directory is created - */ -fn_wrap_t *get_wrap(const char *name_, int *wild, int *missing) -{ - fn_wrap_t *w; - char *name, *sep, *tmp; - int len, n; - - len = strlen(name_); - *wild = name_[len-1] == '*'; - - if (*wild) { - char *pres; - pres = malloc(len+16); - memcpy(pres, name_, len-1); - strcpy(pres+len-1, "presents"); - *missing = get(pres) == NULL; - if (*missing) { /* if there's no /presents, it may be a non-directory node with an actual non-empty string value */ - const char *val; - pres[len-2] = '\0'; - val = get(pres); - if (val != NULL) - *missing = !strlen(val); - } - free(pres); - if (!(*missing)) /* already detected, won't be detected again */ - return NULL; - } - *missing = 1; - - /* check for global --without disable */ - tmp = str_concat("", "/arg/without", db_cwd, "/", name_, NULL); - sep = tmp + strlen(tmp) - 1; - for(n = 0; n < 4; n++) { - const char *d = get(tmp); - if (sep < tmp+14) - break; - if (istrue(d)) { - free(tmp); - return USER_WITHOUT; - } - while(*sep != '/') - sep--; - *sep = '\0'; - } - free(tmp); - - /* try full match first */ - w = ht_get(deps, name_); - if (w != NULL) - return w; - - - /* try substituting the last part of the path with * for wildcard matches */ - name = malloc(len+3); /* worst case: ends in a / and we need to append *\0; allocate a bit more */ - memcpy(name, name_, len+1); /* make a copy we can modify */ - if (name[len-1] != '/') { - name[len] = '/'; /* append a / - if name_ was a "directory", this will result in name/ * */ - name[len+1] = '\0'; - } - - *wild = 1; /* if we append a / *, then it's a wildcard request */ - for(;;) { - sep = str_rchr(name, '/'); - if (sep == NULL) - goto error; - sep[1] = '*'; - sep[2] = '\0'; - w = ht_get(deps, name); - if (w != NULL) { - free(name); - return w; - } - *sep = '\0'; - *wild = 0; /* cutting back the second layer - not wildcard request anymore, but a request to a specific node served by a wildcard */ - } - - /* no match, exit with error */ - error:; - *wild = 0; - free(name); - return NULL; -} - - -int require(const char *name, int logdepth, int fatal) -{ - fn_wrap_t *w; - int wild, missing; - - if (get(name) == NULL) { - w = get_wrap(name, &wild, &missing); - if (w == USER_WITHOUT) { - if (fatal) { - error("Node %s is required by the software but disabled by the user using --without\n", name); - abort(); - } - else { - logprintf(logdepth, "(disabled using --without)"); - return 1; - } - } - if (!missing) - return 0; - if ((w == NULL) || (w->fn == NULL)) { - error("Node %s is required but I don't know how to detect it.\n", name); - abort(); - } - - logprintf(logdepth, "(Required node: '%s')\n", name); - if (w->fn(name, logdepth+1, fatal) != 0) { - if (fatal) { - error("Node %s is required but provided detection callback fails to find that feature on that system.\n", name); - abort(); - } - else { - logprintf(logdepth, "(Feature not found, but it is not fatal)"); - return 1; - } - } - if ((!wild) && (get(name) == NULL)) { - error("Node %s is required but provided detection callback didn't create it (looks like an internal error in scconfig). (db_cwd='%s')\n", name, db_cwd); - abort(); - } - } - return 0; -} - -const char *dep_add(const char *name, int (*finder)(const char *name, int logdepth, int fatal)) -{ - fn_wrap_t *w; - w = malloc(sizeof(fn_wrap_t)); - w->fn = finder; - return ht_set(deps, name, w); -} - -int asked_for(const char *cando, const char *needtodo) -{ - int len; - - /* foo/bar/baz matches /foo/bar/baz */ - if (strcmp(cando, needtodo) == 0) - goto yes; - - len = strlen(needtodo); - if (len == 0) - return 0; - - /* foo/bar/baz matches /foo/bar/ * */ - if ((needtodo[len-1] == '*') && (strncmp(cando, needtodo, len-1) == 0)) - goto yes; - - return 0; - - - yes:; /* asked for it, but have to see if it's already detected */ - if (get(cando) != NULL) - return 0; - - return 1; -} - -int is_dep_wild(const char *path) -{ - int len = strlen(path); - if (len == 0) - return 0; - return (path[len-1] == '*'); -} - -const char *det_list_target(const char *path) -{ - const char *res; - - if (path == NULL) - goto unk; - - res = strrchr(path, '/'); - if (res == NULL) - goto unk; - - return res + 1; -unk:; - return ""; -} - - -void dep_init(void) -{ - deps = ht_resize(ht_alloc(0), 128); -} - -void dep_uninit(void) -{ - ht_free(deps); -} - -int is_dep_known(const char *name) -{ - return (ht_get(deps, name) != NULL); -} - -void require_all(int fatal) -{ - ht_entry_t *h; - - for(h = ht_first(deps); h != NULL; h = ht_next(deps, h)) - require(h->key, 0, fatal); -} diff --git a/scconfig/src/default/.svn/pristine/e1/e183c40b05ad272d46b25c1bfe070da68466fbae.svn-base b/scconfig/src/default/.svn/pristine/e1/e183c40b05ad272d46b25c1bfe070da68466fbae.svn-base deleted file mode 100644 index a78de79a..00000000 --- a/scconfig/src/default/.svn/pristine/e1/e183c40b05ad272d46b25c1bfe070da68466fbae.svn-base +++ /dev/null @@ -1,493 +0,0 @@ -/* - scconfig - detect features of the system or the host/target computer - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_sys_ptrwidth(const char *name, int logdepth, int fatal) -{ - char *end, W[32]; - char *out = NULL; - int w; - - char *test_c = - NL "#include " - NL "int main() {" - NL " void *ptr;" - NL " printf(\"%d\\n\", sizeof(ptr));" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for pointer width... "); - logprintf(logdepth, "find_sys_ptrwidth: trying to find pointer width...\n"); - logdepth++; - - if (compile_run(logdepth, test_c, NULL, NULL, NULL, &out) == 0) { - w = strtol(out, &end, 10); - if ((*end != '\0') && (*end != '\n') && (*end != '\r')) { - report("FAILED (test code failed)\n"); - logprintf(logdepth+1, "FAILED: returned '%s' which is not a valid decimal number (at '%s')\n", out, end); - return 1; - } - sprintf(W, "%d", w * 8); - report("OK (%s bits)\n", W); - put("sys/ptrwidth", W); - logprintf(logdepth+1, "OK (%s bits)\n", W); - } - return 0; -} - -int find_sys_byte_order(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " long int i = 8;" - NL " char *s = (char *)&i;" - NL " printf(\"%d\\n\", s[0]);" - NL " return 0;" - NL "}" - NL; - const char* test_c_blind_template = - NL "#include " - NL "#include " - NL "#ifndef __BYTE_ORDER" - NL "#error \"ERROR 1\"" - NL "void void *;" - NL "#endif" - NL "#ifndef __%s_ENDIAN" - NL "#error \"ERROR 2\"" - NL "char char *;" - NL "#endif" - NL "#if __BYTE_ORDER != __%s_ENDIAN" - NL "#error \"ERROR 3\"" - NL "int int *;" - NL "#endif" - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *key = "sys/byte_order"; - const char *endians1[] = { "LITTLE", "BIG", NULL }; - const char *endians2[] = { "LSB", "MSB", NULL }; - int index; - char test_c_blind[1024]; - char *end; - const char *W; - char *out = NULL; - int w; - - require("cc/cc", logdepth, fatal); - - report("Checking for byte order... "); - logprintf(logdepth, "find_sys_byte_order: trying to find byte order...\n"); - logdepth++; - - if ((!isblind(db_cwd)) && compile_run(logdepth, test_c, NULL, NULL, NULL, &out) == 0) { - w = strtol(out, &end, 10); - if (((*end != '\0') && (*end != '\n') && (*end != '\r')) || ((w != 0) && (w != 8))) { - report("FAILED (test code failed)\n"); - logprintf(logdepth+1, "FAILED: returned '%s' which is not a valid decimal number (at '%s')\n", out, end); - return 1; - } - if (w == 0) - W = "MSB"; - else - W = "LSB"; - - report("OK (%s first)\n", W); - put("sys/byte_order", W); - logprintf(logdepth+1, "OK (%s first)\n", W); - return 0; - } - - for (index=0; endians1[index]!=NULL; ++index) - { - sprintf(test_c_blind, test_c_blind_template, endians1[index], endians1[index]); - - if (compile_run(logdepth, test_c_blind, NULL, NULL, NULL, NULL) == 0) - { - W = endians2[index]; - report("OK (%s first)\n", W); - put(key, W); - return 0; - } - } - - report("FAILED (cannot determine byte order, you must supply it)\n"); - return try_fail(logdepth, key); -} - -static int test_shell_eats_backslash(int logdepth) -{ - char *test = "echo c:\\n"; - char *out; - - - logprintf(logdepth, "testing if shell eats \\...\n"); - run_shell(logdepth+1, test, &out); - if (out == NULL) { - logprintf(logdepth+1, "oops, couldn't run shell?! (returned NULL)\n"); - report("ERROR: shell fails."); - abort(); - } - if (out[2] == '\\') { - logprintf(logdepth, "shell does NOT eat \\...\n"); - put("sys/shell_eats_backslash", sfalse); - free(out); - return 0; - } - - free(out); - logprintf(logdepth, "shell eats \\...\n"); - put("sys/shell_eats_backslash", strue); - return 1; -} - - -static int try_get_cwd(int logdepth, const char *cmd) -{ - char *cwd, *end; - run_shell(logdepth+1, cmd, &cwd); - if (cwd != NULL) { - end = strpbrk(cwd, "\r\n"); - if (end != NULL) - *end = '\0'; - if (*cwd != '\0') { - end = cwd + strlen(cwd) - 1; - while((*end == ' ') || (*end == '\t')) { *end = '\0'; end--; } - put("sys/tmp", cwd); - /* ugly hack for win32: paths there start as c:\ */ - if ((cwd[1] == ':') && (cwd[2] == '\\')) - append("sys/tmp", "\\"); - else - append("sys/tmp", "/"); - logprintf(logdepth, "cwd is '%s'\n", get("sys/tmp")); - free(cwd); - return 1; - } - else - free(cwd); - } - return 0; -} - -static int try_tmp(int logdepth) -{ - char *fn; - - logprintf(logdepth, "validating temp dir '%s'\n", get("sys/tmp")); - fn = tempfile_new_noabort(""); - if (fn != NULL) { - unlink(fn); - free(fn); - logprintf(logdepth, "temp dir works!\n"); - return 1; - } - - logprintf(logdepth, "temp dir fails\n"); - return 0; -} - -/* test temp dir with all sort of workarounds */ -static int try_tmp_all(int logdepth) -{ - const char *tmp, *si; - char c; - char *t, *so, *old_tmp; - int eats, n; - - tmp = get("sys/tmp"); - - /* path must end in path separator */ - c = tmp[strlen(tmp)-1]; - if ((c != '/') && (c != '\\')) { - append("sys/tmp", "/"); - tmp = get("sys/tmp"); - } - - logprintf(logdepth, "trying detected temp dir '%s'\n", tmp); - if (try_tmp(logdepth+1)) return 1; - - /* try msys-on-windows hack: if path starts with /d/something, try d:/ instead */ - if ((tmp[0] == '/') && (isalpha(tmp[1])) && (tmp[2] == '/')) { - /* for the next test we shouldn't use our half-detected tmp path but go with . */ - old_tmp = strclone(tmp); - put("sys/tmp", ""); - eats = istrue(get("sys/shell_eats_backslash")); - tmp = old_tmp; - logprintf(logdepth, "tmp2='%s' eats=%d\n", tmp, eats); - t = malloc(strlen(tmp) * 2); - t[0] = tmp[1]; - t[1] = ':'; - for(si = tmp + 2, so = t + 2; *si != '\0'; si++, so++) { - if (*si == '/') { - *so = '\\'; - if (eats) { - for(n = 0; n < 3; n++) { - so++; - *so = '\\'; - } - } - } - else - *so = *si; - } - *so = '\0'; - free(old_tmp); - - logprintf(logdepth, "trying windows fix: '%s'\n", t); - put("sys/tmp", t); - free(t); - if (try_tmp(logdepth+1)) { - if (eats) - put("sys/path_sep", "\\\\\\\\"); - else - put("sys/path_sep", "\\"); - put("sys/path_sep_escaped", "\\\\"); - return 1; - } - tmp = get("sys/tmp"); - } - - /* fail. Set back tmp to empty so next command has a chance to run */ - put("sys/tmp", ""); - return 0; -} - -int find_tmp(const char *name, int logdepth, int fatal) -{ - const char *usertmp; - - if (in_cross_target) { - report("Temp dir for cross compilation target is the same as for host..."); - logprintf(logdepth, "Copying temp dir from host to target\n"); - require("/host/sys/tmp", logdepth, fatal); - usertmp = get("/host/sys/tmp"); - if (usertmp == NULL) { - report("Host temp dir not found.\n"); - logprintf(logdepth, "Host temp dir not found.\n"); - return 1; - } - put("sys/tmp", usertmp); - return 0; - } - - /* we need shell for later tests; do this detection in . */ - put("sys/tmp", ""); - require("sys/shell", logdepth, fatal); - - put("sys/path_sep", "/"); - put("sys/path_sep_escaped", "/"); - - report("Detecting temp dir..."); - logprintf(logdepth, "Finding temp dir (current working directory)...\n"); - - usertmp = get("/arg/sys/tmp"); - - /* . as tmp would fail for commands including a "cd" - this would cause - temporary files left in the target dir. We start out with empty - string (which is ., but on windows ./ would fail), and run - pwd (without cd) to find out the current directory (as getcwd() is not - portable). If pwd fails, we stay with ./ */ - put("sys/tmp", ""); - - /* we need to know about shell backslash problem regardless of how - we end up with tmp - currently tmp is ., where the test could run - safely */ - test_shell_eats_backslash(logdepth+1); - - /* Special case: cross-compilation with emulator; we can not assume - the emulator uses the same paths as the host system, while we mix - accessing files from host and emu. If we stay in ., both emulator - and host system should be (more or less) happy. */ - if (istarget(db_cwd) && iscross) { - if (usertmp == NULL) { - report("using temp dir . for cross-compilation\n"); - logprintf(logdepth, "staying with . for cross-compilation\n"); - } - else { - put("sys/tmp", usertmp); - report("using user supplied temp dir '%s' for cross-compilation\n", usertmp); - logprintf(logdepth, "using user supplied temp dir '%s' for cross-compilation\n", usertmp); - } - return 0; - } - - if ((usertmp != NULL)) - put("sys/tmp", usertmp); - - if ( - ((usertmp != NULL) && (try_tmp_all(logdepth+2))) || /* try user supplied temp dir */ - ((try_get_cwd(logdepth+1, "pwd")) && (try_tmp_all(logdepth+2))) || /* try pwd for finding out cwd */ - ((try_get_cwd(logdepth+1, "echo %cd%") && (try_tmp_all(logdepth+2))))) { /* try windows-specific way for finding out cwd */ - - report(" validated %s\n", get("sys/tmp")); - logprintf(logdepth, "Detected temp dir '%s'\n", get("sys/tmp")); - return 0; - } - - put("sys/tmp", ""); - report("using temp dir fallback .\n"); - logprintf(logdepth, "all temp directories failed, using . as tmp\n"); - return 0; -} - -int test_shell(const char *shell, int logdepth, int quote) -{ - char *test = "echo hello"; - char *cmd; - char *out; - char *q; - - if (quote) - q = "\""; - else - q = ""; - - logprintf(logdepth, "testing '%s' as shell\n", shell); - cmd = malloc(strlen(test) + strlen(shell) + 8); - sprintf(cmd, "%s %s%s%s", shell, q, test, q); - - run(logdepth+1, cmd, &out); - - free(cmd); - - if ((out != NULL) && (strncmp(out, "hello", 5) == 0)) { - put("sys/shell", shell); - if (quote) - put("sys/shell_needs_quote", strue); - else - put("sys/shell_needs_quote", sfalse); - logprintf(logdepth, "accepted.\n"); - free(out); - return 1; - } - - logprintf(logdepth, "refused.\n"); - free(out); - return 0; -} - -static int find_shell_escape(const char *name, int logdepth, int fatal, const char *shell) -{ - char cmdline[256]; - char **t; - char *tests[] = { - "\\", "\\ {}&;|", - "^", "^ &", - NULL, NULL - }; - (void) fatal; /* not used */ - (void) shell; /* not used */ - - report("Looking for a shell escape character... "); - logprintf(logdepth, "finding shell escape character...\n"); - - for(t = tests; *t != NULL; t += 2) { - char *s, *end, *out, *start; - strcpy(cmdline, "echo "); - end = cmdline+5; - for(s = t[1]; *s != '\0'; s++) { - *end++ = *t[0]; - *end++ = *s; - } - *end = '\0'; - run(logdepth+1, cmdline, &out); - if (out != NULL) { - int res; - if (*out == '\"') /* wine likes to wrap the output in quotes for some reason */ - start = out+1; - else - start = out; - - res = strncmp(start, t[1], strlen(t[1])); - free(out); - if (res == 0) { - report("found: '%s'\n", t[0]); - logprintf(logdepth, "found shell escape char '%s'\n", t[0]); - put("sys/shell_escape_char", t[0]); - return 0; - } - } - } - report("NOT FOUND\n"); - logprintf(logdepth, "shell escape character not found\n"); - - return 1; -} - -int find_shell(const char *name, int logdepth, int fatal) -{ - const char *shells[] = { - "/bin/sh -c", - "/bin/bash -c", - "bash -c", - "cmd.exe /c", - "sh -c", - "/bin/dash -c", - "dash -c", - "/bin/ksh -c", - "ksh -c", - NULL - }; - const char **s; - - if (cross_blind) { - const char *shell = get("/arg/sys/target-shell"); - if (shell == NULL) { - report("Need to specify sys/target-shell in blind cross compiling mode, because the shell cannot be detected (note: scconfig will not attempt to run the target shell)\n"); - exit(1); - } - - put("sys/shell", shell); - report("Blind cross compiling: accepting '%s' as shell\n", shell); - logprintf(logdepth, "Blind cross compiling: accepting '%s' as shell\n", shell); - return 0; - } - - report("Looking for a shell... "); - logprintf(logdepth, "finding a shell\n"); - - for(s = shells; *s != NULL; s++) { - if ((test_shell(*s, logdepth+1, 0)) || (test_shell(*s, logdepth+1, 1))) { - report("%s\n", *s); - logprintf(logdepth, "found a shell '%s', need quote: %s\n", *s, get("sys/shell_needs_quote")); - return find_shell_escape(name, logdepth, fatal, *s); - } - } - - report("NOT FOUND\n"); - logprintf(logdepth, "shell not found\n"); - return 1; -} diff --git a/scconfig/src/default/.svn/pristine/ef/ef2a1b9e12f41234b5e5777b0c3b48bf7c1dd262.svn-base b/scconfig/src/default/.svn/pristine/ef/ef2a1b9e12f41234b5e5777b0c3b48bf7c1dd262.svn-base deleted file mode 100644 index 3b33700b..00000000 --- a/scconfig/src/default/.svn/pristine/ef/ef2a1b9e12f41234b5e5777b0c3b48bf7c1dd262.svn-base +++ /dev/null @@ -1,141 +0,0 @@ -DEFAULT_NOMAIN_OBJS = \ - $(BIN)/default/find_cc.o \ - $(BIN)/default/lib_compile.o \ - $(BIN)/default/lib_uniqinc.o \ - $(BIN)/default/lib_file.o \ - $(BIN)/default/lib_try.o \ - $(BIN)/default/str.o \ - $(BIN)/default/ht.o \ - $(BIN)/default/log.o \ - $(BIN)/default/arg.o \ - $(BIN)/default/db.o \ - $(BIN)/default/dep.o \ - $(BIN)/default/deps_default.o \ - $(BIN)/default/find_libs.o \ - $(BIN)/default/find_fscalls.o \ - $(BIN)/default/find_printf.o \ - $(BIN)/default/find_proc.o \ - $(BIN)/default/find_fstools.o \ - $(BIN)/default/find_uname.o \ - $(BIN)/default/find_target.o \ - $(BIN)/default/find_thread.o \ - $(BIN)/default/find_io.o \ - $(BIN)/default/find_time.o \ - $(BIN)/default/find_types.o \ - $(BIN)/default/find_signal.o \ - $(BIN)/default/find_environ.o \ - $(BIN)/default/regex.o \ - $(BIN)/default/lib_filelist.o \ - $(BIN)/default/lib_srctree.o \ - $(BIN)/default/lib_pkg_config.o \ - $(BIN)/default/find_str.o \ - $(BIN)/default/find_sys.o - -DEFAULT_MAIN_OBJS = \ - $(BIN)/default/main.o \ - $(BIN)/default/main_custom_args.o \ - $(BIN)/default/main_lib.o - -DEFAULT_OBJS = $(DEFAULT_NOMAIN_OBJS) $(DEFAULT_MAIN_OBJS) - -$(BIN)/default/lib_compile.o: $(SRC)/default/lib_compile.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/lib_compile.c -o $(BIN)/default/lib_compile.o - -$(BIN)/default/lib_file.o: $(SRC)/default/lib_file.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/lib_file.c -o $(BIN)/default/lib_file.o - -$(BIN)/default/lib_try.o: $(SRC)/default/lib_try.c $(SRC)/default/log.h $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/lib_try.c -o $(BIN)/default/lib_try.o - -$(BIN)/default/str.o: $(SRC)/default/str.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/str.c -o $(BIN)/default/str.o - -$(BIN)/default/ht.o: $(SRC)/default/ht.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/ht.c -o $(BIN)/default/ht.o - -$(BIN)/default/log.o: $(SRC)/default/log.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/log.c -o $(BIN)/default/log.o - -$(BIN)/default/arg.o: $(SRC)/default/arg.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/arg.c -o $(BIN)/default/arg.o - -$(BIN)/default/db.o: $(SRC)/default/db.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/db.c -o $(BIN)/default/db.o - -$(BIN)/default/dep.o: $(SRC)/default/dep.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/dep.c -o $(BIN)/default/dep.o - -$(BIN)/default/deps_default.o: $(SRC)/default/deps_default.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/deps_default.c -o $(BIN)/default/deps_default.o - -$(BIN)/default/find_libs.o: $(SRC)/default/find_libs.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_libs.c -o $(BIN)/default/find_libs.o - -$(BIN)/default/find_fscalls.o: $(SRC)/default/find_fscalls.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_fscalls.c -o $(BIN)/default/find_fscalls.o - -$(BIN)/default/find_signal.o: $(SRC)/default/find_signal.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_signal.c -o $(BIN)/default/find_signal.o - -$(BIN)/default/find_printf.o: $(SRC)/default/find_printf.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_printf.c -o $(BIN)/default/find_printf.o - -$(BIN)/default/find_proc.o: $(SRC)/default/find_proc.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_proc.c -o $(BIN)/default/find_proc.o - -$(BIN)/default/find_fstools.o: $(SRC)/default/find_fstools.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_fstools.c -o $(BIN)/default/find_fstools.o - -$(BIN)/default/find_uname.o: $(SRC)/default/find_uname.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_uname.c -o $(BIN)/default/find_uname.o - -$(BIN)/default/find_target.o: $(SRC)/default/find_target.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_target.c -o $(BIN)/default/find_target.o - -$(BIN)/default/regex.o: $(SRC)/default/regex.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/regex.c -o $(BIN)/default/regex.o - -$(BIN)/default/lib_filelist.o: $(SRC)/default/lib_filelist.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/lib_filelist.c -o $(BIN)/default/lib_filelist.o - -$(BIN)/default/lib_srctree.o: $(SRC)/default/lib_srctree.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/lib_srctree.c -o $(BIN)/default/lib_srctree.o - -$(BIN)/default/lib_pkg_config.o: $(SRC)/default/lib_pkg_config.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/lib_pkg_config.c -o $(BIN)/default/lib_pkg_config.o - -$(BIN)/default/lib_uniqinc.o: $(SRC)/default/lib_uniqinc.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/lib_uniqinc.c -o $(BIN)/default/lib_uniqinc.o - -$(BIN)/default/find_sys.o: $(SRC)/default/find_sys.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_sys.c -o $(BIN)/default/find_sys.o - -$(BIN)/default/find_str.o: $(SRC)/default/find_str.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_str.c -o $(BIN)/default/find_str.o - -$(BIN)/default/find_cc.o: $(SRC)/default/find_cc.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_cc.c -o $(BIN)/default/find_cc.o - -$(BIN)/default/find_environ.o: $(SRC)/default/find_environ.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_environ.c -o $(BIN)/default/find_environ.o - -$(BIN)/default/find_io.o: $(SRC)/default/find_io.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_io.c -o $(BIN)/default/find_io.o - -$(BIN)/default/find_time.o: $(SRC)/default/find_time.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_time.c -o $(BIN)/default/find_time.o - -$(BIN)/default/find_types.o: $(SRC)/default/find_types.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_types.c -o $(BIN)/default/find_types.o - -$(BIN)/default/main.o: $(SRC)/default/main.c $(SRC)/default/dep.h $(SRC)/default/libs.h Makefile - $(CC) $(CFLAGS) -c $(SRC)/default/main.c -o $(BIN)/default/main.o - -$(BIN)/default/main_custom_args.o: $(SRC)/default/main_custom_args.c - $(CC) $(CFLAGS) -c $(SRC)/default/main_custom_args.c -o $(BIN)/default/main_custom_args.o - -$(BIN)/default/main_lib.o: $(SRC)/default/main_lib.c - $(CC) $(CFLAGS) -c $(SRC)/default/main_lib.c -o $(BIN)/default/main_lib.o - -$(BIN)/default/find_thread.o: $(SRC)/default/find_thread.c $(SRC)/default/dep.h $(SRC)/default/libs.h - $(CC) $(CFLAGS) -c $(SRC)/default/find_thread.c -o $(BIN)/default/find_thread.o diff --git a/scconfig/src/default/.svn/pristine/f3/f3e54718e2e1803c33fb40a100f019d1a831e9ac.svn-base b/scconfig/src/default/.svn/pristine/f3/f3e54718e2e1803c33fb40a100f019d1a831e9ac.svn-base deleted file mode 100644 index 5dc894dc..00000000 --- a/scconfig/src/default/.svn/pristine/f3/f3e54718e2e1803c33fb40a100f019d1a831e9ac.svn-base +++ /dev/null @@ -1,833 +0,0 @@ -/* - scconfig - detection of file system tools - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" -#include "dep.h" - -static int test_cp_ln(int logdepth, const char *command, int link) -{ - char *src, *dst, *src_esc, *dst_esc; - char *cmd, *result; - char *test_string = "works."; - int ret; - - logprintf(logdepth, "trying '%s'\n", command); - - src = tempfile_dump(test_string, ""); - dst = tempfile_new(""); - if (link) - unlink(dst); - - src_esc = shell_escape_dup(src); - dst_esc = shell_escape_dup(dst); - cmd = malloc(strlen(command) + strlen(src_esc) + strlen(dst_esc) + 32); - sprintf(cmd, "%s %s %s", command, src_esc, dst_esc); - run_shell(logdepth, cmd, NULL); - free(cmd); - free(src_esc); - free(dst_esc); - - result = load_file(dst); - ret = !strcmp(result, test_string); - logprintf(logdepth+1, "result: '%s' == '%s' (%d)\n", result, test_string, ret); - free(result); - - unlink(src); - free(src); - - result = load_file(dst); - if (link) { - if (strcmp(result, test_string) == 0) { - report("Warning: link is copy (or hard link). "); - logprintf(logdepth+1, "Warning: link is copy (or hard link).\n"); - } - } - else { - if (strcmp(result, test_string) != 0) { - report("Warning: copy is symlink. "); - logprintf(logdepth+1, "Warning: copy is symlink.\n"); - } - } - free(result); - - if (ret) { - if (link) - put("fstools/ln", command); - else - put("fstools/cp", command); - - report("OK (%s)\n", command); - } - - unlink(dst); - free(dst); - return ret; -} - -static int test_mv(int logdepth, const char *command) -{ - char *src, *dst, *src_esc, *dst_esc; - char *cmd, *result; - char *test_string = "works."; - int ret; - - logprintf(logdepth, "trying '%s'\n", command); - - src = tempfile_dump(test_string, ""); - dst = tempfile_new(""); - unlink(dst); - - src_esc = shell_escape_dup(src); - dst_esc = shell_escape_dup(dst); - cmd = malloc(strlen(command) + strlen(src_esc) + strlen(dst_esc) + 32); - sprintf(cmd, "%s %s %s", command, src_esc, dst_esc); - run_shell(logdepth, cmd, NULL); - free(cmd); - free(src_esc); - free(dst_esc); - - result = load_file(dst); - ret = !strcmp(result, test_string); - logprintf(logdepth+1, "result: '%s' == '%s' (%d)\n", result, test_string, ret); - free(result); - - if (file_size(src) > 0) { - report("Warning: mv is copy. "); - logprintf(logdepth+1, "Warning: mv is copy.\n"); - } - - if (ret) { - put("fstools/mv", command); - report("OK (%s)\n", command); - } - - unlink(dst); - unlink(src); - free(dst); - free(src); - return ret; -} - -static int test_mkdir(int logdepth, const char *command) -{ - char *dir, *file; - char *dir_esc; - char *cmd, *result; - char *test_string = "works."; - int ret = 0, had_p; - FILE *f; - - logprintf(logdepth, "trying '%s'\n", command); - dir = tempfile_new(""); - dir_esc = shell_escape_dup(dir); - unlink(dir); - - had_p = is_dir("-p"); - - cmd = malloc(strlen(command) + strlen(dir_esc) + 32); - sprintf(cmd, "%s %s", command, dir_esc); - run_shell(logdepth, cmd, NULL); - free(cmd); - - file = malloc(strlen(dir) + 32); - sprintf(file, "%s/test", dir); - f = fopen(file, "w"); - if (f != NULL) { - fputs(test_string, f); - fclose(f); - result = load_file(file); - if (strcmp(result, test_string) == 0) - ret = 1; - free(result); - } - - unlink(file); - unlink(dir); - - cmd = malloc(strlen(dir) + 32); - sprintf(cmd, "rmdir %s", dir_esc); - run_shell(logdepth, cmd, NULL); - free(cmd); - - free(file); - free(dir); - free(dir_esc); - - /* This is a bit ugly, but on win32 or other systems where mkdir works - but -p doesn't have an effect, a directory called -p may be left over... */ - if ((!had_p) && (is_dir("-p"))) { - unlink("-p"); - return 0; - } - - if (ret != 0) { - put("fstools/mkdir", command); - report("OK (%s)\n", command); - } - - return ret; -} - -static int test_rm(int logdepth, const char *command) -{ - char *src, *src_esc, *cmd, *test_string = "works."; - int ret; - - logprintf(logdepth, "trying '%s'\n", command); - - src = tempfile_dump(test_string, ""); - - if (file_size(src) < 0) { - report("error: can't create temp file\n"); - free(src); - return 0; - } - - - src_esc = shell_escape_dup(src); - cmd = malloc(strlen(command) + strlen(src_esc) + 32); - sprintf(cmd, "%s %s", command, src_esc); - run_shell(logdepth, cmd, NULL); - free(cmd); - free(src_esc); - - ret = file_size(src) < 0; - - if (ret) { - put("fstools/rm", command); - report("OK (%s)\n", command); - } - else - unlink(src); - - free(src); - return ret; -} - -static int test_ar(int logdepth, const char *command) -{ - char *src, *dst, *src_esc, *dst_esc; - char *cmd, *result, *expected; - char *test_string = "works."; - const char *path_sep; - int ret = 0; - - logprintf(logdepth, "trying '%s'\n", command); - path_sep = get("sys/path_sep"); - - src = tempfile_dump(test_string, ""); - dst = tempfile_new(""); - unlink(dst); - - src_esc = shell_escape_dup(src); - dst_esc = shell_escape_dup(dst); - cmd = malloc(strlen(command) + strlen(src_esc) + strlen(dst_esc) + 32); - sprintf(cmd, "%s ru %s %s", command, dst_esc, src_esc); - run_shell(logdepth, cmd, NULL); - sprintf(cmd, "%s t %s", command, dst_esc); - run_shell(logdepth, cmd, &result); - free(cmd); - free(dst_esc); - free(src_esc); - - if (result != NULL) { - expected = str_rchr(src, *path_sep); - if (expected == NULL) - expected = src; - else - expected++; - - ret = strncmp(expected, result, strlen(expected)) == 0; - if (ret) { - put("fstools/ar", command); - report("OK (%s)\n", command); - } - free(result); - } - - unlink(src); - unlink(dst); - free(src); - free(dst); - return ret; -} - -static int test_ranlib(int logdepth, const char *command, const char *obj) -{ - char *cmd, *archive, *archive_esc, *obj_esc; - const char *ar; - int ret; - ar = get("fstools/ar"); - logprintf(logdepth, "trying '%s'\n", command); - - archive = tempfile_new(".a"); - archive_esc = shell_escape_dup(archive); - obj_esc = shell_escape_dup(obj); - cmd = malloc(strlen(command) + strlen(obj_esc) + strlen(archive_esc) + 64); - - sprintf(cmd, "%s r %s %s", ar, archive_esc, obj_esc); - unlink(archive); - ret = run_shell(logdepth, cmd, NULL) == 0; - if (!ret) - goto fin; - - sprintf(cmd, "%s %s", command, archive_esc); - ret = run_shell(logdepth, cmd, NULL) == 0; - - if (ret) { - put("fstools/ranlib", command); - report("OK (%s)\n", command); - } - -fin:; - unlink(archive); - free(archive); - free(cmd); - free(archive_esc); - free(obj_esc); - return ret; -} - -static int test_awk(int logdepth, const char *command) -{ - char cmd[1024]; - char *out; - int ret = 0; - char *script, *script_esc; - - /* For some reason windows awk doesn't like the code with NLs */ - char *test_awk = - "BEGIN {" - " gsub(\"b\", \"B\", t);" - " print t;" - "}"; - - logprintf(logdepth, "trying '%s'\n", command); - script = tempfile_dump(test_awk, ".awk"); - script_esc = shell_escape_dup(script); - sprintf(cmd, "%s -v \"t=blobb\" -f %s", command, script_esc); - free(script_esc); - run_shell(logdepth, cmd, &out); - unlink(script); - free(script); - - if ((out != NULL) && (strncmp(out, "BloBB", 5) == 0)) { - put("fstools/awk", command); - report("OK (%s)\n", command); - ret = 1; - } - - free(out); - return ret; -} - -static int test_cat(int logdepth, const char *command) -{ - char cmd[1024]; - char *out; - int ret = 0; - char *fn, *fn_esc; - const char *test_str = "hello world"; - - logprintf(logdepth, "trying '%s'\n", command); - fn = tempfile_dump(test_str, ".txt"); - fn_esc = shell_escape_dup(fn); - sprintf(cmd, "%s %s", command, fn_esc); - run_shell(logdepth, cmd, &out); - unlink(fn); - free(fn); - free(fn_esc); - - if ((out != NULL) && (strncmp(out, test_str, strlen(test_str)) == 0)) { - put("fstools/cat", command); - report("OK (%s)\n", command); - ret = 1; - } - - free(out); - return ret; -} - -static int test_sed(int logdepth, const char *command) -{ - char cmd[1024]; - char *out; - int ret = 0; - char *fn, *fn_esc; - const char *test_str_in = "hello world"; - const char *test_str_out = "he11o wor1d"; - - logprintf(logdepth, "trying '%s'\n", command); - fn = tempfile_dump(test_str_in, ".txt"); - fn_esc = shell_escape_dup(fn); - sprintf(cmd, "%s \"s/l/1/g\" < %s", command, fn_esc); - run_shell(logdepth, cmd, &out); - unlink(fn); - free(fn); - free(fn_esc); - - if ((out != NULL) && (strncmp(out, test_str_out, strlen(test_str_out)) == 0)) { - put("fstools/sed", command); - report("OK (%s)\n", command); - ret = 1; - } - - free(out); - return ret; -} - -static int test_chmodx(int logdepth, const char *command) -{ - char *cmd, *tmp, *tmp_esc, *out, *s; - int ret; - - logprintf(logdepth, "trying '%s'\n", command); - tmp = tempfile_dump("#!/bin/sh\necho OK\n", ".bat"); - - tmp_esc = shell_escape_dup(tmp); - cmd = malloc(strlen(command) + strlen(tmp_esc) + 16); - sprintf(cmd, "%s %s", command, tmp_esc); - ret = run_shell(logdepth, cmd, NULL) == 0; - free(cmd); - if (!ret) { - free(tmp_esc); - return ret; - } - - ret = run(logdepth+1, tmp_esc, &out); - free(tmp_esc); - - if (ret == 0) { - for(s = out; s != NULL; s = str_chr(s, '\n')) { - logprintf(logdepth+1, "chmod line to test: '%s'\n", s); - if ((s[0] == 'O') && (s[1] == 'K')) { - logprintf(logdepth+2, "(OK)\n"); - ret = 1; - break; - } - s++; - } - } - else - ret = 0; - - free(out); - if (ret) { - put("fstools/chmodx", command); - logprintf(logdepth, "chmodx command validated: '%s'\n", command); - report("OK (%s)\n", command); - } - unlink(tmp); - return ret; -} - -static int test_file(int logdepth, const char *node, const char *command) -{ - char cmd[1024]; - char *out; - int ret = 0; - char *fn, *fn_esc; - - logprintf(logdepth, "trying '%s'\n", command); - fn = tempfile_dump("plain text file\r\n", ".txt"); - fn_esc = shell_escape_dup(fn); - sprintf(cmd, "%s %s", command, fn_esc); - run_shell(logdepth, cmd, &out); - unlink(fn); - free(fn); - free(fn_esc); - - if ((out != NULL) && (strstr(out, "text") != NULL)) { - put(node, command); - report("OK (%s)\n", command); - ret = 1; - } - - free(out); - return ret; -} - -int find_fstools_cp(const char *name, int logdepth, int fatal) -{ - const char *cp; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for cp... "); - logprintf(logdepth, "find_fstools_cp: trying to find cp...\n"); - logdepth++; - - cp = get("/arg/fstools/cp"); - if (cp == NULL) { - if (test_cp_ln(logdepth, "cp -rp", 0)) return 0; - if (test_cp_ln(logdepth, "cp -r", 0)) return 0; - if (test_cp_ln(logdepth, "copy /r", 0)) return 0; /* wine */ - } - else { - report(" user provided (%s)...", cp); - if (test_cp_ln(logdepth, cp, 0)) return 0; - } - return 1; -} - -int find_fstools_ln(const char *name, int logdepth, int fatal) -{ - const char *ln; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for ln... "); - logprintf(logdepth, "find_fstools_ln: trying to find ln...\n"); - logdepth++; - - ln = get("/arg/fstools/ln"); - if (ln == NULL) { - if (test_cp_ln(logdepth, "ln -sf",1 )) return 0; - if (test_cp_ln(logdepth, "ln -s",1 )) return 0; - if (test_cp_ln(logdepth, "ln", 1)) return 0; - /* "mklink /H" -> win32 equivalent to "ln" */ - /* "cp -s" -> same as "ln -s" */ - /* "cp -l" -> same as "ln" */ - if (test_cp_ln(logdepth, "cp", 1)) return 0; - } - else { - report(" user provided (%s)...", ln); - if (test_cp_ln(logdepth, ln, 1)) return 0; - } - return 1; -} - -int find_fstools_mv(const char *name, int logdepth, int fatal) -{ - const char *mv; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for mv... "); - logprintf(logdepth, "find_fstools_mv: trying to find mv...\n"); - logdepth++; - - mv = get("/arg/fstools/mv"); - if (mv == NULL) { - if (test_mv(logdepth, "mv")) return 0; - if (test_mv(logdepth, "move")) return 0; /* win32 */ - if (test_mv(logdepth, "cp")) return 0; - } - else { - report(" user provided (%s)...", mv); - if (test_mv(logdepth, mv)) return 0; - } - return 1; -} - -int find_fstools_rm(const char *name, int logdepth, int fatal) -{ - const char *rm; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for rm... "); - logprintf(logdepth, "find_fstools_rm: trying to find rm...\n"); - logdepth++; - - rm = get("/arg/fstools/rm"); - if (rm == NULL) { - if (test_rm(logdepth, "rm -rf")) return 0; - if (test_rm(logdepth, "rm -f")) return 0; - if (test_rm(logdepth, "rm")) return 0; - if (test_rm(logdepth, "del")) return 0; /* for win32 */ - } - else { - report(" user provided (%s)...", rm); - if (test_rm(logdepth, rm)) return 0; - } - return 1; -} - -int find_fstools_mkdir(const char *name, int logdepth, int fatal) -{ - const char *mkdir; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for mkdir... "); - logprintf(logdepth, "find_fstools_mkdir: trying to find mkdir...\n"); - logdepth++; - - mkdir = get("/arg/fstools/mkdir"); - if (mkdir == NULL) { - if (test_mkdir(logdepth, "mkdir -p")) return 0; - if (test_mkdir(logdepth, "md")) return 0; /* for win32 */ - } - else { - report(" user provided (%s)...", mkdir); - if (test_mkdir(logdepth, mkdir)) return 0; - } - return 1; -} - -int find_fstools_ar(const char *name, int logdepth, int fatal) -{ - const char *ar, *target; - char *targetar; - int len; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - require("sys/path_sep", logdepth, fatal); - - - report("Checking for ar... "); - logprintf(logdepth, "find_fstools_ar: trying to find ar...\n"); - logdepth++; - - ar = get("/arg/fstools/ar"); - if (ar == NULL) { - target = get("/arg/sys/target"); - if (target != NULL) { - logprintf(logdepth+1, "find_ar: crosscompiling for '%s', looking for target ar\n", target); - len = strlen(target); - targetar = malloc(len + 8); - memcpy(targetar, target, len); - strcpy(targetar + len, "-ar"); - if (test_ar(logdepth, targetar)) { - free(targetar); - return 0; - } - free(targetar); - } - if (test_ar(logdepth, "ar")) return 0; - if (test_ar(logdepth, "/usr/bin/ar")) return 0; - } - else { - report(" user provided (%s)...", ar); - if (test_ar(logdepth, ar)) return 0; - } - return 1; -} - -int find_fstools_ranlib(const char *name, int logdepth, int fatal) -{ - const char *ranlib, *target; - char *targetranlib; - int len; - char *test_code = NL "int zero() { return 0; }" NL; - char *obj = ".o"; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - require("fstools/ar", logdepth, fatal); - require("cc/cc", logdepth, fatal); - - report("Checking for ranlib... "); - logprintf(logdepth, "find_fstools_ranlib: trying to find ranlib...\n"); - logdepth++; - - logprintf(logdepth, "compiling test object...\n"); - if (compile_code(logdepth+1, test_code, &obj, NULL, "-c", NULL) != 0) { - logprintf(logdepth, "ERROR: Can't compile test object\n"); - report("ERROR: Can't compile test object\n"); - abort(); - } - - ranlib = get("/arg/fstools/ranlib"); - if (ranlib == NULL) { - target = get("/arg/sys/target"); - if (target != NULL) { - logprintf(logdepth+1, "find_ranlib: crosscompiling for '%s', looking for target ranlib\n", target); - len = strlen(target); - targetranlib = malloc(len + 16); - memcpy(targetranlib, target, len); - strcpy(targetranlib + len, "-ranlib"); - if (test_ranlib(logdepth, targetranlib, obj)) { - free(targetranlib); - return 0; - } - free(targetranlib); - } - if (test_ranlib(logdepth, "ranlib", obj)) goto found; - if (test_ranlib(logdepth, "/usr/bin/ranlib", obj)) goto found; - if (test_ranlib(logdepth, "ar -s", obj)) goto found; - if (test_ranlib(logdepth, "/usr/bin/ar -s", obj)) goto found; - - /* some systems (for example IRIX) can't run s without doing - something else; t is harmless */ - if (test_ranlib(logdepth, "ar ts", obj)) goto found; - if (test_ranlib(logdepth, "/usr/bin/ar ts", obj)) goto found; - - /* final fallback: some systems (for example minix3) simply - do not have ranlib or ar equivalent; it's easier to detect - a dummy command than to force conditions into Makefiles */ - if (test_ranlib(logdepth, "true", obj)) goto found; - } - else { - report(" user provided (%s)...", ranlib); - if (test_ranlib(logdepth, ranlib, obj)) goto found; - } - unlink(obj); - free(obj); - return 1; -found:; - unlink(obj); - free(obj); - return 0; -} - -int find_fstools_awk(const char *name, int logdepth, int fatal) -{ - const char *awk; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for awk... "); - logprintf(logdepth, "find_fstools_awk: trying to find awk...\n"); - logdepth++; - - awk = get("/arg/fstools/awk"); - if (awk == NULL) { - if (test_awk(logdepth, "awk")) return 0; - if (test_awk(logdepth, "gawk")) return 0; - if (test_awk(logdepth, "mawk")) return 0; - if (test_awk(logdepth, "nawk")) return 0; - } - else { - report(" user provided (%s)...", awk); - if (test_awk(logdepth, awk)) return 0; - } - return 1; -} - -int find_fstools_chmodx(const char *name, int logdepth, int fatal) -{ - const char *chmod; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for chmod to executable... "); - logprintf(logdepth, "find_fstools_awk: trying to find chmod to executable...\n"); - logdepth++; - - chmod = get("/arg/fstools/chmodx"); - if (chmod == NULL) { - if (test_chmodx(logdepth, "chmod +x")) return 0; - if (test_chmodx(logdepth, "chmod 755")) return 0; - if (test_chmodx(logdepth, "")) return 0; /* on some systems we don't need to do anything */ - } - else { - report(" user provided (%s)...", chmod); - if (test_chmodx(logdepth, chmod)) return 0; - } - return 1; -} - -int find_fstools_cat(const char *name, int logdepth, int fatal) -{ - const char *cat; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for cat... "); - logprintf(logdepth, "find_fstools_cat: trying to find cat...\n"); - logdepth++; - - cat = get("/arg/fstools/cat"); - if (cat == NULL) { - if (test_cat(logdepth, "cat")) return 0; - if (test_cat(logdepth, "type")) return 0; - } - else { - report(" user provided (%s)...", cat); - if (test_cat(logdepth, cat)) return 0; - } - return 1; -} - -int find_fstools_sed(const char *name, int logdepth, int fatal) -{ - const char *sed; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for sed... "); - logprintf(logdepth, "find_fstools_sed: trying to find sed...\n"); - logdepth++; - - sed = get("/arg/fstools/sed"); - if (sed == NULL) { - if (test_sed(logdepth, "sed")) return 0; - } - else { - report(" user provided (%s)...", sed); - if (test_sed(logdepth, sed)) return 0; - } - return 1; -} - -int find_fstools_file_l(const char *name, int logdepth, int fatal) -{ - const char *file; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for file... "); - logprintf(logdepth, "find_fstools_file_l: trying to find file -L...\n"); - logdepth++; - - file = get("/arg/fstools/file_l"); - if (file == NULL) { - if (test_file(logdepth, "fstools/file_l", "file -L")) return 0; - if (test_file(logdepth, "fstools/file_l", "file")) return 0; - } - else { - report(" user provided (%s)...", file); - if (test_file(logdepth, "fstools/file_l", file)) return 0; - } - return 1; -} - -int find_fstools_file(const char *name, int logdepth, int fatal) -{ - const char *file; - - (void) fatal; /* to suppress compiler warnings about not using fatal */ - - report("Checking for file... "); - logprintf(logdepth, "find_fstools_file: trying to find file...\n"); - logdepth++; - - file = get("/arg/fstools/file"); - if (file == NULL) { - if (test_file(logdepth, "fstools/file", "file")) return 0; - } - else { - report(" user provided (%s)...", file); - if (test_file(logdepth, "fstools/file", file)) return 0; - } - return 1; -} diff --git a/scconfig/src/default/.svn/pristine/f4/f458e9506b214649900809367c684ea62b74b5a6.svn-base b/scconfig/src/default/.svn/pristine/f4/f458e9506b214649900809367c684ea62b74b5a6.svn-base deleted file mode 100644 index 54256a06..00000000 --- a/scconfig/src/default/.svn/pristine/f4/f458e9506b214649900809367c684ea62b74b5a6.svn-base +++ /dev/null @@ -1,338 +0,0 @@ -/* - scconfig - library for listing files in a directory - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "db.h" -#include "libs.h" -#include "log.h" -#include "dep.h" - -static void destroy_testdir(int logdepth, char *dir) -{ - const char *rm; - char *cmd, *dir_esc; - - rm = get("fstools/rm"); - if (rm == NULL) { - logprintf(logdepth, "CAN NOT delete test directory '%s': no rm available\n", dir); - return; - } - - if (dir == NULL) - return; - - logprintf(logdepth, "deleting test directory '%s'\n", dir); - - cmd = malloc(strlen(dir) + strlen(rm) + 4); - dir_esc = shell_escape_dup(dir); - sprintf(cmd, "%s %s", rm, dir_esc); - run_shell(0, cmd, NULL); - free(cmd); - free(dir); - free(dir_esc); -} - -static char *create_testdir(int logdepth) -{ - char *dir, *fn, *cmd; - const char *mkdir; - int n; - logprintf(logdepth, "creating test directory\n"); - - dir = tempdir_new(logdepth+1, ""); - logprintf(logdepth, "sandbox is: '%s'\n", dir); - - fn = malloc(strlen(dir) + 32); - for(n = 0; n < 2; n++) { - FILE *f; - sprintf(fn, "%s%sfile%d", dir, get("sys/path_sep"), n+1); - f = fopen(fn, "w"); - if (f != NULL) { - fclose(f); - if (!is_file(fn)) { - logprintf(logdepth, "Can not create file %s\n", fn); - free(fn); - destroy_testdir(logdepth, dir); - return NULL; - } - } - } - - mkdir = get("fstools/mkdir"); - - cmd = malloc(strlen(dir) + 64); - for(n = 0; n < 2; n++) { - char *fn_esc; - sprintf(fn, "%s%sdir%d", dir, get("sys/path_sep"), n+1); - fn_esc = shell_escape_dup(fn); - sprintf(cmd, "%s %s", mkdir, fn_esc); - free(fn_esc); - if (run_shell(logdepth+1, cmd, NULL) || (!is_dir(fn))) { - logprintf(logdepth, "Can not create directory %s\n", fn); - free(fn); - free(cmd); - destroy_testdir(logdepth, dir); - return NULL; - } - } - free(cmd); - free(fn); - return dir; -} - -static int test(int logdepth, int argc, char *argv[]) -{ - int dir[2], file[2], n; - int *arr, idx; - - for(n = 0; n < 2; n++) { - dir[n] = 0; - file[n] = 0; - } - - /* count the list of files, increase arrays by hit */ - for(n = 0; n < argc; n++) { - arr = NULL; - if (strncmp(argv[n], "dir", 3) == 0) { arr = dir; idx = atoi(argv[n]+3); } - if (strncmp(argv[n], "file", 4) == 0) { arr = file; idx = atoi(argv[n]+4); } - if (arr == NULL) { - logprintf(logdepth, "test fails: unknown existing file on the list: '%s'\n", argv[n]); - return 0; - } - idx--; - if ((idx < 0) || (idx > 1)) { - logprintf(logdepth, "test fails: file name changed: '%s'\n", argv[n]); - return 0; - } - arr[idx]++; - } - - /* check if every item was found exactly once */ - for(n = 0; n < 2; n++) { - if ((dir[n] != 1) || (file[n] != 1)) { - logprintf(logdepth, "test fails: %s%d not found \n", dir[n] ? "file" : "dir", n); - return 0; - } - } - - return 1; -} - -static void filelist_extract(char *out, const char *dir, const char *method, int *argc, char ***argv) -{ - char *s, sep, *start, *end; - int len, allocated = 0, count = 0; - char **arr = NULL; - const char *psep; - - psep = get("sys/path_sep"); - - len = strlen(dir); - - /* uniform separator */ - if (*method == 'w') { - /* if word splitting then convert newlines to spaces and convert tabs to spaces */ - for(s = out; *s != '\0'; s++) { - if ((*s == '\n') || (*s == '\r') || (*s == '\t')) - *s = ' '; - } - sep = ' '; - } - else { - for(s = out; *s != '\0'; s++) { - if (*s == '\r') - *s = '\n'; - } - sep = '\n'; - } - - start = out; - while((s = str_chr(start, sep)) != NULL) { - *s = '\0'; - if (strncmp(dir, start, len) == 0) - start += len; - while(*start == *psep) - start++; - - if (*start != '\0') { - end = str_chr(start, *psep); - if (end != NULL) - *end = '\0'; - - /* add only if not the same as previous and exists */ - if ((!((count > 0) && (strcmp(arr[count - 1], start) == 0))) && (exists_in(dir, start))) { - - if (count >= allocated) { - allocated = count + 32; - arr = realloc(arr, sizeof(char *) * allocated); - } - arr[count] = strclone(start); - count++; - } - } - - start = s+1; - while(*start == sep) start++; - } - *argc = count; - *argv = arr; -} - -void filelist_free(int *argc, char ***argv) -{ - int n; - - if (*argv == NULL) - return; - - for(n = 0; n < *argc; n++) - free((*argv)[n]); - free(*argv); - *argc = 0; -} - -static char *filelist_asmcmd(const char *dir, const char *list_cmd) -{ - char *cmd; - - cmd = malloc(strlen(dir) + strlen(list_cmd) + 32); - sprintf(cmd, list_cmd, dir); - return cmd; -} - -static int try(int logdepth, const char *dir, const char *list_cmd, const char *method) -{ - char *cmd, *out, *dir_esc; - int argc, res; - char **argv; - - dir_esc = shell_escape_dup(dir); - cmd = filelist_asmcmd(dir_esc, list_cmd); - free(dir_esc); - logprintf(logdepth, "trying '%s'...\n", cmd); - - run_shell(logdepth+1, cmd, &out); - if (out != NULL) { - filelist_extract(out, dir, method, &argc, &argv); - res = test(logdepth+1, argc, argv); - filelist_free(&argc, &argv); - free(out); - } - - if (res) { - logprintf(logdepth+1, "Works.", cmd); - put("/internal/filelist/cmd", list_cmd); - put("/internal/filelist/method", method); - report("OK ('%s' with %s split)\n", list_cmd, method); - } - - free(cmd); - return res; -} - -int find_filelist(const char *name, int logdepth, int fatal) -{ - char *dir; - char *old_cwd; - int ret; - - old_cwd = strclone(db_cwd); - db_cd("/host"); - - require("fstools/mkdir", logdepth, fatal); - require("fstools/rm", logdepth, fatal); - - - report("Checking for filelist... "); - logprintf(logdepth, "find_filelist: trying to find file listing...\n"); - logdepth++; - - - dir = create_testdir(logdepth); - if (dir == NULL) { - report("Failed to creat sandbox\n"); - ret = 1; - goto end; - } - - if ( - try(logdepth, dir, "ls %s", "line") || /* should return one file name per line since the output is redirected */ - try(logdepth, dir, "ls -1 %s", "line") || /* try to force one file name per line */ - try(logdepth, dir, "ls --format=single-column %s", "line") || /* for gnu ls */ - try(logdepth, dir, "find %s", "line") || /* if ls fails, we try find */ - try(logdepth, dir, "ls %s", "word") || /* if that fails too, ls may still have a list in multiple columns */ - try(logdepth, dir, "dir %s", "word") || /* or we are on windows where we need to use dir maybe */ - try(logdepth, dir, "echo %s/*", "word")) { /* or on a system without ls, dir or anything alike, but shell globbing may still work */ - - destroy_testdir(logdepth, dir); - ret = 0; - goto end; - } - - destroy_testdir(logdepth, dir); - ret = 1; - end:; - db_cd(old_cwd); - free(old_cwd); - return ret; -} - - -void filelist(int logdepth, const char *dir, int *argc, char ***argv) -{ - const char *list_cmd, *method; - char *cmd, *out, *dir_esc; - char *old_cwd; - - old_cwd = strclone(db_cwd); - db_cd("/host"); - - /* make sure these are set to invalid for easier return in case we fail anywhere later */ - *argc = -1; - *argv = NULL; - - if (!is_dir(dir)) - goto end; - - require("/internal/filelist/cmd", logdepth, 1); - require("/internal/filelist/method", logdepth, 1); - - list_cmd = get("/internal/filelist/cmd"); - method = get("/internal/filelist/method"); - - dir_esc = shell_escape_dup(dir); - cmd = filelist_asmcmd(dir_esc, list_cmd); - free(dir_esc); - run_shell(logdepth+1, cmd, &out); - if (out != NULL) { - filelist_extract(out, dir, method, argc, argv); - logprintf(logdepth, "filelist: Getting list of files in %s\n", dir); - free(out); - } - - free(cmd); - end:; - db_cd(old_cwd); - free(old_cwd); -} diff --git a/scconfig/src/default/.svn/pristine/f6/f6c08e4bed2b3e26b8deabd67b60aee5f11e6406.svn-base b/scconfig/src/default/.svn/pristine/f6/f6c08e4bed2b3e26b8deabd67b60aee5f11e6406.svn-base deleted file mode 100644 index 8b17ecd9..00000000 --- a/scconfig/src/default/.svn/pristine/f6/f6c08e4bed2b3e26b8deabd67b60aee5f11e6406.svn-base +++ /dev/null @@ -1,255 +0,0 @@ -/* - scconfig - dependencies - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include "dep.h" -#include "db.h" -#include "log.h" -#include "libs.h" - -typedef struct { - int (*fn)(const char *name, int logdepth, int fatal); -} fn_wrap_t; - - -static ht_t *deps = NULL; - -static const char *USER_WITHOUT = ""; - -/* find name_ and decide if it was a wildcard request; - NOTE: there are requests and servers, both can be wildcard independently. - - if a request ends with a / *, it is an explicit wildcard request (*wild=1) - - if a request names a "directory" that is wildcard-server, that's a wildcard request (*wild=1) - - else the request is a normal request (*wild=0). - For normal requests, a required node was explicitly named; if that node is - not created by the detection function, that's a failure. For wildcard - requests we don't look for any specific node to be created. - TODO: we may still check if at least the directory is created - */ -fn_wrap_t *get_wrap(const char *name_, int *wild, int *missing) -{ - fn_wrap_t *w; - char *name, *sep, *tmp; - int len, n; - - len = strlen(name_); - *wild = name_[len-1] == '*'; - - if (*wild) { - char *pres; - pres = malloc(len+16); - memcpy(pres, name_, len-1); - strcpy(pres+len-1, "presents"); - *missing = get(pres) == NULL; - if (*missing) { /* if there's no /presents, it may be a non-directory node with an actual non-empty string value */ - const char *val; - pres[len-2] = '\0'; - val = get(pres); - if (val != NULL) - *missing = !strlen(val); - } - free(pres); - if (!(*missing)) /* already detected, won't be detected again */ - return NULL; - } - *missing = 1; - - /* check for global --without disable */ - tmp = str_concat("", "/arg/without", db_cwd, "/", name_, NULL); - sep = tmp + strlen(tmp) - 1; - for(n = 0; n < 4; n++) { - const char *d = get(tmp); - if (sep < tmp+14) - break; - if (istrue(d)) { - free(tmp); - return (fn_wrap_t *)USER_WITHOUT; - } - while(*sep != '/') - sep--; - *sep = '\0'; - } - free(tmp); - - /* try full match first */ - w = ht_get(deps, name_); - if (w != NULL) - return w; - - - /* try substituting the last part of the path with * for wildcard matches */ - name = malloc(len+3); /* worst case: ends in a / and we need to append *\0; allocate a bit more */ - memcpy(name, name_, len+1); /* make a copy we can modify */ - if (name[len-1] != '/') { - name[len] = '/'; /* append a / - if name_ was a "directory", this will result in name/ * */ - name[len+1] = '\0'; - } - - *wild = 1; /* if we append a / *, then it's a wildcard request */ - for(;;) { - sep = str_rchr(name, '/'); - if (sep == NULL) - goto error; - sep[1] = '*'; - sep[2] = '\0'; - w = ht_get(deps, name); - if (w != NULL) { - free(name); - return w; - } - *sep = '\0'; - *wild = 0; /* cutting back the second layer - not wildcard request anymore, but a request to a specific node served by a wildcard */ - } - - /* no match, exit with error */ - error:; - *wild = 0; - free(name); - return NULL; -} - - -int require(const char *name, int logdepth, int fatal) -{ - fn_wrap_t *w; - int wild, missing; - - if (get(name) == NULL) { - w = get_wrap(name, &wild, &missing); - if (w == (fn_wrap_t *)USER_WITHOUT) { - if (fatal) { - error("Node %s is required by the software but disabled by the user using --without\n", name); - abort(); - } - else { - logprintf(logdepth, "(disabled using --without)"); - return 1; - } - } - if (!missing) - return 0; - if ((w == NULL) || (w->fn == NULL)) { - error("Node %s is required but I don't know how to detect it.\n", name); - abort(); - } - - logprintf(logdepth, "(Required node: '%s')\n", name); - if (w->fn(name, logdepth+1, fatal) != 0) { - if (fatal) { - error("Node %s is required but provided detection callback fails to find that feature on that system.\n", name); - abort(); - } - else { - logprintf(logdepth, "(Feature not found, but it is not fatal)"); - return 1; - } - } - if ((!wild) && (get(name) == NULL)) { - error("Node %s is required but provided detection callback didn't create it (looks like an internal error in scconfig). (db_cwd='%s')\n", name, db_cwd); - abort(); - } - } - return 0; -} - -const char *dep_add(const char *name, int (*finder)(const char *name, int logdepth, int fatal)) -{ - fn_wrap_t *w; - w = malloc(sizeof(fn_wrap_t)); - w->fn = finder; - return ht_set(deps, name, w); -} - -int asked_for(const char *cando, const char *needtodo) -{ - int len; - - /* foo/bar/baz matches /foo/bar/baz */ - if (strcmp(cando, needtodo) == 0) - goto yes; - - len = strlen(needtodo); - if (len == 0) - return 0; - - /* foo/bar/baz matches /foo/bar/ * */ - if ((needtodo[len-1] == '*') && (strncmp(cando, needtodo, len-1) == 0)) - goto yes; - - return 0; - - - yes:; /* asked for it, but have to see if it's already detected */ - if (get(cando) != NULL) - return 0; - - return 1; -} - -int is_dep_wild(const char *path) -{ - int len = strlen(path); - if (len == 0) - return 0; - return (path[len-1] == '*'); -} - -const char *det_list_target(const char *path) -{ - const char *res; - - if (path == NULL) - goto unk; - - res = strrchr(path, '/'); - if (res == NULL) - goto unk; - - return res + 1; -unk:; - return ""; -} - - -void dep_init(void) -{ - deps = ht_resize(ht_alloc(0), 128); -} - -void dep_uninit(void) -{ - ht_free(deps); -} - -int is_dep_known(const char *name) -{ - return (ht_get(deps, name) != NULL); -} - -void require_all(int fatal) -{ - ht_entry_t *h; - - for(h = ht_first(deps); h != NULL; h = ht_next(deps, h)) - require(h->key, 0, fatal); -} diff --git a/scconfig/src/default/.svn/pristine/f7/f7fa55b999d3b0d563d2eb68212a6412ba473912.svn-base b/scconfig/src/default/.svn/pristine/f7/f7fa55b999d3b0d563d2eb68212a6412ba473912.svn-base deleted file mode 100644 index 6ba61776..00000000 --- a/scconfig/src/default/.svn/pristine/f7/f7fa55b999d3b0d563d2eb68212a6412ba473912.svn-base +++ /dev/null @@ -1,1134 +0,0 @@ -/* - scconfig - detection of cc and compiler features - Copyright (C) 2009..2012 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - - - -static int try_flags(int logdepth, const char *cc, const char *test_c, const char *cflags, const char *ldflags, const char *expected) -{ - char *out; - - logprintf(logdepth, "trying cc:try_flags with cc='%s' cflags='%s' ldflags='%s'\n", (cc == NULL ? get("cc/cc") : cc), cflags == NULL ? "" : cflags, ldflags == NULL ? "" : ldflags); - - if (compile_run(logdepth+1, test_c, cc, cflags, ldflags, &out) == 0) { - if (((out == NULL) && (iscross)) || (strncmp(out, expected, strlen(expected)) == 0)) { - free(out); - return 1; - } - free(out); - } - return 0; -} - -static int try_flags_inv(int logdepth, const char *cc, const char *test_c, const char *cflags, const char *ldflags, const char *expected_bad) -{ - char *out; - - logprintf(logdepth, "trying cc:try_flags with cc='%s' cflags='%s' ldflags='%s'\n", (cc == NULL ? get("cc/cc") : cc), cflags == NULL ? "" : cflags, ldflags == NULL ? "" : ldflags); - - if (compile_run(logdepth+1, test_c, cc, cflags, ldflags, &out) == 0) { - if (((out == NULL) && (iscross)) || (strncmp(out, expected_bad, strlen(expected_bad)) != 0)) { - free(out); - return 1; - } - free(out); - } - return 0; -} - -static int try(int logdepth, const char *cc, const char *test_c, const char *expected) -{ - return try_flags(logdepth, cc, test_c, NULL, NULL, expected); -} - - -static int trycc(int logdepth, const char *cc, const char *test_c) -{ - int ret; - - if (cc == NULL) - return 0; - - ret = try(logdepth, cc, test_c, "OK"); - if (ret) - put("cc/cc", cc); - return ret; -} - -int find_cc(const char *name, int logdepth, int fatal) -{ - char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL, *targetcc; - const char *cc, *cflags, *ldflags, *target, *sys; - int len; - - require("sys/name", logdepth, fatal); - - sys = istarget(db_cwd) ? "target" : "host"; - report("Checking for cc (%s)... ", sys); - logprintf(logdepth, "find_cc: trying to find cc (%s)...\n", sys); - logdepth++; - - /* cflags */ - cflags = get("/arg/cc/cflags"); - if (cflags != NULL) { - logprintf(logdepth+1, "using user supplied cflags '%s'\n", cflags); - put("cc/cflags", cflags); - } - - /* ldflags */ - ldflags = get("/arg/cc/ldflags"); - if (ldflags != NULL) { - logprintf(logdepth+1, "using user supplied ldflags '%s'\n", ldflags); - put("cc/ldflags", ldflags); - } - - cc = get("/arg/cc/cc"); - if (cc == NULL) { - target = get("sys/target"); - if (target != NULL) { - logprintf(logdepth+1, "find_cc: crosscompiling for '%s', looking for target cc\n", target); - len = strlen(target); - targetcc = malloc(len + 8); - memcpy(targetcc, target, len); - strcpy(targetcc + len, "-gcc"); - if (!trycc(logdepth+1, targetcc, test_c)) { - strcpy(targetcc + len, "-cc"); - if (!trycc(logdepth+1, targetcc, test_c)) { - report("FAILED: failed to find crosscompiler for target '%s'\n", target); - logprintf(logdepth, "find_cc: FAILED to find a crosscompiler for target '%s'\n", target); - return 1; - } - } - put("cc/cc", targetcc); - } - else { - cc = getenv("CC"); - logprintf(logdepth, "find_cc: Detecting cc (host)\n"); - /* Find a working cc (no arguments) */ - if (!(((cc != NULL) && (trycc(logdepth+1, cc, test_c))) || trycc(logdepth+1, "gcc", test_c) || trycc(logdepth+1, "cc", test_c))) { - report("FAILED to find a compiler\n"); - logprintf(logdepth, "find_cc: FAILED to find a compiler\n"); - return 1; - } - } - } - else { - put("cc/cc", cc); - logprintf(logdepth+1, "using user supplied '%s' (will test later)\n", cc); - } - - /* cflags (again) */ - if (cflags == NULL) { - logprintf(logdepth, "find_cc: Detecting -pipe\n"); - - if (compile_run(logdepth+1, test_c, NULL, "-pipe", "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - append("cc/cflags", " -pipe"); - } - free(out); - } - } - if (get("cc/cflags") == NULL) - put("cc/cflags", ""); - - /* ldflags (again) */ - if (get("cc/ldflags") == NULL) - put("cc/ldflags", ""); - - /* Final test of all arguments together */ - logprintf(logdepth, "find_cc: final test on cc and all flags \n"); - if (compile_run(logdepth+1, test_c, NULL, NULL, NULL, &out) != 0) { - report("FAILED to get the compiler and all flags to work together\n"); - logprintf(logdepth, "find_cc: the compiler and all the flags don't work well together, aborting\n"); - if (out != NULL) - free(out); - return 1; - } - - report("OK ('%s', '%s', '%s')\n", get("cc/cc"), get("cc/cflags"), get("cc/ldflags")); - logprintf(logdepth, "find_cc: conclusion: cc='%s' cflags='%s' ldflags='%s'\n", get("cc/cc"), get("cc/cflags"), get("cc/ldflags")); - if (out != NULL) - free(out); - return 0; -} - -int find_cc_argstd(const char *det_name, int logdepth, int fatal) -{ - char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL; - char **flg, *flags[] = {"-ansi", "-pedantic", "-Wall", "-std=c89", "-std=c99", "-Werror", "-Wextra", "-W", "-pg", "-no-pie", "-static-pie", NULL}; - const char *det_target = det_list_target(det_name); - - require("cc/cc", logdepth, fatal); - - logprintf(logdepth, "find_cc: Detecting CC args %s\n", det_target); - report("Checking for cc args for std %s... ", det_target); - - for(flg = flags; *flg != NULL; flg++) { - char name[128], *end; - const char *found = ""; - sprintf(name, "cc/argstd/%s", (*flg)+1); - end = strchr(name, '='); - if (end != NULL) - *end = '_'; - if (!asked_for(name, det_name)) - continue; - if (compile_run(logdepth+1, test_c, NULL, *flg, "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - found = *flg; - report(" "); - report(found); - } - free(out); - } - put(name, found); - } - - if (is_dep_wild(det_name)) - put("cc/argstd/presents", strue); /* to avoid re-detection*/ - - report("\n"); - return 0; -} - -int find_cc_argmachine(const char *name, int logdepth, int fatal) -{ -#define ARGM(flag) "-m" #flag , "-mno-" #flag - const char *test_c = "#include \nint main() { printf(\"OK\\n\");\nreturn 0;}\n"; - char *out = NULL; - const char **flg, *flags[] = { ARGM(mmx), ARGM(sse), ARGM(sse2), ARGM(sse3), ARGM(ssse3), ARGM(sse4), ARGM(sse4.1), ARGM(sse4.2), ARGM(avx), ARGM(avx2), NULL}; - - require("cc/cc", logdepth, fatal); - - logprintf(logdepth, "find_cc: Detecting CC machine args\n"); - report("Checking for cc args for machine... "); - - for(flg = flags; *flg != NULL; flg++) { - char name[128], *end; - const char *found = ""; - { - const char* ptr = (*flg) + 1; - strcpy(name, "cc/argmachine/"); - end = name + strlen(name); - while(*ptr) { - if('.'!=*ptr && '-'!=*ptr) *end++ = *ptr; - ++ptr; - } - *end = '\0'; - } - end = strchr(name, '='); - if (end != NULL) - *end = '_'; - if (compile_run(logdepth+1, test_c, NULL, *flg, "", &out) == 0) { - if (target_emu_fail(out) || (strncmp(out, "OK", 2) == 0)) { - found = *flg; - report(" "); - report(found); - } - free(out); - } - put(name, found); - } - - report("\n"); - return 0; -#undef ARGM -} - -int find_inline(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "static inline void test_inl()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test_inl();" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for inline... "); - logprintf(logdepth, "find_inline: trying to find inline...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/inline", strue); - report("Found.\n"); - return 0; - } - put("cc/inline", sfalse); - report("Not found.\n"); - return 1; -} - -int find_varargmacro(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#define pr(fmt, x...) {printf(\"PR \"); printf(fmt, x); }" - NL "int main() {" - NL " pr(\"%d %d %s\", 42, 8192, \"test\");" - NL " puts(\"\");" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for vararg macro... "); - logprintf(logdepth, "find_varargmacro: trying to find vararg macro...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "PR 42 8192 test")) { - put("cc/varargmacro", strue); - report("Found.\n"); - return 0; - } - put("cc/varargmacro", sfalse); - report("Not found.\n"); - return 1; -} - -int find_funcmacro(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " printf(\"%s\\n\", __func__);" - NL " return 0;" - NL "}" - NL ; - require("cc/cc", logdepth, fatal); - - report("Checking for __func__ macro... "); - logprintf(logdepth, "find_funcmacro: trying to find __func__ macro...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "main")) { - put("cc/funcmacro", strue); - report("Found.\n"); - return 0; - } - put("cc/funcmacro", sfalse); - report("Not found.\n"); - return 1; -} - -int find_constructor(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "void startup() __attribute__ ((constructor));" - NL "void startup()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for constructor... "); - logprintf(logdepth, "find_constructor: trying to find constructor...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/constructor", strue); - report("Found.\n"); - return 0; - } - put("cc/constructor", sfalse); - report("Not found.\n"); - return 1; -} - -int find_destructor(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "void startup() __attribute__ ((destructor));" - NL "void startup()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for destructor... "); - logprintf(logdepth, "find_destructor: trying to find destructor...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/destructor", strue); - report("Found.\n"); - return 0; - } - put("cc/destructor", sfalse); - report("Not found.\n"); - return 1; -} - -static int test_fattr(const char *name, int logdepth, int fatal, const char *fattr) -{ - char path[64]; - char test_c[256]; - const char *test_c_tmp = - NL "#include " - NL "static void test1() __attribute__ ((%s));" - NL "static void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - sprintf(test_c, test_c_tmp, fattr); - sprintf(path, "cc/func_attr/%s/presents", fattr); - - report("Checking for function attribute %s... ", fattr); - logprintf(logdepth, "test_fattr: trying to find %s...\n", fattr); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put(path, strue); - report("Found.\n"); - return 0; - } - put(path, sfalse); - report("Not found.\n"); - return 1; -} - -int find_fattr_unused(const char *name, int logdepth, int fatal) -{ - return test_fattr(name, logdepth, fatal, "unused"); -} - -static int test_declspec(const char *name, int logdepth, int fatal, const char *dspec) -{ - char path[64]; - char test_c[256]; - const char *test_c_tmp = - NL "#include " - NL "void __declspec (%s) test1();" - NL "void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test1();" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - sprintf(test_c, test_c_tmp, dspec); - sprintf(path, "cc/declspec/%s/presents", dspec); - - report("Checking for declspec %s... ", dspec); - logprintf(logdepth, "test_declspec: trying to find %s...\n", dspec); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put(path, strue); - report("Found.\n"); - return 0; - } - put(path, sfalse); - report("Not found.\n"); - return 1; -} - -int find_declspec_dllimport(const char *name, int logdepth, int fatal) -{ - return test_declspec(name, logdepth, fatal, "dllimport"); -} - -int find_declspec_dllexport(const char *name, int logdepth, int fatal) -{ - return test_declspec(name, logdepth, fatal, "dllexport"); -} - -static int test_dll_auxfile(const char *name, int logdepth, int fatal, const char *path, const char *ldflag, const char *filename) -{ - char *ldflags; - char test_c[256]; - const char *test_c_template = - NL "#include " - NL "void %s test1();" - NL "void test1()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL "int main() {" - NL " test1();" - NL " return 0;" - NL "}" - NL ; - const char *dspec; - - require("cc/cc", logdepth, fatal); - require("cc/declspec/dllexport/*", logdepth, 0); - - if (istrue("cc/declspec/dllexport/presents")) - dspec = " __declspec(dllexport) "; - else - dspec = ""; - - sprintf(test_c, test_c_template, dspec); - - report("Checking for DLL flag %s... ", ldflag); - logprintf(logdepth, "test_dll_auxfile: trying to find %s...\n", ldflag); - logdepth++; - ldflags = str_concat("", ldflag, ",", filename, " ", get("cc/ldflags"), NULL); - if (try_flags(logdepth, NULL, test_c, NULL, ldflags, "OK")) { - unlink(filename); - put(path, ldflag); - free(ldflags); - report("Found.\n"); - return 0; - } - unlink(filename); - free(ldflags); - report("Not found.\n"); - return 1; -} - -int find_cc_wloutimplib(const char *name, int logdepth, int fatal) -{ - return test_dll_auxfile(name, logdepth, fatal, "cc/wloutimplib", "-Wl,--out-implib", "libscconfig_0.a"); -} - -int find_cc_wloutputdef(const char *name, int logdepth, int fatal) -{ - return test_dll_auxfile(name, logdepth, fatal, "cc/wloutputdef", "-Wl,--output-def", "libscconfig_0.def"); -} - -/* Hello world program to test compiler flags */ -static const char *test_hello_world = - NL "#include " - NL "int main() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -static int try_hello(int logdepth, const char *cflags, const char *ldflags, const char *name, const char *value) -{ - if (try_flags(logdepth, NULL, test_hello_world, cflags, ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - return 1; - } - return 0; -} - -int find_rdynamic(const char *name, int logdepth, int fatal) -{ - const char *node = "cc/rdynamic"; - - require("cc/cc", logdepth, fatal); - - report("Checking for rdynamic... "); - logprintf(logdepth, "find_rdynamic: trying to find rdynamic...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-rdynamic", node, "-rdynamic")) return 0; - if (try_hello(logdepth, NULL, "-Wl,-export-dynamic", node, "-Wl,-export-dynamic")) return 0; - if (try_hello(logdepth, NULL, NULL, node, "")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_cc_fpie(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - /* TODO: what about -fpic? */ - - report("Checking for -fpie... "); - logprintf(logdepth, "find_cc_fpie: trying to find -fpie...\n"); - logdepth++; - - /* NOTE: some gcc configuration might not pass the -pie flag to the linker, so */ - /* try to detect whether we can force it to the linker */ - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fpie", "-pie -Wl,-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fPIE", "-pie -Wl,-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fpie", "-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, "-fPIE", "-pie")) return 0; - if (try_icl(logdepth, "cc/fpie", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fpie"); -} - -int find_cc_fnopie(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - - report("Checking for -fno-pie... "); - logprintf(logdepth, "find_cc_fnopie: trying to find -fno-pie...\n"); - logdepth++; - - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, "-fno-pie", NULL)) return 0; - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, "-fno-pie", "-static")) return 0; - if (try_icl(logdepth, "cc/fnopie", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fnopie"); -} - -int find_cc_fnopic(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - - require("cc/cc", logdepth, fatal); - - report("Checking for -fno-pic... "); - logprintf(logdepth, "find_cc_fnopic: trying to find -fno-pic...\n"); - logdepth++; - - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, "-fno-pic", NULL)) return 0; - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, "-fno-pic", "-static")) return 0; - if (try_icl(logdepth, "cc/fnopic", test_c, NULL, NULL, NULL)) return 0; - return try_fail(logdepth, "cc/fnopic"); -} - -int find_soname(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for soname... "); - logprintf(logdepth, "find_soname: trying to find soname...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-Wl,-soname,libscconfig.0", "cc/soname", "-Wl,-soname,")) return 0; - if (try_hello(logdepth, NULL, NULL, "cc/soname", "")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_so_undefined(const char *name, int logdepth, int fatal) -{ - static const char *test_c = - NL "#include " - NL "void intentionally_undefined_symbol(void);" - NL "int main() {" - NL " intentionally_undefined_symbol();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - const char **t, *try_ldflags[] = { - "", - "-undefined dynamic_lookup", /* OSX + clang */ - NULL - }; - - require("cc/cc", logdepth, fatal); - require("cc/ldflags_dynlib", logdepth, fatal); - - report("Checking for so_undefined... "); - logprintf(logdepth, "find_so_undefined: trying to find so_undefined...\n"); - logdepth++; - - for(t = try_ldflags; *t != NULL; t++) { - const char *fpic; - char *ldf, *oname, *libname_dyn, *cflags_c; - int res1, res2; - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - cflags_c = str_concat(" ", "-c", fpic, NULL); - - libname_dyn = (char *)get("sys/ext_dynlib"); - ldf = str_concat(" ", get("cc/ldflags_dynlib"), *t, NULL); - res1 = compile_code(logdepth, test_c, &oname, NULL, cflags_c, NULL); - res2 = compile_file(logdepth, oname, &libname_dyn, NULL, NULL, ldf); - unlink(libname_dyn); - unlink(oname); - free(libname_dyn); - free(oname); - free(cflags_c); - - if ((res1 == 0) && (res2 == 0)) { - put(name, *t); - report("OK (%s)\n", *t); - return 0; - } - } - - report("Not found.\n"); - return 1; -} - - -int find_wlrpath(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for rpath... "); - logprintf(logdepth, "find_wlrpath: trying to find rpath...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-Wl,-rpath=.", "cc/wlrpath", "-Wl,-rpath=")) return 0; - - report("Not found.\n"); - return 1; -} - -int find_fpic(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - - report("Checking for -fpic... "); - logprintf(logdepth, "find_fpic: trying to find -fpic...\n"); - logdepth++; - - if (try_hello(logdepth, NULL, "-fPIC", "cc/fpic", "-fPIC")) return 0; - if (try_hello(logdepth, NULL, "-fpic", "cc/fpic", "-fpic")) return 0; - if (try_hello(logdepth, NULL, NULL, "cc/fpic", "")) return 0; - - report("Not found.\n"); - return 1; -} - -/* Hello world lib... */ -static const char *test_lib = - NL "#include " - NL "int hello() {" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -/* ...and the corresponding host application */ -static const char *test_host = - NL "#include " - NL "#include " - NL "#include %s" - NL "int main() {" - NL " void *handle = NULL;" - NL " void (*func)() = NULL;" - NL " char *error;" - NL - NL " handle = dlopen(\"%s\", RTLD_NOW);" - NL " if (handle == NULL) {" - NL " printf(\"dlopen fails: \", dlerror());" - NL " return 1;" - NL " }" - NL " func = dlsym(handle, \"hello\");" - NL " if (func == NULL) {" - NL " printf(\"dlsym fails: \", dlerror());" - NL " return 1;" - NL " }" - NL " func();" - NL " return 0;" - NL "}" - NL ; - -static int try_dynlib(int logdepth, const char *cflags, char *concated_ldflags, const char *name, const char *value, const char *host_app_cflags, const char *host_app_ldflags) -{ - char test_host_app[1024]; - const char *fpic; - const char *ld_include; - const char *dlc; - char *libname, *libname_dyn; - char *cflags_c; - char *oname = ".o"; - int ret = 0; - - - dlc = get("libs/dl-compat"); - if ((dlc != NULL) && (strcmp(dlc, strue) == 0)) - ld_include = ""; - else - ld_include = ""; - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - if (cflags == NULL) - cflags=""; - - cflags_c = malloc(strlen(cflags) + 8 + strlen(fpic)); - sprintf(cflags_c, "%s -c %s", cflags, fpic); - - - libname_dyn = libname = (char *)get("sys/ext_dynlib"); - if ((compile_code(logdepth, test_lib, &oname, NULL, cflags_c, NULL) != 0) || - (compile_file(logdepth, oname, &libname_dyn, NULL, NULL, concated_ldflags) != 0)) { - report("FAILED (compiling dynlib)\n"); - } - else { - sprintf(test_host_app, test_host, ld_include, libname_dyn); - if (try_flags(logdepth, NULL, test_host_app, host_app_cflags, host_app_ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - ret = 1; - } - } - unlink(libname_dyn); - unlink(oname); - if (libname != libname_dyn) - free(libname_dyn); - free(oname); - free(concated_ldflags); - free(cflags_c); - return ret; -} - - -int find_ldflags_dynlib(const char *name, int logdepth, int fatal) -{ - - require("cc/cc", logdepth, fatal); - require("cc/rdynamic", logdepth, fatal); - require("cc/fpic", logdepth, fatal); - require("libs/ldl", logdepth, fatal); - - report("Checking for dynamic library ldflags... "); - logprintf(logdepth, "find_ldflags_dynlib: trying to find dynamic library ldflags...\n"); - logdepth++; - - if (try_dynlib(logdepth, NULL, concat_nodes("-dynamic -shared", "cc/rdynamic", "libs/ldl", NULL), "cc/ldflags_dynlib", "-dynamic -shared", NULL, get("libs/ldl"))) return 0; - if (try_dynlib(logdepth, NULL, concat_nodes("-shared", "cc/rdynamic", "libs/ldl", NULL), "cc/ldflags_dynlib", "-shared", NULL, get("libs/ldl"))) return 0; - report("Not found.\n"); - return 1; -} - -static int try_dll_or_so(int logdepth, int is_dll, const char *lib_ldflags, const char *name, const char *value, - const char *dspec_dllexport, const char *dspec_dllimport, - const char *app_cflags, const char *app_ldflags) -{ - static const char *test_lib_template = - NL "#include " - NL "%s void hello();" - NL "void hello() {" - NL " puts(\"OK\");" - NL "}" - NL ; - static const char *test_app_template = - NL "%s void hello();" - NL "int main() {" - NL " hello();" - NL " return 0;" - NL "}" - NL ; - char test_lib[1024]; - char test_app[1024]; - const char *fpic; - char *cflags_c; - char *oname, *oname_ext; - char *libname, *libname_ext; - char *appname = NULL, *appname_ext = NULL; - char *lib_filename = NULL, *lib_dirname = NULL; - char *lib_ldflags_new = NULL; - char *app_ldflags_new = NULL; - size_t len, ii; - int ret = 0; - - ++logdepth; - - require("cc/cc", logdepth, 0); - require("cc/cflags", logdepth, 0); - require("cc/ldflags", logdepth, 0); - require("cc/fpic", logdepth, 0); - require("sys/ext_exe", logdepth, 0); - require("sys/ext_dynlib_native", logdepth, 0); - - fpic = get("cc/fpic"); - if (fpic == NULL) fpic = ""; - - if (app_cflags == NULL) - app_cflags = ""; - - if (app_ldflags == NULL) - app_ldflags = ""; - - cflags_c = str_concat(" ", get("cc/cflags"), "-c", fpic, NULL); - - oname = oname_ext = ".o"; - libname = libname_ext = (char *)get("sys/ext_dynlib_native"); - sprintf(test_lib, test_lib_template, dspec_dllexport); - lib_ldflags_new = str_concat(" ", get("cc/ldflags"), lib_ldflags, NULL); - if ((compile_code(logdepth, test_lib, &oname, NULL, cflags_c, NULL) != 0) || - (compile_file(logdepth, oname, &libname, NULL, NULL, lib_ldflags_new) != 0)) { - report("FAILED (compiling %s)\n", (is_dll?"DLL":"SO")); - } - else { - lib_filename = file_name(libname); - lib_dirname = dir_name(libname); - - if (!is_dll) { - len = strlen(lib_filename) - strlen(libname_ext); - for (ii=3; ii" - NL "int main() {" - NL " char *s;" - NL " s = alloca(128);" - NL " if (s != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL ; - -static int try_alloca(int logdepth, const char *cflags, const char *ldflags, const char *name, const char *value) -{ - if (try_flags(logdepth, NULL, test_alloca, cflags, ldflags, "OK")) { - put(name, value); - report("OK (%s)\n", value); - return 1; - } - return 0; -} - -int find_alloca(const char *name, int logdepth, int fatal) -{ - require("cc/cc", logdepth, fatal); - - report("Checking for alloca()... "); - logprintf(logdepth, "find_alloca: trying to find alloca()...\n"); - logdepth++; - - if (try_alloca(logdepth, NULL, NULL, "cc/alloca/presents", "true")) return 0; - - put("cc/alloca/presents", "false"); - report("Not found.\n"); - return 1; -} - - -int find__exit(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main() {" - NL " _exit(0);" - NL " puts(\"BAD\");" - NL " return 0;" - NL "}" - NL ; - - require("cc/cc", logdepth, fatal); - - report("Checking for _exit()... "); - logprintf(logdepth, "find__exit: trying to find _exit()...\n"); - logdepth++; - - if (try_flags_inv(logdepth, NULL, test_c, NULL, NULL, "BAD")) { - put("cc/_exit/presents", strue); - report("found\n"); - return 0; - } - - put("cc/_exit/presents", sfalse); - report("Not found.\n"); - return 1; -} - -int find_cc_pragma_message(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#define DO_PRAGMA(arg) _Pragma(#arg)" - NL "#define TODO(x) DO_PRAGMA(message(\"TODO: \" #x))" - NL "TODO(test)" - NL "int main()" - NL "{" - NL " puts(\"OK\");" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for _Pragma(message)... "); - logprintf(logdepth, "find_cc_pragma_message: trying to find pragma_message...\n"); - logdepth++; - if (try(logdepth, NULL, test_c, "OK")) { - put("cc/pragma_message", strue); - report("Found.\n"); - return 0; - } - put("cc/pragma_message", sfalse); - report("Not found.\n"); - return 1; -} - -int find_cc_static_libgcc(const char *name, int logdepth, int fatal) -{ - const char *test_c = test_hello_world; - const char *key = "cc/static_libgcc"; - - require("cc/cc", logdepth, fatal); - - report("Checking for -static-libgcc... "); - logprintf(logdepth, "find_cc_static_libgcc: trying to find -static-libgcc...\n"); - logdepth++; - - if (try_icl(logdepth, key, test_c, NULL, NULL, "-static-libgcc")) return 0; - return try_fail(logdepth, key); -} diff --git a/scconfig/src/default/.svn/pristine/f8/f8f0c746b99c8983536b2437ed20e1b8739e0cac.svn-base b/scconfig/src/default/.svn/pristine/f8/f8f0c746b99c8983536b2437ed20e1b8739e0cac.svn-base deleted file mode 100644 index 42920330..00000000 --- a/scconfig/src/default/.svn/pristine/f8/f8f0c746b99c8983536b2437ed20e1b8739e0cac.svn-base +++ /dev/null @@ -1,611 +0,0 @@ -/* - - * regex - Regular expression pattern matching and replacement - * - * By: Ozan S. Yigit (oz) - * Dept. of Computer Science - * York University - * - * These routines are the PUBLIC DOMAIN equivalents of regex - * routines as found in 4.nBSD UN*X, with minor extensions. - * - * These routines are derived from various implementations found - * in software tools books, and Conroy's grep. They are NOT derived - * from licensed/restricted software. - * For more interesting/academic/complicated implementations, - * see Henry Spencer's regexp routines, or GNU Emacs pattern - * matching module. - * - * const correctness patch by Tibor 'Igor2' Palinkas in 2009..2010 - * new subs code by Tibor 'Igor2' Palinkas in 2015 - */ -#include -#include -#include "regex.h" - -#define MAXNFA 1024 -#define MAXTAG 10 - -#define OKP 1 -#define NOP 0 - -#define CHR 1 -#define ANY 2 -#define CCL 3 -#define BOL 4 -#define EOL 5 -#define BOT 6 -#define EOT 7 -#define BOW 8 -#define EOW 9 -#define REF 10 -#define CLO 11 - -#define END 0 - -/* - * The following defines are not meant to be changeable. - * They are for readability only. - */ -#define MAXCHR 128 -#define CHRBIT 8 -#define BITBLK MAXCHR/CHRBIT -#define BLKIND 0170 -#define BITIND 07 - -#define ASCIIB 0177 - -#ifdef NO_UCHAR -typedef char CHAR; -#else -typedef unsigned char CHAR; -#endif - -static int tagstk[MAXTAG]; /* subpat tag stack..*/ -static CHAR nfa[MAXNFA]; /* automaton.. */ -static int sta = NOP; /* status of lastpat */ - -static CHAR bittab[BITBLK]; /* bit table for CCL */ - /* pre-set bits... */ -static CHAR bitarr[] = {1,2,4,8,16,32,64,128}; - -static void -chset(CHAR c) -{ - bittab[(CHAR) ((c) & BLKIND) >> 3] |= bitarr[(c) & BITIND]; -} - -#define badpat(x) (*nfa = END, x) -#define store(x) *mp++ = x - -char * -re_comp(const char *pat) -{ - register const char *p; /* pattern pointer */ - register CHAR *mp=nfa; /* nfa pointer */ - register CHAR *lp; /* saved pointer.. */ - register CHAR *sp=nfa; /* another one.. */ - - register int tagi = 0; /* tag stack index */ - register int tagc = 1; /* actual tag count */ - - register int n; - register CHAR mask; /* xor mask -CCL/NCL */ - int c1, c2; - - if (!pat || !*pat) { - if (sta) - return 0; - else - return badpat("No previous regular expression"); - } - sta = NOP; - - for (p = pat; *p; p++) { - lp = mp; - switch(*p) { - - case '.': /* match any char.. */ - store(ANY); - break; - - case '^': /* match beginning.. */ - if (p == pat) - store(BOL); - else { - store(CHR); - store(*p); - } - break; - - case '$': /* match endofline.. */ - if (!*(p+1)) - store(EOL); - else { - store(CHR); - store(*p); - } - break; - - case '[': /* match char class..*/ - store(CCL); - - if (*++p == '^') { - mask = 0377; - p++; - } - else - mask = 0; - - if (*p == '-') /* real dash */ - chset(*p++); - if (*p == ']') /* real brac */ - chset(*p++); - while (*p && *p != ']') { - if (*p == '-' && *(p+1) && *(p+1) != ']') { - p++; - c1 = *(p-2) + 1; - c2 = *p++; - while (c1 <= c2) - chset((CHAR)c1++); - } -#ifdef EXTEND - else if (*p == '\\' && *(p+1)) { - p++; - chset(*p++); - } -#endif - else - chset(*p++); - } - if (!*p) - return badpat("Missing ]"); - - for (n = 0; n < BITBLK; bittab[n++] = (char) 0) - store(mask ^ bittab[n]); - - break; - - case '*': /* match 0 or more.. */ - case '+': /* match 1 or more.. */ - if (p == pat) - return badpat("Empty closure"); - lp = sp; /* previous opcode */ - if (*lp == CLO) /* equivalence.. */ - break; - switch(*lp) { - - case BOL: - case BOT: - case EOT: - case BOW: - case EOW: - case REF: - return badpat("Illegal closure"); - default: - break; - } - - if (*p == '+') - for (sp = mp; lp < sp; lp++) - store(*lp); - - store(END); - store(END); - sp = mp; - while (--mp > lp) - *mp = mp[-1]; - store(CLO); - mp = sp; - break; - - case '\\': /* tags, backrefs .. */ - switch(*++p) { - - case '(': - if (tagc < MAXTAG) { - tagstk[++tagi] = tagc; - store(BOT); - store(tagc++); - } - else - return badpat("Too many \\(\\) pairs"); - break; - case ')': - if (*sp == BOT) - return badpat("Null pattern inside \\(\\)"); - if (tagi > 0) { - store(EOT); - store(tagstk[tagi--]); - } - else - return badpat("Unmatched \\)"); - break; - case '<': - store(BOW); - break; - case '>': - if (*sp == BOW) - return badpat("Null pattern inside \\<\\>"); - store(EOW); - break; - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - n = *p-'0'; - if (tagi > 0 && tagstk[tagi] == n) - return badpat("Cyclical reference"); - if (tagc > n) { - store(REF); - store(n); - } - else - return badpat("Undetermined reference"); - break; -#ifdef EXTEND - case 'b': - store(CHR); - store('\b'); - break; - case 'n': - store(CHR); - store('\n'); - break; - case 'f': - store(CHR); - store('\f'); - break; - case 'r': - store(CHR); - store('\r'); - break; - case 't': - store(CHR); - store('\t'); - break; -#endif - default: - store(CHR); - store(*p); - } - break; - - default : /* an ordinary char */ - store(CHR); - store(*p); - break; - } - sp = lp; - } - if (tagi > 0) - return badpat("Unmatched \\("); - store(END); - sta = OKP; - return 0; -} - - -static const char *bol; -const char *bopat[MAXTAG]; -const char *eopat[MAXTAG]; -static const char *pmatch(const char *, CHAR *, int *); - -/* - * re_exec: - * execute nfa to find a match. - * - * special cases: (nfa[0]) - * BOL - * Match only once, starting from the - * beginning. - * CHR - * First locate the character without - * calling pmatch, and if found, call - * pmatch for the remaining string. - * END - * re_comp failed, poor luser did not - * check for it. Fail fast. - * - * If a match is found, bopat[0] and eopat[0] are set - * to the beginning and the end of the matched fragment, - * respectively. - * - */ - -int -re_exec(const char *lp) -{ - register CHAR c; - register const char *ep = 0; - register CHAR *ap = nfa; - int score = 1; - - bol = lp; - - bopat[0] = 0; - bopat[1] = 0; - bopat[2] = 0; - bopat[3] = 0; - bopat[4] = 0; - bopat[5] = 0; - bopat[6] = 0; - bopat[7] = 0; - bopat[8] = 0; - bopat[9] = 0; - - switch(*ap) { - - case BOL: /* anchored: match from BOL only */ - ep = pmatch(lp,ap, &score); - break; - case CHR: /* ordinary char: locate it fast */ - c = *(ap+1); - while (*lp && *lp != c) - lp++; - if (!*lp) /* if EOS, fail, else fall thru. */ - return 0; - default: /* regular matching all the way. */ -#ifdef OLD - while (*lp) { - if ((ep = pmatch(lp,ap, &score))) - break; - lp++; - } -#else /* match null string */ - do { - if ((ep = pmatch(lp,ap, &score))) - break; - } while (*lp++); -#endif - break; - case END: /* munged automaton. fail always */ - return 0; - } - if (!ep) - return 0; - - bopat[0] = lp; - eopat[0] = ep; - return score; -} - -/* - * pmatch: internal routine for the hard part - * - * This code is partly snarfed from an early grep written by - * David Conroy. The backref and tag stuff, and various other - * innovations are by oz. - * - * special case optimizations: (nfa[n], nfa[n+1]) - * CLO ANY - * We KNOW .* will match everything up to the - * end of line. Thus, directly go to the end of - * line, without recursive pmatch calls. As in - * the other closure cases, the remaining pattern - * must be matched by moving backwards on the - * string recursively, to find a match for xy - * (x is ".*" and y is the remaining pattern) - * where the match satisfies the LONGEST match for - * x followed by a match for y. - * CLO CHR - * We can again scan the string forward for the - * single char and at the point of failure, we - * execute the remaining nfa recursively, same as - * above. - * - * At the end of a successful match, bopat[n] and eopat[n] - * are set to the beginning and end of subpatterns matched - * by tagged expressions (n = 1 to 9). - * - */ - -#ifndef re_fail -extern void re_fail(char *, unsigned char); -#endif - -/* - * character classification table for word boundary operators BOW - * and EOW. the reason for not using ctype macros is that we can - * let the user add into our own table. see re_modw. This table - * is not in the bitset form, since we may wish to extend it in the - * future for other character classifications. - * - * TRUE for 0-9 A-Z a-z _ - */ -static CHAR chrtyp[MAXCHR] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 0, 0 - }; - -#define inascii(x) (0177&(x)) -#define iswordc(x) chrtyp[inascii(x)] -#define isinset(x,y) ((x)[((y)&BLKIND)>>3] & bitarr[(y)&BITIND]) - -/* - * skip values for CLO XXX to skip past the closure - */ - -#define ANYSKIP 2 /* [CLO] ANY END ... */ -#define CHRSKIP 3 /* [CLO] CHR chr END ... */ -#define CCLSKIP 18 /* [CLO] CCL 16bytes END ... */ - -static const char * -pmatch(const char *lp, CHAR *ap, int *score) -{ - register int op, c, n; - register const char *e; /* extra pointer for CLO */ - register const char *bp; /* beginning of subpat.. */ - register const char *ep; /* ending of subpat.. */ - const char *are; /* to save the line ptr. */ - - while ((op = *ap++) != END) - switch(op) { - - case CHR: - if (*lp++ != *ap++) - return 0; - (*score) += 100; - break; - case ANY: - if (!*lp++) - return 0; - (*score)++; - break; - case CCL: - c = *lp++; - if (!isinset(ap,c)) - return 0; - ap += BITBLK; - (*score) += 2; - break; - case BOL: - if (lp != bol) - return 0; - (*score) += 10; - break; - case EOL: - if (*lp) - return 0; - (*score) += 10; - break; - case BOT: - bopat[*ap++] = lp; - break; - case EOT: - eopat[*ap++] = lp; - break; - case BOW: - if ((lp!=bol && iswordc(lp[-1])) || !iswordc(*lp)) - return 0; - (*score) += 5; - break; - case EOW: - if (lp==bol || !iswordc(lp[-1]) || iswordc(*lp)) - return 0; - (*score) += 5; - break; - case REF: - n = *ap++; - bp = bopat[n]; - ep = eopat[n]; - while (bp < ep) { - if (*bp++ != *lp++) - return 0; - (*score) += 2; - } - break; - case CLO: - are = lp; - switch(*ap) { - - case ANY: - while (*lp) - lp++; - n = ANYSKIP; - (*score)++; - break; - case CHR: - c = *(ap+1); - while (*lp && c == *lp) - lp++; - n = CHRSKIP; - (*score) += 100; - break; - case CCL: - while ((c = *lp) && isinset(ap+1,c)) - lp++; - n = CCLSKIP; - (*score) += 2; - break; - default: - re_fail("closure: bad nfa.", *ap); - return 0; - } - - ap += n; - - while (lp >= are) { - e = pmatch(lp, ap, score); - if (e) - return e; - --lp; - } - return 0; - default: - re_fail("re_exec: bad nfa.", op); - return 0; - } - return lp; -} - -/* - * re_modw: - * add new characters into the word table to change re_exec's - * understanding of what a word should look like. Note that we - * only accept additions into the word definition. - * - * If the string parameter is 0 or null string, the table is - * reset back to the default containing A-Z a-z 0-9 _. [We use - * the compact bitset representation for the default table] - */ - -static CHAR deftab[16] = { - 0, 0, 0, 0, 0, 0, 0377, 003, 0376, 0377, 0377, 0207, - 0376, 0377, 0377, 007 -}; - -void -re_modw(char *s) -{ - register int i; - - if (!s || !*s) { - for (i = 0; i < MAXCHR; i++) - if (!isinset(deftab,i)) - iswordc(i) = 0; - } - else - while(*s) - iswordc(*s++) = 1; -} - -/* Substitute the matching part in the last re_exec call with sub. The - result is returned in a newly allocated string. */ -char *re_subs_dup(char *sub) -{ - char *dst; - const char *end; - int l1, l2, l3; - end = bol + strlen(bol); - l1 = bopat[0] - bol; - if (sub != NULL) - l2 = strlen(sub); - else - l2 = 0; - l3 = end - eopat[0]; - if (l3 < 0) - l3 = 0; - dst = malloc(l1+l2+l3+1); - memcpy(dst, bol, l1); - if (l2 != 0) - memcpy(dst+l1, sub, l2); - memcpy(dst+l1+l2, eopat[0], l3+1); - return dst; -} diff --git a/scconfig/src/default/.svn/pristine/fa/fa293701e0d218d1db8bdbaec96318423787a1e5.svn-base b/scconfig/src/default/.svn/pristine/fa/fa293701e0d218d1db8bdbaec96318423787a1e5.svn-base deleted file mode 100644 index 1b5e5b37..00000000 --- a/scconfig/src/default/.svn/pristine/fa/fa293701e0d218d1db8bdbaec96318423787a1e5.svn-base +++ /dev/null @@ -1,8 +0,0 @@ -int main_init(void); -int main_process_args(int argc, char *argv[]); -void main_uninit(void); - -/* internal */ -void init(void); -void uninit(void); -void run_custom_reqs(void); diff --git a/scconfig/src/default/.svn/wc.db b/scconfig/src/default/.svn/wc.db deleted file mode 100644 index 5dbfb76b..00000000 Binary files a/scconfig/src/default/.svn/wc.db and /dev/null differ diff --git a/scconfig/src/default/.svn/wc.db-journal b/scconfig/src/default/.svn/wc.db-journal deleted file mode 100644 index e69de29b..00000000 diff --git a/scconfig/src/gui/.svn/entries b/scconfig/src/gui/.svn/entries deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/gui/.svn/entries +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/gui/.svn/format b/scconfig/src/gui/.svn/format deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/gui/.svn/format +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/gui/.svn/pristine/04/04f0d485a1c7d6eb48d2665b7dce617e22e53b78.svn-base b/scconfig/src/gui/.svn/pristine/04/04f0d485a1c7d6eb48d2665b7dce617e22e53b78.svn-base deleted file mode 100644 index b5afad5a..00000000 --- a/scconfig/src/gui/.svn/pristine/04/04f0d485a1c7d6eb48d2665b7dce617e22e53b78.svn-base +++ /dev/null @@ -1,125 +0,0 @@ -/* - scconfig - gui lib detection - gtk2 - Copyright (C) 2013 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -static const char *node = "libs/gui/gtk2"; -static const char *nodegl = "libs/gui/gtk2gl"; -static const char *pkgname = "gtk+-2.0"; -static const char *pkgnamegl = "gtkglext-x11-1.0"; - -int find_gtk2(const char *name, int logdepth, int fatal, const char *call, const char *arg) -{ - const char *test_c = - NL "#include " - NL "#include " - NL - NL "int main(int argc, char *argv[])" - NL "{" - NL " GtkWidget* mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);" - NL " gtk_window_set_default_size(GTK_WINDOW(mainWindow), 500, 500);" - NL " gtk_window_set_title(GTK_WINDOW(mainWindow), \"foobar\");" - NL " gtk_widget_show_all(mainWindow);" - NL " gtk_main();" - NL " return EXIT_SUCCESS;" - NL "}" - NL; - char *cflags; - char *ldflags; - (void) call; /* not used */ - (void) arg; /* not used */ - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for gtk+2... "); - logprintf(logdepth, "find_gtk2: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, pkgname, &cflags, &ldflags) != 0) { - return try_fail(logdepth, node); - } - - if (try_icl_norun(logdepth, node, test_c, NULL, cflags, ldflags) == 0) { - free(cflags); - free(ldflags); - return try_fail(logdepth, node); - } - - free(cflags); - free(ldflags); - return 0; -} - -int find_gtk2gl(const char *name, int logdepth, int fatal, const char *call, const char *arg) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL - NL "int main(int argc, char *argv[])" - NL "{" - NL " gtk_gl_init(&argc, &argv);" - NL " return EXIT_SUCCESS;" - NL "}" - NL; - char *cflags; - char *ldflags; - (void) call; /* not used */ - (void) arg; /* not used */ - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, nodegl); - - report("Checking for gtk+2 with GL... "); - logprintf(logdepth, "find_gtk2gl: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, pkgnamegl, &cflags, &ldflags) != 0) { - return try_fail(logdepth, nodegl); - } - - if (try_icl_norun(logdepth, nodegl, test_c, NULL, cflags, ldflags) == 0) { - free(cflags); - free(ldflags); - return try_fail(logdepth, nodegl); - } - - free(cflags); - free(ldflags); - return 0; -} - -int find_gtk2_modversion(const char *name, int logdepth, int fatal) -{ - if (run_pkg_config_modversion_db(logdepth, node, pkgname) != 0) - return try_fail(logdepth, node); - return 0; -} - - diff --git a/scconfig/src/gui/.svn/pristine/20/20156310593ce254b4752dbe27ce7eddfec5dda3.svn-base b/scconfig/src/gui/.svn/pristine/20/20156310593ce254b4752dbe27ce7eddfec5dda3.svn-base deleted file mode 100644 index 9996864b..00000000 --- a/scconfig/src/gui/.svn/pristine/20/20156310593ce254b4752dbe27ce7eddfec5dda3.svn-base +++ /dev/null @@ -1,100 +0,0 @@ -/* - scconfig - gui lib detection - cairo - Copyright (C) 2017 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_cairo(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "#include \"cairo.h\"" - NL "int main() {" - NL " cairo_t *ctx;" - NL " cairo_surface_t *surf;" - NL - NL " if (cairo_image_surface_create(CAIRO_FORMAT_RGB24, 100, 100) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/cairo"; - char *cflags = NULL; - char *ldflags = NULL; - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for cairo... "); - logprintf(logdepth, "find_cairo: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, "cairo", &cflags, &ldflags) == 0) { - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) != 0) - goto success; - } - - return try_fail(logdepth, node); - - success:; - if (cflags != NULL) - free(cflags); - if (ldflags != NULL) - free(ldflags); - return 0; -} - - -int find_cairo_xcb(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " if (cairo_xcb_device_debug_get_precision(NULL) == -1)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/cairo-xcb", *cflags, *ldflags; - - if (require("libs/gui/cairo", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for cairo-xcb... "); - logprintf(logdepth, "find_cairo-xcb: \n"); - logdepth++; - - cflags = get("libs/gui/cairo/cflags"); - ldflags = get("libs/gui/cairo/ldflags"); - - if (try_icl(logdepth, node, test_c, "#include ", cflags, ldflags) != 0) - return 0; - - return try_fail(logdepth, node); -} diff --git a/scconfig/src/gui/.svn/pristine/25/258d0a58fcc3cffd2bc719e3c8da1f82113abd1b.svn-base b/scconfig/src/gui/.svn/pristine/25/258d0a58fcc3cffd2bc719e3c8da1f82113abd1b.svn-base deleted file mode 100644 index 348105a8..00000000 --- a/scconfig/src/gui/.svn/pristine/25/258d0a58fcc3cffd2bc719e3c8da1f82113abd1b.svn-base +++ /dev/null @@ -1,2 +0,0 @@ -int find_cairo(const char *name, int logdepth, int fatal); - diff --git a/scconfig/src/gui/.svn/pristine/48/4853d2ab0a02f7e7f3875ce45adea47da67e98c4.svn-base b/scconfig/src/gui/.svn/pristine/48/4853d2ab0a02f7e7f3875ce45adea47da67e98c4.svn-base deleted file mode 100644 index e47c8946..00000000 --- a/scconfig/src/gui/.svn/pristine/48/4853d2ab0a02f7e7f3875ce45adea47da67e98c4.svn-base +++ /dev/null @@ -1,8 +0,0 @@ -int find_xinerama(const char *name, int logdepth, int fatal); -int find_xrender(const char *name, int logdepth, int fatal); -int find_xopendisplay(const char *name, int logdepth, int fatal); -int find_xcb(const char *name, int logdepth, int fatal); -int find_xcb_render(const char *name, int logdepth, int fatal); -int find_xgetxcbconnection(const char *name, int logdepth, int fatal); -int find_xpm(const char *name, int logdepth, int fatal); - diff --git a/scconfig/src/gui/.svn/pristine/4d/4dd363b7efabebdf6520cb9b303de45755b30bfa.svn-base b/scconfig/src/gui/.svn/pristine/4d/4dd363b7efabebdf6520cb9b303de45755b30bfa.svn-base deleted file mode 100644 index 17158861..00000000 --- a/scconfig/src/gui/.svn/pristine/4d/4dd363b7efabebdf6520cb9b303de45755b30bfa.svn-base +++ /dev/null @@ -1 +0,0 @@ -int find_libstroke(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/gui/.svn/pristine/4e/4ed3efb3a715693271f01c366c187ec3e09ed85c.svn-base b/scconfig/src/gui/.svn/pristine/4e/4ed3efb3a715693271f01c366c187ec3e09ed85c.svn-base deleted file mode 100644 index 8939df93..00000000 --- a/scconfig/src/gui/.svn/pristine/4e/4ed3efb3a715693271f01c366c187ec3e09ed85c.svn-base +++ /dev/null @@ -1,2 +0,0 @@ -int find_gtk3(const char *name, int logdepth, int fatal); - diff --git a/scconfig/src/gui/.svn/pristine/4f/4f36b26f31f5b0b0d0e21b36d792cdb61f524d47.svn-base b/scconfig/src/gui/.svn/pristine/4f/4f36b26f31f5b0b0d0e21b36d792cdb61f524d47.svn-base deleted file mode 100644 index 74bf5a52..00000000 --- a/scconfig/src/gui/.svn/pristine/4f/4f36b26f31f5b0b0d0e21b36d792cdb61f524d47.svn-base +++ /dev/null @@ -1,40 +0,0 @@ -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -#include "find_x.h" -#include "find_gtk2.h" -#include "find_gtk3.h" -#include "find_lesstif2.h" -#include "find_gd.h" -#include "find_cairo.h" -#include "find_misc.h" -#include "find_gl.h" - -void deps_gui_init() -{ - dep_add("libs/gui/xopendisplay/*", find_xopendisplay); - dep_add("libs/gui/xinerama/*", find_xinerama); - dep_add("libs/gui/xrender/*", find_xrender); - dep_add("libs/gui/xcb/*", find_xcb); - dep_add("libs/gui/xcb_render/*", find_xcb_render); - dep_add("libs/gui/xgetxcbconnection/*", find_xgetxcbconnection); - dep_add("libs/gui/xpm/*", find_xpm); - dep_add("libs/gui/gtk2/*", find_gtk2); - dep_add("libs/gui/gtk2gl/*", find_gtk2gl); - dep_add("libs/gui/gtk2/modversion", find_gtk2_modversion); - dep_add("libs/gui/gtk3/*", find_gtk3); - dep_add("libs/gui/lesstif2/*", find_lesstif2); - dep_add("libs/gui/libstroke/*", find_libstroke); - dep_add("libs/gui/gd/gdImagePng/*", find_gdimagepng); - dep_add("libs/gui/gd/gdImageGif/*", find_gdimagegif); - dep_add("libs/gui/gd/gdImageJpeg/*", find_gdimagejpeg); - dep_add("libs/gui/gd/gdImageSetResolution/*", find_gdimagesetresolution); - dep_add("libs/gui/gd/*", find_gd); - dep_add("libs/gui/cairo/*", find_cairo); - dep_add("libs/gui/gl/*", find_gl); - dep_add("libs/gui/glu/*", find_glu); - dep_add("libs/gui/glut/*", find_glut); - dep_add("libs/gui/wgl/*", find_gui_wgl); -} diff --git a/scconfig/src/gui/.svn/pristine/56/56151130d28dd8685e5f1a17069bdd8f01f0fddb.svn-base b/scconfig/src/gui/.svn/pristine/56/56151130d28dd8685e5f1a17069bdd8f01f0fddb.svn-base deleted file mode 100644 index 29a2f513..00000000 --- a/scconfig/src/gui/.svn/pristine/56/56151130d28dd8685e5f1a17069bdd8f01f0fddb.svn-base +++ /dev/null @@ -1,70 +0,0 @@ -/* - scconfig - gui lib detection - cairo - Copyright (C) 2017 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_cairo(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "#include \"cairo.h\"" - NL "int main() {" - NL " cairo_t *ctx;" - NL " cairo_surface_t *surf;" - NL - NL " if (cairo_image_surface_create(CAIRO_FORMAT_RGB24, 100, 100) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/cairo"; - char *cflags = NULL; - char *ldflags = NULL; - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for cairo... "); - logprintf(logdepth, "find_cairo: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, "cairo", &cflags, &ldflags) == 0) { - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) != 0) - goto success; - } - - return try_fail(logdepth, node); - - success:; - if (cflags != NULL) - free(cflags); - if (ldflags != NULL) - free(ldflags); - return 0; -} - diff --git a/scconfig/src/gui/.svn/pristine/56/56f921de73d14e62d23faeb765ce4e2c5839efa4.svn-base b/scconfig/src/gui/.svn/pristine/56/56f921de73d14e62d23faeb765ce4e2c5839efa4.svn-base deleted file mode 100644 index 48cddb1e..00000000 --- a/scconfig/src/gui/.svn/pristine/56/56f921de73d14e62d23faeb765ce4e2c5839efa4.svn-base +++ /dev/null @@ -1,171 +0,0 @@ -/* - scconfig - gui lib detection - gtk2 - Copyright (C) 2013 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -static const char *node = "libs/gui/gtk2"; -static const char *nodegl = "libs/gui/gtk2gl"; -static const char *pkgname = "gtk+-2.0"; -static const char *pkgnamegl = "gtkglext-x11-1.0"; - -int find_gtk2(const char *name, int logdepth, int fatal, const char *call, const char *arg) -{ - const char *test_c = - NL "#include " - NL "#include " - NL - NL "int main(int argc, char *argv[])" - NL "{" - NL " GtkWidget* mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);" - NL " gtk_window_set_default_size(GTK_WINDOW(mainWindow), 500, 500);" - NL " gtk_window_set_title(GTK_WINDOW(mainWindow), \"foobar\");" - NL " gtk_widget_show_all(mainWindow);" - NL " gtk_main();" - NL " return EXIT_SUCCESS;" - NL "}" - NL; - char *cflags; - char *ldflags; - (void) call; /* not used */ - (void) arg; /* not used */ - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for gtk+2... "); - logprintf(logdepth, "find_gtk2: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, pkgname, &cflags, &ldflags) != 0) { - return try_fail(logdepth, node); - } - - if (try_icl_norun(logdepth, node, test_c, NULL, cflags, ldflags) == 0) { - free(cflags); - free(ldflags); - return try_fail(logdepth, node); - } - - free(cflags); - free(ldflags); - return 0; -} - -int find_gtk2gl(const char *name, int logdepth, int fatal, const char *call, const char *arg) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL - NL "int main(int argc, char *argv[])" - NL "{" - NL " gtk_gl_init(&argc, &argv);" - NL " return EXIT_SUCCESS;" - NL "}" - NL; - char *cflags; - char *ldflags; - (void) call; /* not used */ - (void) arg; /* not used */ - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, nodegl); - - report("Checking for gtk+2 with GL... "); - logprintf(logdepth, "find_gtk2gl: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, pkgnamegl, &cflags, &ldflags) != 0) { - return try_fail(logdepth, nodegl); - } - - if (try_icl_norun(logdepth, nodegl, test_c, NULL, cflags, ldflags) == 0) { - free(cflags); - free(ldflags); - return try_fail(logdepth, nodegl); - } - - free(cflags); - free(ldflags); - return 0; -} - -int find_gtk2_key_prefix(const char *name, int logdepth, int fatal) -{ - const char *node = "libs/gui/gtk2/key_prefix"; - char test_c[512]; - const char *test_c_ = - NL "#include " - NL "#include " - NL - NL "int main(int argc, char *argv[])" - NL "{" - NL " if (%s != 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *includes, *cflags, *ldflags; - - - if (require("libs/gui/gtk2/cflags", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for gtk+2 key prefix... "); - logprintf(logdepth, "Checking for gtk+2 key prefix...\n"); - logdepth++; - - includes = get("libs/gui/gtk2/includes"); - cflags = get("libs/gui/gtk2/cflags"); - ldflags = get("libs/gui/gtk2/ldflags"); - - sprintf(test_c, test_c_, "GDK_KEY_Tab"); - if (try_icl(logdepth, node, test_c, includes, cflags, ldflags)) { - report("GDK_KEY_\n"); - put(node, "GDK_KEY_"); - return 0; - } - - sprintf(test_c, test_c_, "GDK_Tab"); - if (try_icl(logdepth, node, test_c, includes, cflags, ldflags)) { - report("GDK_\n"); - put(node, "GDK_"); - return 0; - } - - return try_fail(logdepth, node); -} - -int find_gtk2_modversion(const char *name, int logdepth, int fatal) -{ - if (run_pkg_config_modversion_db(logdepth, node, pkgname) != 0) - return try_fail(logdepth, node); - return 0; -} - - diff --git a/scconfig/src/gui/.svn/pristine/5a/5a4f0df5864e7e07cf0c3d3306e3ba070390a481.svn-base b/scconfig/src/gui/.svn/pristine/5a/5a4f0df5864e7e07cf0c3d3306e3ba070390a481.svn-base deleted file mode 100644 index 5fede0af..00000000 --- a/scconfig/src/gui/.svn/pristine/5a/5a4f0df5864e7e07cf0c3d3306e3ba070390a481.svn-base +++ /dev/null @@ -1,39 +0,0 @@ -GUI_CFLAGS = -DPLUGIN_GUI -GUI_OBJS = \ - $(BIN)/gui/find_gtk2.o \ - $(BIN)/gui/find_gtk3.o \ - $(BIN)/gui/find_lesstif2.o \ - $(BIN)/gui/find_x.o \ - $(BIN)/gui/find_gd.o \ - $(BIN)/gui/find_cairo.o \ - $(BIN)/gui/find_misc.o \ - $(BIN)/gui/find_gl.o \ - $(BIN)/gui/gui.o - - -$(BIN)/gui/find_gtk2.o: $(SRC)/gui/find_gtk2.c - $(CC) $(CFLAGS) -c $(SRC)/gui/find_gtk2.c -o $(BIN)/gui/find_gtk2.o - -$(BIN)/gui/find_gtk3.o: $(SRC)/gui/find_gtk3.c - $(CC) $(CFLAGS) -c $(SRC)/gui/find_gtk3.c -o $(BIN)/gui/find_gtk3.o - -$(BIN)/gui/find_lesstif2.o: $(SRC)/gui/find_lesstif2.c - $(CC) $(CFLAGS) -c $(SRC)/gui/find_lesstif2.c -o $(BIN)/gui/find_lesstif2.o - -$(BIN)/gui/find_x.o: $(SRC)/gui/find_x.c - $(CC) $(CFLAGS) -c $(SRC)/gui/find_x.c -o $(BIN)/gui/find_x.o - -$(BIN)/gui/find_gd.o: $(SRC)/gui/find_gd.c - $(CC) $(CFLAGS) -c $(SRC)/gui/find_gd.c -o $(BIN)/gui/find_gd.o - -$(BIN)/gui/find_misc.o: $(SRC)/gui/find_misc.c - $(CC) $(CFLAGS) -c $(SRC)/gui/find_misc.c -o $(BIN)/gui/find_misc.o - -$(BIN)/gui/find_gl.o: $(SRC)/gui/find_gl.c - $(CC) $(CFLAGS) -c $(SRC)/gui/find_gl.c -o $(BIN)/gui/find_gl.o - -$(BIN)/gui/find_cairo.o: $(SRC)/gui/find_cairo.c - $(CC) $(CFLAGS) -c $(SRC)/gui/find_cairo.c -o $(BIN)/gui/find_cairo.o - -$(BIN)/gui/gui.o: $(SRC)/gui/gui.c - $(CC) $(CFLAGS) -c $(SRC)/gui/gui.c -o $(BIN)/gui/gui.o diff --git a/scconfig/src/gui/.svn/pristine/65/65f7986d567c793a969327a70d6caefcdee154ff.svn-base b/scconfig/src/gui/.svn/pristine/65/65f7986d567c793a969327a70d6caefcdee154ff.svn-base deleted file mode 100644 index 104b921c..00000000 --- a/scconfig/src/gui/.svn/pristine/65/65f7986d567c793a969327a70d6caefcdee154ff.svn-base +++ /dev/null @@ -1,6 +0,0 @@ -int find_gd(const char *name, int logdepth, int fatal); -int find_gdimagepng(const char *name, int logdepth, int fatal); -int find_gdimagegif(const char *name, int logdepth, int fatal); -int find_gdimagejpeg(const char *name, int logdepth, int fatal); -int find_gdimagesetresolution(const char *name, int logdepth, int fatal); - diff --git a/scconfig/src/gui/.svn/pristine/66/66f45cd2d3b10a85de45643805167399b460d092.svn-base b/scconfig/src/gui/.svn/pristine/66/66f45cd2d3b10a85de45643805167399b460d092.svn-base deleted file mode 100644 index 0828cac9..00000000 --- a/scconfig/src/gui/.svn/pristine/66/66f45cd2d3b10a85de45643805167399b460d092.svn-base +++ /dev/null @@ -1,67 +0,0 @@ -/* - scconfig - gui lib detection - misc libs - Copyright (C) 2016 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_libstroke(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " char msg[256];" - NL " int n;" - NL " stroke_init();" - NL " for(n = 1000; n < 2000; n+=123)" - NL " stroke_record(n, 1000);" - NL " stroke_trans(msg);" - NL " return !(atoi(msg) == 456);" - NL "}" - NL; - - const char *node = "libs/gui/libstroke"; - char **cflags, *cflags_arr[] = {"", NULL}; - char **ldflags, *ldflags_arr[] = {"-lstroke", NULL}; - - if (require("cc/cc", logdepth, fatal)) - return 1; - - report("Checking for libstroke... "); - logprintf(logdepth, "find_libstroke:\n"); - logdepth++; - - for(cflags = cflags_arr; *cflags != NULL; cflags++) { - for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { - if (try_icl_norun(logdepth, node, test_c, NULL, *cflags, *ldflags) != 0) { - return 0; - } - } - } - return try_fail(logdepth, node); -} - diff --git a/scconfig/src/gui/.svn/pristine/6e/6e97342a5ec2a09a9733091dc41863a673887af7.svn-base b/scconfig/src/gui/.svn/pristine/6e/6e97342a5ec2a09a9733091dc41863a673887af7.svn-base deleted file mode 100644 index 2c26a56f..00000000 --- a/scconfig/src/gui/.svn/pristine/6e/6e97342a5ec2a09a9733091dc41863a673887af7.svn-base +++ /dev/null @@ -1,240 +0,0 @@ -/* - scconfig - gui lib detection - libgd - Copyright (C) 2013 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_gd(const char *name, int logdepth, int fatal, const char *call, const char *arg) -{ - const char *test_c = - NL "#include \"gd.h\"" - NL "int main() {" - NL " gdImagePtr imtype;" - NL - NL " if (gdImageCreateTrueColor(32, 32) != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/gd"; - char *cflags = NULL; - char *ldflags = NULL; - (void) call; /* not used */ - (void) arg; /* not used */ - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for gd... "); - logprintf(logdepth, "find_gd: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, "gdlib", &cflags, &ldflags) == 0) { - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) != 0) - goto success; - } - - if ((run_gen_config(logdepth, "gdlib-config", "", &cflags, &ldflags) == 0) || (run_pkg_config(logdepth, "gdlib", &cflags, &ldflags) == 0)) { - char *tmp; - - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) != 0) - goto success; - - /* Some versions of gdlib-config --libs is broken and does not return -lgd */ - tmp = ldflags; - ldflags = str_concat(" ", ldflags, "-lgd", NULL); - free(tmp); - - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) != 0) - goto success; - - /* none of the above worked, fail */ - free(cflags); - free(ldflags); - return try_fail(logdepth, node); - } - - return try_fail(logdepth, node); - - success:; - if (cflags != NULL) - free(cflags); - if (ldflags != NULL) - free(ldflags); - return 0; -} - -int find_gdimagepng(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include \"gd.h\"" - NL "int main() {" - NL " gdImagePtr img;" - NL - NL " if ((img = gdImageCreateTrueColor(32, 32)) == NULL)" - NL " return 1;" - NL " gdImagePng(img, stderr);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/gd/gdImagePng"; - const char *cflags, *ldflags; - - if (require("cc/cc", logdepth, fatal)) - return 1; - if (require("libs/gui/gd/presents", logdepth, fatal)) - return 1; - if (!istrue(get("libs/gui/gd/presents"))) - return 1; - - cflags = get("libs/gui/gd/cflags"); - ldflags = get("libs/gui/gd/ldflags"); - - report("Checking for gdImagePng... "); - logprintf(logdepth, "find_gdimagepng: running pkg-config...\n"); - logdepth++; - - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) == 0) - return try_fail(logdepth, node); - - return 0; -} - -int find_gdimagejpeg(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include \"gd.h\"" - NL "int main() {" - NL " gdImagePtr img;" - NL - NL " if ((img = gdImageCreateTrueColor(32, 32)) == NULL)" - NL " return 1;" - NL " gdImageJpeg(img, stderr, 0.5);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/gd/gdImageJpeg"; - const char *cflags, *ldflags; - - if (require("cc/cc", logdepth, fatal)) - return 1; - if (require("libs/gui/gd/presents", logdepth, fatal)) - return 1; - if (!istrue(get("libs/gui/gd/presents"))) - return 1; - - cflags = get("libs/gui/gd/cflags"); - ldflags = get("libs/gui/gd/ldflags"); - - report("Checking for gdImageJpeg... "); - logprintf(logdepth, "find_gdimagejpeg: running pkg-config...\n"); - logdepth++; - - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) == 0) - return try_fail(logdepth, node); - - return 0; -} - -int find_gdimagegif(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include \"gd.h\"" - NL "int main() {" - NL " gdImagePtr img;" - NL - NL " if ((img = gdImageCreateTrueColor(32, 32)) == NULL)" - NL " return 1;" - NL " gdImageGif(img, stderr);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/gd/gdImageGif"; - const char *cflags, *ldflags; - - if (require("cc/cc", logdepth, fatal)) - return 1; - if (require("libs/gui/gd/presents", logdepth, fatal)) - return 1; - if (!istrue(get("libs/gui/gd/presents"))) - return 1; - - cflags = get("libs/gui/gd/cflags"); - ldflags = get("libs/gui/gd/ldflags"); - - report("Checking for gdImageGif... "); - logprintf(logdepth, "find_gdimagesetresolution: running pkg-config...\n"); - logdepth++; - - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) == 0) - return try_fail(logdepth, node); - - return 0; -} - -int find_gdimagesetresolution(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include \"gd.h\"" - NL "int main() {" - NL " gdImagePtr img;" - NL - NL " if ((img = gdImageCreateTrueColor(32, 32)) == NULL)" - NL " return 1;" - NL " gdImageSetResolution(img, 100, 100);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/gd/gdImageSetResolution"; - const char *cflags, *ldflags; - - if (require("cc/cc", logdepth, fatal)) - return 1; - if (require("libs/gui/gd/presents", logdepth, fatal)) - return 1; - if (!istrue(get("libs/gui/gd/presents"))) - return 1; - - cflags = get("libs/gui/gd/cflags"); - ldflags = get("libs/gui/gd/ldflags"); - - report("Checking for gdImageSetResolution... "); - logprintf(logdepth, "find_gdimagesetresolution: running pkg-config...\n"); - logdepth++; - - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) == 0) - return try_fail(logdepth, node); - - return 0; -} diff --git a/scconfig/src/gui/.svn/pristine/7b/7b69c46ebf6827b07879b3b4ab276ae8ee10ed82.svn-base b/scconfig/src/gui/.svn/pristine/7b/7b69c46ebf6827b07879b3b4ab276ae8ee10ed82.svn-base deleted file mode 100644 index dfbc227e..00000000 --- a/scconfig/src/gui/.svn/pristine/7b/7b69c46ebf6827b07879b3b4ab276ae8ee10ed82.svn-base +++ /dev/null @@ -1,69 +0,0 @@ -/* - scconfig - gui lib detection - lesstif - Copyright (C) 2015 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_lesstif2(const char *name, int logdepth, int fatal, const char *call, const char *arg) -{ - const char *test_c = - NL "#include " - NL "int main(int argc, char *argv[])" - NL "{" - NL " XtAppContext context;" - NL " Display *dsp;" - NL " Colormap cmap;" - NL " XColor color;" - NL " Widget toplevel;" - NL " toplevel = XtAppInitialize(& context, \"\", NULL, 0, &argc, argv, NULL, NULL, 0);" - NL " XAllocColor(dsp, cmap, &color);" - NL " return toplevel != NULL;" - NL "}" - NL; - - const char *node = "libs/gui/lesstif2"; - char **cflags, *cflags_arr[] = {"", "-I/opt/X11/include", NULL}; - char **ldflags, *ldflags_arr[] = {"-lXm -lX11", "-lXm -lXt", "-L/opt/X11/lib -lXm -lXt -lX11", NULL}; /* note: -lXt must be after -lXm else lesstif fails to init with runtime error */ - (void) call; /* not used */ - (void) arg; /* not used */ - - if (require("cc/cc", logdepth, fatal)) - return 1; - - report("Checking for lesstif2... "); - logprintf(logdepth, "find_lesstif:\n"); - logdepth++; - - for(cflags = cflags_arr; *cflags != NULL; cflags++) { - for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { - if (try_icl_norun(logdepth, node, test_c, NULL, *cflags, *ldflags) != 0) { - return 0; - } - } - } - return try_fail(logdepth, node); - -} diff --git a/scconfig/src/gui/.svn/pristine/8f/8ffd03b37935b947398064778faf338218b11074.svn-base b/scconfig/src/gui/.svn/pristine/8f/8ffd03b37935b947398064778faf338218b11074.svn-base deleted file mode 100644 index 6a70968b..00000000 --- a/scconfig/src/gui/.svn/pristine/8f/8ffd03b37935b947398064778faf338218b11074.svn-base +++ /dev/null @@ -1,41 +0,0 @@ -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -#include "find_x.h" -#include "find_gtk2.h" -#include "find_gtk3.h" -#include "find_lesstif2.h" -#include "find_gd.h" -#include "find_cairo.h" -#include "find_misc.h" -#include "find_gl.h" - -void deps_gui_init() -{ - dep_add("libs/gui/xopendisplay/*", find_xopendisplay); - dep_add("libs/gui/xinerama/*", find_xinerama); - dep_add("libs/gui/xrender/*", find_xrender); - dep_add("libs/gui/xcb/*", find_xcb); - dep_add("libs/gui/xcb_render/*", find_xcb_render); - dep_add("libs/gui/xgetxcbconnection/*", find_xgetxcbconnection); - dep_add("libs/gui/xpm/*", find_xpm); - dep_add("libs/gui/gtk2/*", find_gtk2); - dep_add("libs/gui/gtk2gl/*", find_gtk2gl); - dep_add("libs/gui/gtk2/modversion", find_gtk2_modversion); - dep_add("libs/gui/gtk3/*", find_gtk3); - dep_add("libs/gui/lesstif2/*", find_lesstif2); - dep_add("libs/gui/libstroke/*", find_libstroke); - dep_add("libs/gui/gd/gdImagePng/*", find_gdimagepng); - dep_add("libs/gui/gd/gdImageGif/*", find_gdimagegif); - dep_add("libs/gui/gd/gdImageJpeg/*", find_gdimagejpeg); - dep_add("libs/gui/gd/gdImageSetResolution/*", find_gdimagesetresolution); - dep_add("libs/gui/gd/*", find_gd); - dep_add("libs/gui/cairo/*", find_cairo); - dep_add("libs/gui/cairo-xcb/*", find_cairo_xcb); - dep_add("libs/gui/gl/*", find_gl); - dep_add("libs/gui/glu/*", find_glu); - dep_add("libs/gui/glut/*", find_glut); - dep_add("libs/gui/wgl/*", find_gui_wgl); -} diff --git a/scconfig/src/gui/.svn/pristine/9b/9b15fe854778b9fd95dbd1fadb03066cbba380bc.svn-base b/scconfig/src/gui/.svn/pristine/9b/9b15fe854778b9fd95dbd1fadb03066cbba380bc.svn-base deleted file mode 100644 index 0669f3be..00000000 --- a/scconfig/src/gui/.svn/pristine/9b/9b15fe854778b9fd95dbd1fadb03066cbba380bc.svn-base +++ /dev/null @@ -1,2 +0,0 @@ - deps_gui_init(); - diff --git a/scconfig/src/gui/.svn/pristine/9c/9c74033085a5298c7e2918541bf6bddc1d561bc1.svn-base b/scconfig/src/gui/.svn/pristine/9c/9c74033085a5298c7e2918541bf6bddc1d561bc1.svn-base deleted file mode 100644 index ba50150c..00000000 --- a/scconfig/src/gui/.svn/pristine/9c/9c74033085a5298c7e2918541bf6bddc1d561bc1.svn-base +++ /dev/null @@ -1,322 +0,0 @@ -/* - scconfig - gui lib detection - lesstif - Copyright (C) 2015 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - - -int find_xopendisplay(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " Display *d = XOpenDisplay(NULL);" - NL " return 0;" - NL "}" - NL; - - const char *node = "libs/gui/xopendisplay"; - char **cflags, *cflags_arr[] = {"", "-I/opt/X11/include", "-I/usr/X11R6/include", NULL}; - char **ldflags, *ldflags_arr[] = {"-lX11", "-L/opt/X11/lib -lX11", "-L/usr/X11R6/lib -lX11", NULL}; - char **Lflags, *Lflags_arr[] = {"", "-L/opt/X11/lib", "-L/usr/X11R6/lib", NULL}; - - if (require("cc/cc", logdepth, fatal)) - return 1; - - report("Checking for XOpenDisplay... "); - logprintf(logdepth, "find_xopendisplay:\n"); - logdepth++; - - for(cflags = cflags_arr; *cflags != NULL; cflags++) { - for(ldflags = ldflags_arr, Lflags = Lflags_arr; *ldflags != NULL; ldflags++,Lflags++) { - if (try_icl_norun(logdepth, node, test_c, NULL, *cflags, *ldflags) != 0) { - put("libs/gui/xopendisplay/Lflags", *Lflags); - return 0; - } - } - } - return try_fail(logdepth, node); -} - - - -int find_xinerama(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " Display *d = XOpenDisplay(NULL);" - NL " if (d != NULL)" - NL " XineramaIsActive(d);" - NL " return 0;" - NL "}" - NL; - - const char *node = "libs/gui/xinerama"; - char **cflags, *cflags_arr[] = {"", NULL}; - char **ldflags, *ldflags_arr[] = {"-lXinerama", NULL}; - const char *xincludes, *xcflags, *xldflags; - - if (require("cc/cc", logdepth, fatal)) - return 1; - - if (require("libs/gui/xopendisplay/*", logdepth, fatal)) - return 1; - - xincludes = get("libs/gui/xopendisplay/includes"); - xcflags = get("libs/gui/xopendisplay/cflags"); - xldflags = get("libs/gui/xopendisplay/ldflags"); - - report("Checking for Xinerama... "); - logprintf(logdepth, "find_xinerama:\n"); - logdepth++; - - for(cflags = cflags_arr; *cflags != NULL; cflags++) { - for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { - if (try_icl_with_deps(logdepth, node, test_c, NULL, *cflags, *ldflags, xincludes, xcflags, xldflags, 0) != 0) { - return 0; - } - } - } - return try_fail(logdepth, node); -} - -int find_xrender(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " Display *d = XOpenDisplay(NULL);" - NL " XRenderFreePicture (d, 0);" - NL " return 0;" - NL "}" - NL; - - const char *node = "libs/gui/xrender"; - char **cflags, *cflags_arr[] = {"", NULL}; - char **ldflags, *ldflags_arr[] = {"-lXrender", NULL}; - const char *xincludes, *xcflags, *xldflags; - - if (require("cc/cc", logdepth, fatal)) - return 1; - - if (require("libs/gui/xopendisplay/*", logdepth, fatal)) - return 1; - - xincludes = get("libs/gui/xopendisplay/includes"); - xcflags = get("libs/gui/xopendisplay/cflags"); - xldflags = get("libs/gui/xopendisplay/ldflags"); - - report("Checking for Xrender... "); - logprintf(logdepth, "find_xrender:\n"); - logdepth++; - - for(cflags = cflags_arr; *cflags != NULL; cflags++) { - for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { - if (try_icl_with_deps(logdepth, node, test_c, NULL, *cflags, *ldflags, xincludes, xcflags, xldflags, 0) != 0) { - return 0; - } - } - } - return try_fail(logdepth, node); -} - -int find_xcb(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " char *host;" - NL " int display, screen;" - NL " if (xcb_parse_display(\"ford:42.8\", &host, &display, &screen) == 0) return 0;" - NL " if ((strcmp(host, \"ford\") == 0) && (display == 42) && (screen == 8))" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/xcb"; - char **cflags, *cflags_arr[] = {"", NULL}; - char **ldflags, *ldflags_arr[] = {"-lxcb", NULL}; - const char *xincludes, *xcflags, *xldflags; - - if (require("cc/cc", logdepth, fatal)) - return 1; - - if (require("libs/gui/xopendisplay/*", logdepth, fatal)) - return 1; - - xincludes = get("libs/gui/xopendisplay/includes"); - xcflags = get("libs/gui/xopendisplay/cflags"); - xldflags = get("libs/gui/xopendisplay/ldflags"); - - report("Checking for xcb... "); - logprintf(logdepth, "find_xcb:\n"); - logdepth++; - - for(cflags = cflags_arr; *cflags != NULL; cflags++) { - for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { - if (try_icl_with_deps(logdepth, node, test_c, NULL, *cflags, *ldflags, xincludes, xcflags, xldflags, 1) != 0) { - return 0; - } - } - } - return try_fail(logdepth, node); -} - -int find_xgetxcbconnection(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " XGetXCBConnection(NULL);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/xgetxcbconnection"; - char **cflags, *cflags_arr[] = {"", NULL}; - char **ldflags, *ldflags_arr[] = {"-lX11-xcb", NULL}; - const char *xincludes, *xcflags, *xldflags; - - if (require("cc/cc", logdepth, fatal)) - return 1; - - if (require("libs/gui/xopendisplay/*", logdepth, fatal)) - return 1; - - xincludes = get("libs/gui/xopendisplay/includes"); - xcflags = get("libs/gui/xopendisplay/cflags"); - xldflags = get("libs/gui/xopendisplay/ldflags"); - - report("Checking for xgetxcbconnection... "); - logprintf(logdepth, "find_xgetxcbconnection:\n"); - logdepth++; - - for(cflags = cflags_arr; *cflags != NULL; cflags++) { - for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { - if (try_icl_with_deps(logdepth, node, test_c, NULL, *cflags, *ldflags, xincludes, xcflags, xldflags, 0) != 0) { - return 0; - } - } - } - return try_fail(logdepth, node); -} - -int find_xcb_render(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " xcb_render_query_pict_formats_formats(NULL);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/xcb_render"; - char **cflags, *cflags_arr[] = {"", NULL}; - char **ldflags, *ldflags_arr[] = {"-lxcb-render", NULL}; - const char *xincludes, *xcflags, *xldflags; - - if (require("cc/cc", logdepth, fatal)) - return 1; - - if (require("libs/gui/xopendisplay/*", logdepth, fatal)) - return 1; - - xincludes = get("libs/gui/xopendisplay/includes"); - xcflags = get("libs/gui/xopendisplay/cflags"); - xldflags = get("libs/gui/xopendisplay/ldflags"); - - report("Checking for xcb_render... "); - logprintf(logdepth, "find_xcb_render:\n"); - logdepth++; - - for(cflags = cflags_arr; *cflags != NULL; cflags++) { - for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { - if (try_icl_with_deps(logdepth, node, test_c, NULL, *cflags, *ldflags, xincludes, xcflags, xldflags, 0) != 0) { - return 0; - } - } - } - return try_fail(logdepth, node); -} - -int find_xpm(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "#include " - NL "int main()" - NL "{" - NL " if (XpmLibraryVersion() == XpmIncludeVersion)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/xpm"; - char **cflags, *cflags_arr[] = {"", NULL}; - char **ldflags, *ldflags_arr[] = {"-lXpm", NULL}; - const char *xincludes, *xcflags, *xldflags; - - if (require("cc/cc", logdepth, fatal)) - return 1; - - if (require("libs/gui/xopendisplay/*", logdepth, fatal)) - return 1; - - xincludes = get("libs/gui/xopendisplay/includes"); - xcflags = get("libs/gui/xopendisplay/cflags"); - xldflags = get("libs/gui/xopendisplay/ldflags"); - - report("Checking for xpm... "); - logprintf(logdepth, "find_xpm:\n"); - logdepth++; - - for(cflags = cflags_arr; *cflags != NULL; cflags++) { - for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { - if (try_icl_with_deps(logdepth, node, test_c, NULL, *cflags, *ldflags, xincludes, xcflags, xldflags, 1) != 0) { - return 0; - } - } - } - return try_fail(logdepth, node); -} diff --git a/scconfig/src/gui/.svn/pristine/ad/ad751a77e93daad924eb9d9760360a8a6d800f8e.svn-base b/scconfig/src/gui/.svn/pristine/ad/ad751a77e93daad924eb9d9760360a8a6d800f8e.svn-base deleted file mode 100644 index 88f8db1f..00000000 --- a/scconfig/src/gui/.svn/pristine/ad/ad751a77e93daad924eb9d9760360a8a6d800f8e.svn-base +++ /dev/null @@ -1,2 +0,0 @@ -int find_lesstif2(const char *name, int logdepth, int fatal); - diff --git a/scconfig/src/gui/.svn/pristine/b2/b23d834a00e13fb95ea42e521856d388db9ced09.svn-base b/scconfig/src/gui/.svn/pristine/b2/b23d834a00e13fb95ea42e521856d388db9ced09.svn-base deleted file mode 100644 index 7e173cd9..00000000 --- a/scconfig/src/gui/.svn/pristine/b2/b23d834a00e13fb95ea42e521856d388db9ced09.svn-base +++ /dev/null @@ -1,4 +0,0 @@ -int find_gl(const char *name, int logdepth, int fatal); -int find_glu(const char *name, int logdepth, int fatal); -int find_glut(const char *name, int logdepth, int fatal); -int find_gui_wgl(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/gui/.svn/pristine/b2/b2b4b1c1797d5b9c305bb544c606b163184138f9.svn-base b/scconfig/src/gui/.svn/pristine/b2/b2b4b1c1797d5b9c305bb544c606b163184138f9.svn-base deleted file mode 100644 index 4a629dec..00000000 --- a/scconfig/src/gui/.svn/pristine/b2/b2b4b1c1797d5b9c305bb544c606b163184138f9.svn-base +++ /dev/null @@ -1,3 +0,0 @@ -int find_gtk2(const char *name, int logdepth, int fatal); -int find_gtk2gl(const char *name, int logdepth, int fatal); -int find_gtk2_modversion(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/gui/.svn/pristine/c3/c3f249a13e0e0282c960f670344a684d7b548c95.svn-base b/scconfig/src/gui/.svn/pristine/c3/c3f249a13e0e0282c960f670344a684d7b548c95.svn-base deleted file mode 100644 index 565d0010..00000000 --- a/scconfig/src/gui/.svn/pristine/c3/c3f249a13e0e0282c960f670344a684d7b548c95.svn-base +++ /dev/null @@ -1,42 +0,0 @@ -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -#include "find_x.h" -#include "find_gtk2.h" -#include "find_gtk3.h" -#include "find_lesstif2.h" -#include "find_gd.h" -#include "find_cairo.h" -#include "find_misc.h" -#include "find_gl.h" - -void deps_gui_init() -{ - dep_add("libs/gui/xopendisplay/*", find_xopendisplay); - dep_add("libs/gui/xinerama/*", find_xinerama); - dep_add("libs/gui/xrender/*", find_xrender); - dep_add("libs/gui/xcb/*", find_xcb); - dep_add("libs/gui/xcb_render/*", find_xcb_render); - dep_add("libs/gui/xgetxcbconnection/*", find_xgetxcbconnection); - dep_add("libs/gui/xpm/*", find_xpm); - dep_add("libs/gui/gtk2/*", find_gtk2); - dep_add("libs/gui/gtk2gl/*", find_gtk2gl); - dep_add("libs/gui/gtk2/key_prefix", find_gtk2_key_prefix); - dep_add("libs/gui/gtk2/modversion", find_gtk2_modversion); - dep_add("libs/gui/gtk3/*", find_gtk3); - dep_add("libs/gui/lesstif2/*", find_lesstif2); - dep_add("libs/gui/libstroke/*", find_libstroke); - dep_add("libs/gui/gd/gdImagePng/*", find_gdimagepng); - dep_add("libs/gui/gd/gdImageGif/*", find_gdimagegif); - dep_add("libs/gui/gd/gdImageJpeg/*", find_gdimagejpeg); - dep_add("libs/gui/gd/gdImageSetResolution/*", find_gdimagesetresolution); - dep_add("libs/gui/gd/*", find_gd); - dep_add("libs/gui/cairo/*", find_cairo); - dep_add("libs/gui/cairo-xcb/*", find_cairo_xcb); - dep_add("libs/gui/gl/*", find_gl); - dep_add("libs/gui/glu/*", find_glu); - dep_add("libs/gui/glut/*", find_glut); - dep_add("libs/gui/wgl/*", find_gui_wgl); -} diff --git a/scconfig/src/gui/.svn/pristine/ce/ceb78d58ea27378cc1818f1dfdb6740bbc4ef3cf.svn-base b/scconfig/src/gui/.svn/pristine/ce/ceb78d58ea27378cc1818f1dfdb6740bbc4ef3cf.svn-base deleted file mode 100644 index 9b799ba8..00000000 --- a/scconfig/src/gui/.svn/pristine/ce/ceb78d58ea27378cc1818f1dfdb6740bbc4ef3cf.svn-base +++ /dev/null @@ -1 +0,0 @@ -void deps_gui_init(); diff --git a/scconfig/src/gui/.svn/pristine/d2/d20f4a574b433278a7e85ce578c858a92c7dfa85.svn-base b/scconfig/src/gui/.svn/pristine/d2/d20f4a574b433278a7e85ce578c858a92c7dfa85.svn-base deleted file mode 100644 index f422f231..00000000 --- a/scconfig/src/gui/.svn/pristine/d2/d20f4a574b433278a7e85ce578c858a92c7dfa85.svn-base +++ /dev/null @@ -1,4 +0,0 @@ -int find_gtk2(const char *name, int logdepth, int fatal); -int find_gtk2gl(const char *name, int logdepth, int fatal); -int find_gtk2_modversion(const char *name, int logdepth, int fatal); -int find_gtk2_key_prefix(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/gui/.svn/pristine/db/db950bc0d6bad6f7eeabb824ecd2be20fcd02ca0.svn-base b/scconfig/src/gui/.svn/pristine/db/db950bc0d6bad6f7eeabb824ecd2be20fcd02ca0.svn-base deleted file mode 100644 index 0657be7f..00000000 --- a/scconfig/src/gui/.svn/pristine/db/db950bc0d6bad6f7eeabb824ecd2be20fcd02ca0.svn-base +++ /dev/null @@ -1,89 +0,0 @@ -/* - scconfig - gui lib detection - gtk3 - Copyright (C) 2017 Alain Vigne - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_gtk3(const char *name, int logdepth, int fatal, const char *call, const char *arg) -{ - const char *test_c = - NL "#include " - NL - NL "static void" - NL "activate (GtkApplication* app," - NL " gpointer user_data)" - NL "{" - NL " GtkWidget *window;" - NL - NL " window = gtk_application_window_new (app);" - NL " gtk_window_set_title (GTK_WINDOW (window), \"Window\");" - NL " gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);" - NL " gtk_widget_show_all (window);" - NL "}" - NL - NL "int" - NL "main (int argc," - NL " char **argv)" - NL "{" - NL " GtkApplication *app;" - NL " int status;" - NL - NL " app = gtk_application_new (\"org.gtk.example\", G_APPLICATION_FLAGS_NONE);" - NL " g_signal_connect (app, \"activate\", G_CALLBACK (activate), NULL);" - NL " status = g_application_run (G_APPLICATION (app), argc, argv);" - NL " g_object_unref (app);" - NL - NL " return status;" - NL "}" - NL; - const char *node = "libs/gui/gtk3"; - const char *pkgname = "gtk+-3.0"; - char *cflags; - char *ldflags; - (void) call; /* not used */ - (void) arg; /* not used */ - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for gtk+3... "); - logprintf(logdepth, "find_gtk3: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, pkgname, &cflags, &ldflags) != 0) { - return try_fail(logdepth, node); - } - - if (try_icl_norun(logdepth, node, test_c, NULL, cflags, ldflags) == 0) { - free(cflags); - free(ldflags); - return try_fail(logdepth, node); - } - - free(cflags); - free(ldflags); - return 0; -} diff --git a/scconfig/src/gui/.svn/pristine/dd/dd5edf72fee204ab36d163f9821f04b336abb927.svn-base b/scconfig/src/gui/.svn/pristine/dd/dd5edf72fee204ab36d163f9821f04b336abb927.svn-base deleted file mode 100644 index 87568911..00000000 --- a/scconfig/src/gui/.svn/pristine/dd/dd5edf72fee204ab36d163f9821f04b336abb927.svn-base +++ /dev/null @@ -1,267 +0,0 @@ -/* - scconfig - gui lib detection - opengl related calls - Copyright (C) 2017 Tibor Palinkas - Copyright (C) 2018 Aron Barath - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_gl(const char *name, int logdepth, int fatal, const char *call, const char *arg) -{ - char test_c[256]; - const char *test_c_templ = - NL "#include <%s/gl.h>" - NL "#include " - NL "int main()" - NL "{" - NL " GLenum err = glGetError();" - NL " if (err == 0 || err == GL_INVALID_OPERATION)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/gl"; - char **id, *incdirs[] = {"GL", "OpenGL", NULL}; - char **cf, *cflgs[] = {"", "-I/usr/include/libdrm", NULL}; - const char **lf, *ldflgs[] = {"-lGL", "-lopengl32", NULL}; - char *cflags = NULL; - char *ldflags = NULL; - (void) call; /* not used */ - (void) arg; /* not used */ - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - report("Checking for gl... "); - logprintf(logdepth, "find_gl: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, "gl", &cflags, &ldflags) == 0) { - for(id = incdirs; *id != NULL; id++) { - sprintf(test_c, test_c_templ, *id); - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) != 0) - goto success; - } - } - - logdepth--; - logprintf(logdepth, "find_gl: manual tries...\n"); - logdepth++; - - for(lf = ldflgs; *lf != NULL; lf++) { - ldflags = strclone(*lf); - for(cf = cflgs; *cf != NULL; cf++) { - for(id = incdirs; *id != NULL; id++) { - sprintf(test_c, test_c_templ, *id); - if (try_icl(logdepth, node, test_c, NULL, *cf, ldflags) != 0) - goto success; - } - } - free(ldflags); - } - - return try_fail(logdepth, node); - - success:; - put("libs/gui/gl/include_prefix", *id); - if (cflags != NULL) - free(cflags); - if (ldflags != NULL) - free(ldflags); - return 0; -} - -int find_glu(const char *name, int logdepth, int fatal, const char *call, const char *arg) -{ - char test_c[256]; - const char *test_c_templ = - NL "#include <%s/gl.h>" - NL "#include <%s/glu.h>" - NL "#include " - NL "int main()" - NL "{" - NL " GLUtesselator *g = gluNewTess();" - NL " if (g != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/glu", *ipr; - char **cf, *cflgs[] = {"", "-I/usr/include/libdrm", NULL}; - char *cflags = NULL; - char *ldflags = NULL; - (void) call; /* not used */ - (void) arg; /* not used */ - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - if (require("libs/gui/gl/include_prefix", logdepth, fatal)) - return try_fail(logdepth, node); - - ipr = get("libs/gui/gl/include_prefix"); - if (ipr == NULL) - return try_fail(logdepth, node); - - sprintf(test_c, test_c_templ, ipr, ipr); - - report("Checking for glu... "); - logprintf(logdepth, "find_glu: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, "glu", &cflags, &ldflags) == 0) { - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) != 0) - goto success; - } - - logdepth--; - logprintf(logdepth, "find_glu: manual tries...\n"); - logdepth++; - - ldflags = strclone("-lGLU"); - for(cf = cflgs; *cf != NULL; cf++) - if (try_icl(logdepth, node, test_c, NULL, *cf, ldflags) != 0) - goto success; - free(ldflags); - - ldflags = strclone("-lglu32"); - for(cf = cflgs; *cf != NULL; cf++) - if (try_icl(logdepth, node, test_c, NULL, *cf, ldflags) != 0) - goto success; - free(ldflags); - - return try_fail(logdepth, node); - - success:; - if (cflags != NULL) - free(cflags); - if (ldflags != NULL) - free(ldflags); - return 0; -} - -int find_glut(const char *name, int logdepth, int fatal, const char *call, const char *arg) -{ - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " glutGet(GLUT_ELAPSED_TIME);" - NL " if (glutGet!=NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/glut", *ipr; - char freeglut[4096]; - char **inc, *incs[] = {"", "#include ", NULL}; - char *cflags = NULL; - char *ldflags = NULL; - (void) call; /* not used */ - (void) arg; /* not used */ - - incs[0] = freeglut; - - if (require("cc/cc", logdepth, fatal)) - return try_fail(logdepth, node); - - - report("Checking for glut... "); - logprintf(logdepth, "find_glut: running pkg-config...\n"); - logdepth++; - - if (run_pkg_config(logdepth, "glut", &cflags, &ldflags) == 0) { - if (try_icl(logdepth, node, test_c, NULL, cflags, ldflags) != 0) - goto success; - } - - if (require("libs/gui/gl/include_prefix", logdepth, fatal)) - return try_fail(logdepth, node); - ipr = get("libs/gui/gl/include_prefix"); - if (ipr == NULL) - return try_fail(logdepth, node); - - if (cflags != NULL) { - free(cflags); - cflags = NULL; - } - - if (ldflags != NULL) { - free(ldflags); - ldflags = NULL; - } - - logdepth--; - logprintf(logdepth, "find_glut: manual tries...\n"); - logdepth++; - - sprintf(freeglut, "#include <%s/freeglut.h>", ipr); - ldflags = strclone("-lglut"); - for(inc = incs; *inc != NULL; inc++) - if (try_icl(logdepth, node, test_c, *inc, NULL, ldflags) != 0) - goto success; - free(ldflags); - - sprintf(freeglut, "#include \n#include <%s/glut.h>", ipr); - ldflags = strclone("-lglut32"); - for(inc = incs; *inc != NULL; inc++) - if (try_icl(logdepth, node, test_c, *inc, NULL, ldflags) != 0) - goto success; - free(ldflags); - - return try_fail(logdepth, node); - - success:; - if (cflags != NULL) - free(cflags); - if (ldflags != NULL) - free(ldflags); - return 0; -} - -int find_gui_wgl(const char *name, int logdepth, int fatal) -{ - const char *test_c = - NL "#include " - NL "int main()" - NL "{" - NL " if(wglGetCurrentDC() == NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - const char *node = "libs/gui/wgl"; - - require("cc/cc", logdepth, fatal); - - report("Checking for wgl()... "); - logprintf(logdepth, "find_gui_wgl: trying to find wgl...\n"); - logdepth++; - - /* wgl exists only on windows, so try what the documentation says */ - /* ("wgl" stands for "Windows GL" oslt) */ - if (try_icl(logdepth, node, test_c, "#include ", NULL, "-lopengl32")) return 0; - return try_fail(logdepth, node); -} diff --git a/scconfig/src/gui/.svn/pristine/fe/fe69174d732475c114078a4c8282f1071ec7e674.svn-base b/scconfig/src/gui/.svn/pristine/fe/fe69174d732475c114078a4c8282f1071ec7e674.svn-base deleted file mode 100644 index ff9eea89..00000000 --- a/scconfig/src/gui/.svn/pristine/fe/fe69174d732475c114078a4c8282f1071ec7e674.svn-base +++ /dev/null @@ -1,3 +0,0 @@ -int find_cairo(const char *name, int logdepth, int fatal); -int find_cairo_xcb(const char *name, int logdepth, int fatal); - diff --git a/scconfig/src/gui/.svn/wc.db b/scconfig/src/gui/.svn/wc.db deleted file mode 100644 index 43f3deb1..00000000 Binary files a/scconfig/src/gui/.svn/wc.db and /dev/null differ diff --git a/scconfig/src/gui/.svn/wc.db-journal b/scconfig/src/gui/.svn/wc.db-journal deleted file mode 100644 index e69de29b..00000000 diff --git a/scconfig/src/parsgen/.svn/entries b/scconfig/src/parsgen/.svn/entries deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/parsgen/.svn/entries +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/parsgen/.svn/format b/scconfig/src/parsgen/.svn/format deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/parsgen/.svn/format +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/parsgen/.svn/pristine/1a/1a78a39cbbb8033bcabddaa9828dd08c0fbb5341.svn-base b/scconfig/src/parsgen/.svn/pristine/1a/1a78a39cbbb8033bcabddaa9828dd08c0fbb5341.svn-base deleted file mode 100644 index 248ce975..00000000 --- a/scconfig/src/parsgen/.svn/pristine/1a/1a78a39cbbb8033bcabddaa9828dd08c0fbb5341.svn-base +++ /dev/null @@ -1 +0,0 @@ -void deps_parsgen_init(); diff --git a/scconfig/src/parsgen/.svn/pristine/63/63af3acf45de2cacaa38545340c69756002410a4.svn-base b/scconfig/src/parsgen/.svn/pristine/63/63af3acf45de2cacaa38545340c69756002410a4.svn-base deleted file mode 100644 index 9aab1fe1..00000000 --- a/scconfig/src/parsgen/.svn/pristine/63/63af3acf45de2cacaa38545340c69756002410a4.svn-base +++ /dev/null @@ -1,139 +0,0 @@ -/* - scconfig - parser generator detection - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_parsgen_flex(const char *name, int logdepth, int fatal) -{ - const char *test_flex = - NL "%%" - NL "foo { return 1; }" - NL "%%" - NL ; - char *out, *temp_in, *temp_in_esc, *cmd; - int ret; - char *lexfile = "lex.yy.c"; - (void) fatal; /* not used */ - - report("Checking for flex... "); - logprintf(logdepth, "find_flex: trying to find flex...\n"); - logdepth++; - - if (is_file(lexfile)) { - report("ERROR: %s exists, and I don't dare to delete it. Can't test flex, please remove the file by hand.\n", lexfile); - logprintf(logdepth, "ERROR: %s exists, and I don't dare to delete it. Can't test flex, please remove the file by hand.\n", lexfile); - exit(1); - } - temp_in = tempfile_dump(test_flex, ".lex"); - temp_in_esc = shell_escape_dup(temp_in); - cmd = malloc(strlen(temp_in_esc) + 16); - sprintf(cmd, "flex %s", temp_in_esc); - free(temp_in_esc); - ret = run(logdepth, cmd, &out); - remove(temp_in); - free(temp_in); - if (out != NULL) - free(out); - - if (is_file(lexfile)) { - remove(lexfile); - if (ret == 0) { - put("parsgen/flex", "flex"); - put("parsgen/flex/presents", strue); - report("Found.\n"); - return 0; - } - } - - put("parsgen/flex/presents", sfalse); - report("Not found.\n"); - return 1; -} - -int find_parsgen_bison(const char *name, int logdepth, int fatal) -{ - const char *test_bison = - NL "%union { char *str; double num;}" - NL "%%" - NL "%token TOK1;" - NL "%token TOK2;" - NL "root: one | two;" - NL "one: TOK1;" - NL "two: TOK2;" - NL ; - char *out, *temp_in, *temp_in_esc, *cmd; - int ret; - char *bisfile, *s; - (void) fatal; /* not used */ - - report("Checking for bison... "); - logprintf(logdepth, "find_bison: trying to find bison...\n"); - logdepth++; - - temp_in = tempfile_dump(test_bison, ".y"); - bisfile = malloc(strlen(temp_in) + 32); - strcpy(bisfile, temp_in); - s = strrchr(bisfile+1, '.'); - strcpy(s, ".tab.c"); - if (is_file(bisfile)) { - report("ERROR: %s exists, and I don't dare to delete it. Can't test bison, please remove the file by hand.\n", bisfile); - logprintf(logdepth, "ERROR: %s exists, and I don't dare to delete it. Can't test bison, please remove the file by hand.\n", bisfile); - exit(1); - } - temp_in_esc = shell_escape_dup(temp_in); - cmd = malloc(strlen(temp_in_esc) + 16); - sprintf(cmd, "bison %s", temp_in_esc); - free(temp_in_esc); - - - ret = run(logdepth, cmd, &out); - remove(temp_in); - free(temp_in); - if (out != NULL) - free(out); - - if (is_file(bisfile)) { - remove(bisfile); - if (ret == 0) { - put("parsgen/bison", "bison"); - put("parsgen/bison/presents", strue); - report("Found.\n"); - return 0; - } - } - - put("parsgen/bison/presents", sfalse); - report("Not found.\n"); - return 1; -} - -void deps_parsgen_init() -{ - dep_add("parsgen/flex/*", find_parsgen_flex); - dep_add("parsgen/bison/*", find_parsgen_bison); -} diff --git a/scconfig/src/parsgen/.svn/pristine/6e/6efa64172b87c17c985e0da8dcb1368af4b49302.svn-base b/scconfig/src/parsgen/.svn/pristine/6e/6efa64172b87c17c985e0da8dcb1368af4b49302.svn-base deleted file mode 100644 index 02a7cbac..00000000 --- a/scconfig/src/parsgen/.svn/pristine/6e/6efa64172b87c17c985e0da8dcb1368af4b49302.svn-base +++ /dev/null @@ -1,238 +0,0 @@ -/* - scconfig - parser generator detection - Copyright (C) 2009,2020 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int find_parsgen_flex(const char *name, int logdepth, int fatal) -{ - const char *test_flex = - NL "%%" - NL "foo { return 1; }" - NL "%%" - NL ; - char *out, *temp_in, *temp_in_esc, *cmd; - int ret; - char *lexfile = "lex.yy.c"; - (void) fatal; /* not used */ - - report("Checking for flex... "); - logprintf(logdepth, "find_flex: trying to find flex...\n"); - logdepth++; - - if (is_file(lexfile)) { - report("ERROR: %s exists, and I don't dare to delete it. Can't test flex, please remove the file by hand.\n", lexfile); - logprintf(logdepth, "ERROR: %s exists, and I don't dare to delete it. Can't test flex, please remove the file by hand.\n", lexfile); - exit(1); - } - temp_in = tempfile_dump(test_flex, ".lex"); - temp_in_esc = shell_escape_dup(temp_in); - cmd = malloc(strlen(temp_in_esc) + 16); - sprintf(cmd, "flex %s", temp_in_esc); - free(temp_in_esc); - ret = run(logdepth, cmd, &out); - remove(temp_in); - free(temp_in); - if (out != NULL) - free(out); - - if (is_file(lexfile)) { - remove(lexfile); - if (ret == 0) { - put("parsgen/flex", "flex"); - put("parsgen/flex/presents", strue); - report("Found.\n"); - return 0; - } - } - - put("parsgen/flex/presents", sfalse); - report("Not found.\n"); - return 1; -} - -static const char *test_yacc = - NL "%union { char *str; double num;}" - NL "%token TOK1;" - NL "%token TOK2;" - NL "%%" - NL "root: one | two;" - NL "one: TOK1;" - NL "two: TOK2;" - NL ; - -int find_parsgen_bison(const char *name, int logdepth, int fatal) -{ - char *out, *temp_in, *temp_in_esc, *cmd; - int ret; - char *bisfile, *s; - (void) fatal; /* not used */ - - report("Checking for bison... "); - logprintf(logdepth, "find_bison: trying to find bison...\n"); - logdepth++; - - temp_in = tempfile_dump(test_yacc, ".y"); - bisfile = malloc(strlen(temp_in) + 32); - strcpy(bisfile, temp_in); - s = strrchr(bisfile+1, '.'); - strcpy(s, ".tab.c"); - if (is_file(bisfile)) { - report("ERROR: %s exists, and I don't dare to delete it. Can't test bison, please remove the file by hand.\n", bisfile); - logprintf(logdepth, "ERROR: %s exists, and I don't dare to delete it. Can't test bison, please remove the file by hand.\n", bisfile); - exit(1); - } - temp_in_esc = shell_escape_dup(temp_in); - cmd = malloc(strlen(temp_in_esc) + 16); - sprintf(cmd, "bison %s", temp_in_esc); - free(temp_in_esc); - - - ret = run(logdepth, cmd, &out); - remove(temp_in); - free(temp_in); - if (out != NULL) - free(out); - - if (is_file(bisfile)) { - remove(bisfile); - if (ret == 0) { - put("parsgen/bison", "bison"); - put("parsgen/bison/presents", strue); - report("Found.\n"); - return 0; - } - } - - put("parsgen/bison/presents", sfalse); - report("Not found.\n"); - return 1; -} - -int find_parsgen_byaccic(const char *name, int logdepth, int fatal) -{ - char *out, *temp_in, *temp_in_esc, *cmd; - int ret; - char *bisfile, *s; - (void) fatal; /* not used */ - - report("Checking for byaccic... "); - logprintf(logdepth, "find_byaccic: trying to find byaccic...\n"); - logdepth++; - - temp_in = tempfile_dump(test_yacc, ".y"); - bisfile = malloc(strlen(temp_in) + 32); - strcpy(bisfile, temp_in); - s = strrchr(bisfile+1, '.'); - strcpy(s, ".tab.c"); - if (is_file(bisfile)) { - report("ERROR: %s exists, and I don't dare to delete it. Can't test byaccic, please remove the file by hand.\n", bisfile); - logprintf(logdepth, "ERROR: %s exists, and I don't dare to delete it. Can't test byaccic, please remove the file by hand.\n", bisfile); - exit(1); - } - temp_in_esc = shell_escape_dup(temp_in); - cmd = malloc(strlen(temp_in_esc)*2 + 32); - sprintf(cmd, "byaccic -o %s %s", bisfile, temp_in_esc); - free(temp_in_esc); - - ret = run(logdepth, cmd, &out); - remove(temp_in); - free(temp_in); - if (out != NULL) - free(out); - - if (is_file(bisfile)) { - remove(bisfile); - if (ret == 0) { - put("parsgen/byaccic", "byaccic"); - put("parsgen/byaccic/presents", strue); - report("Found.\n"); - return 0; - } - } - - put("parsgen/byaccic/presents", sfalse); - report("Not found.\n"); - return 1; -} - -int find_parsgen_ureglex(const char *name, int logdepth, int fatal) -{ - const char *test_ureglex = - NL "rule blank" - NL "regex [ \t\r]+" - NL "code" - NL " ULX_IGNORE;" - NL "rulestring 3D_DXF return 0;" - NL ; - char *out, *temp_in, *temp_in_esc, *cmd; - int ret; - char *lexfile = "lex.yy.c"; - (void) fatal; /* not used */ - - report("Checking for ureglex... "); - logprintf(logdepth, "find_ureglex: trying to find ureglex...\n"); - logdepth++; - - if (is_file(lexfile)) { - report("ERROR: %s exists, and I don't dare to delete it. Can't test ureglex, please remove the file by hand.\n", lexfile); - logprintf(logdepth, "ERROR: %s exists, and I don't dare to delete it. Can't test ureglex, please remove the file by hand.\n", lexfile); - exit(1); - } - temp_in = tempfile_dump(test_ureglex, ".lex"); - temp_in_esc = shell_escape_dup(temp_in); - cmd = malloc(strlen(temp_in_esc) + 32); - sprintf(cmd, "ureglex -l %s -c %s", temp_in_esc, lexfile); - free(temp_in_esc); - ret = run(logdepth, cmd, &out); - remove(temp_in); - free(temp_in); - if (out != NULL) - free(out); - - if (is_file(lexfile)) { - remove(lexfile); - if (ret == 0) { - put("parsgen/ureglex", "ureglex"); - put("parsgen/ureglex/presents", strue); - report("Found.\n"); - return 0; - } - } - - put("parsgen/ureglex/presents", sfalse); - report("Not found.\n"); - return 1; -} - -void deps_parsgen_init() -{ - dep_add("parsgen/flex/*", find_parsgen_flex); - dep_add("parsgen/bison/*", find_parsgen_bison); - dep_add("parsgen/byaccic/*", find_parsgen_byaccic); - dep_add("parsgen/ureglex/*", find_parsgen_ureglex); -} diff --git a/scconfig/src/parsgen/.svn/pristine/95/952f44752b5a9e9a69fa88ba8d4d92dd5cd55c6d.svn-base b/scconfig/src/parsgen/.svn/pristine/95/952f44752b5a9e9a69fa88ba8d4d92dd5cd55c6d.svn-base deleted file mode 100644 index 8f2c8bb0..00000000 --- a/scconfig/src/parsgen/.svn/pristine/95/952f44752b5a9e9a69fa88ba8d4d92dd5cd55c6d.svn-base +++ /dev/null @@ -1,6 +0,0 @@ -PARSGEN_CFLAGS = -DPLUGIN_PARSGEN -PARSGEN_OBJS = \ - $(BIN)/parsgen/find_parsgen.o - -$(BIN)/parsgen/find_parsgen.o: $(SRC)/parsgen/find_parsgen.c - $(CC) $(CFLAGS) -c $(SRC)/parsgen/find_parsgen.c -o $(BIN)/parsgen/find_parsgen.o diff --git a/scconfig/src/parsgen/.svn/pristine/eb/eb86ddef99c49256a67cd95e3109cfd8a9666b34.svn-base b/scconfig/src/parsgen/.svn/pristine/eb/eb86ddef99c49256a67cd95e3109cfd8a9666b34.svn-base deleted file mode 100644 index f0f30d60..00000000 --- a/scconfig/src/parsgen/.svn/pristine/eb/eb86ddef99c49256a67cd95e3109cfd8a9666b34.svn-base +++ /dev/null @@ -1,2 +0,0 @@ - deps_parsgen_init(); - diff --git a/scconfig/src/parsgen/.svn/wc.db b/scconfig/src/parsgen/.svn/wc.db deleted file mode 100644 index 8ea1d95c..00000000 Binary files a/scconfig/src/parsgen/.svn/wc.db and /dev/null differ diff --git a/scconfig/src/parsgen/.svn/wc.db-journal b/scconfig/src/parsgen/.svn/wc.db-journal deleted file mode 100644 index e69de29b..00000000 diff --git a/scconfig/src/scripts/.svn/entries b/scconfig/src/scripts/.svn/entries deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/scripts/.svn/entries +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/scripts/.svn/format b/scconfig/src/scripts/.svn/format deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/scripts/.svn/format +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/scripts/.svn/pristine/03/036c774d61cb4649db7ceb74f3641385c6890d20.svn-base b/scconfig/src/scripts/.svn/pristine/03/036c774d61cb4649db7ceb74f3641385c6890d20.svn-base deleted file mode 100644 index 2fa898af..00000000 --- a/scconfig/src/scripts/.svn/pristine/03/036c774d61cb4649db7ceb74f3641385c6890d20.svn-base +++ /dev/null @@ -1,67 +0,0 @@ -/* - scconfig - guile lib detection - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - - -int find_script_guile(const char *name, int logdepth, int fatal) -{ - char *cflags, *ldflags; - -/* temp hack: guile/gh makes sure we have the old, 1.8 version */ - char *test_c = - NL "#include " - NL "#include " - NL "int main(int argc, char *argv[]) {" - NL " scm_init_guile();" - NL - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for guile... "); - logprintf(logdepth, "find_guile: trying to find guile...\n"); - logdepth++; - - if (run(logdepth, "guile-config compile", &cflags) + run(logdepth, "guile-config link", &ldflags) > 0) { - free(cflags); - free(ldflags); - put("libs/script/guile/presents", sfalse); - report("FAILED (guile-config failed)\n"); - return 1; - } - - /* TODO: do we need -ldl? */ - if (try_icl(logdepth, "libs/script/guile", test_c, NULL, cflags, ldflags)) { - free(ldflags); - free(cflags); - return 0; - } - - free(ldflags); - free(cflags); - return try_fail(logdepth, "libs/script/guile"); -} diff --git a/scconfig/src/scripts/.svn/pristine/0a/0aa9b50e5ac6ec6d2106179866ea247ac7c85b2f.svn-base b/scconfig/src/scripts/.svn/pristine/0a/0aa9b50e5ac6ec6d2106179866ea247ac7c85b2f.svn-base deleted file mode 100644 index 20e75fa2..00000000 --- a/scconfig/src/scripts/.svn/pristine/0a/0aa9b50e5ac6ec6d2106179866ea247ac7c85b2f.svn-base +++ /dev/null @@ -1,124 +0,0 @@ -/* - scconfig - ruby lib detection - Copyright (C) 2009..2015 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" - -static int brute_force(int logdepth, const char *test_c, const char *basedir) -{ - char **files, **ifiles, *tmp, *ldflags; - int fileno, n, m, ifileno, res; - - res = 0; - filelist(logdepth, basedir, &fileno, &files); - if (fileno <= 0) - return res; - - for(n = 0; (n < fileno) && !res; n++) { - tmp = malloc(strlen(basedir) + strlen(files[n]) + 4); - sprintf(tmp, "%s/%s", basedir, files[n]); - filelist(logdepth+1, tmp, &ifileno, &ifiles); - free(tmp); - for(m = 0; (m < ifileno) && !res; m++) { - tmp = malloc(strlen(basedir) + strlen(files[n]) + strlen(ifiles[m]) + 16); - sprintf(tmp, "%s/%s/%s/ruby.h", basedir, files[n], ifiles[m]); - - if (is_file(tmp)) { - sprintf(tmp, "-I%s/%s/%s", basedir, files[n], ifiles[m]); - ldflags = malloc(strlen(files[n]) + 16); - sprintf(ldflags, "-lruby%s", files[n]); - res = try_icl(logdepth, "libs/script/ruby", test_c, NULL, tmp, ldflags); - free(ldflags); - } - free(tmp); - } - filelist_free(&ifileno, &ifiles); - } - filelist_free(&fileno, &files); - - return res; -} - -int find_script_ruby(const char *name, int logdepth, int fatal) -{ - int require18; - const char *require18s; - - char *test_c = - NL "#include " - NL "int main() {" - NL " ruby_init();" - NL " ruby_finalize();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - char *test_c18 = - NL "#include " - NL "#include " - NL "int main() {" - NL " ruby_init();" - NL " ruby_frame->orig_func;" - NL " ruby_finalize();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for ruby... "); - logprintf(logdepth, "find_ruby: trying to find ruby...\n"); - logdepth++; - - require18s = get("libs/script/ruby/require_18"); - if (require18s != NULL) - require18 = istrue(require18s); - else - require18 = 0; - - if ((!require18) && (try_icl_pkg_config(logdepth, "libs/script/ruby", test_c, NULL, "ruby-*", get("/arg/ruby-version")))) - return 0; - - if (try_icl_pkg_config(logdepth, "libs/script/ruby", test_c18, NULL, "ruby-*", get("/arg/ruby-version"))) - return 0; - - /* Look at some standard places */ - if ((!require18) && (try_icl(logdepth, "libs/script/ruby", test_c, NULL, NULL, "-lruby"))) - return 0; - if (try_icl(logdepth, "libs/script/ruby", test_c18, NULL, NULL, "-lruby")) - return 0; - - require("/internal/filelist/method", logdepth, fatal); - - /* no luck - try to find by brute force, listing directory names */ - if ((!require18) && (brute_force(logdepth, test_c, "/usr/lib/ruby") || - brute_force(logdepth, test_c, "/usr/local/lib/ruby"))) { - return 0; - } - if (brute_force(logdepth, test_c18, "/usr/lib/ruby") || - brute_force(logdepth, test_c18, "/usr/local/lib/ruby")) { - return 0; - } - - return try_fail(logdepth, "libs/script/ruby"); -} diff --git a/scconfig/src/scripts/.svn/pristine/0d/0d559aed8a8545ea02ad9acd001565d7f3fd7b28.svn-base b/scconfig/src/scripts/.svn/pristine/0d/0d559aed8a8545ea02ad9acd001565d7f3fd7b28.svn-base deleted file mode 100644 index a14224e0..00000000 --- a/scconfig/src/scripts/.svn/pristine/0d/0d559aed8a8545ea02ad9acd001565d7f3fd7b28.svn-base +++ /dev/null @@ -1,55 +0,0 @@ -/* - scconfig - mawk lib detection - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - - -int find_script_mawk(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "#include " - NL "int main() {" - NL " int argc = 1;" - NL " char *argv[] = {" - NL " \"mawk\"," - NL " NULL" - NL " };" - NL " libmawk_initialize(argc, argv);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for mawk... "); - logprintf(logdepth, "find_mawk: trying to find mawk...\n"); - logdepth++; - - /* Look at the standard place */ - if (try_icl(logdepth, "libs/script/mawk", test_c, NULL, NULL, "-lmawk")) return 0; - - return try_fail(logdepth, "libs/script/mawk"); -} diff --git a/scconfig/src/scripts/.svn/pristine/2b/2ba6b5b2ca6c83c13242032cfc8a08ceb601e8c6.svn-base b/scconfig/src/scripts/.svn/pristine/2b/2ba6b5b2ca6c83c13242032cfc8a08ceb601e8c6.svn-base deleted file mode 100644 index d9986b2a..00000000 --- a/scconfig/src/scripts/.svn/pristine/2b/2ba6b5b2ca6c83c13242032cfc8a08ceb601e8c6.svn-base +++ /dev/null @@ -1,92 +0,0 @@ -/* - scconfig - lua lib detection - Copyright (C) 2018 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - -int find_script_fungw(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " fgw_ctx_t ctx;" - NL " fgw_obj_t *obj;" - NL " fgw_init(&ctx, \"host\");" - NL " obj = fgw_obj_reg(&ctx, \"foo\");" - NL " if (obj != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - - require("cc/cc", logdepth, fatal); - - report("Checking for fungw... "); - logprintf(logdepth, "find_fungw: trying to find fungw...\n"); - logdepth++; - - /* Look at some standard place */ - if (try_icl(logdepth, "libs/script/fungw", test_c, NULL, NULL, "-lfungw -lm -lgenht")) return 0; - - return try_fail(logdepth, "libs/script/fungw"); -} - -int find_script_fungw_user_call_ctx(const char *name, int logdepth, int fatal) -{ - const char *lf, *cf, *inc; - char *test_c = - NL "#include " - NL "int main() {" - NL " fgw_value_t val;" - NL " val.argv0.user_call_ctx = &val;" - NL " if (0) fgw_uvcall(NULL, NULL, NULL, \"funcname\", NULL);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - - require("cc/cc", logdepth, fatal); - require("libs/script/fungw/presents", logdepth, fatal); - - report("Checking for fungw user_call_ctx... "); - logprintf(logdepth, "find_fungw_user_call_ctx: trying to find fungw...\n"); - logdepth++; - - inc = get("libs/script/fungw/includes"); - lf = get("libs/script/fungw/ldflags"); - cf = get("libs/script/fungw/cflags"); - - if (try_icl(logdepth, "libs/script/fungw/user_call_ctx", test_c, inc, cf, lf)) return 0; - - return try_fail(logdepth, "libs/script/fungw/user_call_ctx"); -} - - -int find_script_fungw_all(const char *name, int logdepth, int fatal) -{ - if (require("libs/script/fungw/presents", logdepth, fatal) != 0) - return 1; - require("libs/script/fungw/user_call_ctx/*", logdepth, 0); - return 0; -} \ No newline at end of file diff --git a/scconfig/src/scripts/.svn/pristine/2e/2ece35e67c661ffece52006a2ffd9d30c4f54980.svn-base b/scconfig/src/scripts/.svn/pristine/2e/2ece35e67c661ffece52006a2ffd9d30c4f54980.svn-base deleted file mode 100644 index 87c486e4..00000000 --- a/scconfig/src/scripts/.svn/pristine/2e/2ece35e67c661ffece52006a2ffd9d30c4f54980.svn-base +++ /dev/null @@ -1 +0,0 @@ -void deps_scripts_init(); diff --git a/scconfig/src/scripts/.svn/pristine/2f/2f96a5d7b111f325665e12f6594a0d2b3c1fdd3a.svn-base b/scconfig/src/scripts/.svn/pristine/2f/2f96a5d7b111f325665e12f6594a0d2b3c1fdd3a.svn-base deleted file mode 100644 index b08ceb2a..00000000 --- a/scconfig/src/scripts/.svn/pristine/2f/2f96a5d7b111f325665e12f6594a0d2b3c1fdd3a.svn-base +++ /dev/null @@ -1,84 +0,0 @@ -/* - scconfig - perl lib detection - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" - -int find_script_perl(const char *name, int logdepth, int fatal) -{ - char *cflags, *ldflags, *s; - int res; - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " PerlInterpreter *interp;" - NL - NL " interp = perl_alloc();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("sys/class", logdepth, fatal); - require("cc/cc", logdepth, fatal); - require("/internal/filelist/method", logdepth, fatal); - - report("Checking for perl... "); - logprintf(logdepth, "find_perl: trying to find perl...\n"); - logdepth++; - - res = run(logdepth, "perl -MExtUtils::Embed -e ccopts", &cflags); - if (res) { - logprintf(logdepth, "perl executable not found or broken (%d) at cflags\n", res); - report("FAILED (perl exec fail)\n"); - return 1; - } - - res = run(logdepth, "perl -MExtUtils::Embed -e ldopts", &ldflags); - if (res) { - logprintf(logdepth, "perl executable not found or broken (%d) aat ldflags\n", res); - report("FAILED (perl exec fail)\n"); - free(cflags); - return 1; - } - - /* workarounds for windows [TODO] */ - if (strcmp(get("sys/class"), "win32") == 0) { - for(s = cflags; *s != '\0'; s++) - if (*s == '\\') *s = '/'; - - for(s = ldflags; *s != '\0'; s++) - if (*s == '\\') *s = '/'; - - /* TODO: do we need to remove double quotes as well? */ - } - - res = try_icl(logdepth, "libs/script/perl", test_c, NULL, strip(cflags), strip(ldflags)); - - free(cflags); - free(ldflags); - - if (res) - return 0; - - return try_fail(logdepth, "libs/script/perl"); -} diff --git a/scconfig/src/scripts/.svn/pristine/30/303e8dcd4a23738bd8eed6fc08b67acd87e8612f.svn-base b/scconfig/src/scripts/.svn/pristine/30/303e8dcd4a23738bd8eed6fc08b67acd87e8612f.svn-base deleted file mode 100644 index f3900032..00000000 --- a/scconfig/src/scripts/.svn/pristine/30/303e8dcd4a23738bd8eed6fc08b67acd87e8612f.svn-base +++ /dev/null @@ -1,2 +0,0 @@ - deps_scripts_init(); - diff --git a/scconfig/src/scripts/.svn/pristine/37/37965c6edd23ae0836328ee29684505a994d8304.svn-base b/scconfig/src/scripts/.svn/pristine/37/37965c6edd23ae0836328ee29684505a994d8304.svn-base deleted file mode 100644 index 06fa84f6..00000000 --- a/scconfig/src/scripts/.svn/pristine/37/37965c6edd23ae0836328ee29684505a994d8304.svn-base +++ /dev/null @@ -1,51 +0,0 @@ -/* - scconfig - ruby lib detection - Copyright (C) 2015 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" - -int find_script_mruby(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " mrb_state *ctx = mrb_open();" - NL " mrb_close(ctx);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for mruby... "); - logprintf(logdepth, "find_mruby: trying to find mruby...\n"); - logdepth++; - - if (try_icl_pkg_config(logdepth, "libs/script/mruby", test_c, NULL, "mruby-*", get("/arg/mruby-version"))) - return 0; - - /* Look at the most standard place */ - if (try_icl(logdepth, "libs/script/mruby", test_c, NULL, NULL, "-lmruby -lm")) - return 0; - - return try_fail(logdepth, "libs/script/ruby"); -} diff --git a/scconfig/src/scripts/.svn/pristine/43/439d4bb57d476ec33fb4f43f7d3fcfc1c68f2702.svn-base b/scconfig/src/scripts/.svn/pristine/43/439d4bb57d476ec33fb4f43f7d3fcfc1c68f2702.svn-base deleted file mode 100644 index efde6a8d..00000000 --- a/scconfig/src/scripts/.svn/pristine/43/439d4bb57d476ec33fb4f43f7d3fcfc1c68f2702.svn-base +++ /dev/null @@ -1,110 +0,0 @@ -/* - scconfig - python lib detection - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" - -static int find_script_python_(const char *name, int logdepth, int fatal, int vermajor, const char *nodedir) -{ - char *ldflags_base, *cflags, *ldflags, *nodebn; - int iswin32, res; - char test_c[1024]; - char *test_c_in = - NL "#include " - NL "#include " - NL "int main() {" - NL " char *s;" - NL " Py_Initialize();" - NL - NL " s = PY_VERSION;" - NL " if (s[0] != '%d') return 1;" - NL " if ((s[2] >= '0') && (s[2] <= '9')) puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - char *inc_py = - NL "import distutils.sysconfig;" - NL "print '-I' + distutils.sysconfig.get_python_inc().replace('\\\\','/')" - NL; - char *lib_py = - NL "import distutils.sysconfig;" - NL "print '-L' + distutils.sysconfig.PREFIX.replace('\\\\','/') + '/libs',;" - NL "import sys;" - NL "print '-lpython' + str(sys.version_info[0]) + str(sys.version_info[1])" - NL; - - - require("sys/class", logdepth, fatal); - iswin32 = strcmp(get("sys/class"), "win32") == 0; - if (iswin32) - require("libs/lpthread", logdepth, fatal); - require("cc/cc", logdepth, fatal); - require("/internal/filelist/method", logdepth, fatal); - - sprintf(test_c, test_c_in, vermajor); - - report("Checking for python (%d)... ", vermajor); - logprintf(logdepth, "find_python: trying to find python %d...\n", vermajor); - logdepth++; - - if (iswin32) - ldflags_base = strclone(get("libs/lpthread")); - else - ldflags_base = strclone("-L/usr/bin -L/usr/local/bin"); - - /* Look at some standard places */ - if (try_icl(logdepth, nodedir, test_c, NULL, NULL, "-lpython")) return 0; - - /* Ask python using the python executables on path; use + so both runs and can free out of both */ - if (run_script(logdepth, "python", inc_py, ".py", &cflags) + run_script(logdepth, "python", lib_py, ".py", &ldflags) == 0) - res = try_icl(logdepth, nodedir, test_c, NULL, strip(cflags), strip(ldflags)); - else - res = 0; - - free(cflags); - free(ldflags); - if (res) - return 0; - - /* no luck - try to find by brute force, listing directory names */ - nodebn = strrchr(nodedir, '/'); - nodebn++; - if (brute_force_include(logdepth, nodebn, test_c, ldflags_base, "/usr/include") || - brute_force_include(logdepth, nodebn, test_c, ldflags_base, "/usr/local/include")) { - free(ldflags_base); - return 0; - } - - free(ldflags_base); - - return try_fail(logdepth, nodedir); -} - -int find_script_python(const char *name, int logdepth, int fatal) -{ - return find_script_python_(name, logdepth, fatal, 2, "libs/script/python"); -} - -int find_script_python3(const char *name, int logdepth, int fatal) -{ - return find_script_python_(name, logdepth, fatal, 3, "libs/script/python3"); -} diff --git a/scconfig/src/scripts/.svn/pristine/51/5106d8757ab82d7552e54182ddbf75daa9195325.svn-base b/scconfig/src/scripts/.svn/pristine/51/5106d8757ab82d7552e54182ddbf75daa9195325.svn-base deleted file mode 100644 index f0abd544..00000000 --- a/scconfig/src/scripts/.svn/pristine/51/5106d8757ab82d7552e54182ddbf75daa9195325.svn-base +++ /dev/null @@ -1,52 +0,0 @@ -/* - scconfig - lua lib detection - Copyright (C) 2018 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - -int find_script_fungw(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " fgw_ctx_t ctx;" - NL " fgw_obj_t *obj;" - NL " fgw_init(&ctx, \"host\");" - NL " obj = fgw_obj_reg(&ctx, \"foo\");" - NL " if (obj != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - - require("cc/cc", logdepth, fatal); - - report("Checking for fungw... "); - logprintf(logdepth, "find_fungw: trying to find fungw...\n"); - logdepth++; - - /* Look at some standard place */ - if (try_icl(logdepth, "libs/script/fungw", test_c, NULL, NULL, "-lfungw -lm -lgenht")) return 0; - - return try_fail(logdepth, "libs/script/fungw"); -} diff --git a/scconfig/src/scripts/.svn/pristine/6c/6ca5879081c0eddb48683ee0460314a73dc8ab9d.svn-base b/scconfig/src/scripts/.svn/pristine/6c/6ca5879081c0eddb48683ee0460314a73dc8ab9d.svn-base deleted file mode 100644 index 36ca55a0..00000000 --- a/scconfig/src/scripts/.svn/pristine/6c/6ca5879081c0eddb48683ee0460314a73dc8ab9d.svn-base +++ /dev/null @@ -1,49 +0,0 @@ -/* - scconfig - duktape lib detection - Copyright (C) 2018 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - -int find_script_duktape(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " duk_context *ctx = duk_create_heap_default();" - NL " if (ctx != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - - require("cc/cc", logdepth, fatal); - - report("Checking for duktape... "); - logprintf(logdepth, "find_duktape: trying to find duktape...\n"); - logdepth++; - - /* Look at the standard place */ - if (try_icl(logdepth, "libs/script/duktape", test_c, NULL, NULL, "-lduktape -lm")) return 0; - - return try_fail(logdepth, "libs/script/duktape"); -} diff --git a/scconfig/src/scripts/.svn/pristine/82/8274c2e40298bbd91acce342fa4cfa9162ba92ab.svn-base b/scconfig/src/scripts/.svn/pristine/82/8274c2e40298bbd91acce342fa4cfa9162ba92ab.svn-base deleted file mode 100644 index e3943110..00000000 --- a/scconfig/src/scripts/.svn/pristine/82/8274c2e40298bbd91acce342fa4cfa9162ba92ab.svn-base +++ /dev/null @@ -1,62 +0,0 @@ -SCRIPT_CFLAGS = -DPLUGIN_SCRIPTS -SCRIPT_OBJS = \ - $(BIN)/scripts/scripts.o \ - $(BIN)/scripts/find_gpmi.o \ - $(BIN)/scripts/find_tcl.o \ - $(BIN)/scripts/find_ruby.o \ - $(BIN)/scripts/find_mruby.o \ - $(BIN)/scripts/find_python.o \ - $(BIN)/scripts/find_perl.o \ - $(BIN)/scripts/find_mawk.o \ - $(BIN)/scripts/find_lua.o \ - $(BIN)/scripts/find_guile.o \ - $(BIN)/scripts/find_stutter.o \ - $(BIN)/scripts/find_funlisp.o \ - $(BIN)/scripts/find_duktape.o \ - $(BIN)/scripts/find_fungw.o \ - $(BIN)/scripts/find_m4.o - -$(BIN)/scripts/scripts.o: $(SRC)/scripts/scripts.c - $(CC) $(CFLAGS) -c $(SRC)/scripts/scripts.c -o $(BIN)/scripts/scripts.o - -$(BIN)/scripts/find_tcl.o: $(SRC)/scripts/find_tcl.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_tcl.c -o $(BIN)/scripts/find_tcl.o - -$(BIN)/scripts/find_gpmi.o: $(SRC)/scripts/find_gpmi.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_gpmi.c -o $(BIN)/scripts/find_gpmi.o - -$(BIN)/scripts/find_ruby.o: $(SRC)/scripts/find_ruby.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_ruby.c -o $(BIN)/scripts/find_ruby.o - -$(BIN)/scripts/find_mruby.o: $(SRC)/scripts/find_mruby.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_mruby.c -o $(BIN)/scripts/find_mruby.o - -$(BIN)/scripts/find_python.o: $(SRC)/scripts/find_python.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_python.c -o $(BIN)/scripts/find_python.o - -$(BIN)/scripts/find_perl.o: $(SRC)/scripts/find_perl.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_perl.c -o $(BIN)/scripts/find_perl.o - -$(BIN)/scripts/find_mawk.o: $(SRC)/scripts/find_mawk.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_mawk.c -o $(BIN)/scripts/find_mawk.o - -$(BIN)/scripts/find_lua.o: $(SRC)/scripts/find_lua.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_lua.c -o $(BIN)/scripts/find_lua.o - -$(BIN)/scripts/find_guile.o: $(SRC)/scripts/find_guile.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_guile.c -o $(BIN)/scripts/find_guile.o - -$(BIN)/scripts/find_stutter.o: $(SRC)/scripts/find_stutter.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_stutter.c -o $(BIN)/scripts/find_stutter.o - -$(BIN)/scripts/find_m4.o: $(SRC)/scripts/find_m4.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_m4.c -o $(BIN)/scripts/find_m4.o - -$(BIN)/scripts/find_duktape.o: $(SRC)/scripts/find_duktape.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_duktape.c -o $(BIN)/scripts/find_duktape.o - -$(BIN)/scripts/find_funlisp.o: $(SRC)/scripts/find_funlisp.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_funlisp.c -o $(BIN)/scripts/find_funlisp.o - -$(BIN)/scripts/find_fungw.o: $(SRC)/scripts/find_fungw.c $(SRC)/scripts/scripts.h - $(CC) $(CFLAGS) -c $(SRC)/scripts/find_fungw.c -o $(BIN)/scripts/find_fungw.o diff --git a/scconfig/src/scripts/.svn/pristine/87/87b26a575b2d1749bec2b0074764f85d88fd57b0.svn-base b/scconfig/src/scripts/.svn/pristine/87/87b26a575b2d1749bec2b0074764f85d88fd57b0.svn-base deleted file mode 100644 index 6ff40701..00000000 --- a/scconfig/src/scripts/.svn/pristine/87/87b26a575b2d1749bec2b0074764f85d88fd57b0.svn-base +++ /dev/null @@ -1,93 +0,0 @@ -/* - scconfig - lua lib detection - Copyright (C) 2018 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - -int find_script_fungw(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " fgw_ctx_t ctx;" - NL " fgw_obj_t *obj;" - NL " fgw_init(&ctx, \"host\");" - NL " obj = fgw_obj_reg(&ctx, \"foo\");" - NL " if (obj != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - - require("cc/cc", logdepth, fatal); - - report("Checking for fungw... "); - logprintf(logdepth, "find_fungw: trying to find fungw...\n"); - logdepth++; - - /* Look at some standard place */ - if (try_icl(logdepth, "libs/script/fungw", test_c, NULL, NULL, "-lfungw -lm -lgenht")) return 0; - if (try_icl(logdepth, "libs/script/fungw", test_c, NULL, "-I/usr/local/include", "-L/usr/local/lib -lfungw -lm -lgenht")) return 0; - - return try_fail(logdepth, "libs/script/fungw"); -} - -int find_script_fungw_user_call_ctx(const char *name, int logdepth, int fatal) -{ - const char *lf, *cf, *inc; - char *test_c = - NL "#include " - NL "int main() {" - NL " fgw_value_t val;" - NL " val.argv0.user_call_ctx = &val;" - NL " if (0) fgw_uvcall(NULL, NULL, NULL, \"funcname\", NULL);" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - - require("cc/cc", logdepth, fatal); - require("libs/script/fungw/presents", logdepth, fatal); - - report("Checking for fungw user_call_ctx... "); - logprintf(logdepth, "find_fungw_user_call_ctx: trying to find fungw...\n"); - logdepth++; - - inc = get("libs/script/fungw/includes"); - lf = get("libs/script/fungw/ldflags"); - cf = get("libs/script/fungw/cflags"); - - if (try_icl(logdepth, "libs/script/fungw/user_call_ctx", test_c, inc, cf, lf)) return 0; - - return try_fail(logdepth, "libs/script/fungw/user_call_ctx"); -} - - -int find_script_fungw_all(const char *name, int logdepth, int fatal) -{ - if (require("libs/script/fungw/presents", logdepth, fatal) != 0) - return 1; - require("libs/script/fungw/user_call_ctx/*", logdepth, 0); - return 0; -} \ No newline at end of file diff --git a/scconfig/src/scripts/.svn/pristine/8e/8e3c5a9985c385d7c4cf9f3acf699977a3963d05.svn-base b/scconfig/src/scripts/.svn/pristine/8e/8e3c5a9985c385d7c4cf9f3acf699977a3963d05.svn-base deleted file mode 100644 index e05db438..00000000 --- a/scconfig/src/scripts/.svn/pristine/8e/8e3c5a9985c385d7c4cf9f3acf699977a3963d05.svn-base +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int brute_force_include(int logdepth, const char *language, const char *test_c, const char *ldflags_base, const char *basedir); - - -/* script detection */ -int find_script_gpmi(const char *name, int logdepth, int fatal); -int find_script_tcl(const char *name, int logdepth, int fatal); -int find_script_tk(const char *name, int logdepth, int fatal); -int find_script_ruby(const char *name, int logdepth, int fatal); -int find_script_mruby(const char *name, int logdepth, int fatal); -int find_script_python(const char *name, int logdepth, int fatal); -int find_script_python3(const char *name, int logdepth, int fatal); -int find_script_perl(const char *name, int logdepth, int fatal); -int find_script_mawk(const char *name, int logdepth, int fatal); -int find_script_lua(const char *name, int logdepth, int fatal); -int find_script_guile(const char *name, int logdepth, int fatal); -int find_script_stutter(const char *name, int logdepth, int fatal); -int find_script_estutter(const char *name, int logdepth, int fatal); -int find_script_funlisp(const char *name, int logdepth, int fatal); -int find_script_duktape(const char *name, int logdepth, int fatal); -int find_script_fungw(const char *name, int logdepth, int fatal); -int find_script_fungw_user_call_ctx(const char *name, int logdepth, int fatal); -int find_script_fungw_all(const char *name, int logdepth, int fatal); -int find_script_m4(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/scripts/.svn/pristine/9b/9b850b8b0b20266b48c16d1a9e3ec4be04c77f8a.svn-base b/scconfig/src/scripts/.svn/pristine/9b/9b850b8b0b20266b48c16d1a9e3ec4be04c77f8a.svn-base deleted file mode 100644 index cffdf8c4..00000000 --- a/scconfig/src/scripts/.svn/pristine/9b/9b850b8b0b20266b48c16d1a9e3ec4be04c77f8a.svn-base +++ /dev/null @@ -1,89 +0,0 @@ -/* - scconfig - helper functions for detecting script libs - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include -#include "find.h" - -void deps_scripts_init() -{ - dep_add("libs/script/gpmi/*", find_script_gpmi); - dep_add("libs/script/tcl/*", find_script_tcl); - dep_add("libs/script/tk/*", find_script_tk); - dep_add("libs/script/ruby/*", find_script_ruby); - dep_add("libs/script/mruby/*", find_script_mruby); - dep_add("libs/script/python/*", find_script_python); - dep_add("libs/script/python3/*", find_script_python3); - dep_add("libs/script/perl/*", find_script_perl); - dep_add("libs/script/mawk/*", find_script_mawk); - dep_add("libs/script/lua/*", find_script_lua); - dep_add("libs/script/guile/*", find_script_guile); - dep_add("libs/script/stutter/*", find_script_stutter); - dep_add("libs/script/estutter/*", find_script_estutter); - dep_add("libs/script/funlisp/*", find_script_funlisp); - dep_add("libs/script/duktape/*", find_script_duktape); - dep_add("libs/script/m4/bin/*", find_script_m4); - - dep_add("libs/script/fungw/presents", find_script_fungw); - dep_add("libs/script/fungw/user_call_ctx/*", find_script_fungw_user_call_ctx); - dep_add("libs/script/fungw/*", find_script_fungw_all); -} - -int brute_force_include(int logdepth, const char *language, const char *test_c, const char *ldflags_base, const char *basedir) -{ - char **files, *cflags, *ldflags; - char nodename[1024], deflink[sizeof(nodename)]; - int fileno, n, res; - size_t llen; - - if (ldflags_base == NULL) - ldflags_base = ""; - - llen = strlen(language); - assert(llen < sizeof(nodename) - 16); - sprintf(nodename, "libs/script/%s", language); - sprintf(deflink, "-l%s", language); - - res = 0; - filelist(logdepth, basedir, &fileno, &files); - if (fileno > 0) { - for(n = 0; (n < fileno) && !res; n++) { - if (strncmp(files[n], language, llen) == 0) { - ldflags = malloc(strlen(files[n]) + strlen(ldflags_base) + 16); - sprintf(ldflags, "%s -l%s", ldflags_base, files[n]); - cflags = malloc(strlen(files[n]) + strlen(basedir) + 16); - sprintf(cflags, "-I%s/%s", basedir, files[n]); - if (try_icl(logdepth, nodename, test_c, NULL, cflags, ldflags) || try_icl(logdepth, nodename, test_c, NULL, cflags, deflink)) { - filelist_free(&fileno, &files); - free(cflags); - free(ldflags); - return 1; - } - free(cflags); - free(ldflags); - } - } - filelist_free(&fileno, &files); - } - - return res; -} diff --git a/scconfig/src/scripts/.svn/pristine/bd/bd903d01b8442a0fe44afc17df90757251991b1d.svn-base b/scconfig/src/scripts/.svn/pristine/bd/bd903d01b8442a0fe44afc17df90757251991b1d.svn-base deleted file mode 100644 index 862ba93a..00000000 --- a/scconfig/src/scripts/.svn/pristine/bd/bd903d01b8442a0fe44afc17df90757251991b1d.svn-base +++ /dev/null @@ -1,86 +0,0 @@ -/* - scconfig - helper functions for detecting script libs - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include -#include "find.h" - -void deps_scripts_init() -{ - dep_add("libs/script/gpmi/*", find_script_gpmi); - dep_add("libs/script/tcl/*", find_script_tcl); - dep_add("libs/script/tk/*", find_script_tk); - dep_add("libs/script/ruby/*", find_script_ruby); - dep_add("libs/script/mruby/*", find_script_mruby); - dep_add("libs/script/python/*", find_script_python); - dep_add("libs/script/python3/*", find_script_python3); - dep_add("libs/script/perl/*", find_script_perl); - dep_add("libs/script/mawk/*", find_script_mawk); - dep_add("libs/script/lua/*", find_script_lua); - dep_add("libs/script/guile/*", find_script_guile); - dep_add("libs/script/stutter/*", find_script_stutter); - dep_add("libs/script/estutter/*", find_script_estutter); - dep_add("libs/script/funlisp/*", find_script_funlisp); - dep_add("libs/script/duktape/*", find_script_duktape); - dep_add("libs/script/fungw/*", find_script_fungw); - dep_add("libs/script/m4/bin/*", find_script_m4); -} - -int brute_force_include(int logdepth, const char *language, const char *test_c, const char *ldflags_base, const char *basedir) -{ - char **files, *cflags, *ldflags; - char nodename[1024], deflink[sizeof(nodename)]; - int fileno, n, res; - size_t llen; - - if (ldflags_base == NULL) - ldflags_base = ""; - - llen = strlen(language); - assert(llen < sizeof(nodename) - 16); - sprintf(nodename, "libs/script/%s", language); - sprintf(deflink, "-l%s", language); - - res = 0; - filelist(logdepth, basedir, &fileno, &files); - if (fileno > 0) { - for(n = 0; (n < fileno) && !res; n++) { - if (strncmp(files[n], language, llen) == 0) { - ldflags = malloc(strlen(files[n]) + strlen(ldflags_base) + 16); - sprintf(ldflags, "%s -l%s", ldflags_base, files[n]); - cflags = malloc(strlen(files[n]) + strlen(basedir) + 16); - sprintf(cflags, "-I%s/%s", basedir, files[n]); - if (try_icl(logdepth, nodename, test_c, NULL, cflags, ldflags) || try_icl(logdepth, nodename, test_c, NULL, cflags, deflink)) { - filelist_free(&fileno, &files); - free(cflags); - free(ldflags); - return 1; - } - free(cflags); - free(ldflags); - } - } - filelist_free(&fileno, &files); - } - - return res; -} diff --git a/scconfig/src/scripts/.svn/pristine/c2/c2c5f382a33e02821ea0f9429546beafd8c1580c.svn-base b/scconfig/src/scripts/.svn/pristine/c2/c2c5f382a33e02821ea0f9429546beafd8c1580c.svn-base deleted file mode 100644 index d2b921d4..00000000 --- a/scconfig/src/scripts/.svn/pristine/c2/c2c5f382a33e02821ea0f9429546beafd8c1580c.svn-base +++ /dev/null @@ -1,285 +0,0 @@ -/* - scconfig - tcl lib detection - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - -static int all_vers[] = { 86, 85, 84, 0, -1 }; - -int find_script_tcl_(const char *name, int logdepth, int fatal, int *vers, int fallback) -{ - char *out, *temp, *temp2, *cmd, *I, *L, *end, **tclsh; - int *v; - - char *tclshs[] = { - "tclsh", - "tclsh86", - "tclsh85", - "tclsh84", - "tclsh8.6", - "tclsh8.5", - "tclsh8.4", - NULL - }; - - char *test_c = - NL "#include " - NL "int main() {" - NL " Tcl_Obj *res;" - NL " Tcl_Interp *interp;" - NL " interp = Tcl_CreateInterp();" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - char *tcl_config = - NL "proc tclConfigFile {} {" - NL " set d [info library]" - NL " set f [file join $d \"tclConfig.sh\"]" - NL " if {[file exists $f]} {return $f}" - NL "" - NL " set d [file dirname $d]" - NL " set f [file join $d \"tclConfig.sh\"]" - NL " if {[file exists $f]} {return $f}" - NL "" - NL " set d [file dirname $d]" - NL " set f [file join $d \"tclConfig.sh\"]" - NL " if {[file exists $f]} {return $f}" - NL "" - NL " set d [file dirname $d]" - NL " set f [file join $d \"tclConfig.sh\"]" - NL " if {[file exists $f]} {return $f}" - NL "}" - NL "" - NL "puts [tclConfigFile]" - NL; - - /* Look at some standard places */ - for(v = vers; *v != -1; v++) { - int major = *v / 10, minor = *v % 10; - char ifl[64], lfl[64]; - - if (*v == 0) { - report("plain... "); - if (try_icl(logdepth, "libs/script/tcl", test_c, NULL, NULL, "-ltcl")) return 0; - continue; - } - - report("%d.%d... ", major, minor); - - sprintf(lfl, "-ltcl%d", *v); - if (try_icl(logdepth, "libs/script/tcl", test_c, NULL, NULL, lfl)) return 0; - - sprintf(lfl, "-ltcl%d.%d", major, minor); - if (try_icl(logdepth, "libs/script/tcl", test_c, NULL, NULL, lfl)) return 0; - - sprintf(lfl, "-ltcl%d", *v); - sprintf(ifl, "-I/usr/include/tcl%d", *v); - if (try_icl(logdepth, "libs/script/tcl", test_c, NULL, ifl, lfl)) return 0; - - sprintf(lfl, "-ltcl%d.%d", major, minor); - sprintf(ifl, "-I/usr/include/tcl%d.%d", major, minor); - if (try_icl(logdepth, "libs/script/tcl", test_c, NULL, ifl, lfl)) return 0; - } - - if (!fallback) - return 1; - - - report(" not found by version, trying tclsh.\n"); - - /* Try the config script */ - logprintf(logdepth, "running config tcl\n"); - temp = tempfile_dump(tcl_config, ".tcl"); - cmd = malloc(strlen(temp) + 16); - for(tclsh = tclshs; *tclsh != NULL; tclsh++) { - sprintf(cmd, "%s %s", *tclsh, temp); - report("Trying: %s\n", cmd); - if (run(logdepth+1, cmd, &out) == 0) { - free(cmd); - cmd = malloc(strlen(out) + 256); - sprintf(cmd, "#!/bin/sh\n. %s\necho $TCL_INCLUDE_SPEC\necho $TCL_LIB_SPEC\n", out); - temp2 = tempfile_dump(cmd, ".sh"); - free(out); - out = malloc(strlen(temp2) + 32); - sprintf(out, "chmod +x %s", temp2); - system(out); - free(out); - if (run(logdepth+1, temp2, &out) == 0) { - remove(temp2); - I = out; - L = strchr(I, '\n'); - if (L != NULL) { - *L = '\0'; - L++; - end = strchr(L, '\n'); - if (end != NULL) - *end = '\0'; - } - if (try_icl(logdepth, "libs/script/tcl", test_c, NULL, I, L)) { - remove(temp); - free(cmd); - if (out != NULL) - free(out); - return 0; - } - } - remove(temp2); - } - } - remove(temp); - free(cmd); - if (out != NULL) - free(out); - - return 1; -} - -int find_script_tcl(const char *name, int logdepth, int fatal) -{ - int res, rver[2], *vers = all_vers, fallback = 1; - const char *reqver; - - - require("cc/cc", logdepth, fatal); - - report("Checking for tcl... "); - logprintf(logdepth, "find_tcl: trying to find tcl...\n"); - logdepth++; - - reqver = get("/arg/tcl-version"); - if ((reqver != NULL) && (reqver[0] != '\0')) { - if (reqver[1] == '.') - rver[0] = (reqver[0] - '0') * 10 + (reqver[2] - '0'); - else - rver[0] = atoi(reqver); - rver[1] = -1; - vers = rver; - fallback = 0; - } - - res = find_script_tcl_(name, logdepth, fatal, vers, fallback); - if (res == 0) - return 0; - return try_fail(logdepth, "libs/script/tcl"); -} - - -static int try_icl_tk(int logdepth, const char *prefix, const char *test_c_in, const char *includes, const char *cflags, const char *ldflags, int ver) -{ - const char *XL = get("libs/gui/xopendisplay/Lflags"); - const char *Xc = get("libs/gui/xopendisplay/cflags"); - const char *tl, *tc; - char *tmpl, *tmpc; - int res; - - tl = get("libs/script/tcl/ldflags"); - tc = get("libs/script/tcl/cflags"); - - if (XL == NULL) XL = ""; - if (Xc == NULL) Xc = ""; - if (tl == NULL) tl = ""; - if (tc == NULL) tc = ""; - - if ((*XL == '\0') && (*Xc == '\0') && (*tl == '\0') && (*tc == '\0')) - return try_icl(logdepth, prefix, test_c_in, includes, cflags, ldflags); - - tmpl = str_concat(" ", tl, XL, ldflags, NULL); - tmpc = str_concat(" ", tc, Xc, cflags, NULL); - - res = try_icl(logdepth, prefix, test_c_in, includes, tmpc, tmpl); - - free(tmpl); - free(tmpc); - - return res; -} - - -int find_script_tk(const char *name, int logdepth, int fatal) -{ - int *v, rver[2], *vers = all_vers; - const char *reqver, *tclreqver; - - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " if (Tk_GetNumMainWindows() == 0)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - require("libs/gui/xopendisplay/cflags", logdepth, fatal); - require("libs/gui/xopendisplay/Lflags", logdepth, fatal); - - report("Checking for tk... "); - logprintf(logdepth, "find_tk: trying to find tk...\n"); - logdepth++; - - reqver = get("/arg/tk-version"); - if ((reqver != NULL) && (reqver[0] != '\0')) { - tclreqver = get("/arg/tcl-version"); - if ((tclreqver != NULL) && (tclreqver[0] != '\0')) { - if (strcmp(tclreqver, reqver) != 0) { - report("\n\nFatal argument error: if both tcl and tk version are forced, they must match\n\n"); - exit(1); - } - } - if (reqver[1] == '.') - rver[0] = (reqver[0] - '0') * 10 + (reqver[2] - '0'); - else - rver[0] = atoi(reqver); - rver[1] = -1; - vers = rver; - } - - /* Look at some standard places, per version */ - for(v = vers; *v != -1; v++) { - int major = *v / 10, minor = *v % 10; - char lfl[64]; - int tvers[2]; - - tvers[0] = *v; - tvers[1] = -1; - if (find_script_tcl_("libs/script/tcl", logdepth+1, 0, tvers, 0) != 0) { - report("(no tcl) "); - continue; - } - - if (*v == 0) { - if (try_icl_tk(logdepth, "libs/script/tk", test_c, NULL, NULL, "-ltk", 0)) return 0; - continue; - } - - sprintf(lfl, "-ltk%d", *v); - if (try_icl_tk(logdepth, "libs/script/tk", test_c, NULL, NULL, lfl, *v)) return 0; - - sprintf(lfl, "-ltk%d.%d", major, minor); - if (try_icl_tk(logdepth, "libs/script/tk", test_c, NULL, NULL, lfl, *v)) return 0; - } - - return try_fail(logdepth, "libs/script/tk"); -} diff --git a/scconfig/src/scripts/.svn/pristine/e1/e1027ecee847dc988ddcafe700067f6d374c354e.svn-base b/scconfig/src/scripts/.svn/pristine/e1/e1027ecee847dc988ddcafe700067f6d374c354e.svn-base deleted file mode 100644 index 7e87d909..00000000 --- a/scconfig/src/scripts/.svn/pristine/e1/e1027ecee847dc988ddcafe700067f6d374c354e.svn-base +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include "libs.h" -#include "log.h" -#include "db.h" -#include "dep.h" - -int brute_force_include(int logdepth, const char *language, const char *test_c, const char *ldflags_base, const char *basedir); - - -/* script detection */ -int find_script_gpmi(const char *name, int logdepth, int fatal); -int find_script_tcl(const char *name, int logdepth, int fatal); -int find_script_tk(const char *name, int logdepth, int fatal); -int find_script_ruby(const char *name, int logdepth, int fatal); -int find_script_mruby(const char *name, int logdepth, int fatal); -int find_script_python(const char *name, int logdepth, int fatal); -int find_script_python3(const char *name, int logdepth, int fatal); -int find_script_perl(const char *name, int logdepth, int fatal); -int find_script_mawk(const char *name, int logdepth, int fatal); -int find_script_lua(const char *name, int logdepth, int fatal); -int find_script_guile(const char *name, int logdepth, int fatal); -int find_script_stutter(const char *name, int logdepth, int fatal); -int find_script_estutter(const char *name, int logdepth, int fatal); -int find_script_funlisp(const char *name, int logdepth, int fatal); -int find_script_duktape(const char *name, int logdepth, int fatal); -int find_script_fungw(const char *name, int logdepth, int fatal); -int find_script_m4(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/scripts/.svn/pristine/e4/e442e33e25d1a8326c05e258e159f029e19a2be2.svn-base b/scconfig/src/scripts/.svn/pristine/e4/e442e33e25d1a8326c05e258e159f029e19a2be2.svn-base deleted file mode 100644 index dc1295ea..00000000 --- a/scconfig/src/scripts/.svn/pristine/e4/e442e33e25d1a8326c05e258e159f029e19a2be2.svn-base +++ /dev/null @@ -1,94 +0,0 @@ -/* - scconfig - libgpmi detection - Copyright (C) 2015 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - - -int find_script_gpmi(const char *name, int logdepth, int fatal) -{ - char *out, *cmd, *end, **cfg; - const char *usr; - char *cfgs[] = { - NULL, - "gpmi-config", - "/usr/bin/gpmi-config", - "/usr/local/bin/gpmi-config", - "~/bin/gpmi-config", - NULL - }; - - (void) fatal; /* not used */ - - report("Checking for gpmi... "); - logprintf(logdepth, "find_gpmi: trying to find gpmi...\n"); - logdepth++; - - /* Try the config script */ - logprintf(logdepth, "running config tcl\n"); - cmd = malloc(128); - usr = get("/arg/gpmi/prefix"); - if (usr != NULL) { - const char *rp1 = NULL; - require("cc/wlrpath", logdepth, 0); - rp1 = get("cc/wlrpath"); - cfgs[0] = str_concat("/", usr, "bin/gpmi-config", NULL); - put("libs/script/gpmi/ldflags", str_concat("", "-L", usr, "/lib", " -lgpmi ", rp1, usr, "/lib", NULL)); - put("libs/script/gpmi/cflags", str_concat("", "-I", usr, "/include", NULL)); - cfg = cfgs; - } - else { - cfg = cfgs+1; - put("libs/script/gpmi/cflags", ""); - put("libs/script/gpmi/ldflags", "-lgpmi"); - } - for(; *cfg != NULL; cfg++) { - sprintf(cmd, "%s --version", *cfg); - if (run(logdepth+1, cmd, &out) == 0) { - put("libs/script/gpmi/gpmi-config", *cfg); - put("libs/script/gpmi/presents", strue); - end = strrchr(out, ' '); - if (end != NULL) - put("libs/script/gpmi/version", strip(end)); - free(out); - sprintf(cmd, "%s --id", *cfg); - if (run(logdepth+1, cmd, &out) == 0) { - end = strrchr(out, ' '); - if (end != NULL) - put("libs/script/gpmi/configapi", strip(end)); - free(out); - } - free(cmd); - if (cfgs[0] != NULL) - free(cfgs[0]); - return 0; - } - } - free(cmd); - if (out != NULL) - free(out); - - if (cfg[0] != NULL) - free(cfg[0]); - - return try_fail(logdepth, "libs/script/gpmi"); -} diff --git a/scconfig/src/scripts/.svn/pristine/e6/e62cae92d25abbc92e0032391c26d8f0f32ab43d.svn-base b/scconfig/src/scripts/.svn/pristine/e6/e62cae92d25abbc92e0032391c26d8f0f32ab43d.svn-base deleted file mode 100644 index f76c31bd..00000000 --- a/scconfig/src/scripts/.svn/pristine/e6/e62cae92d25abbc92e0032391c26d8f0f32ab43d.svn-base +++ /dev/null @@ -1,92 +0,0 @@ -/* - scconfig - lua lib detection - Copyright (C) 2018 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - -int find_script_fungw(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " fgw_ctx_t ctx;" - NL " fgw_obj_t *obj;" - NL " fgw_init(&ctx, \"host\");" - NL " obj = fgw_obj_reg(&ctx, \"foo\");" - NL " if (obj != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - - require("cc/cc", logdepth, fatal); - - report("Checking for fungw... "); - logprintf(logdepth, "find_fungw: trying to find fungw...\n"); - logdepth++; - - /* Look at some standard place */ - if (try_icl(logdepth, "libs/script/fungw", test_c, NULL, NULL, "-lfungw -lm -lgenht")) return 0; - - return try_fail(logdepth, "libs/script/fungw"); -} - -int find_script_fungw_user_call_ctx(const char *name, int logdepth, int fatal) -{ - const char *lf, *cf, *inc; - char *test_c = - NL "#include " - NL "int main() {" - NL " fgw_value_t val;" - NL " val.argv0.user_call_ctx = &val;" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - - require("cc/cc", logdepth, fatal); - require("libs/script/fungw/presents", logdepth, fatal); - - report("Checking for fungw user_call_ctx... "); - logprintf(logdepth, "find_fungw_user_call_ctx: trying to find fungw...\n"); - logdepth++; - - inc = get("libs/script/fungw/includes"); - lf = get("libs/script/fungw/ldflags"); - cf = get("libs/script/fungw/cflags"); - - if (try_icl(logdepth, "libs/script/fungw/user_call_ctx", test_c, inc, cf, lf)) return 0; - - return try_fail(logdepth, "libs/script/fungw/user_call_ctx"); -} - - -int find_script_fungw_all(const char *name, int logdepth, int fatal) -{ - printf("ALLLLLL\n"); - if (require("libs/script/fungw/presents", logdepth, fatal) != 0) - return 1; - require("libs/script/fungw/user_call_ctx/*", logdepth, 0); - return 0; -} \ No newline at end of file diff --git a/scconfig/src/scripts/.svn/pristine/eb/eb667a96a8e527129f35b828a0b1141ac798f50c.svn-base b/scconfig/src/scripts/.svn/pristine/eb/eb667a96a8e527129f35b828a0b1141ac798f50c.svn-base deleted file mode 100644 index 8361e260..00000000 --- a/scconfig/src/scripts/.svn/pristine/eb/eb667a96a8e527129f35b828a0b1141ac798f50c.svn-base +++ /dev/null @@ -1,86 +0,0 @@ -/* - scconfig - stutter lib detection - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - - -int find_script_stutter(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " varctx *global;" - NL " global = varctx_create(NULL, 256);" - NL - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for stutter... "); - logprintf(logdepth, "find_stutter: trying to find stutter...\n"); - logdepth++; - - /* TODO: do we need -ldl? */ - if ( - try_icl(logdepth, "libs/script/stutter", test_c, NULL, NULL, "-lstutter") || - try_icl(logdepth, "libs/script/stutter", test_c, NULL, "-I/usr/include/stutter", "-lstutter") || - try_icl(logdepth, "libs/script/stutter", test_c, NULL, "-I/usr/local/include/stutter", "-lstutter") - ) - return 0; - - return try_fail(logdepth, "libs/script/stutter"); -} - -int find_script_estutter(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " stt_ctx_t stt;" - NL " stt.next_serial = 4242;" - NL " stt_init(&stt);" - NL " if (stt.next_serial != 4242)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for estutter... "); - logprintf(logdepth, "find_estutter: trying to find estutter...\n"); - logdepth++; - - /* TODO: do we need -ldl? */ - if ( - try_icl(logdepth, "libs/script/estutter", test_c, NULL, NULL, "-lestutter") || - try_icl(logdepth, "libs/script/estutter", test_c, NULL, "-I/usr/include/estutter", "-lestutter") || - try_icl(logdepth, "libs/script/estutter", test_c, NULL, "-I/usr/local/include/estutter", "-lestutter") - ) - return 0; - - return try_fail(logdepth, "libs/script/estutter"); -} diff --git a/scconfig/src/scripts/.svn/pristine/ef/ef6d3b811176eecd7145081834d01e65d357cd35.svn-base b/scconfig/src/scripts/.svn/pristine/ef/ef6d3b811176eecd7145081834d01e65d357cd35.svn-base deleted file mode 100644 index 803be3c6..00000000 --- a/scconfig/src/scripts/.svn/pristine/ef/ef6d3b811176eecd7145081834d01e65d357cd35.svn-base +++ /dev/null @@ -1,51 +0,0 @@ -/* - scconfig - stutter lib detection - Copyright (C) 2018 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - -int find_script_funlisp(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "int main() {" - NL " lisp_runtime *rt = lisp_runtime_new();" - NL " if (rt != NULL)" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - require("cc/cc", logdepth, fatal); - - report("Checking for funlisp... "); - logprintf(logdepth, "find_funlisp: trying to find funlisp...\n"); - logdepth++; - - if ( - try_icl(logdepth, "libs/script/funlisp", test_c, NULL, NULL, "/usr/local/lib/libfunlisp.a") || - try_icl(logdepth, "libs/script/funlisp", test_c, NULL, NULL, "/usr/lib/libfunlisp.a") - ) - return 0; - - return try_fail(logdepth, "libs/script/funlisp"); -} diff --git a/scconfig/src/scripts/.svn/pristine/f1/f15302e42965c67d8bee9ff95a8a4ffbf1e74885.svn-base b/scconfig/src/scripts/.svn/pristine/f1/f15302e42965c67d8bee9ff95a8a4ffbf1e74885.svn-base deleted file mode 100644 index 06809be4..00000000 --- a/scconfig/src/scripts/.svn/pristine/f1/f15302e42965c67d8bee9ff95a8a4ffbf1e74885.svn-base +++ /dev/null @@ -1,72 +0,0 @@ -/* - scconfig - lua lib detection - Copyright (C) 2009 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - -int find_script_lua(const char *name, int logdepth, int fatal) -{ - char *test_c = - NL "#include " - NL "#include " - NL "int main() {" - NL " lua_State *state;" - NL " state = luaL_newstate();" - NL " luaL_loadfile(state, \"nothing\");" - NL " puts(\"OK\");" - NL " return 0;" - NL "}" - NL; - - - require("cc/cc", logdepth, fatal); - require("/internal/filelist/method", logdepth, fatal); - - report("Checking for lua... "); - logprintf(logdepth, "find_lua: trying to find lua...\n"); - logdepth++; - - /* Look at some standard places */ - /* TODO: do we need -ldl? */ - if (try_icl(logdepth, "libs/script/lua", test_c, NULL, NULL, "-llua -llualib -lm")) return 0; - - /* lualib doesn't exist in lua 5.1.1 */ - if (try_icl(logdepth, "libs/script/lua", test_c, NULL, NULL, "-llua -lm")) return 0; - - /* OS specific include dir */ - if (try_icl(logdepth, "libs/script/lua", test_c, NULL, "-I/usr/include", "-llua -llualib -lm")) return 0; - if (try_icl(logdepth, "libs/script/lua", test_c, NULL, "-I/usr/include/lua5.2", "-llua5.2 -lm")) return 0; - if (try_icl(logdepth, "libs/script/lua", test_c, NULL, "-I/usr/local/include", "-llua -llualib -lm")) return 0; - if (try_icl(logdepth, "libs/script/lua", test_c, NULL, "-I/usr/include", "-llua -lm")) return 0; - if (try_icl(logdepth, "libs/script/lua", test_c, NULL, "-I/usr/local/include", "-llua -lm")) return 0; - - /* This one is for OSX (by Bjarni) */ - if (try_icl(logdepth, "libs/script/lua", test_c, NULL, "-I/sw/include", "-llua -llualib -lm")) return 0; - - /* no luck - try to find by brute force, listing directory names */ - if (brute_force_include(logdepth, "lua", test_c, NULL, "/usr/include") || - brute_force_include(logdepth, "lua", test_c, NULL, "/usr/local/include")) { - return 0; - } - - return try_fail(logdepth, "libs/script/lua"); -} diff --git a/scconfig/src/scripts/.svn/pristine/f7/f72ad871125e3750e92ca7ceaeecf63af1e668c5.svn-base b/scconfig/src/scripts/.svn/pristine/f7/f72ad871125e3750e92ca7ceaeecf63af1e668c5.svn-base deleted file mode 100644 index 84924c21..00000000 --- a/scconfig/src/scripts/.svn/pristine/f7/f72ad871125e3750e92ca7ceaeecf63af1e668c5.svn-base +++ /dev/null @@ -1,89 +0,0 @@ -/* - scconfig - m4 binary detection - Copyright (C) 2015 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include "scripts.h" -#include - -static int test_m4(const char *name, int logdepth, int fatal, char *bin) -{ - char *script = - NL "define(baz, foo)" - NL "baz bar" - NL; - char *out, *cmd, *tmpf, *tmpf_esc; - (void) fatal; /* not used */ - - tmpf = tempfile_dump(script, ".m4"); - tmpf_esc = shell_escape_dup(tmpf); - cmd = str_concat(" ", bin, tmpf_esc, NULL); - free(tmpf_esc); - - run(logdepth, cmd, &out); - if (out != NULL) { - char *s = out; - - while((*s == ' ') || (*s == '\r') || (*s == '\n')) - s++; - - if (strncmp(s, "foo bar", 7) == 0) { - unlink(tmpf); - free(tmpf); - free(out); - report("found (%s)\n", bin); - logprintf(logdepth, "found (%s)", bin); - put("libs/script/m4/bin/presents", strue); - put("libs/script/m4/bin/path", bin); - return 1; - } - - free(out); - } - - unlink(tmpf); - free(tmpf); - free(cmd); - return 0; -} - -int find_script_m4(const char *name, int logdepth, int fatal) -{ - char *m4_paths[] = { - "/usr/bin/m4", - "/usr/local/bin/m4", - "/bin/m4", - "/usr/bin/gm4", - "/usr/local/bin/gm4", - "/bin/gm4", - NULL - }; - char **s; - - report("Checking for m4 binary... "); - logprintf(logdepth, "find_m4: trying to find m4 binary...\n"); - logdepth++; - - for(s = m4_paths; *s != NULL; s++) - if (test_m4(name, logdepth, fatal, *s)) - return 0; - - return try_fail(logdepth, "libs/script/m4/bin"); -} diff --git a/scconfig/src/scripts/.svn/wc.db b/scconfig/src/scripts/.svn/wc.db deleted file mode 100644 index 5a2d250a..00000000 Binary files a/scconfig/src/scripts/.svn/wc.db and /dev/null differ diff --git a/scconfig/src/scripts/.svn/wc.db-journal b/scconfig/src/scripts/.svn/wc.db-journal deleted file mode 100644 index e69de29b..00000000 diff --git a/scconfig/src/tmpasm/.svn/entries b/scconfig/src/tmpasm/.svn/entries deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/tmpasm/.svn/entries +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/tmpasm/.svn/format b/scconfig/src/tmpasm/.svn/format deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/tmpasm/.svn/format +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/tmpasm/.svn/pristine/07/07eba02f85b888b6c5f998e3ad763b4f3820307c.svn-base b/scconfig/src/tmpasm/.svn/pristine/07/07eba02f85b888b6c5f998e3ad763b4f3820307c.svn-base deleted file mode 100644 index e091176c..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/07/07eba02f85b888b6c5f998e3ad763b4f3820307c.svn-base +++ /dev/null @@ -1,35 +0,0 @@ -print [at 7:1] - arg: {this is a string} - arg: { -} -print [at 9:1] - arg: {-- -} -put [at 11:1] - arg: myblk - arg: {a block -of multiline -data. -} -print [at 16:1] - arg: myblk -put [at 24:1] - arg: myvar - arg: {world} -print [at 25:1] - arg: {-- -} -print [at 26:1] - arg: [~ hello ~myvar~! ~] - arg: { -} -print [at 27:1] - arg: {-- -} -print [at 28:1] - arg: { - hi @myvar@! -} -print [at 31:1] - arg: {-- -} diff --git a/scconfig/src/tmpasm/.svn/pristine/09/099beba91c8c335830d875d2c6df8efe1f4b43e1.svn-base b/scconfig/src/tmpasm/.svn/pristine/09/099beba91c8c335830d875d2c6df8efe1f4b43e1.svn-base deleted file mode 100644 index 47288690..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/09/099beba91c8c335830d875d2c6df8efe1f4b43e1.svn-base +++ /dev/null @@ -1,159 +0,0 @@ -put [at 2:1] - arg: list - arg: {one two three four} -print [at 4:1] - arg: list - arg: { -} -print [at 6:1] - arg: { -nothing: -} -order [at 9:1] - arg: out - arg: list - arg: {one} - arg: {before} - arg: {two} -print [at 10:1] - arg: out - arg: { -} -order [at 12:1] - arg: out - arg: list - arg: {one} - arg: {before} - arg: {one} -print [at 13:1] - arg: out - arg: { -} -order [at 15:1] - arg: out - arg: list - arg: {one} - arg: {after} - arg: {one} -print [at 16:1] - arg: out - arg: { -} -order [at 18:1] - arg: out - arg: list - arg: {two} - arg: {after} - arg: {one} -print [at 19:1] - arg: out - arg: { -} -order [at 22:1] - arg: out - arg: list - arg: {nine} - arg: {after} - arg: {one} -print [at 23:1] - arg: out - arg: { -} -order [at 24:1] - arg: out - arg: list - arg: {one} - arg: {after} - arg: {nine} -print [at 25:1] - arg: out - arg: { -} -print [at 27:1] - arg: { -before: -} -order [at 28:1] - arg: out - arg: list - arg: {two} - arg: {before} - arg: {one} -print [at 29:1] - arg: out - arg: { -} -order [at 31:1] - arg: out - arg: list - arg: {four} - arg: {before} - arg: {one} -print [at 32:1] - arg: out - arg: { -} -order [at 34:1] - arg: out - arg: list - arg: {four} - arg: {before} - arg: {three} -print [at 35:1] - arg: out - arg: { -} -order [at 37:1] - arg: out - arg: list - arg: {three} - arg: {before} - arg: {two} -print [at 38:1] - arg: out - arg: { -} -print [at 40:1] - arg: { -after: -} -order [at 41:1] - arg: out - arg: list - arg: {one} - arg: {after} - arg: {two} -print [at 42:1] - arg: out - arg: { -} -order [at 44:1] - arg: out - arg: list - arg: {one} - arg: {after} - arg: {four} -print [at 45:1] - arg: out - arg: { -} -order [at 47:1] - arg: out - arg: list - arg: {two} - arg: {after} - arg: {three} -print [at 48:1] - arg: out - arg: { -} -order [at 50:1] - arg: out - arg: list - arg: {two} - arg: {after} - arg: {four} -print [at 51:1] - arg: out - arg: { -} diff --git a/scconfig/src/tmpasm/.svn/pristine/0a/0a1b3ec04c96093e00f44532056dde82e1ea8ff3.svn-base b/scconfig/src/tmpasm/.svn/pristine/0a/0a1b3ec04c96093e00f44532056dde82e1ea8ff3.svn-base deleted file mode 100644 index 77473862..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/0a/0a1b3ec04c96093e00f44532056dde82e1ea8ff3.svn-base +++ /dev/null @@ -1,2 +0,0 @@ -error: unexpected end of if switch statement; expected a data at 1:7 -(NOP) diff --git a/scconfig/src/tmpasm/.svn/pristine/10/10d5e4a7c02d7a72da0c176ea4f4e66a7f3806ba.svn-base b/scconfig/src/tmpasm/.svn/pristine/10/10d5e4a7c02d7a72da0c176ea4f4e66a7f3806ba.svn-base deleted file mode 100644 index 5b1526bd..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/10/10d5e4a7c02d7a72da0c176ea4f4e66a7f3806ba.svn-base +++ /dev/null @@ -1,26 +0,0 @@ -# Variables are stored in a hash. Variable names follow the normal -# identifier rules with less restrictions (can start with number) -# To set the value of a variable, use: put var value -put myvar {Hello world!\n} - -# Referencing the variable is done by using its name -print myvar - -# In most context arguments are data; data can be both string literal and -# variable reference: -print {Hello universe! } myvar - -# the second var of put is just data, can be string or variable; copying -# a variable: -put str {cats raining from the sky} -put tmp str -print str {==} tmp {\n} - -# the ? prefix results in empty string if a variable doesnt exist, instead -# of throwing a runtime error -print {safe get: '} ?nonexist {'\n} - -# the & prefix evaluates to "true" or "false" depending on whether the node -# exists in the tree or not -print {exists (no): } &nonexist {\n} -print {exists (yes): } &myvar {\n} diff --git a/scconfig/src/tmpasm/.svn/pristine/15/1538057a16760c6148d3b32a190be58fcd0f31f5.svn-base b/scconfig/src/tmpasm/.svn/pristine/15/1538057a16760c6148d3b32a190be58fcd0f31f5.svn-base deleted file mode 100644 index 080e24c9..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/15/1538057a16760c6148d3b32a190be58fcd0f31f5.svn-base +++ /dev/null @@ -1,51 +0,0 @@ -# test if without an else -put list {one two three four} - -print list {\n} - -print {\nnothing:\n} - -# do nothing: order matches -order out list {one} {before} {two} -print out {\n} - -order out list {one} {before} {one} -print out {\n} - -order out list {one} {after} {one} -print out {\n} - -order out list {two} {after} {one} -print out {\n} - -# do nothing: not on list matches -order out list {nine} {after} {one} -print out {\n} -order out list {one} {after} {nine} -print out {\n} - -print {\nbefore:\n} -order out list {two} {before} {one} -print out {\n} - -order out list {four} {before} {one} -print out {\n} - -order out list {four} {before} {three} -print out {\n} - -order out list {three} {before} {two} -print out {\n} - -print {\nafter:\n} -order out list {one} {after} {two} -print out {\n} - -order out list {one} {after} {four} -print out {\n} - -order out list {two} {after} {three} -print out {\n} - -order out list {two} {after} {four} -print out {\n} diff --git a/scconfig/src/tmpasm/.svn/pristine/15/15fa8d9f0beec404f874e04e223ef7949971715f.svn-base b/scconfig/src/tmpasm/.svn/pristine/15/15fa8d9f0beec404f874e04e223ef7949971715f.svn-base deleted file mode 100644 index 752ca42f..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/15/15fa8d9f0beec404f874e04e223ef7949971715f.svn-base +++ /dev/null @@ -1,89 +0,0 @@ -put [at 7:1] - arg: list - arg: {this -is -a -list -of -words, -a -list -of -words. -} -print [at 18:1] - arg: {original: -} - arg: list - arg: { -} -uniq [at 19:1] - arg: list -print [at 20:1] - arg: {uniq: -} - arg: list - arg: { -} -put [at 24:1] - arg: foo - arg: {this -foo -is -a -this -foo -} -uniq [at 31:1] - arg: tmp - arg: foo -print [at 32:1] - arg: {original: -} - arg: foo - arg: { -uniq: -} - arg: tmp - arg: { -} -sortuniq [at 39:1] - arg: tmp - arg: foo -print [at 40:1] - arg: { -sortuniq: -} - arg: tmp - arg: { -} -put [at 49:1] - arg: list - arg: {#define foo -#include "foo20.h" -#include "foo10.h" -/* misc1 */ -#define bar -#include "bar1.h" -#include "bar2.h" -/* misc2 */ -} -put [at 61:1] - arg: /tmpasm/IFS - arg: { -} -uniq [at 63:1] - arg: tmp - arg: list - arg: {^#define} - arg: {^#include} -print [at 64:1] - arg: {original: -} - arg: list - arg: { -grouped uniq: -} - arg: tmp - arg: { -} diff --git a/scconfig/src/tmpasm/.svn/pristine/16/166ece40583ebe9068cec95c5f63943ee56b7e93.svn-base b/scconfig/src/tmpasm/.svn/pristine/16/166ece40583ebe9068cec95c5f63943ee56b7e93.svn-base deleted file mode 100644 index 6e0aa88c..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/16/166ece40583ebe9068cec95c5f63943ee56b7e93.svn-base +++ /dev/null @@ -1,42 +0,0 @@ -# Switch is similar to case in posix shell and switch in C. It takes a -# data argument and matches is against cases until the first match. It -# executes the code for that match and stops executing the switch (unlike -# in C, and like in sh, there is no fall-thru). A default case can be -# defined as a catch-all rule. -# -# Scconfig uses regex matching (unlike sh (shell globbing) and C (integer)). -# -# The first word after the switch keyword is the string that is matched -# against case patterns; the first word after a case is the pattern -# the string is matched against. Each branch must be terminated by an "end", -# just as the whole switch. Default doesn't have pattern, instructions start -# immediately. - -put myvar {foobar} -switch myvar - case {baz} put res {1}; print {this is baz.\n}; end; - case {^oob} put res {2}; print {did you mean out-of-band?\n}; end; - case {^f} put res {3}; print {starts with f.\n}; end; - case {oob} put res {4}; print {OOB!\n}; end; - default put res {0}; print {none.\n}; end; -end; - -print {result is: } res {\n} - - -# data is data - can be block as well, anywhere, in switch or case: -put patt {^number$} -put REF {3} -switch [@num @res@ ber@] - case patt print {empty\n}; end; - case [!^num !REF!!] print {reference\n}; end; -end - -# one of the uses of switch is to construct an if-then-else that uses -# matching instead of checking for true/false; the following example -# demonstrates how an "if cond matches {lob}" is done with switch. -put cond {blobb} -switch cond - case {lob} print {"then"\n}; end - default print {"else"\n}; end -end diff --git a/scconfig/src/tmpasm/.svn/pristine/1a/1a9147d822006e8a6f3e47affcb228d5dd927bfe.svn-base b/scconfig/src/tmpasm/.svn/pristine/1a/1a9147d822006e8a6f3e47affcb228d5dd927bfe.svn-base deleted file mode 100644 index 7290a2be..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/1a/1a9147d822006e8a6f3e47affcb228d5dd927bfe.svn-base +++ /dev/null @@ -1,15 +0,0 @@ -put [at 1:1] - arg: a - arg: 1 -if a [at 2:6] -then: - if b [at 3:7] - then: - print [at 4:3] - arg: {then-then} - else: - print [at 6:3] - arg: {then-else} -else: - print [at 9:2] - arg: {else} diff --git a/scconfig/src/tmpasm/.svn/pristine/26/264d1a37e4eb814fdcc7bd7f8a305ed562e7681d.svn-base b/scconfig/src/tmpasm/.svn/pristine/26/264d1a37e4eb814fdcc7bd7f8a305ed562e7681d.svn-base deleted file mode 100644 index a7007f3e..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/26/264d1a37e4eb814fdcc7bd7f8a305ed562e7681d.svn-base +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include "tmpasm.h" -#include "tmpasm_scconfig.h" -#include "debug.h" -#include "db.h" - -tmpasm_t *ctx; - -void re_fail(char *s, char c) -{ - fprintf(stderr, "Regex error: %s [opcode %o]\n", s, c); - abort(); -} - -static void do_dump() -{ - tmpasm_dump(ctx, stdout); -} - -static void do_exec() -{ - if (ctx->dead) - fprintf(stderr, "Can not execute the script due to the above compilation error.\n"); - else - tmpasm_execute(ctx); -} - -static void scc_init(void) -{ - db_init(); - db_mkdir("/local"); - db_cd("/local"); -} - -int main(int argc, char *argv[]) -{ - scc_init(); - ctx = tmpasm_init(&scc_cb); - scc_tmpasm_parse(ctx, NULL, stdin, stdout); - - if (argc > 1) { - char *cmd; - cmd = argv[1]; - while(*cmd == '-') cmd++; - switch(*cmd) { - case 'd': do_dump(); break; - case 'e': do_exec(); break; - } - } - else - do_dump(); - - if (ctx->runtime_error != 0) { - const char *fmt = tmpasm_runtime_error_fmt(ctx); - fprintf(stderr, "Runtime error at %d:%d: ", ctx->runtime_error_line, ctx->runtime_error_col); - fprintf(stderr, fmt, (ctx->runtime_error_data == NULL ? "" : ctx->runtime_error_data)); - fprintf(stderr, "\n"); - } - - tmpasm_uninit(ctx); - db_uninit(); - return 0; -} diff --git a/scconfig/src/tmpasm/.svn/pristine/29/2913618b4c26aa3234dac101ab59077b4fb76b69.svn-base b/scconfig/src/tmpasm/.svn/pristine/29/2913618b4c26aa3234dac101ab59077b4fb76b69.svn-base deleted file mode 100644 index 6e6d67ca..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/29/2913618b4c26aa3234dac101ab59077b4fb76b69.svn-base +++ /dev/null @@ -1,41 +0,0 @@ -put [at 1:1] - arg: a - arg: {1} -put [at 2:1] - arg: foo - arg: {example-FOO} -put [at 3:1] - arg: bar - arg: {example-BAR} -put [at 4:1] - arg: baz - arg: {example-BAZ} -put [at 5:1] - arg: hah - arg: {haha} -foreach n in [~foo ~bar~ baz~] [at 9:1] - print [at 10:2] - arg: {n=} - arg: n - arg: { -} - print [at 11:2] - arg: {a11} - arg: [~a12 ~hah~ a14~] - arg: { -} - print [at 12:2] - arg: {a21} - arg: {a22 a23} - arg: { -} - print [at 13:2] - arg: {a31 -} -print [at 15:1] - arg: {a41} - arg: {a42} - arg: {a43} - arg: { -} -print [at 16:1] diff --git a/scconfig/src/tmpasm/.svn/pristine/32/3231c051ce48c9bf671271cd19cb8dc908a2465a.svn-base b/scconfig/src/tmpasm/.svn/pristine/32/3231c051ce48c9bf671271cd19cb8dc908a2465a.svn-base deleted file mode 100644 index 72b27387..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/32/3231c051ce48c9bf671271cd19cb8dc908a2465a.svn-base +++ /dev/null @@ -1,47 +0,0 @@ -### set up internal variables ### -put /local/cflags {-std=c99 -Wall} -put /local/ldflags {-lm} -put /local/objs {main.o foo.o bar.o} - -# turn off optimization and add -g in debug mode -if /local/debug then - append /local/cflags {-g} -else - append /local/cflags {-O2} -end - -# if somelib is selected, add -I and -l -isempty /local/r /local/somelib -invert /local/r -if /local/r then - append /local/cflags { -I/usr/include/somelib} - append /local/ldflags { -lsomelib} -end - -### Generate the Makefile ### -print [@ -# Makefile generated by scconfig - DO NOT EDIT - please edit Makefile.in -CFLAGS=@/local/cflags@ -LDFLAGS=@/local/ldflags@ -OBJS=@/local/objs@ - -all: main - -main: $(OBJS) - $(CC) $(LDFLAGS) - -@] - -# loop over each object and generate an explicit rule -# (we are generating a dumb Makefile that would work with any -# old version of make) -foreach /local/o in /local/objs - put /local/c /local/o - sub /local/c {.o$} {.c} - print [@ -@/local/o@: @/local/c@ - $(CC) -c $(CFLAGS) @/local/c@ -o @/local/o@ - @] -end - -print {#end\n} diff --git a/scconfig/src/tmpasm/.svn/pristine/33/33bd871223a2dd493a51f42b239d0fb1360e3df1.svn-base b/scconfig/src/tmpasm/.svn/pristine/33/33bd871223a2dd493a51f42b239d0fb1360e3df1.svn-base deleted file mode 100644 index 75c9d9ef..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/33/33bd871223a2dd493a51f42b239d0fb1360e3df1.svn-base +++ /dev/null @@ -1,8 +0,0 @@ -put swdata {lol} -switch swdata - case data1 print {1a} {11}; print {1b} 12; print {1c} 13; print {1d} 14; end; - case [~data2 ~a~~] print {2a} 21; print {2b} 22; print {2c} 23; print {2d} 24; end; - default print {3a} 31; print {3b} 32; print {3c} 33; print {3d} 34; end; -end; -print {i1} -print {i2} diff --git a/scconfig/src/tmpasm/.svn/pristine/36/3623f965655fa57794d2b334a2d6faf1770e6541.svn-base b/scconfig/src/tmpasm/.svn/pristine/36/3623f965655fa57794d2b334a2d6faf1770e6541.svn-base deleted file mode 100644 index 82a1bf06..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/36/3623f965655fa57794d2b334a2d6faf1770e6541.svn-base +++ /dev/null @@ -1,3 +0,0 @@ -pritn {foo} -switch {cond} - case {1} print {foo}; end diff --git a/scconfig/src/tmpasm/.svn/pristine/3b/3bc5afda83b5c0695638a3f69cb264bdc93d0f0c.svn-base b/scconfig/src/tmpasm/.svn/pristine/3b/3bc5afda83b5c0695638a3f69cb264bdc93d0f0c.svn-base deleted file mode 100644 index d37cb2ba..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/3b/3bc5afda83b5c0695638a3f69cb264bdc93d0f0c.svn-base +++ /dev/null @@ -1,18 +0,0 @@ -# Comments start with # and end at the end of the line; comments -# can be started anywhere outside of strings and blocks - -# Print will print each argument without appending a newline. An argument -# is a data, string literals are written in brace. Escape sequences -# are as usual -print {hello world!\n} - -# Print doesn't have any hidden side effect: no separators printed -# between arguments -print {hello} {world!} {\n} - -# Print works without an argument as well: it just prints nothing -print - -# instructions are separated by newlines and/or semicolons: -print {HELLO}; print { WORLD!};;;; print {\n}; - diff --git a/scconfig/src/tmpasm/.svn/pristine/40/409cdddfe79d7502143f9636dee9024a16488f83.svn-base b/scconfig/src/tmpasm/.svn/pristine/40/409cdddfe79d7502143f9636dee9024a16488f83.svn-base deleted file mode 100644 index 92ac58d3..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/40/409cdddfe79d7502143f9636dee9024a16488f83.svn-base +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include -#include "openfiles.h" -#include "libs.h" - -static openfile_t *find_file_by_name(openfiles_t *of, const char *name, int alloc, const char *mode, int recursion) -{ - int n; - struct stat buf; - FILE *f; - - if (recursion > 4) { - fprintf(stderr, "scconfig internal error: openfiles infinite recursion for %s\n", name); - abort(); - } - - if (stat(name, &buf) != 0) { - /* File does not exist - try to create it or return NULL */ - if (*mode == 'w') { - f = fopen(name, "w"); - if (f == NULL) - return NULL; - fclose(f); - return find_file_by_name(of, name, alloc, mode, recursion + 1); - } - return NULL; - } - - /* look for an existing open file in the list */ - for(n = 0; n < of->used; n++) - if ((of->files[n].dev == buf.st_dev) && (of->files[n].ino == buf.st_ino) && (strcmp(of->files[n].mode, mode) == 0)) - return &(of->files[n]); - - if (!alloc) - return NULL; - - /* File exists but not on the list yet, allocate a new slot for it */ - /* TODO: try to find an empty slot first */ - if (of->used >= of->alloced) { - of->alloced += 16; - of->files = realloc(of->files, sizeof(openfile_t) * of->alloced); - } - - n = of->used; - of->files[n].dev = buf.st_dev; - of->files[n].ino = buf.st_ino; - of->files[n].f = NULL; - of->files[n].mode = strclone(mode); - of->used++; - return &(of->files[n]); -} - -void release(openfile_t *o) -{ - if (o->mode != NULL) { - free(o->mode); - o->mode = NULL; - } - if (o->f != NULL) { - fclose(o->f); - o->f = NULL; - } - o->dev = -1; - o->ino = -1; -} - -FILE *openfile_open(openfiles_t *of, const char *fn, const char *mode) -{ - openfile_t *o; - o = find_file_by_name(of, fn, 1, mode, 0); - if (o == NULL) - return NULL; - o->f = fopen(fn, mode); - if (o->f == NULL) { - release(o); - return NULL; - } - return o->f; -} - -void openfile_closeall(openfiles_t *of) -{ - int n; - if (of->files == NULL) - return; - for(n = 0; n < of->used; n++) - release(&(of->files[n])); -} - -void openfile_free(openfiles_t *of) -{ - openfile_closeall(of); - if (of->files != NULL) - free(of->files); -} diff --git a/scconfig/src/tmpasm/.svn/pristine/41/417fefa8c41035e443bcae7d0649575f42a8520e.svn-base b/scconfig/src/tmpasm/.svn/pristine/41/417fefa8c41035e443bcae7d0649575f42a8520e.svn-base deleted file mode 100644 index 1c851245..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/41/417fefa8c41035e443bcae7d0649575f42a8520e.svn-base +++ /dev/null @@ -1,16 +0,0 @@ -TMPASM_OBJS = \ - $(BIN)/tmpasm/tmpasm.o \ - $(BIN)/tmpasm/tmpasm_scconfig.o \ - $(BIN)/tmpasm/openfiles.o - -TMPASM_CFLAGS = -I$(SRC)/tmpasm - -$(BIN)/tmpasm/tmpasm.o: $(SRC)/tmpasm/tmpasm.c $(SRC)/tmpasm/tmpasm.h $(SRC)/default/dep.h $(SRC)/default/log.h $(SRC)/default/regex.h - $(CC) $(CFLAGS) -c $(SRC)/tmpasm/tmpasm.c -o $(BIN)/tmpasm/tmpasm.o - -$(BIN)/tmpasm/tmpasm_scconfig.o: $(SRC)/tmpasm/tmpasm_scconfig.c $(SRC)/tmpasm/tmpasm.h $(SRC)/default/libs.h $(SRC)/default/log.h $(SRC)/default/regex.h - $(CC) $(CFLAGS) -c $(SRC)/tmpasm/tmpasm_scconfig.c -o $(BIN)/tmpasm/tmpasm_scconfig.o - -$(BIN)/tmpasm/openfiles.o: $(SRC)/tmpasm/openfiles.c - $(CC) $(CFLAGS) -c $(SRC)/tmpasm/openfiles.c -o $(BIN)/tmpasm/openfiles.o - diff --git a/scconfig/src/tmpasm/.svn/pristine/43/43a1689a65b96d1ee5c9d5229c18b5ad9833fe04.svn-base b/scconfig/src/tmpasm/.svn/pristine/43/43a1689a65b96d1ee5c9d5229c18b5ad9833fe04.svn-base deleted file mode 100644 index 268aeed7..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/43/43a1689a65b96d1ee5c9d5229c18b5ad9833fe04.svn-base +++ /dev/null @@ -1,18 +0,0 @@ -put a {1} -put foo {example-FOO} -put bar {example-BAR} -put baz {example-BAZ} -put hah {haha} - -# should set n to the string foo, the value of bar and the string baz -# per iteration -foreach n in [~foo ~bar~ baz~] - print {n=} n {\n} - print {a11} [@a12 @hah@ a14@] {\n} - print {a21} {a22 a23} {\n} - print {a31\n} -end -print {a41} {a42} {a43} {\n} -print - - diff --git a/scconfig/src/tmpasm/.svn/pristine/46/46bdaf2d2389d2758765319309ef6fd7b32016d4.svn-base b/scconfig/src/tmpasm/.svn/pristine/46/46bdaf2d2389d2758765319309ef6fd7b32016d4.svn-base deleted file mode 100644 index 4b0587a6..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/46/46bdaf2d2389d2758765319309ef6fd7b32016d4.svn-base +++ /dev/null @@ -1,14 +0,0 @@ -# Instruction "halt" breaks the execution of the current script file -# (returning from the C call to tmpasm() or stop processing an "include", -# returning to executing the parent script). It is useful for cheap -# termination of the script file from deep inside nested loops/ifs. - -put tmp {true} -if tmp then - foreach item in {foo bar true baz} - print item {\n} - if item then - halt - end - end -end diff --git a/scconfig/src/tmpasm/.svn/pristine/49/4975ca087137bae6240cb4758020a485ba476945.svn-base b/scconfig/src/tmpasm/.svn/pristine/49/4975ca087137bae6240cb4758020a485ba476945.svn-base deleted file mode 100644 index bb378c64..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/49/4975ca087137bae6240cb4758020a485ba476945.svn-base +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include - -typedef struct openfile_s { - FILE *f; - - /* identify the file: */ - dev_t dev; - ino_t ino; - - char *mode; -} openfile_t; - -typedef struct openfiles_s { - int alloced, used; - openfile_t *files; -} openfiles_t; - -FILE *openfile_open(openfiles_t *of, const char *fn, const char *mode); -void openfile_closeall(openfiles_t *of); -void openfile_free(openfiles_t *of); diff --git a/scconfig/src/tmpasm/.svn/pristine/4b/4b36c9d1ae03b924b7c95e7a45d17a6746e27932.svn-base b/scconfig/src/tmpasm/.svn/pristine/4b/4b36c9d1ae03b924b7c95e7a45d17a6746e27932.svn-base deleted file mode 100644 index 56807613..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/4b/4b36c9d1ae03b924b7c95e7a45d17a6746e27932.svn-base +++ /dev/null @@ -1,42 +0,0 @@ -put [at 1:1] - arg: myvar - arg: {true} -if myvar [at 6:10] -then: - print [at 7:2] - arg: {myvar is true (1) -} -else: - print [at 9:2] - arg: {myvar is false (1) -} -if myvar [at 14:10] -then: - print [at 15:2] - arg: {myvar is true (2) -} -else: - (NOP) -if myvar [at 19:10] -then: - (NOP) -else: - print [at 20:2] - arg: {myvar is false (3) -} -put [at 24:1] - arg: foo - arg: {false} -if myvar [at 25:10] -then: - if foo [at 26:9] - then: - print [at 27:3] - arg: {myvar and bar are true (4) -} - else: - print [at 29:3] - arg: {myvar is true, bar is false (4) -} -else: - (NOP) diff --git a/scconfig/src/tmpasm/.svn/pristine/5a/5a30f67b1a0e743e01fa18502ebdbc7617218890.svn-base b/scconfig/src/tmpasm/.svn/pristine/5a/5a30f67b1a0e743e01fa18502ebdbc7617218890.svn-base deleted file mode 100644 index f8fccde3..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/5a/5a30f67b1a0e743e01fa18502ebdbc7617218890.svn-base +++ /dev/null @@ -1,32 +0,0 @@ -foreach item in {this is a list of words} [at 7:1] - print [at 8:2] - arg: item - arg: { -} -put [at 15:1] - arg: nl - arg: { -} -foreach item in {foo bar baz} [at 16:1] - foreach w in [~next: ~item~~nl~~] [at 17:2] - print [at 18:3] - arg: w -put [at 27:1] - arg: libs - arg: {-lsdl -ltcl8.4} -foreach l in libs [at 28:1] - print [at 29:2] - arg: {l=} - arg: l - arg: { -} - switch l [at 30:2] - case {^-lsdl} - put [at 31:19] - arg: libs - arg: [~-lm ~libs~ -lsvga~] -print [at 34:1] - arg: {libs=} - arg: libs - arg: { -} diff --git a/scconfig/src/tmpasm/.svn/pristine/5f/5f93926e7778ab54443ce7e8db7011c899dd0d88.svn-base b/scconfig/src/tmpasm/.svn/pristine/5f/5f93926e7778ab54443ce7e8db7011c899dd0d88.svn-base deleted file mode 100644 index 3b45fa76..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/5f/5f93926e7778ab54443ce7e8db7011c899dd0d88.svn-base +++ /dev/null @@ -1,31 +0,0 @@ -put myvar {true} - -# The simplest flow control is an if. It takes its first argument and -# calls the environment to decide if it is true or false. If it's true -# the "then" branch is executed, if it's false, the "else" branch runs. -if myvar then - print {myvar is true (1)\n} -else - print {myvar is false (1)\n} -end - - -# it is possible to omit the else branch -if myvar then - print {myvar is true (2)\n} -end - -# the then branch may be empty: -if myvar then else - print {myvar is false (3)\n} -end - -# embedding controls is legal: -put foo {false} -if myvar then - if foo then - print {myvar and bar are true (4)\n} - else - print {myvar is true, bar is false (4)\n} - end -end diff --git a/scconfig/src/tmpasm/.svn/pristine/60/602d4938bb83b6b1757d503924889db549543fb4.svn-base b/scconfig/src/tmpasm/.svn/pristine/60/602d4938bb83b6b1757d503924889db549543fb4.svn-base deleted file mode 100644 index a59ad252..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/60/602d4938bb83b6b1757d503924889db549543fb4.svn-base +++ /dev/null @@ -1,40 +0,0 @@ -put [at 6:1] - arg: myvar - arg: {Hello world! -} -sub [at 7:1] - arg: myvar - arg: {l} - arg: {2} -print [at 8:1] - arg: myvar -sub [at 13:1] - arg: {myvar} - arg: {l} - arg: {3} -print [at 14:1] - arg: myvar -put [at 19:1] - arg: pointer - arg: {myvar} -sub [at 20:1] - arg: [~~pointer~~] - arg: {l} - arg: {4} -print [at 21:1] - arg: myvar -put [at 25:1] - arg: punctuation - arg: {[!?.]} -sub [at 26:1] - arg: [~~pointer~~] - arg: punctuation - arg: [~ PUNCT:~punctuation~~] -print [at 27:1] - arg: myvar -gsub [at 30:1] - arg: [~~pointer~~] - arg: {o} - arg: {_0_} -print [at 31:1] - arg: myvar diff --git a/scconfig/src/tmpasm/.svn/pristine/63/632aa13b9c237cc28c49166a01e7bf1b04750863.svn-base b/scconfig/src/tmpasm/.svn/pristine/63/632aa13b9c237cc28c49166a01e7bf1b04750863.svn-base deleted file mode 100644 index a2e38281..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/63/632aa13b9c237cc28c49166a01e7bf1b04750863.svn-base +++ /dev/null @@ -1,6 +0,0 @@ -# test if without an else -if cnd then - print a1 a2 a3 -end - -print a1 a2 a3 diff --git a/scconfig/src/tmpasm/.svn/pristine/63/639d7ed97ea4e08638252ec813667b6c72a8e1d1.svn-base b/scconfig/src/tmpasm/.svn/pristine/63/639d7ed97ea4e08638252ec813667b6c72a8e1d1.svn-base deleted file mode 100644 index 0d67ac2e..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/63/639d7ed97ea4e08638252ec813667b6c72a8e1d1.svn-base +++ /dev/null @@ -1,10 +0,0 @@ -if ?a [at 5:7] -then: - print [at 6:2] - arg: {empty} -else: - print [at 8:2] - arg: {not empty} -put [at 11:1] - arg: b - arg: ?a diff --git a/scconfig/src/tmpasm/.svn/pristine/67/672303a2eb68e2c26fa5899ea4a73ea59eb5904f.svn-base b/scconfig/src/tmpasm/.svn/pristine/67/672303a2eb68e2c26fa5899ea4a73ea59eb5904f.svn-base deleted file mode 100644 index cace30d8..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/67/672303a2eb68e2c26fa5899ea4a73ea59eb5904f.svn-base +++ /dev/null @@ -1,3 +0,0 @@ -if {1} then -end -end diff --git a/scconfig/src/tmpasm/.svn/pristine/6e/6e7deb5c1d9257a9870e4a3127e210f87a79281d.svn-base b/scconfig/src/tmpasm/.svn/pristine/6e/6e7deb5c1d9257a9870e4a3127e210f87a79281d.svn-base deleted file mode 100644 index 18003e08..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/6e/6e7deb5c1d9257a9870e4a3127e210f87a79281d.svn-base +++ /dev/null @@ -1,31 +0,0 @@ -# Blocks are special syntax to make it easier to handle large, -# to-be-printed-verbatim blocks of data, which is essential in a template -# language. Blocks are enclosed in [$ $], where $ is an arbitrary character -# that shall be chosen by the programmer, per block; once a characher is -# chosen, it can not appear in the string. There is no backslash escaping -# in blocks. Blocks can be used anywhere where strings could be used. -print [@this is a string@] {\n} - -print {--\n} - -put myblk [!a block -of multiline -data. -!] - -print myblk - -# A special feature of the block is inline variable substitution using the same -# separator character chosen at the opening brace. In the example below -# myvar is substituted because it is sorrounded by the separator (@ in -# the first case and $ in the second case). Whitespace and newlines -# are preserved in the block, even in the inline variable name! - -put myvar {world} -print {--\n} -print [@ hello @myvar@! @] {\n} -print {--\n} -print [$ - hi @myvar@! -$] -print {--\n} diff --git a/scconfig/src/tmpasm/.svn/pristine/77/7763fad034b761bb2177e3f8521f906007f6ecb5.svn-base b/scconfig/src/tmpasm/.svn/pristine/77/7763fad034b761bb2177e3f8521f906007f6ecb5.svn-base deleted file mode 100644 index 00ba084a..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/77/7763fad034b761bb2177e3f8521f906007f6ecb5.svn-base +++ /dev/null @@ -1,71 +0,0 @@ -put [at 15:1] - arg: myvar - arg: {foobar} -switch myvar [at 16:1] - case {baz} - put [at 17:14] - arg: res - arg: {1} - print [at 17:27] - arg: {this is baz. -} - case {^oob} - put [at 18:14] - arg: res - arg: {2} - print [at 18:27] - arg: {did you mean out-of-band? -} - case {^f} - put [at 19:14] - arg: res - arg: {3} - print [at 19:27] - arg: {starts with f. -} - case {oob} - put [at 20:14] - arg: res - arg: {4} - print [at 20:27] - arg: {OOB! -} - default - put [at 21:14] - arg: res - arg: {0} - print [at 21:27] - arg: {none. -} -print [at 24:1] - arg: {result is: } - arg: res - arg: { -} -put [at 28:1] - arg: patt - arg: {^number$} -put [at 29:1] - arg: REF - arg: {3} -switch [~num ~res~ ber~] [at 30:1] - case patt - print [at 31:23] - arg: {empty -} - case [~^num ~REF~~] - print [at 32:23] - arg: {reference -} -put [at 38:1] - arg: cond - arg: {blobb} -switch cond [at 39:1] - case {lob} - print [at 40:15] - arg: {"then" -} - default - print [at 41:15] - arg: {"else" -} diff --git a/scconfig/src/tmpasm/.svn/pristine/7a/7aed6bb2a1a5b49f852d2bff40e98c29886d9155.svn-base b/scconfig/src/tmpasm/.svn/pristine/7a/7aed6bb2a1a5b49f852d2bff40e98c29886d9155.svn-base deleted file mode 100644 index 2dffb085..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/7a/7aed6bb2a1a5b49f852d2bff40e98c29886d9155.svn-base +++ /dev/null @@ -1,2 +0,0 @@ -switch -end diff --git a/scconfig/src/tmpasm/.svn/pristine/7e/7e4c9519245be0aa76029555c07c886ed21b71eb.svn-base b/scconfig/src/tmpasm/.svn/pristine/7e/7e4c9519245be0aa76029555c07c886ed21b71eb.svn-base deleted file mode 100644 index 67520eba..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/7e/7e4c9519245be0aa76029555c07c886ed21b71eb.svn-base +++ /dev/null @@ -1,3 +0,0 @@ -switch -case data print {foo}; end -end diff --git a/scconfig/src/tmpasm/.svn/pristine/8d/8df676eef67150d602746744996efd6e320f9655.svn-base b/scconfig/src/tmpasm/.svn/pristine/8d/8df676eef67150d602746744996efd6e320f9655.svn-base deleted file mode 100644 index 9491210f..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/8d/8df676eef67150d602746744996efd6e320f9655.svn-base +++ /dev/null @@ -1,11 +0,0 @@ -# conditional/safe variable reference: name prefixed by ? -# if the variable does not exist, no error is thrown but empty -# string is returned - -if ?a then - print {empty} -else - print {not empty} -end - -put b ?a diff --git a/scconfig/src/tmpasm/.svn/pristine/8f/8fe561b747ec7714ccf712a626587f84829bce26.svn-base b/scconfig/src/tmpasm/.svn/pristine/8f/8fe561b747ec7714ccf712a626587f84829bce26.svn-base deleted file mode 100644 index 0fb1b524..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/8f/8fe561b747ec7714ccf712a626587f84829bce26.svn-base +++ /dev/null @@ -1,52 +0,0 @@ -# NOTE: THIS EXAMPLE WILL NOT WORK IN THE ON-LINE WEB VERSION - -# These features are scconfig specific. - -# There is a default output file coming from the environment; this -# is the file being generated. In the most common cases this is the -# only file the script will ever write. Any "print" instruction will -# write this file by default. However, sometimes it is handy -# to generate a small misc file during generating a large file. Thus -# the output file that "print" writes is not hardwired. Instead, there -# is the default output file and the current output file. Instruction -# "redir" can change the current output file. - -print {this goes to the default output\n} - -# redirect to Tutor10.inc; any "print" until the next "redir" will -# write that file -redir {Tutor10.inc} -print {# this is a generated file.} -print [@ - print {hello world from my include!\n} -@] - -# switch back to the default output -redir -print {back at default output.\n} - - -# Dynamic include: the script may include another script, runtime. When -# an include instruction is executed, the referred file is open, read, -# parsed and executed, recusively. -# -# Include being dynamic (or runtime) is unusual, but has the following -# advantages: -# - file name for inclusion can be calculated -# - conditional include is easily possible without an extra preprocessing layer -# - it is possible to generate a script on the fly and include it (sort of eval) -# Drawbacks: -# - it is possible to end up in an infinite loop that will only stop when -# resources run out (open fds or memory) -# - it is slow, e.g. if the body of a foreach contains include, the whole -# read-parse-execute procedure is repeated for each item -# Redir files are overwritten when first open from an execution. - -print {Include:\n} -include {Tutor10.inc} - -# NOTE: the above script works only because "redir" has a side effect: -# whenever redirection switches away from a file, that file is flushed. -# This happens even if the new current output is the same as the old -# current output (no actual switch takes place). - diff --git a/scconfig/src/tmpasm/.svn/pristine/92/92a23e1ecacb08f915b59ba66ea8946ef5edaf30.svn-base b/scconfig/src/tmpasm/.svn/pristine/92/92a23e1ecacb08f915b59ba66ea8946ef5edaf30.svn-base deleted file mode 100644 index 1ed50f72..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/92/92a23e1ecacb08f915b59ba66ea8946ef5edaf30.svn-base +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "tmpasm.h" - -int tmpasm(const char *wdir, const char *input, const char *output); - -void scc_tmpasm_parse(tmpasm_t *ctx, const char *cwd, FILE *fin, FILE *fout); - -FILE *tmpasm_fout(tmpasm_t *ctx); - -tmpasm_instr *scc_resolve(tmpasm_t *ctx, const char *name); - -extern tmpasm_cb_t scc_cb; - - diff --git a/scconfig/src/tmpasm/.svn/pristine/92/92f9fc4e254722a7e71c0881c74abd4552c5b528.svn-base b/scconfig/src/tmpasm/.svn/pristine/92/92f9fc4e254722a7e71c0881c74abd4552c5b528.svn-base deleted file mode 100644 index 73807fb8..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/92/92f9fc4e254722a7e71c0881c74abd4552c5b528.svn-base +++ /dev/null @@ -1,6 +0,0 @@ -error: Excess "end" at 3:4 -if {1} [at 1:8] -then: - (NOP) -else: - (NOP) diff --git a/scconfig/src/tmpasm/.svn/pristine/94/948bc986cbc84af4aa7a97ee918de98081023cdf.svn-base b/scconfig/src/tmpasm/.svn/pristine/94/948bc986cbc84af4aa7a97ee918de98081023cdf.svn-base deleted file mode 100644 index 7841be1a..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/94/948bc986cbc84af4aa7a97ee918de98081023cdf.svn-base +++ /dev/null @@ -1,2 +0,0 @@ -void tmpasm_dump(tmpasm_t *ctx, FILE *f); - diff --git a/scconfig/src/tmpasm/.svn/pristine/a1/a10a8730cfbb8a6cc84fa1b1637a2d6c00bfbd55.svn-base b/scconfig/src/tmpasm/.svn/pristine/a1/a10a8730cfbb8a6cc84fa1b1637a2d6c00bfbd55.svn-base deleted file mode 100644 index 318e019c..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/a1/a10a8730cfbb8a6cc84fa1b1637a2d6c00bfbd55.svn-base +++ /dev/null @@ -1,4 +0,0 @@ -if v -else - print {else} -end diff --git a/scconfig/src/tmpasm/.svn/pristine/a1/a124348ee6f023737539d79eda248a896d1ccd36.svn-base b/scconfig/src/tmpasm/.svn/pristine/a1/a124348ee6f023737539d79eda248a896d1ccd36.svn-base deleted file mode 100644 index 9c868bdd..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/a1/a124348ee6f023737539d79eda248a896d1ccd36.svn-base +++ /dev/null @@ -1,810 +0,0 @@ -#include -#include -#include -#include -#include "tmpasm.h" -#include "debug.h" - -#define is_space(c) (((c) == ' ') || ((c) == '\t')) -#define is_sep(c) (((c) == '\n') || ((c) == '\r') || ((c) == ';')) -#define is_addr(c) ( (((c) >= '0') && ((c) <= '9')) || (((c) >= 'a') && ((c) <= 'z')) || (((c) >= 'A') && ((c) <= 'Z')) || ((c) == '_') || ((c) == '?') || ((c) == '.') || ((c) == ',') || ((c) == ',') || ((c) == '-') || ((c) == '/') || ((c) == '&') ) - -/* this local copy is to make tmpasm compile independently */ -static char *strclone(const char *str) -{ - int l; - char *ret; - - if (str == NULL) - return NULL; - - l = strlen(str)+1; - ret = malloc(l); - memcpy(ret, str, l); - return ret; -} - - -#define TOP ctx->st - -static const char *kw_names[] = {"-", "if", "then", "else", "end", "foreach", "in", "switch", "case", "default", "nop", NULL }; - -static tmpasm_kw_t kw_lookup(const char *str) -{ - const char **k; - tmpasm_kw_t i; - -/* slow linear search is enough: we have only a few keywords */ - for(k = kw_names, i = KW_none; *k != NULL; k++,i++) - if (strcmp(*k, str) == 0) - return i; - return KW_none; -} - - -tmpasm_exec_t *code_new(tmpasm_kw_t kw) -{ - tmpasm_exec_t *c; - c = calloc(sizeof(tmpasm_exec_t), 1); - c->kw = kw; - return c; -} - -/*tmpasm_exec_t *code_end(tmpasm_exec_t *start) -{ - while(start->next != NULL) - start = start->next; - return start; -}*/ - -tmpasm_exec_t *code_append(tmpasm_t *ctx, tmpasm_kw_t kw) -{ - tmpasm_exec_t *c; -/* c = code_end(TOP->code);*/ - c = TOP->last_code; - if (TOP->last_code->kw != KW_NOP) { - c->next = code_new(kw); - return c->next; - } - c->kw = kw; - return c; -} - -static void error(tmpasm_t *ctx, char c, char *msg) -{ - fprintf(stderr, "error: %s at %d:%d\n", msg, ctx->line, ctx->col); - if (c != 0) - fprintf(stderr, " character last seen: %c\n", c); - ctx->dead = 1; -} - -static void push(tmpasm_t *ctx, tmpasm_kw_t kw, tmpasm_state_t st, tmpasm_exec_t *code) -{ - tmpasm_stack_t *new; - new = calloc(sizeof(tmpasm_stack_t), 1); - new->kw = kw; - new->state = st; - new->next = ctx->st; - new->last_code = code; - ctx->st = new; -} - -static void pop_(tmpasm_t *ctx, int chk_underfl) -{ - tmpasm_stack_t *old; - old = ctx->st; - ctx->st = old->next; - - /* stack underflow? */ - if (chk_underfl) { - if (TOP == NULL) { - error(ctx, 0, "Excess \"end\""); - TOP = old; - return; - } - } - if (old->argv != NULL) - free(old->argv); - if (old->argend != NULL) - free(old->argend); - if (old->arg_used != NULL) - free(old->arg_used); - if (old->arg_alloced != NULL) - free(old->arg_alloced); - free(old); -} - -static void pop(tmpasm_t *ctx) -{ - pop_(ctx, 1); -} - - -#define grow(arr, size) arr = realloc(arr, sizeof((arr)[0]) * size) - -static void arg_new(tmpasm_t *ctx, int is_addr) -{ - if (TOP->args_used >= TOP->args_alloced) { - TOP->args_alloced = TOP->args_alloced + 16; - grow(TOP->argv, TOP->args_alloced); - grow(TOP->argend, TOP->args_alloced); - grow(TOP->arg_alloced, TOP->args_alloced); - grow(TOP->arg_used, TOP->args_alloced); - } - - TOP->arg_alloced[TOP->args_used] = 64; - TOP->arg_used[TOP->args_used] = 0; - - TOP->argv[TOP->args_used] = malloc(TOP->arg_alloced[TOP->args_used]+sizeof(tmpasm_arg_t)); - TOP->argv[TOP->args_used]->is_addr = is_addr; - TOP->argv[TOP->args_used]->next = NULL; - TOP->argend[TOP->args_used] = TOP->argv[TOP->args_used]; - - TOP->args_used++; -} - - -static void arg_append(tmpasm_t *ctx, char c) -{ - int i = TOP->args_used - 1; - - if (TOP->arg_used[i] >= TOP->arg_alloced[i]) { - tmpasm_arg_t *prev, *last; - - /* since argend[i] is also in the ->next pointer of the previous item in a block chain, we need to look it up */ - for(prev = NULL, last = TOP->argv[i]; last->next != NULL; last = last->next) - prev = last; - - TOP->arg_alloced[i] += 64; - last = realloc(last, TOP->arg_alloced[i]+sizeof(tmpasm_arg_t)); - - if (prev == NULL) - TOP->argv[i] = last; - else - prev->next = last; - - TOP->argend[i] = last; - } - TOP->argend[i]->data[TOP->arg_used[i]] = c; - TOP->arg_used[i]++; -} - -static void arg_free(tmpasm_arg_t *a) -{ - tmpasm_arg_t *next; - if (a == NULL) - return; - next = a->next; - free(a); - if (next != NULL) - arg_free(next); -} - -static void arg_new_next(tmpasm_t *ctx, int is_addr) -{ - tmpasm_arg_t *a; - int id; - - arg_append(ctx, '\0'); - - id = TOP->args_used - 1; - assert(id>=0); - TOP->arg_alloced[id] = 64; - TOP->arg_used[id] = 0; - - a = malloc(TOP->arg_alloced[id]+sizeof(tmpasm_arg_t)); - strcpy(a->data, "QWERT"); - a->is_addr = is_addr; - a->next = NULL; - TOP->argend[id]->next = a; - TOP->argend[id] = a; -} - -static void arg_remove(tmpasm_t *ctx) -{ - assert(TOP->args_used == 1); - TOP->args_used = 0; - TOP->argv[0] = NULL; - TOP->argend[0] = NULL; - TOP->arg_alloced[0] = 0; - TOP->arg_used[0] = 0; -} - -static int arg_is_addr(tmpasm_arg_t *a) -{ - return (a->next == NULL) && (a->is_addr); -} - -static void arg_end(tmpasm_t *ctx, int cmd_ctx) -{ - tmpasm_arg_t *a; - arg_append(ctx, '\0'); - - a = TOP->argv[TOP->args_used-1]; - if (cmd_ctx) { - /* when argument ends in a command context (not in a block inline), we - may may need to switch back to command mode; example: after - the cond of an "if cond then"*/ - switch(TOP->kw) { - case KW_IF: - TOP->state = ST_PRECMD; - break; - case KW_FOREACH: - if (!arg_is_addr(a)) { - error(ctx, 0, "variable of a foreach must be an address"); - return; - } - TOP->last_code->payload.fc_foreach.loop_var = strclone(a->data); - arg_free(a); - arg_remove(ctx); - TOP->state = ST_PRECMD; - break; - case KW_IN: - /* pop will free the argv[] array, but not the elements so "a" is safe to use after this line */ - pop(ctx); - /* in foreach context, after the IN-data */ - TOP->last_code->payload.fc_foreach.data = a; - - /* we are in the body now, TOP is the foreach context, last_code is body */ - TOP->last_code->payload.fc_foreach.code_body = code_new(KW_NOP); - push(ctx, KW_none, ST_PRECMD, TOP->last_code->payload.fc_foreach.code_body); - break; - case KW_CASE: - ctx->st->next->last_code->payload.fc_switch.last->data = a; - arg_remove(ctx); - push(ctx, KW_none, ST_PRECMD, TOP->last_code); - break; - case KW_SWITCH: - TOP->last_code->payload.fc_switch.cond = a; - arg_remove(ctx); - TOP->state = ST_PRECMD; - break; - default: - TOP->state = ST_PREDATA; - } - } -} - - - -/* end of statement; update kw state for a composite control kw; for the rest - just call the lib */ -static void end_of_statement(tmpasm_t *ctx) -{ - switch(TOP->kw) { - case KW_none: - case KW_THEN: - case KW_ELSE: - case KW_CASE: - case KW_DEFAULT: - TOP->last_code->payload.instr.argc = TOP->args_used; - TOP->last_code->payload.instr.argv = TOP->argv; - TOP->argv = NULL; - free(TOP->argend); - TOP->argend = NULL; - TOP->args_used = 0; - TOP->args_alloced = 0; - break; - default: - /* don't mess with the payload */ - ; - } - TOP->state = ST_PRECMD; -} - -#define loc_update() \ - do { \ - TOP->last_code->line = TOP->kwline; \ - TOP->last_code->col = TOP->kwcol; \ - } while(0) - -static void got_kw(tmpasm_t *ctx, tmpasm_kw_t kw, int terminated) -{ - switch(kw) { - case KW_END: - /* then-else threads have their own subcontext within the if subcontext; end needs to pop the innermost subcontext before terminating the if context */ - if (TOP->kw == KW_IF) { - error(ctx, 0, "unexpected \"end\" in \"if\" - expected \"then\""); - goto bind_if_cond; - } - if ((TOP->kw == KW_ELSE) || (TOP->kw == KW_THEN)) - pop(ctx); - - - if (TOP->kw == KW_SWITCH) - TOP->kw = TOP->old_kw; - else { - pop(ctx); - - if ((TOP->kw == KW_CASE) || (TOP->kw == KW_DEFAULT)) - pop(ctx); - - } - TOP->state = ST_PRECMD; - - /* have to restore context keyword after these */ - if (TOP->kw == KW_FOREACH) - TOP->kw = TOP->old_kw; - - break; - case KW_IF: - if (terminated) { - error(ctx, 0, "unexpected end of if statement; expected a condition"); - return; - } - TOP->last_code = code_append(ctx, KW_IF); - TOP->last_code->payload.fc_if.code_then = code_new(KW_NOP); - TOP->last_code->payload.fc_if.code_else = code_new(KW_NOP); - loc_update(); - TOP->state = ST_PRECMD; - /* prepare for reading a condition */ - push(ctx, KW_IF, ST_PREDATA, TOP->last_code); - break; - case KW_THEN: - /* we are in an if context, right after reading a condition */ - if (TOP->kw != KW_IF) { - error(ctx, 0, "unexpected 'then' - must be in an 'if' after the condition"); - return; - } - bind_if_cond:; - TOP->last_code->payload.fc_if.cond = TOP->argv[0]; - loc_update(); - arg_remove(ctx); - push(ctx, KW_THEN, ST_PRECMD, TOP->last_code->payload.fc_if.code_then); - break; - case KW_ELSE: - /* we are in an if context, after and end */ - if (TOP->kw != KW_THEN) { - error(ctx, 0, "unexpected 'else' - must be in a 'then' block before an else"); - return; - } - pop(ctx); /* that was the then branch */ - push(ctx, KW_ELSE, ST_PRECMD, TOP->last_code->payload.fc_if.code_else); - break; - case KW_FOREACH: - if (terminated) { - error(ctx, 0, "unexpected end of if foreach statement; expected an address"); - return; - } - TOP->last_code = code_append(ctx, KW_FOREACH); - loc_update(); - TOP->state = ST_PREDATA; - TOP->old_kw = TOP->kw; - TOP->kw = KW_FOREACH; - break; - case KW_IN: - if (TOP->kw != KW_FOREACH) - error(ctx, 0, "unexpected \"in\"; should be after the address in foreach"); - else - push(ctx, KW_IN, ST_PREDATA, NULL); - break; - case KW_SWITCH: - if (terminated) { - error(ctx, 0, "unexpected end of if switch statement; expected a data"); - return; - } - TOP->last_code = code_append(ctx, KW_SWITCH); - TOP->state = ST_PREDATA; - TOP->old_kw = TOP->kw; - TOP->kw = KW_SWITCH; - loc_update(); - break; - case KW_CASE: - case KW_DEFAULT: - if (TOP->kw == KW_SWITCH) { - tmpasm_case_t *c; - c = malloc(sizeof(tmpasm_case_t)); - c->body = code_new(KW_NOP); - c->data = NULL; - c->next = NULL; - if (TOP->last_code->payload.fc_switch.last == NULL) { - TOP->last_code->payload.fc_switch.first = c; - TOP->last_code->payload.fc_switch.last = c; - } - else { - TOP->last_code->payload.fc_switch.last->next = c; - TOP->last_code->payload.fc_switch.last = c; - } - if (kw == KW_DEFAULT) { - push(ctx, KW_DEFAULT, ST_PRECMD, c->body); - push(ctx, KW_none, ST_PRECMD, c->body); - c->data = NULL; - } - else - push(ctx, KW_CASE, ST_PREDATA, c->body); - } - else - error(ctx, 0, "unexpected \"case\" or \"default\"; should be in a switch (is the last case terminated by an \"end\"?)"); - break; - default: - TOP->last_code = code_append(ctx, KW_none); - TOP->last_code->payload.instr.call_name = strclone(TOP->cmd_buff); - if (TOP->last_code->payload.instr.call_name != NULL) { - TOP->last_code->payload.instr.call = ctx->cb->resolve(ctx, TOP->last_code->payload.instr.call_name); - loc_update(); - } - if (terminated) - TOP->state = ST_PRECMD; - else - TOP->state = ST_PREDATA; - } -} - -static void comment_start(tmpasm_t *ctx) -{ - push(ctx, KW_none, ST_COMMENT, NULL); -} - -int tmpasm_gotchar(tmpasm_t *ctx, char c) -{ - if (ctx->dead) - return -1; - switch(TOP->state) { - case ST_COMMENT: - if ((c == '\n') || (c == '\r')) { - pop(ctx); - if (TOP->state == ST_PREDATA) - end_of_statement(ctx); - } - break; - case ST_PRECMD: - if (c == '#') { - comment_start(ctx); - break; - } - if (is_space(c) || is_sep(c)) - break; - TOP->cmdi = 0; - TOP->state = ST_CMD; - TOP->kwline = ctx->line; - TOP->kwcol = ctx->col; - /* fall thru */ - case ST_CMD: - /* end of command or keyword */ - if (is_space(c) || is_sep(c)) { - TOP->cmd_buff[TOP->cmdi] = '\0'; - got_kw(ctx, kw_lookup(TOP->cmd_buff), is_sep(c)); - } - else { - TOP->cmd_buff[TOP->cmdi] = c; - TOP->cmdi++; - if (TOP->cmdi >= sizeof(TOP->cmd_buff)) - error(ctx, 0, "keyword or instruction name is too long"); - } - break; - case ST_PREDATA: - if (c == '#') { - comment_start(ctx); - break; - } - if (is_space(c)) - break; - if (is_sep(c)) - end_of_statement(ctx); - else if (c == '{') { - TOP->state = ST_STRING; - arg_new(ctx, 0); - } - else if (c == '[') { - TOP->state = ST_PREBLOCKSEP; - arg_new(ctx, 0); - } - else if (is_addr(c)) { - TOP->state = ST_ADDRESS; - arg_new(ctx, 1); - arg_append(ctx, c); - } - else - error(ctx, c, "unexpected character; expected '{' for starting a string or an address"); - break; - case ST_PREBLOCKSEP: - TOP->block_sep = c; - TOP->state = ST_BLOCK; - break; - case ST_BLOCK: - if (c == TOP->block_sep) - TOP->state = ST_BLOCKSEP; - else - arg_append(ctx, c); - break; - case ST_BLOCKSEP: - if (c != ']') { - arg_new_next(ctx, 1); - arg_append(ctx, c); - TOP->state = ST_BLOCK_INLINE; - } - else - arg_end(ctx, 1); - break; - case ST_BLOCK_INLINE: - if (c == TOP->block_sep) { - arg_new_next(ctx, 0); - TOP->state = ST_BLOCK; - } - else - arg_append(ctx, c); - break; - case ST_STRING: - if (c == '}') - arg_end(ctx, 1); - else if (c == '\\') - TOP->state = ST_STRING_ESCAPE; - else - arg_append(ctx, c); - break; - case ST_STRING_ESCAPE: - { - char co; - switch(c) { - case 'n': co = '\n'; break; - case 'r': co = '\r'; break; - case 't': co = '\t'; break; - case '\\': co = '\\'; break; - case 'o': co = '{'; break; - case 'c': co = '}'; break; - default: co = c; - } - arg_append(ctx, co); - TOP->state = ST_STRING; - } - break; - case ST_ADDRESS: - if (is_space(c)) - arg_end(ctx, 1); - else if (is_sep(c)) { - arg_end(ctx, 1); - end_of_statement(ctx); - } - else if (is_addr(c)) - arg_append(ctx, c); - else - error(ctx, c, "unexpected character; expected next character of the address"); - break; - } - if (c == '\n') { - ctx->line++; - ctx->col = 1; - } - else - ctx->col++; - return 0; -} - -tmpasm_t *tmpasm_init(const tmpasm_cb_t *cb) -{ - tmpasm_t *ctx; - ctx = calloc(sizeof(tmpasm_t), 1); - ctx->line = 1; - ctx->col = 1; - ctx->code = code_new(KW_NOP); - ctx->cb = cb; - push(ctx, KW_none, ST_PRECMD, ctx->code); - return ctx; -} - -static void free_exec(tmpasm_exec_t *e) -{ - int n; - tmpasm_case_t *c, *c_next; - tmpasm_exec_t *e_next; - - for(; e != NULL; e = e_next) { - e_next = e->next; - switch(e->kw) { - case KW_none: - if (e->payload.instr.call_name != NULL) - free(e->payload.instr.call_name); - for(n = 0; n < e->payload.instr.argc; n++) - arg_free(e->payload.instr.argv[n]); - free(e->payload.instr.argv); - break; - case KW_IF: - arg_free(e->payload.fc_if.cond); - free_exec(e->payload.fc_if.code_then); - free_exec(e->payload.fc_if.code_else); - break; - case KW_FOREACH: - free(e->payload.fc_foreach.loop_var); - arg_free(e->payload.fc_foreach.data); - free_exec(e->payload.fc_foreach.code_body); - break; - case KW_SWITCH: - arg_free(e->payload.fc_switch.cond); - for(c = e->payload.fc_switch.first; c != NULL; c = c_next) { - c_next = c->next; - if (c->data != NULL) - arg_free(c->data); - free_exec(c->body); - free(c); - } - break; - default:; - } - free(e); - } -} - -void tmpasm_uninit(tmpasm_t *ctx) -{ - free_exec(ctx->code); - while (ctx->st != NULL) - pop_(ctx, 0); - if (ctx->runtime_error_data != NULL) - free(ctx->runtime_error_data); - free(ctx); -} - -/****************** runtime ********************/ - -static const char *tmpasm_runtime_error_fmts[] = { - "success %s", - "variable '%s' does not exist", - "empty argument (broken AST)%s", - "compilation error: control block without an \"end\"; premature end of script%s", - "attempt to call unresolved instruction '%s'", - NULL -}; - -void tmpasm_runtime_error(tmpasm_t *ctx, int code, const char *data) -{ - ctx->runtime_error = code; - if (ctx->runtime_error_data != NULL) - free(ctx->runtime_error_data); - ctx->runtime_error_data = strclone(data); - if (ctx->executing != NULL) { - ctx->runtime_error_line = ctx->executing->line; - ctx->runtime_error_col = ctx->executing->col; - } - else { - ctx->runtime_error_line = 0; - ctx->runtime_error_col = 0; - } -} - -const char *tmpasm_runtime_error_fmt(tmpasm_t *ctx) -{ - if (ctx->runtime_error == 0) - return NULL; - if ((ctx->runtime_error < 0) && (ctx->cb->runtime_error_fmt != NULL)) { - const char *fmt; - fmt = ctx->cb->runtime_error_fmt(ctx); - if (fmt != NULL) - return fmt; - } - if ((ctx->runtime_error < 0) || ((size_t)ctx->runtime_error > (sizeof(tmpasm_runtime_error_fmts)/sizeof(char *)))) - return "invalid error code %s"; - return tmpasm_runtime_error_fmts[ctx->runtime_error]; -} - -char *tmpasm_arg2str(tmpasm_t *ctx, tmpasm_arg_t *a, int keep_addr) -{ - if (a == NULL) { - tmpasm_runtime_error(ctx, 2, NULL); - return strclone(""); - } - if (a->next != NULL) { - /* block mode */ - int alloced = 0, used = 0; - char *s = NULL; - const char *i; - - for(;a != NULL; a = a->next) { - int l; - if (a->is_addr) { - i = ctx->cb->get(ctx, a->data); - if (i == NULL) { - i = ""; - tmpasm_runtime_error(ctx, 1, strclone(a->data)); - } - } - else - i = a->data; - l = strlen(i); - if (used + l >= alloced) { - alloced = used + l + 256; - s = realloc(s, alloced); - } - memcpy(s+used, i, l); - used += l; - } - s[used] = '\0'; - return s; - } - - /* non-block */ - if (a->is_addr) { - const char *i; - if (keep_addr) - i = a->data; - else - i = ctx->cb->get(ctx, a->data); - if (i == NULL) { - i = ""; - tmpasm_runtime_error(ctx, 1, strclone(a->data)); - } - return strclone(i); - } - - return strclone(a->data); -} - -static void execute(tmpasm_t *ctx, tmpasm_exec_t *e) -{ - tmpasm_case_t *c; - void *state; - char *cond, *list; - const char *i; - - while((e != NULL) && (ctx->runtime_error == 0) && (ctx->halt == 0)) { - ctx->executing = e; - switch(e->kw) { - case KW_none: - if (e->payload.instr.call != NULL) - e->payload.instr.call(ctx, e->payload.instr.call_name, e->payload.instr.argc, e->payload.instr.argv); - else - tmpasm_runtime_error(ctx, 4, e->payload.instr.call_name); - break; - case KW_IF: - cond = tmpasm_arg2str(ctx, e->payload.fc_if.cond, 0); - if (ctx->cb->is_true(ctx, cond)) - execute(ctx, e->payload.fc_if.code_then); - else - execute(ctx, e->payload.fc_if.code_else); - free(cond); - break; - case KW_FOREACH: - list = tmpasm_arg2str(ctx, e->payload.fc_foreach.data, 0); - for(i = ctx->cb->first(ctx, &state, list); i != NULL; i = ctx->cb->next(ctx, &state)) { - ctx->cb->set(ctx, e->payload.fc_foreach.loop_var, i); - execute(ctx, e->payload.fc_foreach.code_body); - } - free(list); - break; - case KW_SWITCH: - cond = tmpasm_arg2str(ctx, e->payload.fc_switch.cond, 0); - for(c = e->payload.fc_switch.first; c != NULL; c = c->next) { - char *cv = NULL; - if (c->data != NULL) - cv = tmpasm_arg2str(ctx, c->data, 0); - if ((c->data == NULL) || (ctx->cb->match(ctx, cond, cv))) { - execute(ctx, c->body); - if (cv != NULL) - free(cv); - break; - } - if (cv != NULL) - free(cv); - } - free(cond); - break; - default:; - } - e = e->next; - } -} - -void tmpasm_execute(tmpasm_t *ctx) -{ - if (TOP->next != NULL) { - ctx->executing = TOP->next->last_code; - tmpasm_runtime_error(ctx, 3, NULL); - return; - } - if ((TOP->state != ST_PRECMD) || (TOP->kw != KW_none)) { - ctx->executing = TOP->last_code; - tmpasm_runtime_error(ctx, 3, NULL); - return; - } - ctx->halt = 0; - ctx->runtime_error = 0; - if (ctx->runtime_error_data != NULL) { - free(ctx->runtime_error_data); - ctx->runtime_error_data = NULL; - } - if (ctx->cb->preexec != NULL) - ctx->cb->preexec(ctx); - execute(ctx, ctx->code); - if (ctx->cb->postexec != NULL) - ctx->cb->postexec(ctx); -} - diff --git a/scconfig/src/tmpasm/.svn/pristine/a4/a441f29b8d149b4adf9e62b97658e54d65caa6d1.svn-base b/scconfig/src/tmpasm/.svn/pristine/a4/a441f29b8d149b4adf9e62b97658e54d65caa6d1.svn-base deleted file mode 100644 index 34646b1e..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/a4/a441f29b8d149b4adf9e62b97658e54d65caa6d1.svn-base +++ /dev/null @@ -1,6 +0,0 @@ -pritn [at 1:1] - arg: {foo} -switch {cond} [at 2:1] - case {1} - print [at 3:11] - arg: {foo} diff --git a/scconfig/src/tmpasm/.svn/pristine/a4/a4811f6bd339eca0f3f76c45b6c43dd9496bd8bc.svn-base b/scconfig/src/tmpasm/.svn/pristine/a4/a4811f6bd339eca0f3f76c45b6c43dd9496bd8bc.svn-base deleted file mode 100644 index a41fe0a1..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/a4/a4811f6bd339eca0f3f76c45b6c43dd9496bd8bc.svn-base +++ /dev/null @@ -1,16 +0,0 @@ -CFLAGS = -Wall -g \ - -I../default -DTMPASM_TESTER \ - -tester: tester.o tmpasm.o debug.o tmpasm_scconfig.o openfiles.o \ - ../default/db.o ../default/ht.o ../default/str.o ../default/log.o \ - ../default/regex.o ../default/lib_uniqinc.o - -tmpasm.o: tmpasm.c tmpasm.h - -test: regression/Makefile - cd regression && make - -regression/Makefile: regression/Makefile.in tester - ./tester -e < regression/Makefile.in > regression/Makefile - -debug.o: debug.c debug.h tmpasm.h diff --git a/scconfig/src/tmpasm/.svn/pristine/a7/a77d8f339b11d5e5b4d1dfe616d26b47affbc5ac.svn-base b/scconfig/src/tmpasm/.svn/pristine/a7/a77d8f339b11d5e5b4d1dfe616d26b47affbc5ac.svn-base deleted file mode 100644 index ee3f4e2c..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/a7/a77d8f339b11d5e5b4d1dfe616d26b47affbc5ac.svn-base +++ /dev/null @@ -1,31 +0,0 @@ -# The following regex sub utils are scconfig specific. - -# Regex: substitute the first match of a pattern with str in a variable: -# sub address pattern str - -put myvar {Hello world!\n} -sub myvar {l} {2} -print myvar - -# Address must resolve to an existing variable, pattern and str are data; -# this means address can be a string that holds a variable name, it's the -# same as if it was an addreess: -sub {myvar} {l} {3} -print myvar - -# Or it can be a block, which makes indirect addressing possible: -# in [@@pointer@@] the @pointer@ part will be substituted with -# the value of pointer, which is "myvar". -put pointer {myvar} -sub [@@pointer@@] {l} {4} -print myvar - -# Since pattern and str are also data, address and blocks work there as well -# (but this is _not_ a regex backreference): -put punctuation {[!?.]} -sub [@@pointer@@] punctuation [@ PUNCT:@punctuation@@] -print myvar - -# gsub does the same, but substutites all matches, not only the first: -gsub [@@pointer@@] {o} {_0_} -print myvar diff --git a/scconfig/src/tmpasm/.svn/pristine/b5/b576b1f3c653d308cbbd4cb16adfe1d70472caa6.svn-base b/scconfig/src/tmpasm/.svn/pristine/b5/b576b1f3c653d308cbbd4cb16adfe1d70472caa6.svn-base deleted file mode 100644 index 9f19f02a..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/b5/b576b1f3c653d308cbbd4cb16adfe1d70472caa6.svn-base +++ /dev/null @@ -1,36 +0,0 @@ -put [at 4:1] - arg: myvar - arg: {Hello world! -} -print [at 7:1] - arg: myvar -print [at 11:1] - arg: {Hello universe! } - arg: myvar -put [at 15:1] - arg: str - arg: {cats raining from the sky} -put [at 16:1] - arg: tmp - arg: str -print [at 17:1] - arg: str - arg: {==} - arg: tmp - arg: { -} -print [at 21:1] - arg: {safe get: '} - arg: ?nonexist - arg: {' -} -print [at 25:1] - arg: {exists (no): } - arg: &nonexist - arg: { -} -print [at 26:1] - arg: {exists (yes): } - arg: &myvar - arg: { -} diff --git a/scconfig/src/tmpasm/.svn/pristine/b6/b66683135874f937b71acdcab2f204a84645436e.svn-base b/scconfig/src/tmpasm/.svn/pristine/b6/b66683135874f937b71acdcab2f204a84645436e.svn-base deleted file mode 100644 index 5a7b73e8..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/b6/b66683135874f937b71acdcab2f204a84645436e.svn-base +++ /dev/null @@ -1,57 +0,0 @@ -# list of tests -put tests [@ - Tutor01_hello - Tutor02_vars - Tutor03_blocks - Tutor04_if - Tutor05_switch - Tutor06_foreach - Tutor07_sub - Tutor08_uniq - Tutor09_ui - Tutor10_include_redir - Tutor11_missing - Tutor12_halt - comment - foreach - if - switch - test - then - append - order - err_if_end - err_if_else - err_excess_end - err_switch_end - err_switch_nocond - err_no_end -@] - -uniq tests - -put test_diffs tests -gsub test_diffs {[ \t\r\n]+} { } -gsub test_diffs {\\>} {.diff} -# TODO: replace this with wrap -sub test_diffs {^ *} {} -sub test_diffs { *$} {} - -print [@### PLEASE DO NOT EDIT THIS FILE, it has been generated from Makefile.in. ### - -TESTER=../tester - -all: @test_diffs@ - -# Explicit test rules -@] - -foreach test in tests -print [@ -@test@.out: @test@.gasm $(TESTER) Makefile - $(TESTER) < @test@.gasm > @test@.out 2>&1 - -@test@.diff: @test@.ref @test@.out - diff -u @test@.ref @test@.out -@] -end diff --git a/scconfig/src/tmpasm/.svn/pristine/b6/b681a51d98d1237e512ad08dc98979206c78d8bb.svn-base b/scconfig/src/tmpasm/.svn/pristine/b6/b681a51d98d1237e512ad08dc98979206c78d8bb.svn-base deleted file mode 100644 index 2873077c..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/b6/b681a51d98d1237e512ad08dc98979206c78d8bb.svn-base +++ /dev/null @@ -1,11 +0,0 @@ -put [at 9:1] - arg: myvar - arg: {! -} -report [at 10:1] - arg: {hello } - arg: {world} - arg: myvar -report [at 11:1] - arg: [~hello world~myvar~~] -abort [at 15:1] diff --git a/scconfig/src/tmpasm/.svn/pristine/bc/bc6b66420ab4b66a2c54a0f169eeac78f0edeb67.svn-base b/scconfig/src/tmpasm/.svn/pristine/bc/bc6b66420ab4b66a2c54a0f169eeac78f0edeb67.svn-base deleted file mode 100644 index 680e6c10..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/bc/bc6b66420ab4b66a2c54a0f169eeac78f0edeb67.svn-base +++ /dev/null @@ -1,12 +0,0 @@ -if cnd [at 2:8] -then: - print [at 3:2] - arg: a1 - arg: a2 - arg: a3 -else: - (NOP) -print [at 6:1] - arg: a1 - arg: a2 - arg: a3 diff --git a/scconfig/src/tmpasm/.svn/pristine/c1/c142ebdbe0c314b73848e60f033e0000a9f02d99.svn-base b/scconfig/src/tmpasm/.svn/pristine/c1/c142ebdbe0c314b73848e60f033e0000a9f02d99.svn-base deleted file mode 100644 index 5b3d0931..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/c1/c142ebdbe0c314b73848e60f033e0000a9f02d99.svn-base +++ /dev/null @@ -1,64 +0,0 @@ -# The following string util is scconfig specific. - -# Uniq: filter a list of words and remove duplicate items. This instruction -# is useful for using text nodes as lists. -# The simplest syntax is "uniq address" which will do the filtering on -# the content of a database address. The default separator is \n -put list [@this -is -a -list -of -words, -a -list -of -words. -@] -print {original:\n} list {\n} -uniq list -print {uniq:\n} list {\n} - -# If the original list needs to be left intact, the alternative syntax is -# "uniq dest-addr src-addr": -put foo [@this -foo -is -a -this -foo -@] -uniq tmp foo -print {original:\n} foo {\nuniq:\n} tmp {\n} - -# Note: the algorithm of uniq is slow, and will not be efficient for very long -# lists. Uniq preserves the order of words (by their first appearance). - -# Sortuniq performs the same action, except it also orders the list using -# qsort() (so it is even slower on big lists). -sortuniq tmp foo -print {\nsortuniq:\n} tmp {\n} - - -# A typical use case is having #defines and #includes on a list; #defines -# should end up on the top, but order of #incldues should be preserved, so -# sortuniq is not an option. When uniq is called with more than 2 argument,s -# the extra arguments specify group regexps; the input is first organized into -# groups then uniq is ran on these groups. Anything that doesn't match the -# groups listed are put in a "misc" group that ends up as the last group. -put list [@#define foo -#include "foo20.h" -#include "foo10.h" -/* misc1 */ -#define bar -#include "bar1.h" -#include "bar2.h" -/* misc2 */ -@] - -# set input field separator to \n so uniq is splitting by lines, not by -# words -put /tmpasm/IFS {\n} - -uniq tmp list {^#define} {^#include} -print {original:\n} list {\ngrouped uniq:\n} tmp {\n} diff --git a/scconfig/src/tmpasm/.svn/pristine/c1/c17241d058f06952676d980b083b47fd5aae340f.svn-base b/scconfig/src/tmpasm/.svn/pristine/c1/c17241d058f06952676d980b083b47fd5aae340f.svn-base deleted file mode 100644 index 19f4f47f..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/c1/c17241d058f06952676d980b083b47fd5aae340f.svn-base +++ /dev/null @@ -1,10 +0,0 @@ -put a 1 -if a then - if b then - print {then-then} - else - print {then-else} - end -else - print {else} -end diff --git a/scconfig/src/tmpasm/.svn/pristine/c5/c591146acf0f8030239bd1363613513d18e25089.svn-base b/scconfig/src/tmpasm/.svn/pristine/c5/c591146acf0f8030239bd1363613513d18e25089.svn-base deleted file mode 100644 index 8cc2e5e6..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/c5/c591146acf0f8030239bd1363613513d18e25089.svn-base +++ /dev/null @@ -1,62 +0,0 @@ -put [at 2:1] - arg: /local/cflags - arg: {-std=c99 -Wall} -put [at 3:1] - arg: /local/ldflags - arg: {-lm} -put [at 4:1] - arg: /local/objs - arg: {main.o foo.o bar.o} -if /local/debug [at 7:17] -then: - append [at 8:2] - arg: /local/cflags - arg: {-g} -else: - append [at 10:2] - arg: /local/cflags - arg: {-O2} -isempty [at 14:1] - arg: /local/r - arg: /local/somelib -invert [at 15:1] - arg: /local/r -if /local/r [at 16:13] -then: - append [at 17:2] - arg: /local/cflags - arg: { -I/usr/include/somelib} - append [at 18:2] - arg: /local/ldflags - arg: { -lsomelib} -else: - (NOP) -print [at 22:1] - arg: [~ -# Makefile generated by scconfig - DO NOT EDIT - please edit Makefile.in -CFLAGS=~/local/cflags~ -LDFLAGS=~/local/ldflags~ -OBJS=~/local/objs~ - -all: main - -main: $(OBJS) - $(CC) $(LDFLAGS) - -~] -foreach /local/o in /local/objs [at 38:1] - put [at 39:2] - arg: /local/c - arg: /local/o - sub [at 40:2] - arg: /local/c - arg: {.o$} - arg: {.c} - print [at 41:2] - arg: [~ -~/local/o~: ~/local/c~ - $(CC) -c $(CFLAGS) ~/local/c~ -o ~/local/o~ - ~] -print [at 47:1] - arg: {#end -} diff --git a/scconfig/src/tmpasm/.svn/pristine/ca/ca50ae29403c0f85f37b796523c832ac8ac23cec.svn-base b/scconfig/src/tmpasm/.svn/pristine/ca/ca50ae29403c0f85f37b796523c832ac8ac23cec.svn-base deleted file mode 100644 index 3acbe6d0..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/ca/ca50ae29403c0f85f37b796523c832ac8ac23cec.svn-base +++ /dev/null @@ -1,2 +0,0 @@ -if v -end diff --git a/scconfig/src/tmpasm/.svn/pristine/cd/cd3e0bf01501b617f7f7fca038bf99f382079d39.svn-base b/scconfig/src/tmpasm/.svn/pristine/cd/cd3e0bf01501b617f7f7fca038bf99f382079d39.svn-base deleted file mode 100644 index c907351d..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/cd/cd3e0bf01501b617f7f7fca038bf99f382079d39.svn-base +++ /dev/null @@ -1,3 +0,0 @@ -print data1 # this is a comment; until the end of this line -print data2 # this shall be a second print - diff --git a/scconfig/src/tmpasm/.svn/pristine/d2/d2e549495e1cd5ba437681f1475a78bef271ace9.svn-base b/scconfig/src/tmpasm/.svn/pristine/d2/d2e549495e1cd5ba437681f1475a78bef271ace9.svn-base deleted file mode 100644 index a31b122d..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/d2/d2e549495e1cd5ba437681f1475a78bef271ace9.svn-base +++ /dev/null @@ -1,12 +0,0 @@ -- regression test syntax errors and improve syntax error reporting - - switch: - - data instead of case - - multiple defaults - - deafult must be at end of the list - - case out of switch - - default out of switch - - forarch -- tutorial - - append -- [[]] eval? what's the output? -> generate and include scripts (may need mktemp binding) -- update docs diff --git a/scconfig/src/tmpasm/.svn/pristine/d5/d5c3a6577644c6764554d8835a61604851169492.svn-base b/scconfig/src/tmpasm/.svn/pristine/d5/d5c3a6577644c6764554d8835a61604851169492.svn-base deleted file mode 100644 index e1d68d18..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/d5/d5c3a6577644c6764554d8835a61604851169492.svn-base +++ /dev/null @@ -1,4 +0,0 @@ -print [at 1:1] - arg: data1 -print [at 2:1] - arg: data2 diff --git a/scconfig/src/tmpasm/.svn/pristine/d7/d715546e50c7486b6d01899310dc782d5304d7f9.svn-base b/scconfig/src/tmpasm/.svn/pristine/d7/d715546e50c7486b6d01899310dc782d5304d7f9.svn-base deleted file mode 100644 index 5bfb6d32..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/d7/d715546e50c7486b6d01899310dc782d5304d7f9.svn-base +++ /dev/null @@ -1,657 +0,0 @@ -#include -#include -#include -#include "tmpasm.h" -#include "db.h" -#include "regex.h" -#include "openfiles.h" -#include "libs.h" -#include "tmpasm_scconfig.h" -#include "log.h" -#include "regex.h" - -#ifndef TMPASM_PATH -#define TMPASM_PATH "/tmpasm" -#endif - -#ifndef IFS_PATH -#define IFS_PATH TMPASM_PATH "/IFS" -#endif - -#ifndef IFS_DEFAULT -#define IFS_DEFAULT " \t\r\n" -#endif - -#ifndef OFS_PATH -#define OFS_PATH TMPASM_PATH "/OFS" -#endif - -#ifndef OFS_DEFAULT -#define OFS_DEFAULT "\n" -#endif - -typedef struct scc_s { - openfiles_t ofl; - FILE *fout, *default_fout; - const char *cwd; -} scc_t; - -static const char *scc_runtime_error_fmts[] = { - /* -0 */ "success scc %s", - /* -1 */ "\"put\" requires exactly two arguments (got %s)", - /* -2 */ "not enough arguments for sub; should be \"sub node pattern str\"%s", - /* -3 */ "regex syntax error: %s", - /* -4 */ "not enough arguments for uniq; should be \"uniq destnode\" or \"uniq destnode src\"%s", - /* -5 */ "redir: too many arguments%s", - /* -6 */ "redir: can't open %s", - /* -7 */ "exiting due to a previous runtime error occurred in included file %s", - /* -8 */ "can't include '%s': can't open file", - /* -9 */ "\"put\" requires two or three arguments (got %s)", - /* -10 */ "\"order\" requires 4 or 5 arguments: \"order destnode word before|after word\" or \"order destnode src word before|after word\"", - /* -11 */ "\"uniq\" got too many grouping regular expressions", - NULL -}; - -static int print_runtime_error(tmpasm_t *ctx, const char *ifn) -{ - if (ctx->runtime_error != 0) { - const char *fmt = tmpasm_runtime_error_fmt(ctx); - fprintf(stderr, "Runtime error at %s %d:%d: ", ifn, ctx->runtime_error_line, ctx->runtime_error_col); - fprintf(stderr, fmt, (ctx->runtime_error_data == NULL ? "" : ctx->runtime_error_data)); - fprintf(stderr, "\n"); - return -1; - } - return 0; -} - -/* allocate and build a full path using ud->cwd and fn */ -static char *scc_path(scc_t *ud, const char *fn) -{ - if (ud->cwd == NULL) - return strclone(fn); - return str_concat("", ud->cwd, "/", fn, NULL); -} - -/******** db binding ********/ - -static const char *scc_get(tmpasm_t *ctx, const char *addr) -{ - (void) ctx; /* not used */ - - if (*addr == '&') { /* return whether exists */ - if (get(addr+1) != NULL) - return strue; - return sfalse; - } - - if (*addr == '?') { /* safe get: return "" instead of NULL to avoid runtime error */ - const char *res = get(addr+1); - if (res == NULL) - return ""; - return res; - } - return get(addr); -} - -static void scc_set(tmpasm_t *ctx, const char *addr, const char *data) -{ - (void) ctx; /* not used */ - put(addr, data); -} - -static int scc_is_true(tmpasm_t *ctx, const char *data) -{ - (void) ctx; /* not used */ - return ((strcmp(data, "1") == 0) || istrue(data)); -} - -static int scc_match(tmpasm_t *ctx, const char *str, const char *pat) -{ - (void) ctx; /* not used */ - re_comp(pat); - return re_exec(str); -} - -static const char *scc_ifs(tmpasm_t *ctx) -{ - const char *ifs = get(IFS_PATH); - (void) ctx; /* not used */ - if (ifs == NULL) - return IFS_DEFAULT; - return ifs; -} - -static const char *scc_ofs(tmpasm_t *ctx) -{ - const char *ofs = get(OFS_PATH); - (void) ctx; /* not used */ - if (ofs == NULL) - return OFS_DEFAULT; - return ofs; -} - -static const char *scc_next(tmpasm_t *ctx, void **state) -{ - char **s = (char **)state; - char *start; - const char *IFS; - - IFS = scc_ifs(ctx); - - /* strip leading whitespace */ - while(chr_inset(**s, IFS)) (*s)++; - - /* at the end of the string, no more tokens */ - if (**s == '\0') - return NULL; - - start = *s; - - /* skip non-whitespace */ - while(!(chr_inset(**s, IFS)) && (**s != '\0')) (*s)++; - - if (**s != '\0') { - **s = '\0'; - (*s)++; - } - return start; -} - - -static const char *scc_first(tmpasm_t *ctx, void **state, char *list) -{ - *state = list; - - return scc_next(ctx, state); -} - - -/******** instructions ********/ -static void instr_put(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - char *addr, *val; - (void) iname; /* not used */ - if (argc != 2) { - char str[16]; - sprintf(str, "%d", argc); - tmpasm_runtime_error(ctx, -1, str); - return; - } - addr = tmpasm_arg2str(ctx, argv[0], 1); - val = tmpasm_arg2str(ctx, argv[1], 0); - if (*addr != '\0') - put(addr, val); - free(addr); - free(val); -} - -static void instr_resolve(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - char *dst, *srca; - const char *src; - (void) iname; /* not used */ - if (argc != 2) { - char str[16]; - sprintf(str, "%d", argc); - tmpasm_runtime_error(ctx, -1, str); - return; - } - - dst = tmpasm_arg2str(ctx, argv[0], 1); - srca = tmpasm_arg2str(ctx, argv[1], 0); - src = scc_get(ctx, srca); - if (*dst != '\0') - put(dst, src); - free(dst); - free(srca); -} - - -static void instr_append(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - char *addr, *val; - char *sep; - (void) iname; /* not used */ - - if ((argc < 2) || (argc > 3)) { - char str[16]; - sprintf(str, "%d", argc); - tmpasm_runtime_error(ctx, -9, str); - return; - } - addr = tmpasm_arg2str(ctx, argv[0], 1); - val = tmpasm_arg2str(ctx, argv[1], 0); - if (argc >= 3) - sep = tmpasm_arg2str(ctx, argv[2], 0); - else - sep = strclone(scc_ofs(ctx)); - if (*addr != '\0') { - append(addr, sep); - append(addr, val); - } - free(addr); - free(val); - free(sep); -} - -static void instr_report(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - int n; - (void) iname; /* not used */ - for(n = 0; n < argc; n++) { - char *val; - val = tmpasm_arg2str(ctx, argv[n], 0); - report("%s", val); - free(val); - } -} - -static void instr_abort(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - scc_t *ud = (scc_t *)ctx->user_data; - (void) iname; /* not used */ - (void) argc; /* not used */ - (void) argv; /* not used */ - report("Abort requested by template.\n"); - if (ud->fout) fflush(ud->fout); - fflush(stdout); - fflush(stderr); - abort(); -} - -static void instr_halt(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - (void) iname; /* not used */ - (void) argc; /* not used */ - (void) argv; /* not used */ - ctx->halt = 1; -} - -static void instr_sub(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - char *node, *pat, *err, *csub, *buff, *end; - const char *start; - const char *val; - int score, slen, global; - - if (argc < 3) { - tmpasm_runtime_error(ctx, -2, NULL); - return; - } - - node = tmpasm_arg2str(ctx, argv[0], 1); - pat = tmpasm_arg2str(ctx, argv[1], 0); - csub = tmpasm_arg2str(ctx, argv[2], 0); - global = (*iname == 'g'); - - val = get(node); - if (val == NULL) - val=""; - err = re_comp(pat); - if (err != NULL) { - tmpasm_runtime_error(ctx, -3, err); - return; - } - - slen = strlen(csub); - if (global) - buff = malloc(strlen(val)*(slen+3)+32); /* big enough for worst case, when every letter and $ and ^ are replaced with sub */ - else - buff = malloc(strlen(val)+slen+32); /* only one replacement will be done */ - strcpy(buff, val); - - start = buff; - do { - score = re_exec(start); - if (score == 0) - break; - end = buff + strlen(buff); - if (eopat[0] - bopat[0] != slen) { - int mlen = end - eopat[0]+1; - if (mlen > 0) - memmove((char *)(bopat[0] + slen), eopat[0], mlen); - } - memcpy((char *)bopat[0], csub, slen); - start = bopat[0] + slen; - } while(global); - - buff = realloc(buff, strlen(buff)+1); - put(node, buff); - free(buff); - free(node); - free(pat); - free(csub); -} - -#define UNIQ_ERE_MAX 16 -static char *uniq_eres[UNIQ_ERE_MAX]; - -static void instr_uniq(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - char *node, *strlist, *buff; - int eres = 0; - - if (argc < 1) { - tmpasm_runtime_error(ctx, -4, NULL); - return; - } - node = tmpasm_arg2str(ctx, argv[0], 1); - if (argc > 1) { - int offs = 2; - - strlist = tmpasm_arg2str(ctx, argv[1], 0); - if ((argc-offs) >= UNIQ_ERE_MAX) { - tmpasm_runtime_error(ctx, -11, NULL); - return; - } - while(argc > offs) - uniq_eres[eres++] = tmpasm_arg2str(ctx, argv[offs++], 0); - if (eres > 0) - uniq_eres[eres++] = ".*"; - } - else - strlist = strclone(get(node)); - buff = uniq_inc_str(strlist, scc_ifs(ctx), scc_ofs(ctx), (*iname == 's'), eres, uniq_eres); - put(node, buff); - free(buff); - free(strlist); - free(node); -} - -static void instr_order(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - char *node, *strlist, *buff, *w1, *dirs, *w2; - int offs, dir; - - if ((argc != 4) && (argc != 5)) { - tmpasm_runtime_error(ctx, -10, NULL); - return; - } - node = tmpasm_arg2str(ctx, argv[0], 1); - if (argc > 4) { - strlist = tmpasm_arg2str(ctx, argv[1], 0); - offs = 2; - } - else { - strlist = strclone(get(node)); - offs = 1; - } - - w1 = tmpasm_arg2str(ctx, argv[offs], 0); - dirs = tmpasm_arg2str(ctx, argv[offs+1], 0); - w2 = tmpasm_arg2str(ctx, argv[offs+2], 0); - - if (strcmp(dirs, "before") == 0) - dir = -1; - else if (strcmp(dirs, "after") == 0) - dir = +1; - else { - tmpasm_runtime_error(ctx, -10, NULL); - return; - } - - buff = order_inc_str(strlist, scc_ifs(ctx), w1, dir, w2); - put(node, buff); - free(buff); - free(strlist); - free(node); -} - -static void instr_print(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - int n; - scc_t *ud = (scc_t *)ctx->user_data; - (void) iname; /* not used */ - - for(n = 0; n < argc; n++) { - char *val; - val = tmpasm_arg2str(ctx, argv[n], 0); - fprintf(ud->fout, "%s", val); - free(val); - } -} - -static void instr_print_ternary(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - char *s_cond, *s; - scc_t *ud = (scc_t *)ctx->user_data; - (void) iname; /* not used */ - - if ((argc < 2) || (argc > 3)) { - char str[16]; - sprintf(str, "%d", argc); - tmpasm_runtime_error(ctx, -1, str); - return; - } - - s_cond = tmpasm_arg2str(ctx, argv[0], 0); - - if (ctx->cb->is_true(ctx, s_cond)) - s = tmpasm_arg2str(ctx, argv[1], 0); - else - s = tmpasm_arg2str(ctx, argv[2], 0); - - fprintf(ud->fout, "%s", s); - - free(s_cond); - free(s); -} - -static void scc_tmpasm_parse_(tmpasm_t *ctx, const char *cwd, FILE *fin, FILE *default_fout, FILE *fout) -{ - scc_t *ud = malloc(sizeof(scc_t)); - memset(&ud->ofl, 0, sizeof(ud->ofl)); - ctx->user_data = ud; - ud->default_fout = default_fout; - ud->fout = fout; - ud->cwd = cwd; - - for(;;) { - int c; - c = fgetc(fin); - if (c == EOF) - break; - tmpasm_gotchar(ctx, c); - } - -} - -void scc_tmpasm_parse(tmpasm_t *ctx, const char *cwd, FILE *fin, FILE *fout) -{ - scc_tmpasm_parse_(ctx, cwd, fin, fout, fout); -} - -#ifndef NO_FILE_IO -static void instr_include(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - scc_t *ud = (scc_t *)ctx->user_data; - int n; - (void) iname; /* not used */ - - for(n = 0; n < argc; n++) { - char *fn, *path; - FILE *fin; - tmpasm_t *child; - - fn = tmpasm_arg2str(ctx, argv[n], 0); - path = scc_path(ud, fn); - fin = fopen(path, "r"); - if (fin == NULL) { - tmpasm_runtime_error(ctx, -8, path); - free(fn); - free(path); - return; - } - child = tmpasm_init(ctx->cb); - scc_tmpasm_parse_(child, ud->cwd, fin, ud->default_fout, ud->fout); - tmpasm_execute(child); - if (print_runtime_error(child, path) != 0) - tmpasm_runtime_error(ctx, -7, path); - tmpasm_uninit(child); - fclose(fin); - free(fn); - free(path); - } -} - - -static void instr_redir(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - char *path, *fn, *mode; - scc_t *ud = (scc_t *)ctx->user_data; - (void) iname; /* not used */ - fflush(ud->fout); - switch(argc) { - case 0: ud->fout = ud->default_fout; return; /* set redirection to default */ - case 1: mode = strclone("w"); break; - case 2: mode = tmpasm_arg2str(ctx, argv[1], 0); break; - default: - tmpasm_runtime_error(ctx, -5, NULL); - return; - } - - fn = tmpasm_arg2str(ctx, argv[0], 0); - path = scc_path(ud, fn); - ud->fout = openfile_open(&ud->ofl, path, mode); - if (ud->fout == NULL) { - char *err = malloc(strlen(fn) + strlen(path) + strlen(mode) + 16); - sprintf(err, "%s (%s) for %s", path, fn, mode); - tmpasm_runtime_error(ctx, -6, err); - free(err); - free(path); - return; - } - free(fn); - free(mode); - free(path); -} -#endif - -#ifdef TMPASM_TESTER -static void instr_unknown(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]) -{ - printf("ERROR: unknown instruction '%s'\n", iname); -} -#endif - - -/******** interface ********/ - -tmpasm_instr *scc_resolve(tmpasm_t *ctx, const char *name) -{ - (void) ctx; /* not used */ -/* TODO: make this a hash */ - if (strcmp(name, "put") == 0) - return instr_put; - if (strcmp(name, "resolve") == 0) - return instr_resolve; - if (strcmp(name, "append") == 0) - return instr_append; - if (strcmp(name, "print") == 0) - return instr_print; - if (strcmp(name, "print_ternary") == 0) - return instr_print_ternary; -#ifndef TMPASM_NO_FILE_IO - if (strcmp(name, "redir") == 0) - return instr_redir; - if (strcmp(name, "include") == 0) - return instr_include; -#endif - if (strcmp(name, "report") == 0) - return instr_report; - if (strcmp(name, "abort") == 0) - return instr_abort; - if (strcmp(name, "halt") == 0) - return instr_halt; - if (strcmp(name, "uniq") == 0) - return instr_uniq; - if (strcmp(name, "order") == 0) - return instr_order; - if (strcmp(name, "sortuniq") == 0) - return instr_uniq; - if ((strcmp(name, "sub") == 0) || (strcmp(name, "gsub") == 0)) - return instr_sub; - -#ifndef TMPASM_TESTER - return NULL; -#else - return instr_unknown; -#endif -} - - -static const char *scc_err_fmt(tmpasm_t *ctx) -{ - int code; - code = -ctx->runtime_error; - - if ((code < 0) || ((size_t)code > (sizeof(scc_runtime_error_fmts)/sizeof(char *)))) - return NULL; - return scc_runtime_error_fmts[code]; -} - - -static void scc_preexec(tmpasm_t *ctx) -{ - (void) ctx; /* not used */ - db_mkdir(TMPASM_PATH); -} - -static void scc_postexec(tmpasm_t *ctx) -{ - scc_t *ud = (scc_t *)ctx->user_data; - openfile_free(&ud->ofl); - free(ud); -} - -tmpasm_cb_t scc_cb = { - scc_get, scc_set, scc_is_true, scc_match, scc_first, scc_next, - scc_resolve, scc_preexec, scc_postexec, scc_err_fmt -}; - -int tmpasm(const char *wdir, const char *input, const char *output) -{ - tmpasm_t *ctx; - FILE *fin, *fout; - int ret; - scc_t ud_tmp; - char *path; - - ud_tmp.cwd = wdir; - - path = scc_path(&ud_tmp, input); - fin = fopen(path, "r"); - if (fin == NULL) { - fprintf(stderr, "ERROR: tmpasm: can not open script '%s' (%s in %s)\n", path, input, wdir); - free(path); - return -1; - } - free(path); - - path = scc_path(&ud_tmp, output); - fout = fopen(path, "w"); - if (fout == NULL) { - fprintf(stderr, "ERROR: tmpasm: can not open output '%s' (%s in %s)\n", path, output, wdir); - free(path); - return -1; - } - free(path); - - ctx = tmpasm_init(&scc_cb); - scc_tmpasm_parse_(ctx, wdir, fin, fout, fout); - if (!ctx->dead) - tmpasm_execute(ctx); - fclose(fin); - fclose(fout); - - ret = print_runtime_error(ctx, input); - - tmpasm_uninit(ctx); - return ret; -} - -FILE *tmpasm_fout(tmpasm_t *ctx) -{ - scc_t *ud = (scc_t *)ctx->user_data; - return ud->fout; -} diff --git a/scconfig/src/tmpasm/.svn/pristine/db/db97e42a7e7385da2f9e9b0aa236c60d595e804e.svn-base b/scconfig/src/tmpasm/.svn/pristine/db/db97e42a7e7385da2f9e9b0aa236c60d595e804e.svn-base deleted file mode 100644 index 58800504..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/db/db97e42a7e7385da2f9e9b0aa236c60d595e804e.svn-base +++ /dev/null @@ -1,182 +0,0 @@ -#ifndef TMPASM_H -#define TMPASM_H -#ifndef TMPASM_INSTR_MAXLEN -#define TMPASM_INSTR_MAXLEN 32 -#endif - -typedef struct tmpasm_s tmpasm_t; - -typedef struct tmpasm_arg_s tmpasm_arg_t; - -struct tmpasm_arg_s { - tmpasm_arg_t *next; /* block: the resulting string is a list of strings and addresses */ - char is_addr; /* 1: arg is a node address; 0: arg is a string immediate */ - char data[1]; /* arg string - obviously longer than 1 char (but there's not special hack for that in C89), \0 terminated */ -}; - -/* user specified instruction prototype */ -typedef void tmpasm_instr(tmpasm_t *ctx, char *iname, int argc, tmpasm_arg_t *argv[]); - - -typedef struct tmpasm_cb_s { - /* return the value of a node at addr - NULL is an error */ - const char *(*get)(tmpasm_t *ctx, const char *addr); - - /* set the value of a node at addr to data; data may be NULL */ - void (*set)(tmpasm_t *ctx, const char *addr, const char *data); - - /* return 1 if data is true, 0 otherwise; data may be NULL (if an unknown variable is referenced) */ - int (*is_true)(tmpasm_t *ctx, const char *data); - - /* return 1 if str matches pat, 0 otherwise; str and pat may be NULL */ - int (*match)(tmpasm_t *ctx, const char *str, const char *pat); - - /* first iteration over list; return the first element (or NULL to end); the string returned is not free'd by the caller */ - const char *(*first)(tmpasm_t *ctx, void **state, char *list); - - /* return next element of a list or NULL on end (in which case state shall be also free'd by the caller); the string returned is not free'd by the caller */ - const char *(*next)(tmpasm_t *ctx, void **state); - - /* resolve an instruction name to a function pointer */ - tmpasm_instr *(*resolve)(tmpasm_t *ctx, const char *name); - - /* optional: called once before execution of a context starts */ - void (*preexec)(tmpasm_t *ctx); - - /* optional: called once before execution of a context starts */ - void (*postexec)(tmpasm_t *ctx); - - /* optional: resolve the current runtime error, called only for negative - error codes; should return a format string with exactly one %s in it - or NULL. */ - const char *(*runtime_error_fmt)(tmpasm_t *ctx); -} tmpasm_cb_t; - -int tmpasm_gotchar(tmpasm_t *ctx, char c); - -tmpasm_t *tmpasm_init(const tmpasm_cb_t *cb); -void tmpasm_uninit(tmpasm_t *ctx); - -/* return the string version of an arg in a newly malloc()'d string - if keep_addr is non-zero and a is a single address, no get() is run - but the address is returned as a string */ -char *tmpasm_arg2str(tmpasm_t *ctx, tmpasm_arg_t *a, int keep_addr); - -/* execute the code recursively until it exits */ -void tmpasm_execute(tmpasm_t *ctx); - -/* Set or get the runtime error of a context. 0 means no error, negative - codes are user errors handled by the runtime_error_fmt() callback - and positive codes are internal error. */ -void tmpasm_runtime_error(tmpasm_t *ctx, int code, const char *data); -const char *tmpasm_runtime_error_fmt(tmpasm_t *ctx); - -/* --- internals: not required for normal use --- */ -typedef enum { - ST_PRECMD, /* waiting for a command to start - ignore whitespace */ - ST_CMD, - ST_PREDATA, /* waiting for data */ - ST_PREBLOCKSEP, /* waiting for a block sep when opening a block */ - ST_BLOCKSEP, /* found a block sep within the block - either an address or a termination follows */ - ST_BLOCK, /* in [@ @] block, text part */ - ST_BLOCK_INLINE, /* in [@ @] block, within inline @@ part */ - ST_STRING, /* in {} string */ - ST_STRING_ESCAPE, /* in {} string, right after a \ */ - ST_ADDRESS, /* shifting address bytes */ - ST_COMMENT /* after #, until the next newline */ -} tmpasm_state_t; - -typedef enum { - KW_none, - KW_IF, - KW_THEN, - KW_ELSE, - KW_END, - KW_FOREACH, - KW_IN, - KW_SWITCH, - KW_CASE, - KW_DEFAULT, - - KW_NOP /* virtual instruction */ -} tmpasm_kw_t; - -/* execution structs */ -typedef struct tmpasm_exec_s tmpasm_exec_t; -typedef struct tmpasm_case_s tmpasm_case_t; - -struct tmpasm_case_s { - tmpasm_arg_t *data; - tmpasm_exec_t *body; - tmpasm_case_t *next; -}; - - -struct tmpasm_exec_s { - tmpasm_kw_t kw; /* kw_none means a hook instruction */ - union { - struct { /* normal instruction */ - tmpasm_instr *call; - char *call_name; /* temporary */ - int argc; - tmpasm_arg_t **argv; - } instr; - struct { - tmpasm_arg_t *cond; - tmpasm_exec_t *code_then; - tmpasm_exec_t *code_else; - } fc_if; - struct { - char *loop_var; /* must be a single address */ - tmpasm_arg_t *data; /* what to loop in */ - tmpasm_exec_t *code_body; - } fc_foreach; - struct { - tmpasm_arg_t *cond; - tmpasm_case_t *first; - tmpasm_case_t *last; - } fc_switch; - } payload; - int line, col; - tmpasm_exec_t *next; -}; - - -/* parser structs */ -typedef struct stack_s tmpasm_stack_t; -struct stack_s { - tmpasm_state_t state; -/* tmpasm_state_t kwstate; internal states of composite keywords like switch */ - char cmd_buff[TMPASM_INSTR_MAXLEN+1]; - unsigned int cmdi; - tmpasm_kw_t kw, old_kw; - char block_sep; - int kwcol, kwline; - - int args_used, args_alloced; /* number of arguments in argv[] */ - - tmpasm_arg_t **argv; /* an array of linked lists */ - tmpasm_arg_t **argend; /* each argv[] is a linked list (for blocks); argend points to the tail */ - int *arg_alloced; /* of argend */ - int *arg_used; /* of argend */ - - tmpasm_exec_t *last_code; /* tail of the code list */ - - tmpasm_stack_t *next; -}; - -struct tmpasm_s { - tmpasm_stack_t *st; - int dead; - int col, line; - tmpasm_exec_t *code; - tmpasm_exec_t *executing; /* points to the code most recently executed (or being executed when in callbacks) */ - const tmpasm_cb_t *cb; - int halt; - int runtime_error; - char *runtime_error_data; - int runtime_error_line; - int runtime_error_col; - void *user_data; -}; -#endif diff --git a/scconfig/src/tmpasm/.svn/pristine/e0/e05ec597522fc6d7214a21466a6a669a8bd9aa05.svn-base b/scconfig/src/tmpasm/.svn/pristine/e0/e05ec597522fc6d7214a21466a6a669a8bd9aa05.svn-base deleted file mode 100644 index 8f02c44b..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/e0/e05ec597522fc6d7214a21466a6a669a8bd9aa05.svn-base +++ /dev/null @@ -1,17 +0,0 @@ -put [at 6:1] - arg: tmp - arg: {true} -if tmp [at 7:8] -then: - foreach item in {foo bar true baz} [at 8:2] - print [at 9:3] - arg: item - arg: { -} - if item [at 10:11] - then: - halt [at 11:4] - else: - (NOP) -else: - (NOP) diff --git a/scconfig/src/tmpasm/.svn/pristine/e0/e088d2bbe2df5ac3a6d544bbf12a50c7095d7abe.svn-base b/scconfig/src/tmpasm/.svn/pristine/e0/e088d2bbe2df5ac3a6d544bbf12a50c7095d7abe.svn-base deleted file mode 100644 index b4a77304..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/e0/e088d2bbe2df5ac3a6d544bbf12a50c7095d7abe.svn-base +++ /dev/null @@ -1,15 +0,0 @@ -# The following user interface utils are scconfig specific. - -# The report infrstructure is the main UI in scconfig. It prints -# messages to the console. The "report" instruction works similar -# to print, but its output is always the console, immune to -# redirections and default file output (tmpasm is most commonly -# used for generating files, so the default output file is not -# the console but a file being generated) -put myvar {!\n} -report {hello } {world} myvar -report [@hello world@myvar@@] - -# If an error is detected during generation of a file, the script should abort. -# This is a direct call to abort(2). -abort diff --git a/scconfig/src/tmpasm/.svn/pristine/e0/e0d7a62ddfb6f4f367ac5037ece26fd8b56102f6.svn-base b/scconfig/src/tmpasm/.svn/pristine/e0/e0d7a62ddfb6f4f367ac5037ece26fd8b56102f6.svn-base deleted file mode 100644 index 90b5430b..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/e0/e0d7a62ddfb6f4f367ac5037ece26fd8b56102f6.svn-base +++ /dev/null @@ -1,6 +0,0 @@ -error: unexpected "end" in "if" - expected "then" at 2:4 -if v [at 2:1] -then: - (NOP) -else: - (NOP) diff --git a/scconfig/src/tmpasm/.svn/pristine/e2/e29133ef6e9b652bbc61ac2815b9a1ca17f2aca5.svn-base b/scconfig/src/tmpasm/.svn/pristine/e2/e29133ef6e9b652bbc61ac2815b9a1ca17f2aca5.svn-base deleted file mode 100644 index 6514b4a4..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/e2/e29133ef6e9b652bbc61ac2815b9a1ca17f2aca5.svn-base +++ /dev/null @@ -1,6 +0,0 @@ -error: unexpected 'else' - must be in a 'then' block before an else at 2:5 -if *NULL - broken AST* [at 1:1] -then: - (NOP) -else: - (NOP) diff --git a/scconfig/src/tmpasm/.svn/pristine/e3/e3fca575a4b4705d82a72c44369857466d624560.svn-base b/scconfig/src/tmpasm/.svn/pristine/e3/e3fca575a4b4705d82a72c44369857466d624560.svn-base deleted file mode 100644 index f56acc9f..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/e3/e3fca575a4b4705d82a72c44369857466d624560.svn-base +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include "tmpasm.h" - -static void indent(FILE *f, int depth) -{ - for(;depth > 0; depth--) fputc(' ', f); -} - -static void print_arg(FILE *f, tmpasm_arg_t *a) -{ - if (a == NULL) { - fprintf(f, "*NULL - broken AST*"); - return; - } - if (a->next != NULL) { - /* block mode */ - fprintf(f, "[~"); - for(;a != NULL; a = a->next) { - if (a->is_addr) - fprintf(f, "~%s~", a->data); - else - fprintf(f, "%s", a->data); - } - fprintf(f, "~]"); - } - else { - if (a->is_addr) - fprintf(f, "%s", a->data); - else - fprintf(f, "{%s}", a->data); - } -} - -static void print_loc(FILE *f, tmpasm_exec_t *c) -{ - if ((c->line != 0) || (c->col != 0)) - fprintf(f, " [at %d:%d]\n", c->line, c->col); - else - fprintf(f, "\n"); -} - -static void dump(FILE *f, int depth, tmpasm_exec_t *c) -{ - tmpasm_case_t *cc; - int n; - for(; c != NULL; c = c->next) { - switch(c->kw) { - case KW_NOP: - indent(f, depth); - fprintf(f, "(NOP)"); - print_loc(f, c); - break; - case KW_none: - indent(f, depth); - fprintf(f, "%s", c->payload.instr.call_name); - print_loc(f, c); - for(n = 0; n < c->payload.instr.argc; n++) { - indent(f, depth+1); - fprintf(f, "arg: "); - print_arg(f, c->payload.instr.argv[n]); - fprintf(f, "\n"); - } - break; - case KW_IF: - indent(f, depth); - fprintf(f, "if "); - print_arg(f, c->payload.fc_if.cond); - print_loc(f, c); - indent(f, depth); - fprintf(f, "then:\n"); - dump(f, depth+1, c->payload.fc_if.code_then); - indent(f, depth); - fprintf(f, "else:\n"); - dump(f, depth+1, c->payload.fc_if.code_else); - break; - case KW_FOREACH: - indent(f, depth); - fprintf(f, "foreach %s in ", c->payload.fc_foreach.loop_var); - print_arg(f, c->payload.fc_foreach.data); - print_loc(f, c); - dump(f, depth+1, c->payload.fc_foreach.code_body); - break; - case KW_SWITCH: - indent(f, depth); - fprintf(f, "switch "); - print_arg(f, c->payload.fc_switch.cond); - print_loc(f, c); - for(cc = c->payload.fc_switch.first; cc != NULL; cc = cc->next) { - indent(f, depth+1); - if (cc->data != NULL) { - fprintf(f, "case "); - print_arg(f, cc->data); - fprintf(f, "\n"); - } - else - printf("default\n"); - dump(f, depth+2, cc->body); - } - break; - default: - indent(f, depth); - fprintf(f, "invalid kw "); - print_loc(f, c); - } - } -} - -void tmpasm_dump(tmpasm_t *ctx, FILE *f) -{ - dump(f, 0, ctx->code); -} diff --git a/scconfig/src/tmpasm/.svn/pristine/e5/e578035909632328742a68bdee07af83bba70537.svn-base b/scconfig/src/tmpasm/.svn/pristine/e5/e578035909632328742a68bdee07af83bba70537.svn-base deleted file mode 100644 index b7fea308..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/e5/e578035909632328742a68bdee07af83bba70537.svn-base +++ /dev/null @@ -1,15 +0,0 @@ -append [at 1:1] - arg: tmp - arg: {foo} -append [at 2:1] - arg: tmp - arg: {bar} -append [at 3:1] - arg: tmp - arg: {baz} -foreach n in tmp [at 4:1] - print [at 5:2] - arg: {-> } - arg: n - arg: { -} diff --git a/scconfig/src/tmpasm/.svn/pristine/e8/e8451a17a8de079465f316931b9677b193213ffd.svn-base b/scconfig/src/tmpasm/.svn/pristine/e8/e8451a17a8de079465f316931b9677b193213ffd.svn-base deleted file mode 100644 index db8c6e4a..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/e8/e8451a17a8de079465f316931b9677b193213ffd.svn-base +++ /dev/null @@ -1,47 +0,0 @@ -put [at 1:1] - arg: swdata - arg: {lol} -switch swdata [at 2:1] - case data1 - print [at 3:24] - arg: {1a} - arg: {11} - print [at 3:41] - arg: {1b} - arg: 12 - print [at 3:56] - arg: {1c} - arg: 13 - print [at 3:71] - arg: {1d} - arg: 14 - case [~data2 ~a~~] - print [at 4:24] - arg: {2a} - arg: 21 - print [at 4:41] - arg: {2b} - arg: 22 - print [at 4:56] - arg: {2c} - arg: 23 - print [at 4:71] - arg: {2d} - arg: 24 - default - print [at 5:24] - arg: {3a} - arg: 31 - print [at 5:41] - arg: {3b} - arg: 32 - print [at 5:56] - arg: {3c} - arg: 33 - print [at 5:71] - arg: {3d} - arg: 34 -print [at 7:1] - arg: {i1} -print [at 8:1] - arg: {i2} diff --git a/scconfig/src/tmpasm/.svn/pristine/ea/ea7e920deb2b314b0b6573635aaf32851ec325e4.svn-base b/scconfig/src/tmpasm/.svn/pristine/ea/ea7e920deb2b314b0b6573635aaf32851ec325e4.svn-base deleted file mode 100644 index b38a10be..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/ea/ea7e920deb2b314b0b6573635aaf32851ec325e4.svn-base +++ /dev/null @@ -1,6 +0,0 @@ -append tmp {foo} -append tmp {bar} -append tmp {baz} -foreach n in tmp - print {-> } n {\n} -end diff --git a/scconfig/src/tmpasm/.svn/pristine/f1/f1878f94ce764ed527ccab4a83ebe5deab55040b.svn-base b/scconfig/src/tmpasm/.svn/pristine/f1/f1878f94ce764ed527ccab4a83ebe5deab55040b.svn-base deleted file mode 100644 index c1349f08..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/f1/f1878f94ce764ed527ccab4a83ebe5deab55040b.svn-base +++ /dev/null @@ -1,20 +0,0 @@ -print [at 14:1] - arg: {this goes to the default output -} -redir [at 18:1] - arg: {Tutor10.inc} -print [at 19:1] - arg: {# this is a generated file.} -print [at 20:1] - arg: { - print {hello world from my include!\n} -} -redir [at 25:1] -print [at 26:1] - arg: {back at default output. -} -print [at 45:1] - arg: {Include: -} -include [at 46:1] - arg: {Tutor10.inc} diff --git a/scconfig/src/tmpasm/.svn/pristine/f2/f2c70fb06e40c36beefe2b42ed6f3be1ca4d9be8.svn-base b/scconfig/src/tmpasm/.svn/pristine/f2/f2c70fb06e40c36beefe2b42ed6f3be1ca4d9be8.svn-base deleted file mode 100644 index bfb644bb..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/f2/f2c70fb06e40c36beefe2b42ed6f3be1ca4d9be8.svn-base +++ /dev/null @@ -1,16 +0,0 @@ -print [at 7:1] - arg: {hello world! -} -print [at 11:1] - arg: {hello} - arg: {world!} - arg: { -} -print [at 14:1] -print [at 17:1] - arg: {HELLO} -print [at 17:16] - arg: { WORLD!} -print [at 17:36] - arg: { -} diff --git a/scconfig/src/tmpasm/.svn/pristine/ff/ffacded502b6a779461358eae8ca7eba03eb409b.svn-base b/scconfig/src/tmpasm/.svn/pristine/ff/ffacded502b6a779461358eae8ca7eba03eb409b.svn-base deleted file mode 100644 index c0e57fc0..00000000 --- a/scconfig/src/tmpasm/.svn/pristine/ff/ffacded502b6a779461358eae8ca7eba03eb409b.svn-base +++ /dev/null @@ -1,35 +0,0 @@ -# The only loop tmpasm implements is a foreach that iterates on a list. -# How the list is split into items is up to the environment. In scconfig -# the list is white space separated by default. The word following foreach -# must be the name of a variable (that will be set to the next item before -# each iteration). The word after "in" is data (string, variable, block). - -foreach item in {this is a list of words} - print item {\n} -end - -# Like any other control, foreach can be nested. The following -# example will iterate item on foo, bar and baz, printing 3 words -# for each from a block: {next:}, the item and a newline. The newline -# is specified as a vairable since \ escaping does not work in blocks. -put nl {\n} -foreach item in {foo bar baz} - foreach w in [@next: @item@@nl@@] - print w - end -end - -# Foreach makes a copy of the list before the first iteration. This -# is relevant if the list is a variable that may change during the -# loop. The following exmaple takes a list of libs and if -lsdl is -# present on the list, appends -lsvga to the list and inserts -lm; -# these changes to "libs" will not alter the loop. -put libs {-lsdl -ltcl8.4} -foreach l in libs - print {l=} l {\n} - switch l - case {^-lsdl} put libs [@-lm @libs@ -lsvga@]; end - end -end -print {libs=} libs {\n} - diff --git a/scconfig/src/tmpasm/.svn/wc.db b/scconfig/src/tmpasm/.svn/wc.db deleted file mode 100644 index a6e9b3cc..00000000 Binary files a/scconfig/src/tmpasm/.svn/wc.db and /dev/null differ diff --git a/scconfig/src/tmpasm/.svn/wc.db-journal b/scconfig/src/tmpasm/.svn/wc.db-journal deleted file mode 100644 index e69de29b..00000000 diff --git a/scconfig/src/util/.svn/entries b/scconfig/src/util/.svn/entries deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/util/.svn/entries +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/util/.svn/format b/scconfig/src/util/.svn/format deleted file mode 100644 index 48082f72..00000000 --- a/scconfig/src/util/.svn/format +++ /dev/null @@ -1 +0,0 @@ -12 diff --git a/scconfig/src/util/.svn/pristine/1b/1b414e258b8b33179266687754b3796cae76c0de.svn-base b/scconfig/src/util/.svn/pristine/1b/1b414e258b8b33179266687754b3796cae76c0de.svn-base deleted file mode 100644 index 94e66c28..00000000 --- a/scconfig/src/util/.svn/pristine/1b/1b414e258b8b33179266687754b3796cae76c0de.svn-base +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef ARG_AUTO_SET_H -#define ARG_AUTO_SET_H -/* - Handle a list of --disable-LIBs automatically. - The user sets up a table like: - static const arg_auto_set_t disable_libs[] = { - {"disable-gtk", "libs/gui/gtk2", arg_lib_nodes}, - {"disable-lesstif", "libs/gui/lesstif2", arg_lib_nodes}, - {NULL, NULL, NULL} - }; - and at the end of hook_custom_arg() executes: - return arg_auto_set(key, value, disable_libs); - - The call will set all nodes listed in arg_lib_nodes to disable gtk or - lesstif. - - Mechanism: this happens before require()s on these nodes; require() will - find them already set and won't run the detection. Thus it is suitable for - disabling features (but not for enabling them). -*/ - -/* A table of node name-values to be set under a subtree */ -typedef struct { - const char *name; - const char *value; -} arg_auto_set_node_t; - -/* A table of argument->subtree->subtree_values */ -typedef struct { - const char *arg_key; /* command line argument without the -- prefix */ - const char *subtree; /* subtree path affected, e.g. libs/gui/gtk2 */ - const arg_auto_set_node_t *subvals; /* a set of values to be put() under the subtree */ - const char *help_txt; -} arg_auto_set_t; - -/* node set table for resetting the usual nodes under a library subtree: - presents, cflags, ldflags */ -extern const arg_auto_set_node_t arg_lib_nodes[]; - -/* set the node true or false */ -extern const arg_auto_set_node_t arg_true[]; -extern const arg_auto_set_node_t arg_false[]; - -/* Execute table: find a match on key and set all subvals of the match */ -int arg_auto_set(const char *key, const char *value, const arg_auto_set_t *table); - -/* Print options help from the table, one entry per line; if help text starts - with $, replace that with --arg_key and insert padding after that; padding - should be a string filled with spaces, as long as the longest argument key - plus the separator spaces. */ -void arg_auto_print_options(FILE *fout, const char *line_prefix, const char *padding, const arg_auto_set_t *table); - -#endif diff --git a/scconfig/src/util/.svn/pristine/29/297b15a9f3a02c3d0867b80836f2d465a82376f0.svn-base b/scconfig/src/util/.svn/pristine/29/297b15a9f3a02c3d0867b80836f2d465a82376f0.svn-base deleted file mode 100644 index 7afcf3a8..00000000 --- a/scconfig/src/util/.svn/pristine/29/297b15a9f3a02c3d0867b80836f2d465a82376f0.svn-base +++ /dev/null @@ -1,79 +0,0 @@ -/* - scconfig - ls built on dirent - Copyright (C) 2009 Szabolcs Nagy - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include - -#ifdef _WIN32 -#include -static int ls(char *arg) { - WIN32_FIND_DATA fd; - HANDLE h; - char p[MAX_PATH]; - int i; - - for (i = 0; i+2 < MAX_PATH; i++) - if (arg[i]) - p[i] = arg[i]; - if (i+2 < MAX_PATH) { - p[i] = '\\'; - p[i+1] = '*'; - p[i+2] = 0; - } else - return -1; - - h = FindFirstFile(p, &fd); - if (h == INVALID_HANDLE_VALUE) - return -1; - printf("%s\n", fd.cFileName); - - while (FindNextFile(h, &fd) != 0); - printf("%s\n", fd.cFileName); - - FindClose(h); - return 0; -} -#else -#include -static int ls(char *arg) { - DIR *dirp; - struct dirent *dp; - - if ((dirp = opendir(arg)) == 0) - return -1; - - while ((dp = readdir(dirp)) != 0) - printf("%s\n", dp->d_name); - - closedir(dirp); - return 0; -} -#endif - -int main(int argc, char *argv[]) { - int i; - char *p = "."; - - if (argc > 1) - p = argv[1]; - return ls(p); -} - diff --git a/scconfig/src/util/.svn/pristine/6c/6cb11187be219c54c76d9bef3bf14be4fe653008.svn-base b/scconfig/src/util/.svn/pristine/6c/6cb11187be219c54c76d9bef3bf14be4fe653008.svn-base deleted file mode 100644 index 913c249d..00000000 --- a/scconfig/src/util/.svn/pristine/6c/6cb11187be219c54c76d9bef3bf14be4fe653008.svn-base +++ /dev/null @@ -1,841 +0,0 @@ -/* - scconfig - sccbox: portable copy, link, mkdir and remove - Copyright (C) 2016, 2017 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include - -/*********************** DOCUMENTATION **************************/ - -static void help_generic(const char *prg) -{ - printf("sccbox - Makefile helper\n\n"); - printf("Invocation: %s cmd [switches] [paths]\n\n", prg); - printf("sccbox and provides a basic set of file-system utilities as a single,\n"); - printf("static linkable executable with dependency only on libc. It is implemented\n"); - printf("in C89 and uses only a very thin layer of non-C89 OS calls that trace\n"); - printf("back to early BSD days and are widely available on all platforms.\n\n"); - printf("The intention is to replace 'mkdir -p' and 'rm -f' and similar,\n"); - printf("non-portable commands with a less efficient, but more portable local\n"); - printf("implementation. Using sccbox for mkdir/install/uninstall exclusively also\n"); - printf("simplifies the Makefile rules because the semantics of uninstall\n"); - printf("matches the semantics of install and the same list of source files\n"); - printf("and destination can be passed and source files are not removed.\n\n"); - printf("For more info read the following help topics using --help topic:\n"); - printf(" error error handling\n"); - printf(" rm remove files (e.g. for make clean)\n"); - printf(" mkdir create directories (e.g. for make *install)\n"); - printf(" ln create symlink (e.g. for make *install)\n"); - printf(" install copy-install files (e.g. for make install)\n"); - printf(" linstall symlink-install files (e.g. for make linstall)\n"); - printf(" uninstall remove files (e.g. for make uninstall)\n"); - printf(" touch touch files (open for append)\n"); - printf(" touchnew touch non-existing files, ignore existing files\n"); - printf("\n"); -} - -static void help_error(const char *prg) -{ - printf("sccbox - error handling (all commands)\n\n"); - printf("Any sccbox command by default will try to carry out the requested\n"); - printf("operation assuming no errors, e.g. an mkdir will assume the target\n"); - printf("directory does not exists but all parent directories are in place.\n"); - printf("If such a command fails, the exit status is non-zero and error messages\n"); - printf("are printed to stderr.\n\n"); - printf("If the --quiet switch is specified, the command will try to do the same\n"); - printf("but never prints error messages and always returns 0. This is useful\n"); - printf("in situations when failure is expected (note: 2>/dev/null is not portable)\n\n"); - printf("If the --force switch is specified, the command will make extre efforts,\n"); - printf("sometimes even destructive ones, to fulfill the request. If it fails,\n"); - printf("error messages are printed (unless --quiet).\n\n"); -} - -static void help_rm_common(void) -{ - printf(" --quiet don't print error messages and set exit status to 0\n"); - printf(" --force a non-existing file is not an error\n"); -} - -static void help_rm(const char *prg) -{ - printf("sccbox rm [switches] paths\n\n"); - printf("Remove one or more paths from the file system. Paths can be\n"); - printf("files, symlinks and empty directories. Recursive removal is not\n"); - printf("supported. If multiple paths specified, attempt to remove them all\n"); - printf("even if some can not be removed.\n\n"); - printf("Switches:\n"); - help_rm_common(); - printf("\n"); -} - -static void help_mkdir(const char *prg) -{ - printf("sccbox mkdir [switches] paths\n\n"); - printf("Create one or more directories.\n\n"); - printf("Switches:\n"); - printf(" --quiet don't print error messages and set exit status to 0\n"); - printf(" --force ignored (there's nothing to force)\n"); - printf(" -p create parent directories automatically\n"); - printf(" -i ignored\n"); - printf(" -l ignored\n"); - printf(" -c ignored\n"); - printf(" -u do not do anyhting, exit 0\n"); - printf(" -r do not do anyhting, exit 0\n\n"); -} - -static void help_ln_common(void) -{ - printf(" --quiet don't print error messages and set exit status to 0\n"); - printf(" --force attempt to remove target if it exists\n"); -} - -static void help_ln(const char *prg) -{ - printf("sccbox ln [switches] existing new\n"); - printf("sccbox ln [switches] existing1 existing2 ... dir\n\n"); - printf("Create one or more symlinks. Intended for linking installed paths\n"); - printf("to other installed paths.\n\n"); - printf("Switches:\n"); - help_ln_common(); - printf(" --absolute convert existing paths to absolute paths\n\n"); - printf(" --relative make single symlink point to relative path\n\n"); -} - -static void help_install(const char *prg) -{ - printf("sccbox install [switches] src_file dst_file\n"); - printf("sccbox install [switches] src_file1 src_file2 ... dir\n\n"); - printf("Copies (or links or removes) one or more files. Intended to install\n"); - printf("files from the source or build tree to the installation root.\n\n"); - printf("Switches:\n"); - printf(" --quiet don't print error messages and set exit status to 0\n"); - printf(" --force install: attempt to remove destination\n"); - printf(" --absolute convert existing paths to absolute paths\n"); - printf(" --relative make single symlink point to relative path\n\n"); - printf(" -d force destination to be a directory (even remove old dest)\n"); - printf(" -i install (copy) files\n"); - printf(" -c install (copy) files\n"); - printf(" -u uninstall (remove) files - see --help uninstall\n"); - printf(" -r uninstall (remove) files - see --help uninstall\n"); - printf(" -l linstall (symlink) files - see --help linstall\n\n"); -} - -static void help_linstall(const char *prg) { - printf("sccbox linstall [switches] src_file dst_file\n"); - printf("sccbox linstall [switches] src_file1 src_file2 ... dir\n\n"); - printf("Installs (a) file(s) using symlinks. Automatically convert src_file\n"); - printf("paths to absolute paths. Intended for developers: if a package is\n"); - printf("symlink-installed, it can be run from the installation after a\n"); - printf("recompilation without needing to reinstall.\n\n"); - printf("Switches:\n"); - help_ln_common(); - printf(" --preserve do not convert source paths to absolute\n\n"); -} - -static void help_uninstall(const char *prg) { - printf("sccbox uninstall [switches] src_file dst_file\n"); - printf("sccbox uninstall [switches] src_file1 src_file2 ... dir\n\n"); - printf("Remove (an) installed file(s). In the first form, src_file is ignored.\n"); - printf("In the second form dir is used to calculate destination paths.\n\n"); - printf("The purpose of this command is to unify install and uninstall rules:\n"); - printf("unlike cp and rm, an 'sccbox install' and 'sccbox uninstall' can\n"); - printf("be used with the same parameter list to install and uninstall a set of files\n\n"); - printf("Switches:\n"); - help_rm_common(); - printf("\n"); -} - -static void help_touch(const char *prg) -{ - printf("sccbox touch file1 file2 ... fileN\n"); - printf("sccbox touchnew file1 file2 ... fileN\n\n"); - printf("Open all files listed, for append, and close them immedately.\n"); - printf("This makes sure the files exist and also bumps their modification date.\n"); - printf("Command touchnew ignores existing files; its primary use is to make\n"); - printf("sure a file exists without making changes to already existing files.\n"); -} - -static int help(const char *prg, const char *topic) -{ - if (topic == NULL) help_generic(prg); - else if (strcmp(topic, "error") == 0) help_error(prg); - else if (strcmp(topic, "rm") == 0) help_rm(prg); - else if (strcmp(topic, "mkdir") == 0) help_mkdir(prg); - else if (strcmp(topic, "ln") == 0) help_ln(prg); - else if (strcmp(topic, "install") == 0) help_install(prg); - else if (strcmp(topic, "linstall") == 0) help_linstall(prg); - else if (strcmp(topic, "uninstall") == 0) help_uninstall(prg); - else if (strcmp(topic, "touch") == 0) help_touch(prg); - else if (strcmp(topic, "touchnew") == 0) help_touch(prg); - else { - printf("No such help topic: %s\n", topic); - return 1; - } - return 0; -} - - - -/*********************** IMPLEMENTATION: low level **************************/ -#ifdef PATH_MAX -# define MY_PATH_MAX PATH_MAX -#else -# define MY_PATH_MAX 32768 -#endif - -typedef enum { - INSTALL, /* install with cp */ - LINSTALL, /* install with symlinks */ - UNINSTALL /* remove installed files */ -} scc_mode_t; - -#define kill_flag argv[n] = NULL - -#define load_flags(code) \ - do { \ - int n, flags = 1; \ - for(n = 1; n < argc; n++) { \ - char *arg = argv[n]; \ - if ((*arg == '-') && (flags)) { \ - if ((arg[1] == '-') && (arg[2] == '\0')) { \ - kill_flag; \ - flags = 0; \ - continue; \ - } \ - while(*arg == '-') arg++; \ - { code; } \ - } \ - } \ - } while(0) \ - -#define load_args_minus(delta, code) \ - do { \ - int n; \ - for(n = 1; n < argc-delta; n++) {\ - char *arg = argv[n]; \ - if (arg != NULL) \ - { code; } \ - } \ - } while(0); - -#define load_args(code) load_args_minus(0, code)\ - - -static int safe_isdir(const char *path) -{ - struct stat st; - - if (stat(path, &st) != 0) - return 0; - - return S_ISDIR(st.st_mode); -} - -static int safe_isfile(const char *path) -{ - struct stat st; - - if (stat(path, &st) != 0) - return 0; - - return S_ISREG(st.st_mode); -} - -static int safe_remove(const char *src, int need_existing_fd, int quiet) -{ - struct stat st; - int exists; - - if (quiet) - return remove(src); - - exists = stat(src, &st) == 0; - if ((need_existing_fd) && (!exists)) { - fprintf(stderr, "sccbox: Can't remove %s: no such file or directory\n", src); - return 1; - } - - - if (exists && (remove(src) != 0)) { - perror("sccbox"); - fprintf(stderr, "sccbox: Can't remove %s\n", src); - return 1; - } - return 0; -} - -#define issep(chr) (((chr) == '/') || ((chr) == '\\')) - -static char *my_basename(const char *path) -{ - const char *s = path + strlen(path); - for(s--; s >= path; s--) { - if (issep(*s)) - return (char *)s+1; - } - return (char *)path; -} - -static int path_concat(char *out, size_t out_len, const char *dir, const char *file) -{ - char *bn = my_basename(file); - size_t dlen = strlen(dir), blen = strlen(bn); - - if (dlen+blen+2 > out_len) - return 1; - - memcpy(out, dir, dlen); - out[dlen] = '/'; dlen++; - memcpy(out+dlen, bn, blen+1); - return 0; -} - -static int safe_mkdir_p(const char *path); - - -static int safe_copy(const char *src, const char *dst, int force, int quiet, int dst_is_dir) -{ - char buff[16384], dst2[MY_PATH_MAX]; - const char *dst_name = NULL; - FILE *fd, *fs; - struct stat st, dst_st; - int err = 0, remove_dst = 1; - - if (stat(src, &st) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: can't stat %s\n", src); - return 1; - } - - /* make sure symlinks/sockets/etc. are not copied into: remove any dst that's not a dir or a regular file */ - if (stat(dst, &dst_st) == 0) { - int try_remove = dst_is_dir ? (!S_ISDIR(dst_st.st_mode)) : (!S_ISDIR(dst_st.st_mode) || !S_ISREG(dst_st.st_mode)); - if (try_remove) { - if (remove(dst) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: filed to remove non-regular/non-directory target %s\n", dst); - return 1; - } - } - } - - if (dst_is_dir) { - remove_dst = 0; - if (safe_mkdir_p(dst) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: filed to create target directory %s\n", dst); - return 1; - } - } - - fs = fopen(src, "rb"); - if (fs == NULL) { - if (!quiet) - fprintf(stderr, "sccbox: can't copy %s to %s: can not open source for write\n", src, dst2); - return 1; - } - - if ((force) && (remove_dst)) - remove(dst); - - fd = fopen(dst, "wb"); - - if (fd == NULL) { - /* no luck opening the dest file, maybe dst is a directory, try to create a file under it */ - if (path_concat(dst2, sizeof(dst2), dst, src) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: can't copy %s to %s: resulting path is too long\n", src, dst); - fclose(fs); - return 1; - } - - - fd = fopen(dst2, "wb"); - if ((fd == NULL) && (force)) { - remove(dst2); - fd = fopen(dst2, "wb"); - if (fd == NULL) { - /* dest was not a directory or couldn't host our new file; if force, try to - overwrite whatever dst was */ - remove(dst); - fd = fopen(dst, "wb"); - if (fd == NULL) { - if (!quiet) - fprintf(stderr, "sccbox: can't copy %s to %s: destination can not be overwritten\n", src, dst2); - fclose(fs); - return 1; - } - dst_name = dst; - } - } - if (fd == NULL) { - if (!quiet) - fprintf(stderr, "sccbox: can't copy %s to %s: can not open destination for write\n", src, dst2); - fclose(fs); - return 1; - } - if (dst_name == NULL) - dst_name = dst2; - } - else - dst_name = dst; - - /* manual copy - the only portable way */ - for(;;) { - size_t len = fread(buff, 1, sizeof(buff), fs); - if (len == 0) - break; - if (fwrite(buff, 1, len, fd) != len) { - if (!quiet) { - perror("sccbox"); - fprintf(stderr, "sccbox: can't copy %s to %s\n", src, dst_name); - } - err = 1; - if (!force) - break; - } - } - - chmod(dst_name, st.st_mode); /* this may fail on windows or on strange FS, don't check the return value */ - - fclose(fs); - fclose(fd); - return err; -} - -static const char *safe_get_pwd(int quiet) -{ - static char pwd_buff[MY_PATH_MAX]; - static int valid = 0; - if (!valid) { - FILE *f; - char *end; - f = popen("pwd", "r"); - - if (f == NULL) { - if (!quiet) - perror("sccbox: running pwd"); - return NULL; - } - if (fgets(pwd_buff, sizeof(pwd_buff), f) == NULL) { - if (!quiet) - perror("sccbox: reading pwd's output"); - pclose(f); - return NULL; - } - pclose(f); - end = pwd_buff + strlen(pwd_buff) - 1; - while((end >= pwd_buff) && ((*end == '/') || (*end == '\n') || (*end == '\r'))) { - *end = '\0'; - end--; - } - if (*pwd_buff != '/') { - if (!quiet) - fprintf(stderr, "sccbox: invalid pwd: '%s'\n", pwd_buff); - return NULL; - } - valid = 1; - } - return pwd_buff; -} - -/* Both 'path' and 'from' are absolute paths; recalculate path to be a relative - path from 'from' and copy the result to buf. Returns buf. */ -char *relativize(char *buf, const char *path, const char *from) -{ - const char *p, *f, *c, *lastp, *lastf; - char *end = buf; - int cnt = 0, rem = MY_PATH_MAX-1, len; - - for(lastp = p = path, lastf = f = from; *p == *f; p++,f++) { - /* skip double separators */ - if (issep(p[0])) { - while(issep(p[0]) && issep(p[1])) p++; - lastp = p+1; - } - if (issep(f[0])) { - while(issep(f[0]) && issep(f[1])) f++; - lastf = f+1; - } - } - - p = lastp; - f = lastf; - - for(c = f; *c != '\0'; c++) { - if (issep(c[0])) { - cnt++; - while(issep(c[0]) && issep(c[1])) c++; - } - } - - while(cnt > 0) { - if (rem < 3) - return NULL; - strcpy(end, "../"); - end += 3; - rem -= 3; - cnt--; - } - - len = strlen(p); - if (len >= rem) - return NULL; - strcpy(end, p); - - return buf; -} - -/* create a symlink - needs to work only on UNIX but needs to compile on win32, - so use system("ln -s") and avoid link-related syscalls */ -static int safe_link(const char *src, const char *dst, int absolute, int relative, int force, int quiet, int dst_is_dir) -{ - char cmd[MY_PATH_MAX*2+16], full_src_tmp[MY_PATH_MAX], rel_src_tmp[MY_PATH_MAX]; - const char *full_src, *supp; - int remove_dst = 1; - - if ((absolute) && (*src != '/')) { - /* fix up relative source paths */ - const char *pwd = safe_get_pwd(quiet); - int pwdlen, srclen; - if (pwd == NULL) { - if (!quiet) - fprintf(stderr, "sccbox: can't figure current working directory for relative symlink %s to %s\n", src, dst); - return 1; - } - if ((src[0] == '.') && (src[1] == '/')) - src += 2; - pwdlen = strlen(pwd); - srclen = strlen(src); - - if ((pwdlen + srclen + 2) >= sizeof(full_src_tmp)) { - if (!quiet) - fprintf(stderr, "sccbox: can't link %s to %s: resulting path is too long\n", src, dst); - return 1; - } - memcpy(full_src_tmp, pwd, pwdlen); - full_src_tmp[pwdlen] = '/'; - memcpy(full_src_tmp+pwdlen+1, src, srclen+1); - full_src = full_src_tmp; - } - else - full_src = src; - - if (dst_is_dir) { - struct stat dst_st; - if ((stat(dst, &dst_st) == 0) && (!S_ISDIR(dst_st.st_mode))) { - if (remove(dst) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: filed to remove non-directory target %s\n", dst); - return 1; - } - } - - remove_dst = 0; - if (safe_mkdir_p(dst) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: filed to create target directory %s\n", dst); - return 1; - } - } - - if (force) - remove(dst); - - supp = quiet ? " 2>/dev/null" : ""; - - if (relative) { - const char *fdst; - char full_dst_tmp[MY_PATH_MAX]; - - if (*dst != '/') { - const char *pwd = safe_get_pwd(quiet); - if (pwd == NULL) { - if (!quiet) - fprintf(stderr, "sccbox: can't figure current working directory for relative path '%s'\n", dst); - return 1; - } - if (path_concat(full_dst_tmp, sizeof(full_dst_tmp), pwd, dst) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: can't link %s to %s: resulting path is too long\n", src, dst); - return 1; - } - fdst = full_dst_tmp; - } - else - fdst = dst; - full_src = relativize(rel_src_tmp, full_src, fdst); - } - - sprintf(cmd, "ln -s \"%s\" \"%s\"%s", full_src, dst, supp); - return system(cmd); -} - -static int safe_mkdir_p(const char *path) -{ - char *curr, *next, *s; - int res = 1, len = strlen(path); - char *p = malloc(len+1); - memcpy(p, path, len+1); - - /* do not create existing directories */ - if (safe_isdir(path)) - return 0; - - curr = p; - if ((isalpha(p[0]) && (p[1] == ':') && issep(p[2]))) { - /* windows special case: c:\ */ - curr += 3; - } - - /* remove trailing path separators so we don't create empty dirs at the end */ - s = p+len-1; - while((s >= p) && (issep(*s))) { - *s = '\0'; - s--; - } - - for(next = curr; next != NULL; curr = next) { - char old; - next = strpbrk(curr, "/\\"); - if (next != NULL) { - old = *next; - *next = '\0'; - } - res = mkdir(p, 0755); - if (next != NULL) { - *next = old; - next++; - } - } - - if (res != 0) { - perror("sccbox"); - fprintf(stderr, "sccbox: failed to make directory with parents: %s\n", path); - } - - free(p); - return res; /* return the result of the last mkdir only, previous failures probably meant existing parents */ -} - -static int safe_touch(const char *fn) -{ - FILE *f; - f = fopen(fn, "a"); - if (f == NULL) - return -1; - fclose(f); - return 0; -} - -/*********************** IMPLEMENTATION: high level **************************/ -int cmd_rm(int argc, char *argv[]) -{ - int err = 0, quiet = 0, need_existing_fd = 1; - load_flags( - switch(*arg) { - case 'f': need_existing_fd = 0; kill_flag; break; /* nop: can't do more than remove() */ - case 'q': quiet = 1; kill_flag; break; - } - ); - load_args( - err |= safe_remove(arg, need_existing_fd, quiet); - ); - - - if (quiet) - return 0; - - return err; -} - - -int cmd_install(int argc, char *argv[], scc_mode_t mode, int absolute) -{ - int force = 0, err = 0, quiet = 0, dst_is_dir, force_dst_dir = 0, relative = 0; - const char *last; - - load_flags( - if ((arg[0] == 'r') && (arg[1] == 'e')) arg[0] = 'R'; /* --relative */ - switch(*arg) { - case 'c': /* --copy */ - case 'i': /* --install */ - mode = INSTALL; - kill_flag; - break; - case 'l': /* --ln or --linstall */ - mode = LINSTALL; - kill_flag; - break; - case 'r': /* --rm */ - case 'u': /* --uninstall */ - mode = UNINSTALL; - kill_flag; - break; - case 'f': /* --force */ - force = 1; - kill_flag; - break; - case 'd': /* --directory */ - force_dst_dir = 1; - kill_flag; - break; - case 'q': /* --quiet */ - quiet = 1; - kill_flag; - break; - case 'p': /* --preserve */ - absolute = 0; - kill_flag; - break; - case 'a': /* --absolute */ - absolute = 1; - kill_flag; - break; - case 'R': /* --relative */ - relative = 1; - kill_flag; - break; - } - ); - - last = argv[argc-1]; - dst_is_dir = safe_isdir(last); - - load_args_minus(1, -/*printf("arg=%s last=%s force=%d q=%d d=%d\n", arg, last, force, quiet, force_dst_dir);*/ - switch(mode) { - case INSTALL: err |= safe_copy(arg, last, force, quiet, force_dst_dir); break; - case LINSTALL: err |= safe_link(arg, last, absolute, relative, force, quiet, force_dst_dir); break; - case UNINSTALL: - if (dst_is_dir) { - char path[MY_PATH_MAX]; - if (path_concat(path, sizeof(path), last, arg) != 0) { - if (!quiet) { - fprintf(stderr, "sccbox: can't remove %s/%s: resulting path is too long\n", last, arg); - err |= 1; - } - } - else - err |= safe_remove(path, !force, quiet); - } - break; - } - if ((mode == UNINSTALL) && (!dst_is_dir)) - err |= safe_remove(last, !force, quiet); - ); - - if (quiet) - return 0; - return err; -} - -int cmd_mkdir(int argc, char *argv[]) -{ - int parents = 0, err = 0, quiet = 0; - - load_flags( - switch(*arg) { - case 'q': /* --quiet */ - quiet = 1; kill_flag; break; - case 'f': - kill_flag; break; - case 'i': - case 'l': - case 'c': - kill_flag; break; /* ignore these for compatibility with install */ - case 'r': /* --rm */ - case 'u': /* --uninstall */ - return 0; /* don't do anything for uninstall */ - case 'p': parents = 1; kill_flag; break; - } - ); - - if (!parents) { - load_args( - if ((mkdir(arg, 0755) != 0) && (!quiet)) { - perror("sccbox"); - fprintf(stderr, "sccbox: failed to make directory %s\n", arg); - err |= 1; - } - ) - } - else { - load_args( - err |= safe_mkdir_p(arg); - ); - } - - if (quiet) - return 0; - - return err; -} - -int cmd_touch(int argc, char *argv[], int only_new) -{ - int n, res = 0; - - for(n = 1; n < argc; n++) { - if ((only_new) && (safe_isfile(argv[n]))) - continue; /* skip existing file in touchnew */ - - if (safe_touch(argv[n]) != 0) { - res = 1; - fprintf(stderr, "sccbox: failed to touch %s\n", argv[n]); - } - } - return res; -} - - -int main(int argc, char *argv[]) -{ - const char *prg = argv[0]; - if (argc > 1) { - if (strstr(argv[0], "sccbox") != NULL) { - argv++; - argc--; - } - - if (strcmp(argv[0], "--help") == 0) return help(prg, argv[1]); - if (strcmp(argv[0], "help") == 0) return help(prg, argv[1]); - if (strcmp(argv[0], "-h") == 0) return help(prg, argv[1]); - - if (strcmp(argv[0], "rm") == 0) return cmd_rm(argc, argv); - if (strcmp(argv[0], "install") == 0) return cmd_install(argc, argv, INSTALL, 1); - if (strcmp(argv[0], "linstall") == 0) return cmd_install(argc, argv, LINSTALL, 1); - if (strcmp(argv[0], "uninstall") == 0) return cmd_install(argc, argv, UNINSTALL, 1); - if (strcmp(argv[0], "mkdir") == 0) return cmd_mkdir(argc, argv); - if (strcmp(argv[0], "ln") == 0) return cmd_install(argc, argv, LINSTALL, 0); - if (strcmp(argv[0], "touch") == 0) return cmd_touch(argc, argv, 0); - if (strcmp(argv[0], "touchnew") == 0) return cmd_touch(argc, argv, 1); - fprintf(stderr, "sccbox: unknown command %s\n", argv[0]); - } - else - fprintf(stderr, "sccbox: need arguments\n"); - fprintf(stderr, "sccbox: try --help\n"); - return 1; -} diff --git a/scconfig/src/util/.svn/pristine/86/86d609dcf975c7ee4e5beacfbfebf45cec080f5f.svn-base b/scconfig/src/util/.svn/pristine/86/86d609dcf975c7ee4e5beacfbfebf45cec080f5f.svn-base deleted file mode 100644 index a142a78b..00000000 --- a/scconfig/src/util/.svn/pristine/86/86d609dcf975c7ee4e5beacfbfebf45cec080f5f.svn-base +++ /dev/null @@ -1,106 +0,0 @@ -#include -#include -#include "regex.h" -#include "libs.h" -#include "db.h" -#include "menulib/scmenu.h" -#include "arg_auto_menu.h" - -static const char *get_entry_val(const arg_auto_set_t *as) -{ - char *path; - const char *v, *res; - - if (as->subvals == arg_lib_nodes) { - path = str_concat("/", as->subtree, "presents", NULL); - v = get(path); - if ((v != NULL) && (strcmp(v, sfalse) == 0)) - res = "disable"; - else - res = "enable"; - free(path); - return res; - } -} - -#define next_word(curr, next) \ - do { \ - next = strchr(curr, '|'); \ - if (next != NULL) { \ - *next = '\0'; \ - next++; \ - } \ - } while(0) - -void append_settings_auto_set(scm_menu_entry_t *me, int max, const arg_auto_set_t *as, const char *include, const char *exclude, const char *remove_prefix, int entry_type, void *entry_data) -{ - const arg_auto_set_t *a; - scm_menu_entry_t *e; - int numa, n, ei; - char *accept; - - /* count number of all settings, allocate accept[] */ - numa = 0; - for(a = as; a->arg_key != NULL; a++) - numa++; - accept = calloc(numa, 1); - - /* mark entries included in accept[] */ - if (include != NULL) { - char *all = strclone(include), *next = all, *curr = all; - do { - next_word(curr, next); - re_comp(curr); - for(a = as, n = 0; a->arg_key != NULL; a++,n++) - if (re_exec(a->arg_key)) - accept[n] = 1; - curr = next; - } while((next != NULL) && (*next != '\0')); - free(all); - } - else - memset(accept, 1, numa); - - /* mark entries excluded in accept[] */ - if (exclude != NULL) { - char *all = strclone(exclude), *next = all, *curr = all; - do { - next_word(curr, next); - re_comp(curr); - for(a = as, n = 0; a->arg_key != NULL; a++,n++) - if (re_exec(a->arg_key)) - accept[n] = 0; - curr = next; - } while((next != NULL) && (*next != '\0')); - free(all); - } - - /* find the terminator */ - for(e = me, ei = 0; e->key != SCM_TERMINATOR; e++, ei++) ; - - re_comp(remove_prefix); - printf("exclude:\n"); - for(n = 0; n < numa; n++) { - if (accept[n]) { - char *sd; - if (re_exec(as[n].arg_key)) - sd = re_subs_dup(""); - else - sd = strclone(as[n].arg_key); - - e->type = entry_type; - e->key = sd; - e->value = get_entry_val(&as[n]); - e->user_data = &as[n]; - e->auto_data = entry_data; - e++; - ei++; - if (ei > max - 2) - break; - } - } - - e->type = SCM_TERMINATOR; - - free(accept); -} diff --git a/scconfig/src/util/.svn/pristine/8a/8a0b512415e8d8ca1e7dbd628a6062afbabf58f0.svn-base b/scconfig/src/util/.svn/pristine/8a/8a0b512415e8d8ca1e7dbd628a6062afbabf58f0.svn-base deleted file mode 100644 index 8b67dc90..00000000 --- a/scconfig/src/util/.svn/pristine/8a/8a0b512415e8d8ca1e7dbd628a6062afbabf58f0.svn-base +++ /dev/null @@ -1,7 +0,0 @@ -#CC=i586-mingw32msvc-gcc -#CFLAGS = -Wall -g - -sccbox: sccbox.c Makefile - $(CC) $(CFLAGS) sccbox.c -o sccbox - - diff --git a/scconfig/src/util/.svn/pristine/8c/8c05cfc2b2072d3b55ea52f8d3d2177a18247457.svn-base b/scconfig/src/util/.svn/pristine/8c/8c05cfc2b2072d3b55ea52f8d3d2177a18247457.svn-base deleted file mode 100644 index 6c020c3f..00000000 --- a/scconfig/src/util/.svn/pristine/8c/8c05cfc2b2072d3b55ea52f8d3d2177a18247457.svn-base +++ /dev/null @@ -1,832 +0,0 @@ -/* - scconfig - sccbox: portable copy, link, mkdir and remove - Copyright (C) 2016, 2017 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include -#include -#include -#include - -/*********************** DOCUMENTATION **************************/ - -static void help_generic(const char *prg) -{ - printf("sccbox - Makefile helper\n\n"); - printf("Invocation: %s cmd [switches] [paths]\n\n", prg); - printf("sccbox and provides a basic set of file-system utilities as a single,\n"); - printf("static linkable executable with dependency only on libc. It is implemented\n"); - printf("in C89 and uses only a very thin layer of non-C89 OS calls that trace\n"); - printf("back to early BSD days and are widely available on all platforms.\n\n"); - printf("The intention is to replace 'mkdir -p' and 'rm -f' and similar,\n"); - printf("non-portable commands with a less efficient, but more portable local\n"); - printf("implementation. Using sccbox for mkdir/install/uninstall exclusively also\n"); - printf("simplifies the Makefile rules because the semantics of uninstall\n"); - printf("matches the semantics of install and the same list of source files\n"); - printf("and destination can be passed and source files are not removed.\n\n"); - printf("For more info read the following help topics using --help topic:\n"); - printf(" error error handling\n"); - printf(" rm remove files (e.g. for make clean)\n"); - printf(" mkdir create directories (e.g. for make *install)\n"); - printf(" ln create symlink (e.g. for make *install)\n"); - printf(" install copy-install files (e.g. for make install)\n"); - printf(" linstall symlink-install files (e.g. for make linstall)\n"); - printf(" uninstall remove files (e.g. for make uninstall)\n"); - printf(" touch touch files (open for append)\n"); - printf(" touchnew touch non-existing files, ignore existing files\n"); - printf("\n"); -} - -static void help_error(const char *prg) -{ - printf("sccbox - error handling (all commands)\n\n"); - printf("Any sccbox command by default will try to carry out the requested\n"); - printf("operation assuming no errors, e.g. an mkdir will assume the target\n"); - printf("directory does not exists but all parent directories are in place.\n"); - printf("If such a command fails, the exit status is non-zero and error messages\n"); - printf("are printed to stderr.\n\n"); - printf("If the --quiet switch is specified, the command will try to do the same\n"); - printf("but never prints error messages and always returns 0. This is useful\n"); - printf("in situations when failure is expected (note: 2>/dev/null is not portable)\n\n"); - printf("If the --force switch is specified, the command will make extre efforts,\n"); - printf("sometimes even destructive ones, to fulfill the request. If it fails,\n"); - printf("error messages are printed (unless --quiet).\n\n"); -} - -static void help_rm_common(void) -{ - printf(" --quiet don't print error messages and set exit status to 0\n"); - printf(" --force a non-existing file is not an error\n"); -} - -static void help_rm(const char *prg) -{ - printf("sccbox rm [switches] paths\n\n"); - printf("Remove one or more paths from the file system. Paths can be\n"); - printf("files, symlinks and empty directories. Recursive removal is not\n"); - printf("supported. If multiple paths specified, attempt to remove them all\n"); - printf("even if some can not be removed.\n\n"); - printf("Switches:\n"); - help_rm_common(); - printf("\n"); -} - -static void help_mkdir(const char *prg) -{ - printf("sccbox mkdir [switches] paths\n\n"); - printf("Create one or more directories.\n\n"); - printf("Switches:\n"); - printf(" --quiet don't print error messages and set exit status to 0\n"); - printf(" --force ignored (there's nothing to force)\n"); - printf(" -p create parent directories automatically\n"); - printf(" -i ignored\n"); - printf(" -l ignored\n"); - printf(" -c ignored\n"); - printf(" -u do not do anyhting, exit 0\n"); - printf(" -r do not do anyhting, exit 0\n\n"); -} - -static void help_ln_common(void) -{ - printf(" --quiet don't print error messages and set exit status to 0\n"); - printf(" --force attempt to remove target if it exists\n"); -} - -static void help_ln(const char *prg) -{ - printf("sccbox ln [switches] existing new\n"); - printf("sccbox ln [switches] existing1 existing2 ... dir\n\n"); - printf("Create one or more symlinks. Intended for linking installed paths\n"); - printf("to other installed paths.\n\n"); - printf("Switches:\n"); - help_ln_common(); - printf(" --absolute convert existing paths to absolute paths\n\n"); - printf(" --relative make single symlink point to relative path\n\n"); -} - -static void help_install(const char *prg) -{ - printf("sccbox install [switches] src_file dst_file\n"); - printf("sccbox install [switches] src_file1 src_file2 ... dir\n\n"); - printf("Copies (or links or removes) one or more files. Intended to install\n"); - printf("files from the source or build tree to the installation root.\n\n"); - printf("Switches:\n"); - printf(" --quiet don't print error messages and set exit status to 0\n"); - printf(" --force install: attempt to remove destination\n"); - printf(" --absolute convert existing paths to absolute paths\n"); - printf(" --relative make single symlink point to relative path\n\n"); - printf(" -d force destination to be a directory (even remove old dest)\n"); - printf(" -i install (copy) files\n"); - printf(" -c install (copy) files\n"); - printf(" -u uninstall (remove) files - see --help uninstall\n"); - printf(" -r uninstall (remove) files - see --help uninstall\n"); - printf(" -l linstall (symlink) files - see --help linstall\n\n"); -} - -static void help_linstall(const char *prg) { - printf("sccbox linstall [switches] src_file dst_file\n"); - printf("sccbox linstall [switches] src_file1 src_file2 ... dir\n\n"); - printf("Installs (a) file(s) using symlinks. Automatically convert src_file\n"); - printf("paths to absolute paths. Intended for developers: if a package is\n"); - printf("symlink-installed, it can be run from the installation after a\n"); - printf("recompilation without needing to reinstall.\n\n"); - printf("Switches:\n"); - help_ln_common(); - printf(" --preserve do not convert source paths to absolute\n\n"); -} - -static void help_uninstall(const char *prg) { - printf("sccbox uninstall [switches] src_file dst_file\n"); - printf("sccbox uninstall [switches] src_file1 src_file2 ... dir\n\n"); - printf("Remove (an) installed file(s). In the first form, src_file is ignored.\n"); - printf("In the second form dir is used to calculate destination paths.\n\n"); - printf("The purpose of this command is to unify install and uninstall rules:\n"); - printf("unlike cp and rm, an 'sccbox install' and 'sccbox uninstall' can\n"); - printf("be used with the same parameter list to install and uninstall a set of files\n\n"); - printf("Switches:\n"); - help_rm_common(); - printf("\n"); -} - -static void help_touch(const char *prg) -{ - printf("sccbox touch file1 file2 ... fileN\n"); - printf("sccbox touchnew file1 file2 ... fileN\n\n"); - printf("Open all files listed, for append, and close them immedately.\n"); - printf("This makes sure the files exist and also bumps their modification date.\n"); - printf("Command touchnew ignores existing files; its primary use is to make\n"); - printf("sure a file exists without making changes to already existing files.\n"); -} - -static int help(const char *prg, const char *topic) -{ - if (topic == NULL) help_generic(prg); - else if (strcmp(topic, "error") == 0) help_error(prg); - else if (strcmp(topic, "rm") == 0) help_rm(prg); - else if (strcmp(topic, "mkdir") == 0) help_mkdir(prg); - else if (strcmp(topic, "ln") == 0) help_ln(prg); - else if (strcmp(topic, "install") == 0) help_install(prg); - else if (strcmp(topic, "linstall") == 0) help_linstall(prg); - else if (strcmp(topic, "uninstall") == 0) help_uninstall(prg); - else if (strcmp(topic, "touch") == 0) help_touch(prg); - else if (strcmp(topic, "touchnew") == 0) help_touch(prg); - else { - printf("No such help topic: %s\n", topic); - return 1; - } - return 0; -} - - - -/*********************** IMPLEMENTATION: low level **************************/ -#ifdef PATH_MAX -# define MY_PATH_MAX PATH_MAX -#else -# define MY_PATH_MAX 32768 -#endif - -typedef enum { - INSTALL, /* install with cp */ - LINSTALL, /* install with symlinks */ - UNINSTALL /* remove installed files */ -} scc_mode_t; - -#define kill_flag argv[n] = NULL - -#define load_flags(code) \ - do { \ - int n, flags = 1; \ - for(n = 1; n < argc; n++) { \ - char *arg = argv[n]; \ - if ((*arg == '-') && (flags)) { \ - if ((arg[1] == '-') && (arg[2] == '\0')) { \ - kill_flag; \ - flags = 0; \ - continue; \ - } \ - while(*arg == '-') arg++; \ - { code; } \ - } \ - } \ - } while(0) \ - -#define load_args_minus(delta, code) \ - do { \ - int n; \ - for(n = 1; n < argc-delta; n++) {\ - char *arg = argv[n]; \ - if (arg != NULL) \ - { code; } \ - } \ - } while(0); - -#define load_args(code) load_args_minus(0, code)\ - - -static int safe_isdir(const char *path) -{ - struct stat st; - - if (stat(path, &st) != 0) - return 0; - - return S_ISDIR(st.st_mode); -} - -static int safe_isfile(const char *path) -{ - struct stat st; - - if (stat(path, &st) != 0) - return 0; - - return S_ISREG(st.st_mode); -} - -static int safe_remove(const char *src, int need_existing_fd, int quiet) -{ - struct stat st; - int exists; - - if (quiet) - return remove(src); - - exists = stat(src, &st) == 0; - if ((need_existing_fd) && (!exists)) { - fprintf(stderr, "sccbox: Can't remove %s: no such file or directory\n", src); - return 1; - } - - - if (exists && (remove(src) != 0)) { - perror("sccbox"); - fprintf(stderr, "sccbox: Can't remove %s\n", src); - return 1; - } - return 0; -} - -#define issep(chr) (((chr) == '/') || ((chr) == '\\')) - -static char *my_basename(const char *path) -{ - const char *s = path + strlen(path); - for(s--; s >= path; s--) { - if (issep(*s)) - return (char *)s+1; - } - return (char *)path; -} - -static int path_concat(char *out, size_t out_len, const char *dir, const char *file) -{ - char *bn = my_basename(file); - size_t dlen = strlen(dir), blen = strlen(bn); - - if (dlen+blen+2 > out_len) - return 1; - - memcpy(out, dir, dlen); - out[dlen] = '/'; dlen++; - memcpy(out+dlen, bn, blen+1); - return 0; -} - -static int safe_mkdir_p(const char *path); - - -static int safe_copy(const char *src, const char *dst, int force, int quiet, int dst_is_dir) -{ - char buff[16384], dst2[MY_PATH_MAX]; - const char *dst_name = NULL; - FILE *fd, *fs; - struct stat st, dst_st; - int err = 0, remove_dst = 1; - - if (stat(src, &st) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: can't stat %s\n", src); - return 1; - } - - /* make sure symlinks/sockets/etc. are not copied into: remove any dst that's not a dir or a regular file */ - if (stat(dst, &dst_st) == 0) { - int try_remove = dst_is_dir ? (!S_ISDIR(dst_st.st_mode)) : (!S_ISDIR(dst_st.st_mode) || !S_ISREG(dst_st.st_mode)); - if (try_remove) { - if (remove(dst) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: filed to remove non-regular/non-directory target %s\n", dst); - return 1; - } - } - } - - if (dst_is_dir) { - remove_dst = 0; - if (safe_mkdir_p(dst) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: filed to create target directory %s\n", dst); - return 1; - } - } - - fs = fopen(src, "rb"); - if (fs == NULL) { - if (!quiet) - fprintf(stderr, "sccbox: can't copy %s to %s: can not open source for write\n", src, dst2); - return 1; - } - - if ((force) && (remove_dst)) - remove(dst); - - fd = fopen(dst, "wb"); - - if (fd == NULL) { - /* no luck opening the dest file, maybe dst is a directory, try to create a file under it */ - if (path_concat(dst2, sizeof(dst2), dst, src) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: can't copy %s to %s: resulting path is too long\n", src, dst); - fclose(fs); - return 1; - } - - - fd = fopen(dst2, "wb"); - if ((fd == NULL) && (force)) { - remove(dst2); - fd = fopen(dst2, "wb"); - if (fd == NULL) { - /* dest was not a directory or couldn't host our new file; if force, try to - overwrite whatever dst was */ - remove(dst); - fd = fopen(dst, "wb"); - if (fd == NULL) { - if (!quiet) - fprintf(stderr, "sccbox: can't copy %s to %s: destination can not be overwritten\n", src, dst2); - fclose(fs); - return 1; - } - dst_name = dst; - } - } - if (fd == NULL) { - if (!quiet) - fprintf(stderr, "sccbox: can't copy %s to %s: can not open destination for write\n", src, dst2); - fclose(fs); - return 1; - } - if (dst_name == NULL) - dst_name = dst2; - } - else - dst_name = dst; - - /* manual copy - the only portable way */ - for(;;) { - size_t len = fread(buff, 1, sizeof(buff), fs); - if (len == 0) - break; - if (fwrite(buff, 1, len, fd) != len) { - if (!quiet) { - perror("sccbox"); - fprintf(stderr, "sccbox: can't copy %s to %s\n", src, dst_name); - } - err = 1; - if (!force) - break; - } - } - - chmod(dst_name, st.st_mode); /* this may fail on windows or on strange FS, don't check the return value */ - - fclose(fs); - fclose(fd); - return err; -} - -static const char *safe_get_pwd(int quiet) -{ - static char pwd_buff[MY_PATH_MAX]; - static int valid = 0; - if (!valid) { - FILE *f; - char *end; - f = popen("pwd", "r"); - - if (f == NULL) { - if (!quiet) - perror("sccbox: running pwd"); - return NULL; - } - if (fgets(pwd_buff, sizeof(pwd_buff), f) == NULL) { - if (!quiet) - perror("sccbox: reading pwd's output"); - pclose(f); - return NULL; - } - pclose(f); - end = pwd_buff + strlen(pwd_buff) - 1; - while((end >= pwd_buff) && ((*end == '/') || (*end == '\n') || (*end == '\r'))) { - *end = '\0'; - end--; - } - if (*pwd_buff != '/') { - if (!quiet) - fprintf(stderr, "sccbox: invalid pwd: '%s'\n", pwd_buff); - return NULL; - } - valid = 1; - } - return pwd_buff; -} - -/* Both 'path' and 'from' are absolute paths; recalculate path to be a relative - path from 'from' and copy the result to buf. Returns buf. */ -char *relativize(char *buf, const char *path, const char *from) -{ - const char *p, *f, *c, *lastp, *lastf; - char *end = buf; - int cnt = 0, rem = MY_PATH_MAX-1, len; - - for(lastp = p = path, lastf = f = from; *p == *f; p++,f++) { - /* skip double separators */ - if (issep(p[0])) { - while(issep(p[0]) && issep(p[1])) p++; - lastp = p+1; - } - if (issep(f[0])) { - while(issep(f[0]) && issep(f[1])) f++; - lastf = f+1; - } - } - - p = lastp; - f = lastf; - - for(c = f; *c != '\0'; c++) { - if (issep(c[0])) { - cnt++; - while(issep(c[0]) && issep(c[1])) c++; - } - } - - while(cnt > 0) { - if (rem < 3) - return NULL; - strcpy(end, "../"); - end += 3; - rem -= 3; - cnt--; - } - - len = strlen(p); - if (len >= rem) - return NULL; - strcpy(end, p); - - return buf; -} - -/* create a symlink - needs to work only on UNIX but needs to compile on win32, - so use system("ln -s") and avoid link-related syscalls */ -static int safe_link(const char *src, const char *dst, int absolute, int relative, int force, int quiet, int dst_is_dir) -{ - char cmd[MY_PATH_MAX*2+16], full_src_tmp[MY_PATH_MAX], rel_src_tmp[MY_PATH_MAX]; - const char *full_src, *supp; - int remove_dst = 1; - - if ((absolute) && (*src != '/')) { - /* fix up relative source paths */ - const char *pwd = safe_get_pwd(quiet); - if (pwd == NULL) { - if (!quiet) - fprintf(stderr, "sccbox: can't figure current working directory for relative symlink %s to %s\n", src, dst); - return 1; - } - if (path_concat(full_src_tmp, sizeof(full_src_tmp), pwd, src) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: can't link %s to %s: resulting path is too long\n", src, dst); - return 1; - } - full_src = full_src_tmp; - } - else - full_src = src; - - if (dst_is_dir) { - struct stat dst_st; - if ((stat(dst, &dst_st) == 0) && (!S_ISDIR(dst_st.st_mode))) { - if (remove(dst) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: filed to remove non-directory target %s\n", dst); - return 1; - } - } - - remove_dst = 0; - if (safe_mkdir_p(dst) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: filed to create target directory %s\n", dst); - return 1; - } - } - - if (force) - remove(dst); - - supp = quiet ? " 2>/dev/null" : ""; - - if (relative) { - const char *fdst; - char full_dst_tmp[MY_PATH_MAX]; - - if (*dst != '/') { - const char *pwd = safe_get_pwd(quiet); - if (pwd == NULL) { - if (!quiet) - fprintf(stderr, "sccbox: can't figure current working directory for relative path '%s'\n", dst); - return 1; - } - if (path_concat(full_dst_tmp, sizeof(full_dst_tmp), pwd, dst) != 0) { - if (!quiet) - fprintf(stderr, "sccbox: can't link %s to %s: resulting path is too long\n", src, dst); - return 1; - } - fdst = full_dst_tmp; - } - else - fdst = dst; - full_src = relativize(rel_src_tmp, full_src, fdst); - } - - sprintf(cmd, "ln -s \"%s\" \"%s\"%s", full_src, dst, supp); - return system(cmd); -} - -static int safe_mkdir_p(const char *path) -{ - char *curr, *next, *s; - int res = 1, len = strlen(path); - char *p = malloc(len+1); - memcpy(p, path, len+1); - - /* do not create existing directories */ - if (safe_isdir(path)) - return 0; - - curr = p; - if ((isalpha(p[0]) && (p[1] == ':') && issep(p[2]))) { - /* windows special case: c:\ */ - curr += 3; - } - - /* remove trailing path separators so we don't create empty dirs at the end */ - s = p+len-1; - while((s >= p) && (issep(*s))) { - *s = '\0'; - s--; - } - - for(next = curr; next != NULL; curr = next) { - char old; - next = strpbrk(curr, "/\\"); - if (next != NULL) { - old = *next; - *next = '\0'; - } - res = mkdir(p, 0755); - if (next != NULL) { - *next = old; - next++; - } - } - - if (res != 0) { - perror("sccbox"); - fprintf(stderr, "sccbox: failed to make directory with parents: %s\n", path); - } - - free(p); - return res; /* return the result of the last mkdir only, previous failures probably meant existing parents */ -} - -static int safe_touch(const char *fn) -{ - FILE *f; - f = fopen(fn, "a"); - if (f == NULL) - return -1; - fclose(f); - return 0; -} - -/*********************** IMPLEMENTATION: high level **************************/ -int cmd_rm(int argc, char *argv[]) -{ - int err = 0, quiet = 0, need_existing_fd = 1; - load_flags( - switch(*arg) { - case 'f': need_existing_fd = 0; kill_flag; break; /* nop: can't do more than remove() */ - case 'q': quiet = 1; kill_flag; break; - } - ); - load_args( - err |= safe_remove(arg, need_existing_fd, quiet); - ); - - - if (quiet) - return 0; - - return err; -} - - -int cmd_install(int argc, char *argv[], scc_mode_t mode, int absolute) -{ - int force = 0, err = 0, quiet = 0, dst_is_dir, force_dst_dir = 0, relative = 0; - const char *last; - - load_flags( - if ((arg[0] == 'r') && (arg[1] == 'e')) arg[0] = 'R'; /* --relative */ - switch(*arg) { - case 'c': /* --copy */ - case 'i': /* --install */ - mode = INSTALL; - kill_flag; - break; - case 'l': /* --ln or --linstall */ - mode = LINSTALL; - kill_flag; - break; - case 'r': /* --rm */ - case 'u': /* --uninstall */ - mode = UNINSTALL; - kill_flag; - break; - case 'f': /* --force */ - force = 1; - kill_flag; - break; - case 'd': /* --directory */ - force_dst_dir = 1; - kill_flag; - break; - case 'q': /* --quiet */ - quiet = 1; - kill_flag; - break; - case 'p': /* --preserve */ - absolute = 0; - kill_flag; - break; - case 'a': /* --absolute */ - absolute = 1; - kill_flag; - break; - case 'R': /* --relative */ - relative = 1; - kill_flag; - break; - } - ); - - last = argv[argc-1]; - dst_is_dir = safe_isdir(last); - - load_args_minus(1, -/*printf("arg=%s last=%s force=%d q=%d d=%d\n", arg, last, force, quiet, force_dst_dir);*/ - switch(mode) { - case INSTALL: err |= safe_copy(arg, last, force, quiet, force_dst_dir); break; - case LINSTALL: err |= safe_link(arg, last, absolute, relative, force, quiet, force_dst_dir); break; - case UNINSTALL: - if (dst_is_dir) { - char path[MY_PATH_MAX]; - if (path_concat(path, sizeof(path), last, arg) != 0) { - if (!quiet) { - fprintf(stderr, "sccbox: can't remove %s/%s: resulting path is too long\n", last, arg); - err |= 1; - } - } - else - err |= safe_remove(path, !force, quiet); - } - break; - } - if ((mode == UNINSTALL) && (!dst_is_dir)) - err |= safe_remove(last, !force, quiet); - ); - - if (quiet) - return 0; - return err; -} - -int cmd_mkdir(int argc, char *argv[]) -{ - int parents = 0, err = 0, quiet = 0; - - load_flags( - switch(*arg) { - case 'q': /* --quiet */ - quiet = 1; kill_flag; break; - case 'f': - kill_flag; break; - case 'i': - case 'l': - case 'c': - kill_flag; break; /* ignore these for compatibility with install */ - case 'r': /* --rm */ - case 'u': /* --uninstall */ - return 0; /* don't do anything for uninstall */ - case 'p': parents = 1; kill_flag; break; - } - ); - - if (!parents) { - load_args( - if ((mkdir(arg, 0755) != 0) && (!quiet)) { - perror("sccbox"); - fprintf(stderr, "sccbox: failed to make directory %s\n", arg); - err |= 1; - } - ) - } - else { - load_args( - err |= safe_mkdir_p(arg); - ); - } - - if (quiet) - return 0; - - return err; -} - -int cmd_touch(int argc, char *argv[], int only_new) -{ - int n, res = 0; - - for(n = 1; n < argc; n++) { - if ((only_new) && (safe_isfile(argv[n]))) - continue; /* skip existing file in touchnew */ - - if (safe_touch(argv[n]) != 0) { - res = 1; - fprintf(stderr, "sccbox: failed to touch %s\n", argv[n]); - } - } - return res; -} - - -int main(int argc, char *argv[]) -{ - const char *prg = argv[0]; - if (argc > 1) { - if (strstr(argv[0], "sccbox") != NULL) { - argv++; - argc--; - } - - if (strcmp(argv[0], "--help") == 0) return help(prg, argv[1]); - if (strcmp(argv[0], "help") == 0) return help(prg, argv[1]); - if (strcmp(argv[0], "-h") == 0) return help(prg, argv[1]); - - if (strcmp(argv[0], "rm") == 0) return cmd_rm(argc, argv); - if (strcmp(argv[0], "install") == 0) return cmd_install(argc, argv, INSTALL, 1); - if (strcmp(argv[0], "linstall") == 0) return cmd_install(argc, argv, LINSTALL, 1); - if (strcmp(argv[0], "uninstall") == 0) return cmd_install(argc, argv, UNINSTALL, 1); - if (strcmp(argv[0], "mkdir") == 0) return cmd_mkdir(argc, argv); - if (strcmp(argv[0], "ln") == 0) return cmd_install(argc, argv, LINSTALL, 0); - if (strcmp(argv[0], "touch") == 0) return cmd_touch(argc, argv, 0); - if (strcmp(argv[0], "touchnew") == 0) return cmd_touch(argc, argv, 1); - fprintf(stderr, "sccbox: unknown command %s\n", argv[0]); - } - else - fprintf(stderr, "sccbox: need arguments\n"); - fprintf(stderr, "sccbox: try --help\n"); - return 1; -} diff --git a/scconfig/src/util/.svn/pristine/93/93ae6e1fe2f57a224e360795be3ac1e2796d58bd.svn-base b/scconfig/src/util/.svn/pristine/93/93ae6e1fe2f57a224e360795be3ac1e2796d58bd.svn-base deleted file mode 100644 index 0f7825e5..00000000 --- a/scconfig/src/util/.svn/pristine/93/93ae6e1fe2f57a224e360795be3ac1e2796d58bd.svn-base +++ /dev/null @@ -1,97 +0,0 @@ -/* - scconfig - set nodes from tables upon user CLI arguments - Copyright (C) 2015 Tibor Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include -#include -#include "log.h" -#include "libs.h" -#include "db.h" -#include "arg_auto_set.h" - -const arg_auto_set_node_t arg_lib_nodes[] = { - {"presents", sfalse}, - {"cflags", ""}, - {"ldflags", ""}, - {NULL, NULL} -}; - -const arg_auto_set_node_t arg_true[] = { - {"", strue}, - {NULL, NULL} -}; - -const arg_auto_set_node_t arg_false[] = { - {"", sfalse}, - {NULL, NULL} -}; - - -int arg_auto_set(const char *key, const char *value, const arg_auto_set_t *table) -{ - const arg_auto_set_t *lib; - const arg_auto_set_node_t *node; - - for(lib = table; lib->arg_key != NULL; lib++) { - if (strcmp(key, lib->arg_key) == 0) { - report("Executing lib table: %s\n", lib->arg_key); - for(node = lib->subvals; node->name != NULL; node++) { - char *s; - const char *setval; - - setval = node->value; - if (strcmp(setval, "$") == 0) - setval = value; - - if (*node->name != '\0') { - s = str_concat("/", lib->subtree, node->name, NULL); - put(s, setval); - free(s); - } - else - put(lib->subtree, setval); - } - return 1; - } - } - return 0; -} - -void arg_auto_print_options(FILE *fout, const char *line_prefix, const char *padding, const arg_auto_set_t *table) -{ - const arg_auto_set_t *t; - int pl; - - pl = strlen(padding); - - for(t = table; t->arg_key != NULL; t++) { - if (t->help_txt == NULL) - continue; - if (*t->help_txt == '$') { - int kl = strlen(t->arg_key); - if (kl > pl) - kl = pl; - fprintf(fout, "%s--%s%s%s\n", line_prefix, t->arg_key, padding+kl, t->help_txt+1); - } - else - fprintf(fout, "%s%s\n", line_prefix, t->help_txt); - } -} diff --git a/scconfig/src/util/.svn/pristine/d7/d780c19d6e3f0df00de1ac9985b2d6c3df6b4232.svn-base b/scconfig/src/util/.svn/pristine/d7/d780c19d6e3f0df00de1ac9985b2d6c3df6b4232.svn-base deleted file mode 100644 index 192900f5..00000000 --- a/scconfig/src/util/.svn/pristine/d7/d780c19d6e3f0df00de1ac9985b2d6c3df6b4232.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -#include "util/arg_auto_set.h" - -/* An optional bridge between auto_set and menulib: create a submenu from an - arg_auto_set_t table using regex key matching. */ -void append_settings_auto_set(scm_menu_entry_t *me, int max, const arg_auto_set_t *as, const char *include, const char *exclude, const char *remove_prefix, int entry_type, void *entry_data); diff --git a/scconfig/src/util/.svn/pristine/e4/e45d8267010d0e148e1e1cb5eb7bc853a491315a.svn-base b/scconfig/src/util/.svn/pristine/e4/e45d8267010d0e148e1e1cb5eb7bc853a491315a.svn-base deleted file mode 100644 index 2499d1b2..00000000 --- a/scconfig/src/util/.svn/pristine/e4/e45d8267010d0e148e1e1cb5eb7bc853a491315a.svn-base +++ /dev/null @@ -1,134 +0,0 @@ -/* - scconfig - quote file and pack it in a C string (ANSI C code) - Copyright (C) 2016, 2018 Tibor 'Igor2' Palinkas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Project page: http://repo.hu/projects/scconfig - Contact via email: scconfig [at] igor2.repo.hu -*/ - -#include - -void copy_strlit(const char *inds, const char *varname, const char *dprefix) -{ - int c, nl = 0, qt = 1, ind = 1; - const char *spc = (*dprefix == '\0') ? "" : " "; - - printf("#define NL \"\\n\"\n"); - printf("%s%sconst char *%s = \\\n", dprefix, spc, varname); - - while((c = getc(stdin)) != EOF) { - if (ind) { - printf("%s", inds); - if (!nl) - printf(" "); - ind = 0; - } - if (nl) { - printf("NL "); - nl = 0; - } - if (qt) { - printf("\""); - qt = 0; - } - switch(c) { - case '\t': printf(" "); break; - case '\n': printf("\"\n"); nl = qt = ind = 1; break; - case '\r': break; - case '\\': printf("\\\\"); break; - case '"': printf("\\\""); break; - default: - if ((c < 32) || (c>126)) - printf("\\%3o", c); - else - putc(c, stdout); - } - } - if (!qt) - printf("\""); - if (nl) { - if (ind) - printf("%s", inds); - printf("NL"); - } - printf(";\n"); -} - -void copy_chrarr(const char *inds, const char *varname, const char *dprefix) -{ - int c, col = 16000; - const char *spc = (*dprefix == '\0') ? "" : " "; - - printf("/* (Using character array instead of string literal for long strings) */\n"); - printf("%s%sconst char %s_arr[] = {", dprefix, spc, varname); - - while((c = getc(stdin)) != EOF) { - if (col > 60) { - printf("\n%s", inds); - col = 0; - } - switch(c) { - case '\t': col+=printf("'\\t',"); break; - case '\r': break; - case '\\': col+=printf("'\\\\',"); break; - case '\'': col+=printf("'\\\'',"); break; - case '\n': - col+=printf("'\\n',"); - col = 16000; - break; - default: - if ((c < 32) || (c>126)) - col+=printf("%d,", c); - else - col+=printf("'%c',", c); - break; - } - } - printf("\n%s0};\n", inds); - printf("%s%sconst char *%s = %s_arr;\n", dprefix, spc, varname, varname); - -} - - - -int main(int argc, char *argv[]) -{ - char *varname = "quoted_file"; - char *inds = "\t"; - char *banner = "/* Autogenerated by cquote.c - DO NOT EDIT */\n"; - char *cmd, *arg, *dprefix = ""; - int n, lit = 0; - - for(n = 1; n < argc; n++) { - cmd = argv[n]; - arg = argv[n+1]; - while(*cmd == '-') cmd++; - switch(*cmd) { - case 'n': varname = arg; n++; break; - case 'i': inds = arg; n++; break; - case 'l': lit = 1; break; - case 'p': dprefix = arg; n++; break; - } - } - - printf("%s", banner); - if (lit) - copy_strlit(inds, varname, dprefix); - else - copy_chrarr(inds, varname, dprefix); - return 0; -} diff --git a/scconfig/src/util/.svn/wc.db b/scconfig/src/util/.svn/wc.db deleted file mode 100644 index 99c94b19..00000000 Binary files a/scconfig/src/util/.svn/wc.db and /dev/null differ diff --git a/scconfig/src/util/.svn/wc.db-journal b/scconfig/src/util/.svn/wc.db-journal deleted file mode 100644 index e69de29b..00000000 diff --git a/src/actions.c b/src/actions.c index 998d0750..b18a4fec 100644 --- a/src/actions.c +++ b/src/actions.c @@ -521,12 +521,13 @@ void ask_new_file(void) } } -/* 20071007 */ -/* remove last symbol and decrement lastinstdef */ -void remove_symbol(void) +/* remove symbol and decrement lastinstdef */ +/* Warning: removing a symbol with a loaded schematic will make all symbol references corrupt */ +/* you should clear_drawing() first or load_schematic() or link_symbols_to_instances() + immediately afterwards */ +void remove_symbol(int j) { - int i,c,j; - j = lastinstdef-1; + int i,c; dbg(1, "remove_symbol(): removing symbol %d\n", j); if(instdef[j].prop_ptr != NULL) { my_free(666, &instdef[j].prop_ptr); @@ -597,6 +598,9 @@ void remove_symbol(void) my_free(683, &instdef[j].txtptr); my_free(684, &instdef[j].name); + for(i = j + 1; i < lastinstdef; i++) { + instdef[i-1] = instdef[i]; + } lastinstdef--; } @@ -606,7 +610,7 @@ void remove_symbols(void) for(j=lastinstdef-1;j>=0;j--) { dbg(2, "remove_symbols(): removing symbol %d\n",j); - remove_symbol(); + remove_symbol(j); } dbg(1, "remove_symbols(): done\n"); if(event_reporting) { diff --git a/src/callback.c b/src/callback.c index 11469cc6..e9596b62 100644 --- a/src/callback.c +++ b/src/callback.c @@ -1026,9 +1026,10 @@ int callback(int event, int mx, int my, KeySym key, draw(); break; } - if(0 && (key=='u') && (state==ControlMask)) /* testmode */ + if(1 && (key=='u') && (state==ControlMask)) /* testmode */ { int mult; + remove_symbol(2); expandlabel("/RST", &mult); expandlabel("/CCC[3:0]", &mult); expandlabel("CCC[AA:BB:DD]", &mult); diff --git a/src/netlist.c b/src/netlist.c index 3fcbd910..d68a8662 100644 --- a/src/netlist.c +++ b/src/netlist.c @@ -1248,7 +1248,7 @@ int sym_vs_sch_pins() my_free(848, &pin_dir); } /* for(i=0;i n_syms) remove_symbol(); + while(lastinstdef > n_syms) remove_symbol(lastinstdef - 1); return 0; } diff --git a/src/save.c b/src/save.c index 52d42044..e6b0ee41 100644 --- a/src/save.c +++ b/src/save.c @@ -895,48 +895,18 @@ int save_schematic(char *schname) /* 20171020 added return value */ void link_symbols_to_instances(void) /* 20150326 separated from load_schematic() */ { - int i,symbol, missing; + int i; char *type=NULL; /* 20150407 added static */ - char *symreference; int cond; - missing = 0; for(i=0;i save) remove_symbol(); /* if previous match_symbol() caused a symbol to be loaded unload it now */ + if(lastinstdef> save) remove_symbol(lastinstdef - 1); /* if previous match_symbol() caused a symbol to be loaded unload it now */ lastinstdef--; /* restore symbol we are loading */ if( /* add here symbol types not to consider when loading schematic-as-symbol instances */ @@ -1817,7 +1787,7 @@ int load_sym_def(const char *name, FILE *embed_fd) Gcurrent_sym = current_sym; qsort(instdef[save-1].boxptr[PINLAYER], instdef[save-1].rects[PINLAYER], sizeof(Box), CmpSchBbox); } - if(lastinstdef > save) remove_symbol(); /* if previous match_symbol() caused a symbol to be loaded unload it now */ + if(lastinstdef > save) remove_symbol(lastinstdef - 1); /* if previous match_symbol() caused a symbol to be loaded unload it now */ } recursion_counter--; dbg(1, "load_sym_def(): exiting, recursion_counter=%d\n", recursion_counter); diff --git a/src/spice_netlist.c b/src/spice_netlist.c index c01a3605..f830e85a 100644 --- a/src/spice_netlist.c +++ b/src/spice_netlist.c @@ -116,9 +116,6 @@ void global_spice_netlist(int global) /* netlister driver */ spice_netlist(fd, 0); - /* 20100217 */ - - /* 20150922 */ first = 0; for(i=0;i