Skip to content

Commit fe8f061

Browse files
authored
Merge pull request #41 from ReadAlongs/new_linker_options
feat: stricter emcc linker options in external file
2 parents 2961d78 + 43e83ff commit fe8f061

File tree

5 files changed

+23
-50
lines changed

5 files changed

+23
-50
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
1818
CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
1919
CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
2020
CHECK_SYMBOL_EXISTS(popen stdio.h HAVE_POPEN)
21+
CHECK_SYMBOL_EXISTS(getrusage sys/resource.h HAVE_GETRUSAGE)
2122

2223
# Testing endianness is stupidly hard with CMake
2324
if(EMSCRIPTEN)
24-
# FIXME: and doesn't work at all with emscripten, maybe it's just
25-
# always little-endian?
25+
# Emscripten is always little-endian (requires a linker flag to work
26+
# on big-endian platforms though)
2627
set(WORDS_BIGENDIAN 0)
2728
else()
2829
test_big_endian(WORDS_BIGENDIAN)

config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#cmakedefine HAVE_SYS_STAT_H
55
#cmakedefine HAVE_SNPRINTF
66
#cmakedefine HAVE_POPEN
7+
#cmakedefine HAVE_GETRUSAGE
78
#cmakedefine WITH_PTM_MGAU
89
#cmakedefine WITH_S2_SEMI_MGAU
910
#cmakedefine01 WORDS_BIGENDIAN

js/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ target_compile_options(ssjs PRIVATE -Oz)
1616
# https://stackoverflow.com/questions/68775616/how-not-to-have-dollar-sign-in-target-link-options-mangled
1717
# https://discourse.cmake.org/t/how-not-to-have-dollar-sign-in-target-link-options-mangled/3939/3
1818
target_link_options(ssjs PRIVATE
19-
-Oz
19+
@${CMAKE_SOURCE_DIR}/js/linker_options.txt
2020
-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=@${CMAKE_SOURCE_DIR}/js/library_funcs.txt
21-
-sEXPORTED_FUNCTIONS=@${CMAKE_SOURCE_DIR}/js/exported_functions.txt
22-
-sFILESYSTEM=0 -sMODULARIZE=1 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=33554432)
21+
-sEXPORTED_FUNCTIONS=@${CMAKE_SOURCE_DIR}/js/exported_functions.txt)
2322
# See
2423
# https://github.com/emscripten-core/emscripten/blob/main/cmake/Modules/Platform/Emscripten.cmake
2524
# ...sure would be nice if this were documented

js/linker_options.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-Oz
2+
-sFILESYSTEM=0
3+
-sMODULARIZE=1
4+
-sALLOW_MEMORY_GROWTH=1
5+
-sINITIAL_MEMORY=33554432
6+
-sSUPPORT_BIG_ENDIAN=1
7+
-sSTRICT=1
8+
-sSTRICT_JS=1

src/profile.c

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@
6666
#include <stdlib.h>
6767
#include <string.h>
6868

69-
#if defined(_WIN32) && !defined(__SYMBIAN32__)
69+
#if defined(_WIN32)
7070
# include <windows.h>
71-
# ifndef _WIN32_WCE
72-
# include <time.h>
73-
# endif
7471
#elif defined(HAVE_UNISTD_H) /* I know this, this is Unix... */
7572
# include <unistd.h>
7673
# include <sys/time.h>
@@ -85,23 +82,6 @@
8582
#include <soundswallower/err.h>
8683
#include <soundswallower/ckd_alloc.h>
8784

88-
#if defined(_WIN32_WCE) || defined(_WIN32_WP)
89-
DWORD unlink(const char *filename)
90-
{
91-
WCHAR *wfilename;
92-
DWORD rv;
93-
size_t len;
94-
95-
len = mbstowcs(NULL, filename, 0);
96-
wfilename = ckd_calloc(len+1, sizeof(*wfilename));
97-
mbstowcs(wfilename, filename, len);
98-
rv = DeleteFileW(wfilename);
99-
ckd_free(wfilename);
100-
101-
return rv;
102-
}
103-
#endif
104-
10585
pctr_t *
10686
pctr_new(char *nm)
10787
{
@@ -139,7 +119,7 @@ pctr_free(pctr_t * pc)
139119
}
140120

141121

142-
#if defined(_WIN32) && !defined(GNUWINCE) && !defined(__SYMBIAN32__)
122+
#if defined(_WIN32)
143123

144124
#define TM_LOWSCALE 1e-7
145125
#define TM_HIGHSCALE (4294967296.0 * TM_LOWSCALE);
@@ -169,17 +149,10 @@ make_sec(struct timeval *s)
169149
void
170150
ptmr_start(ptmr_t * tm)
171151
{
172-
#if (!defined(_WIN32)) || defined(GNUWINCE) || defined(__SYMBIAN32__)
152+
#if !defined(_WIN32)
173153
struct timeval e_start; /* Elapsed time */
174154
gettimeofday(&e_start, 0);
175155
tm->start_elapsed = make_sec(&e_start);
176-
#elif defined(_WIN32_WP)
177-
tm->start_cpu = GetTickCount64() / 1000;
178-
tm->start_elapsed = GetTickCount64() / 1000;
179-
#elif defined(_WIN32_WCE)
180-
/* No GetProcessTimes() on WinCE. (Note CPU time will be bogus) */
181-
tm->start_cpu = GetTickCount() / 1000;
182-
tm->start_elapsed = GetTickCount() / 1000;
183156
#else
184157
HANDLE pid;
185158
FILETIME t_create, t_exit, kst, ust;
@@ -199,31 +172,22 @@ ptmr_stop(ptmr_t * tm)
199172
{
200173
float64 dt_cpu, dt_elapsed;
201174

202-
#if (! defined(_WIN32)) || defined(GNUWINCE) || defined(__SYMBIAN32__)
175+
#if !defined(_WIN32)
176+
/* Unix */
203177
struct timeval e_stop; /* Elapsed time */
204-
205-
#if (! defined(_HPUX_SOURCE)) && (! defined(__SYMBIAN32__))
178+
# if defined(HAVE_GETRUSAGE) && !defined(__EMSCRIPTEN__) /* Which LIES */
206179
struct rusage stop; /* CPU time */
207-
208-
/* Unix but not HPUX */
209180
getrusage(RUSAGE_SELF, &stop);
210181
dt_cpu =
211182
make_sec(&stop.ru_utime) + make_sec(&stop.ru_stime) -
212183
tm->start_cpu;
213-
#else
184+
# else
214185
dt_cpu = 0.0;
215-
#endif
216-
/* Unix + HP */
186+
# endif
217187
gettimeofday(&e_stop, 0);
218188
dt_elapsed = (make_sec(&e_stop) - tm->start_elapsed);
219-
#elif defined(_WIN32_WP)
220-
dt_cpu = GetTickCount64() / 1000 - tm->start_cpu;
221-
dt_elapsed = GetTickCount64() / 1000 - tm->start_elapsed;
222-
#elif defined(_WIN32_WCE)
223-
/* No GetProcessTimes() on WinCE. (Note CPU time will be bogus) */
224-
dt_cpu = GetTickCount() / 1000 - tm->start_cpu;
225-
dt_elapsed = GetTickCount() / 1000 - tm->start_elapsed;
226189
#else
190+
/* Windows */
227191
HANDLE pid;
228192
FILETIME t_create, t_exit, kst, ust;
229193

0 commit comments

Comments
 (0)