3 @@ -463,6 +463,121 @@ static int output_executable(const char *out_filename, const char *cfilename,
7 +#elif defined(CONFIG_CC) && defined(_WIN32)
10 +int exec_cmd(char **argv)
13 + PROCESS_INFORMATION pi;
16 + unsigned int cur = 0;
17 + for (char *const *strv = argv; *strv; ++strv) {
18 + for (char const *str = *strv; *str; ++str) {
19 + if (*str != '"') { ++cur; }
20 + else { cur += 2; /* \" */ }
24 + args = (char *)LocalAlloc(0, cur);
26 + for (char *const *strv = argv; *strv; ++strv) {
28 + for (char const *str = *strv; *str; ++str) {
42 + memset(&si, 0, sizeof(si));
43 + memset(&pi, 0, sizeof(pi));
44 + if (CreateProcess(NULL, args, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) {
45 + CloseHandle(pi.hThread);
48 + if (WaitForSingleObject(pi.hProcess, INFINITE) == WAIT_OBJECT_0) {
54 +static int output_executable(const char *out_filename, const char *cfilename,
55 + BOOL use_lto, BOOL verbose, const char *exename)
57 + const char *argv[64];
58 + const char **arg, *lto_suffix;
59 + char libjsname[1024];
60 + char exe_dir[1024], inc_dir[1024], lib_dir[1024], buf[1024], *p;
63 + /* get the directory of the executable */
64 + pstrcpy(exe_dir, sizeof(exe_dir), exename);
65 + p = strrchr(exe_dir, '/');
69 + pstrcpy(exe_dir, sizeof(exe_dir), ".");
72 + /* if 'quickjs.h' is present at the same path as the executable, we
73 + use it as include and lib directory */
74 + snprintf(buf, sizeof(buf), "%s/quickjs.h", exe_dir);
75 + if (access(buf, R_OK) == 0) {
76 + pstrcpy(inc_dir, sizeof(inc_dir), exe_dir);
77 + pstrcpy(lib_dir, sizeof(lib_dir), exe_dir);
79 + snprintf(inc_dir, sizeof(inc_dir), "%s/include/quickjs", CONFIG_PREFIX);
80 + snprintf(lib_dir, sizeof(lib_dir), "%s/lib/quickjs", CONFIG_PREFIX);
87 + *arg++ = "-pthread";
92 + lto_suffix = ".lto";
95 + /* XXX: use the executable path to find the includes files and
97 + *arg++ = "-D_GNU_SOURCE";
98 + *arg++ = "-D__USE_MINGW_ANSI_STDIO";
102 + *arg++ = out_filename;
103 + *arg++ = cfilename;
104 + *arg++ = "-Wl,-Bstatic,--whole-archive";
105 + *arg++ = "-lwinpthread";
106 + *arg++ = "-Wl,--no-whole-archive";
107 + snprintf(libjsname, sizeof(libjsname), "%s/libquickjs%s.a",
108 + lib_dir, lto_suffix);
109 + *arg++ = libjsname;
113 + for(arg = argv; *arg != NULL; arg++)
114 + printf("%s ", *arg);
118 + ret = exec_cmd((char **)argv);
119 + _unlink(cfilename);
123 static int output_executable(const char *out_filename, const char *cfilename,
124 BOOL use_lto, BOOL verbose, const char *exename)
125 @@ -604,7 +719,11 @@ int main(int argc, char **argv)
128 if (output_type == OUTPUT_EXECUTABLE) {
130 + out_filename = "a.exe";
132 out_filename = "a.out";
135 out_filename = "out.c";