change a_float to a_real
[liba.git] / quickjs / 0002.patch
blobe511f00e57e0d764448f35ad058a70f7eded52c1
1 --- a/qjsc.c
2 +++ b/qjsc.c
3 @@ -463,6 +463,121 @@ static int output_executable(const char *out_filename, const char *cfilename,
4 unlink(cfilename);
5 return ret;
7 +#elif defined(CONFIG_CC) && defined(_WIN32)
8 +#include <windows.h>
10 +int exec_cmd(char **argv)
12 + STARTUPINFO si;
13 + PROCESS_INFORMATION pi;
14 + LPSTR args;
15 + {
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; /* \" */ }
21 + }
22 + cur += 3; /* " " */
23 + }
24 + args = (char *)LocalAlloc(0, cur);
25 + cur = 0;
26 + for (char *const *strv = argv; *strv; ++strv) {
27 + args[cur++] = '"';
28 + for (char const *str = *strv; *str; ++str) {
29 + if (*str != '"') {
30 + args[cur++] = *str;
31 + }
32 + else {
33 + args[cur++] = '\\';
34 + args[cur++] = *str;
35 + }
36 + }
37 + args[cur++] = '"';
38 + args[cur++] = ' ';
39 + }
40 + args[cur - 1] = 0;
41 + }
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);
46 + }
47 + LocalFree(args);
48 + if (WaitForSingleObject(pi.hProcess, INFINITE) == WAIT_OBJECT_0) {
49 + return 0;
50 + }
51 + return ~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;
61 + int ret;
63 + /* get the directory of the executable */
64 + pstrcpy(exe_dir, sizeof(exe_dir), exename);
65 + p = strrchr(exe_dir, '/');
66 + if (p) {
67 + *p = '\0';
68 + } else {
69 + pstrcpy(exe_dir, sizeof(exe_dir), ".");
70 + }
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);
78 + } else {
79 + snprintf(inc_dir, sizeof(inc_dir), "%s/include/quickjs", CONFIG_PREFIX);
80 + snprintf(lib_dir, sizeof(lib_dir), "%s/lib/quickjs", CONFIG_PREFIX);
81 + }
83 + lto_suffix = "";
85 + arg = argv;
86 + *arg++ = CONFIG_CC;
87 + *arg++ = "-pthread";
88 + *arg++ = "-O2";
89 +#ifdef CONFIG_LTO
90 + if (use_lto) {
91 + *arg++ = "-flto";
92 + lto_suffix = ".lto";
93 + }
94 +#endif
95 + /* XXX: use the executable path to find the includes files and
96 + libraries */
97 + *arg++ = "-D_GNU_SOURCE";
98 + *arg++ = "-D__USE_MINGW_ANSI_STDIO";
99 + *arg++ = "-I";
100 + *arg++ = inc_dir;
101 + *arg++ = "-o";
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;
110 + *arg = NULL;
112 + if (verbose) {
113 + for(arg = argv; *arg != NULL; arg++)
114 + printf("%s ", *arg);
115 + printf("\n");
118 + ret = exec_cmd((char **)argv);
119 + _unlink(cfilename);
120 + return ret;
122 #else
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)
127 if (!out_filename) {
128 if (output_type == OUTPUT_EXECUTABLE) {
129 +#if defined(_WIN32)
130 + out_filename = "a.exe";
131 +#else /* !_WIN32 */
132 out_filename = "a.out";
133 +#endif /* _WIN32 */
134 } else {
135 out_filename = "out.c";