diff --git a/compile.bat b/compile.bat
index 1009033f4f4daef9b53598014a7703d8659232be..869fd26680f7949056d3e81da223340c601d30e8 100644
--- a/compile.bat
+++ b/compile.bat
@@ -5,6 +5,14 @@
 pushd %~dp0
 SETLOCAL
 
+:: If compile is invoked with "extramemory", set SORT_MEM (used by concatFiles.bat)
+
+SET CMD_OPTION=%~1
+IF DEFINED CMD_OPTION IF /I [%CMD_OPTION%]==[EXTRAMEMORY] SET CMD_OPTION=EXTRAMEM
+IF DEFINED CMD_OPTION IF /I [%CMD_OPTION%]==[EMEMORY] SET CMD_OPTION=EXTRAMEM
+IF DEFINED CMD_OPTION IF /I [%CMD_OPTION%]==[EXTRAMEM] SET SORT_MEM=65535
+
+
 :: See if we can find a git installation
 set GITFOUND=no
 for %%k in (HKCU HKLM) do (
diff --git a/devTools/concatFiles.bat b/devTools/concatFiles.bat
index 5bb64b3584700666249949cd88114f3273feef3e..064696a065023ae555d72b99d019da8a697a0c85 100644
--- a/devTools/concatFiles.bat
+++ b/devTools/concatFiles.bat
@@ -8,10 +8,14 @@ CHCP 65001 > NUL
 :: TODO Proper temp file instead of bin\list.txt
 IF EXIST %3 DEL %3
 SET _LISTFILE=bin\list.txt
+SET _SORT_CMD=sort
+
+:: If SORT_MEM is defined, use memory option for SORT
+IF DEFINED SORT_MEM SET _SORT_CMD=%_SORT_CMD% /m %SORT_MEM%
 
 :: Collect sorted list of files
 ECHO "Ignore the first line to skip the BOM" >%_LISTFILE%
-(FOR /R "%~1" %%F IN (%2) DO echo "%%F") | sort >>%_LISTFILE%
+(FOR /R "%~1" %%F IN (%2) DO echo "%%F") | %_SORT_CMD% >>%_LISTFILE%
 
 :: If we have powershell available, strip the absolute path information
 :: If not, fail silently (which is fine, but will leak path information into the built file)