From 4346e775711021fda1a491d8739e85fde4fb6d9f Mon Sep 17 00:00:00 2001 From: pythonyx135793 Date: Thu, 22 Oct 2026 23:12:10 +0200 Subject: [PATCH 1/3] Test documented Date API and fix calendar boundary handling --- src/base/Array.cpp | 2 +- src/sys/Date.cpp | 23 ++--- tests/tests.cpp | 2 + tests/units/date-test.cpp | 179 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 194 insertions(+), 12 deletions(-) create mode 100644 tests/units/date-test.cpp diff --git a/src/base/Array.cpp b/src/base/Array.cpp index ee7f0a1..8afee81 100644 --- a/src/base/Array.cpp +++ b/src/base/Array.cpp @@ -123,7 +123,7 @@ struct Array { enum Mode { HEAP, STACK, STACK_ONLY }; tmp = a._mode; a._mode = b._mode; b._mode = tmp; } #if __cplusplus >= 201103L //move for C++11 - Array(Array&& tmp) noexcept : _ptr(NULL){ move(*this, tmp); } + Array(Array&& tmp) noexcept : _ptr(NULL), _len(0), _msize(0), _mode(HEAP){ move(*this, tmp); } Array& operator=(Array&& tmp) noexcept { move(*this, tmp); return *this; } Array& steal(Array& tmp){ move(*this, tmp); return *this; } Array& steal(Array&& tmp){ move(*this, tmp); return *this; } diff --git a/src/sys/Date.cpp b/src/sys/Date.cpp index d5c34fc..1ce2678 100644 --- a/src/sys/Date.cpp +++ b/src/sys/Date.cpp @@ -11,17 +11,18 @@ struct Date { long long timestamp; static char utc; struct DValue { long long ye int getMonth() const { return parseTimestamp(timestamp).month; } int getDay() const { return parseTimestamp(timestamp).day; } int getDate() const { return getDay(); } - #define EPOCH_DAYWEEK_OFFSET 4 - int getDayWeek() const { return (timestamp/86400+EPOCH_DAYWEEK_OFFSET)%7; } + #define EPOCH_DAYWEEK_OFFSET 3 + int getDayWeek() const { long long days=timestamp/86400; if(timestamp%86400<0) --days; + int day=(int)((days+EPOCH_DAYWEEK_OFFSET)%7); return day<0?day+7:day; } String toDirectDate(char sp1='.', bool toshort=false) const { DValue dv = parseTimestamp(timestamp+utc*3600); char sp[2]; sp[0]=sp1; sp[1]='\0'; String r; r<<(dv.day<10?"0":"")<= 0 ? days : days - 146096) / 146097; unsigned int doe = days - era * 146097; - unsigned int yoe = (doe * 29397) / 10737418; + unsigned int yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365; long long y = yoe + era * 400; unsigned int doy = doe - (365 * yoe + yoe / 4 - yoe / 100); unsigned int mp = (5 * doy + 2) / 153; dv.day = doy - (153 * mp + 2) / 5 + 1; dv.month = mp + (mp < 10 ? 3 : -9); //dv.year = y + (dv.month <= 2 ? 1 : 0); - dv.year = (int)(y + (mp >= 10)); return dv; } + dv.year = y + (mp >= 10); return dv; } static long long toTimestamp(const DValue& dv){ long long y = dv.year; unsigned int m = dv.month; unsigned int d = dv.day; y -= (m <= 2); @@ -96,12 +97,12 @@ struct Date { long long timestamp; static char utc; struct DValue { long long ye dv.day = stoin(darr[1]); dv.month = getMonth_Idx(darr[2]); dv.year = stoin(darr[3]); darr = darr[4].split(":"); darr.resize(3); dv.hour = stoin(darr[0]); dv.minute = stoin(darr[1]); dv.seconds = stoin(darr[2]); return dv; } - static String getDayWeek_Name(int day) { const char* const W_NAMES[] = { "", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; - return (day>0&&day<=7)?W_NAMES[day]:"UNKNOWN"; } + static String getDayWeek_Name(int day) { const char* const W_NAMES[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; + return (day>=0&&day<7)?W_NAMES[day]:"UNKNOWN"; } static String getMonth_Name(int month) { const char* const M_NAMES[] = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; return (month>0&&month<=12)?M_NAMES[month]:"UNKNOWN"; } static int getMonth_Idx(const CString name){ if(name=="Jan") return 1; if(name=="Feb") return 2; if(name=="Mar") return 3; if(name=="Apr") return 4; if(name=="May") return 5; if(name=="Jun") return 6; if(name=="Jul") return 7; if(name=="Aug") return 8; if(name=="Sep") return 9; if(name=="Oct") return 10; if(name=="Nov") return 11; if(name=="Dec") return 12; return 1; } -}; char Date::utc=0; } \ No newline at end of file +}; char Date::utc=0; } diff --git a/tests/tests.cpp b/tests/tests.cpp index 96f9a4e..9d6919a 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -44,6 +44,7 @@ template void TEST_NE_W(const T1& v1, const T2& v2){ // #endif #include "units/module-base.cpp" //Module_Base_test(); +#include "units/date-test.cpp" void Sys_module_test(); #include "units/module-structs.cpp" //Module_Structs_test(); #include "units/module-crypto.cpp" //Module_Crypto_test(); @@ -55,6 +56,7 @@ void __attribute__((constructor)) _init_chcp(){ SetConsoleOutputCP(CP_UTF8); Set int main(int argc, char* argv[]){ print(NCPP_COMPILE_INFO); _ncpp_check_ver(); os_version(); //setInterval(_dbg_ShowAllocs, 1000); // === BEGIN TEST === Module_Base_test(); + Date_documented_test(); Module_Structs_test(); Module_Crypto_test(); // === END TEST === diff --git a/tests/units/date-test.cpp b/tests/units/date-test.cpp new file mode 100644 index 0000000..c306d4f --- /dev/null +++ b/tests/units/date-test.cpp @@ -0,0 +1,179 @@ +// Complete documented Date API; fixed UTC fixtures, no clock or timezone changes. +// Invalid/malformed input has no documented error contract and is not probed. +static Date::DValue dateValue(long long year, int month, int day, + int hour=0, int minute=0, int second=0){ + Date::DValue value; + value.year=year; value.month=(char)month; value.day=(char)day; + value.hour=(char)hour; value.minute=(char)minute; value.seconds=(float)second; + return value; +} + +void Date_documented_test(){ + NextTest("Date default constructor and now bracketed by clock reads"); + long long before=GetTimestamp('s'); Date current; long long sampled=Date::now(); + long long after=GetTimestamp('s'); + TEST_EQ(current.timestamp>=before && current.timestamp<=after, true); + TEST_EQ(sampled>=before && sampled<=after, true); + + NextTest("Date seconds constructor: zero, positive and negative"); + TEST_EQ(Date(0LL).timestamp, 0LL); TEST_EQ(Date(1LL).timestamp, 1LL); + TEST_EQ(Date(-1LL).timestamp, -1LL); TEST_EQ(Date(-86400LL, 's').timestamp, -86400LL); + TEST_EQ(Date(2147483648LL).timestamp, 2147483648LL); + + NextTest("Date milliseconds constructor: exact seconds and subsecond truncation"); + TEST_EQ(Date(0LL, 'm').timestamp, 0LL); TEST_EQ(Date(2000LL, 'm').timestamp, 2LL); + TEST_EQ(Date(-2000LL, 'm').timestamp, -2LL); + TEST_EQ(Date(2999LL, 'm').timestamp, 2LL); TEST_EQ(Date(-2999LL, 'm').timestamp, -2LL); + + NextTest("Date string constructor: direct, reverse and ISO"); + TEST_EQ(Date("01.01.1970 00:00:00").timestamp, 0LL); + TEST_EQ(Date("1970-01-01 00:00:01").timestamp, 1LL); + TEST_EQ(Date("1969.12.31 23:59:59").timestamp, -1LL); + TEST_EQ(Date("2000-01-01T00:00:00Z").timestamp, 946684800LL); + TEST_EQ(Date("02.02.2026 01:09:05").timestamp, 1769994545LL); + + NextTest("Date IMF constructor: published HTTP fixture and epoch"); + TEST_EQ(Date("Sun, 06 Nov 1994 08:49:37 GMT").timestamp, 784111777LL); + TEST_EQ(Date("Thu, 01 Jan 1970 00:00:00 GMT").timestamp, 0LL); + TEST_EQ(Date("Wed, 31 Dec 1969 23:59:59 GMT").timestamp, -1LL); + + NextTest("Date DValue constructor: all components and signed epoch"); + TEST_EQ(Date(dateValue(1970,1,1)).timestamp, 0LL); + TEST_EQ(Date(dateValue(1969,12,31,23,59,59)).timestamp, -1LL); + TEST_EQ(Date(dateValue(1994,11,6,8,49,37)).timestamp, 784111777LL); + TEST_EQ(Date(dateValue(2026,2,2,1,9,5)).timestamp, 1769994545LL); + Date wideYear(dateValue(3000000000LL,3,1,12,34,56)); + TEST_EQ(wideYear.getYear(), 3000000000LL); + TEST_EQ(wideYear.getMonth(), 3); TEST_EQ(wideYear.getDay(), 1); + TEST_EQ(wideYear.toTime(), "12:34:56"); + + NextTest("Date year, month, day and date getters at epoch boundaries"); + Date epoch(0LL), previous(-1LL), future(2147483648LL); + TEST_EQ(epoch.getYear(), 1970LL); TEST_EQ(epoch.getMonth(), 1); TEST_EQ(epoch.getDay(), 1); + TEST_EQ(previous.getYear(), 1969LL); TEST_EQ(previous.getMonth(), 12); TEST_EQ(previous.getDate(), 31); + TEST_EQ(previous.getDate(), previous.getDay()); + TEST_EQ(future.getYear(), 2038LL); TEST_EQ(future.getMonth(), 1); TEST_EQ(future.getDay(), 19); + + NextTest("Date weekday is Monday zero through Sunday six"); + for(int day=0; day<7; ++day){ + TEST_EQ(Date(345600LL+day*86400LL).getDayWeek(), day); // Monday 1970-01-05 + TEST_EQ(Date(-259200LL+day*86400LL).getDayWeek(), day); // Monday 1969-12-29 + } + TEST_EQ(Date(-1LL).getDayWeek(), 2); TEST_EQ(Date(-86401LL).getDayWeek(), 1); + + NextTest("Date direct formatting: padding, separator and short time"); + Date fixture(784111777LL); + TEST_EQ(fixture.toDirectDate(), "06.11.1994 08:49:37"); + TEST_EQ(fixture.toDirectDate('/'), "06/11/1994 08:49:37"); + TEST_EQ(fixture.toDirectDate('-', true), "06-11-1994 08:49"); + TEST_EQ(epoch.toDirectDate(), "01.01.1970 00:00:00"); + + NextTest("Date reverse formatting: padding, separator and short time"); + TEST_EQ(fixture.toReverseDate(), "1994.11.06 08:49:37"); + TEST_EQ(fixture.toReverseDate('/'), "1994/11/06 08:49:37"); + TEST_EQ(fixture.toReverseDate('-', true), "1994-11-06 08:49"); + TEST_EQ(epoch.toReverseDate(), "1970.01.01 00:00:00"); + + NextTest("Date toString default and character separator"); + TEST_EQ(fixture.toString(), "1994.11.06 08:49:37"); + TEST_EQ(fixture.toString('/'), "1994/11/06 08:49:37"); + + NextTest("Date toString documented modes preserve date separator"); + TEST_EQ(fixture.toString("reverse"), "1994.11.06 08:49:37"); + TEST_EQ(fixture.toString("direct"), "06.11.1994 08:49:37"); + TEST_EQ(fixture.toString("reverse", '/'), "1994/11/06 08:49:37"); + TEST_EQ(fixture.toString("direct", '/'), "06/11/1994 08:49:37"); + TEST_EQ(fixture.toString("iso"), "1994-11-06T08:49:37Z"); + TEST_EQ(fixture.toString("imf"), "Sun, 06 Nov 1994 08:49:37 GMT"); + + NextTest("Date ISO formatting: zero, negative and beyond 32-bit seconds"); + TEST_EQ(epoch.toISOString(), "1970-01-01T00:00:00Z"); + TEST_EQ(previous.toISOString(), "1969-12-31T23:59:59Z"); + TEST_EQ(future.toISOString(), "2038-01-19T03:14:08Z"); + + NextTest("Date IMF formatting: all seven weekday names"); + const char* imfDays[]={"Mon, 05 Jan 1970 00:00:00 GMT", "Tue, 06 Jan 1970 00:00:00 GMT", + "Wed, 07 Jan 1970 00:00:00 GMT", "Thu, 08 Jan 1970 00:00:00 GMT", + "Fri, 09 Jan 1970 00:00:00 GMT", "Sat, 10 Jan 1970 00:00:00 GMT", "Sun, 11 Jan 1970 00:00:00 GMT"}; + for(int day=0; day<7; ++day) TEST_EQ(Date(345600LL+day*86400LL).toIMFDate(), imfDays[day]); + TEST_EQ(fixture.toIMFDate(), "Sun, 06 Nov 1994 08:49:37 GMT"); + TEST_EQ(previous.toIMFDate(), "Wed, 31 Dec 1969 23:59:59 GMT"); + + NextTest("Date time formatting: padding and short mode"); + TEST_EQ(epoch.toTime(), "00:00:00"); TEST_EQ(epoch.toTime(true), "00:00"); + TEST_EQ(Date(3723LL).toTime(), "01:02:03"); TEST_EQ(Date(3723LL).toTime(true), "01:02"); + TEST_EQ(Date(86399LL).toTime(), "23:59:59"); TEST_EQ(Date(86400LL).toTime(), "00:00:00"); + + NextTest("Date negative seconds use the preceding civil day"); + TEST_EQ(previous.toTime(), "23:59:59"); TEST_EQ(previous.toTime(true), "23:59"); + TEST_EQ(previous.toDirectDate(), "31.12.1969 23:59:59"); + TEST_EQ(previous.toReverseDate(), "1969.12.31 23:59:59"); + TEST_EQ(Date(-86400LL).toTime(), "00:00:00"); + TEST_EQ(Date(-86401LL).toReverseDate(), "1969.12.30 23:59:59"); + + NextTest("Date leap-day and non-leap century transitions"); + TEST_EQ(Date(951782400LL).toISOString(), "2000-02-29T00:00:00Z"); + TEST_EQ(Date(951868800LL).toISOString(), "2000-03-01T00:00:00Z"); + TEST_EQ(Date(-2203891200LL).toISOString(), "1900-03-01T00:00:00Z"); + TEST_EQ(Date(4107542400LL).toISOString(), "2100-03-01T00:00:00Z"); + TEST_EQ(Date(dateValue(1900,3,1)).timestamp-Date(dateValue(1900,2,28)).timestamp, 86400LL); + TEST_EQ(Date(dateValue(2000,3,1)).timestamp-Date(dateValue(2000,2,28)).timestamp, 172800LL); + TEST_EQ(Date(dateValue(2100,3,1)).timestamp-Date(dateValue(2100,2,28)).timestamp, 86400LL); + + NextTest("Date every month boundary across a complete Gregorian cycle"); + const int lengths[]={31,28,31,30,31,30,31,31,30,31,30,31}; + for(int year=1800; year<2200; ++year){ + for(int month=1; month<=12; ++month){ + int last=lengths[month-1]; + if(month==2 && year%4==0 && (year%100!=0 || year%400==0)) ++last; + Date start(dateValue(year,month,1)), end(dateValue(year,month,last,23,59,59)); + TEST_EQ(start.getYear(), (long long)year); TEST_EQ(start.getMonth(), month); TEST_EQ(start.getDay(), 1); + TEST_EQ(end.getYear(), (long long)year); TEST_EQ(end.getMonth(), month); TEST_EQ(end.getDate(), last); + TEST_EQ(end.timestamp-start.timestamp, last*86400LL-1); + Date next(end.timestamp+1); + TEST_EQ(next.getYear(), (long long)(month==12?year+1:year)); + TEST_EQ(next.getMonth(), month==12?1:month+1); TEST_EQ(next.getDay(), 1); + } + } + + NextTest("Date IMF month names and valid string round trips"); + const char* months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; + for(int month=1; month<=12; ++month){ + Date value(dateValue(2001,month,15,12,34,56)); + String expectedMonth=" "; expectedMonth+=months[month-1]; expectedMonth+=" "; + TEST_NE(value.toIMFDate().indexOf(expectedMonth), (size_t)-1); + TEST_EQ(Date(value.toIMFDate()).timestamp, value.timestamp); + TEST_EQ(Date(value.toISOString()).timestamp, value.timestamp); + TEST_EQ(Date(value.toDirectDate()).timestamp, value.timestamp); + TEST_EQ(Date(value.toReverseDate()).timestamp, value.timestamp); + } + + NextTest("Date parser Array intermediates retain ownership across moves"); + Array retained; + retained.push("old destination"); + { + Array fields=String("2026-02-02").split("-"); + move(retained, fields); + TEST_EQ(fields.size(), 0U); TEST_EQ(retained.size(), 3U); + TEST_EQ(retained[0], "2026"); TEST_EQ(retained[1], "02"); TEST_EQ(retained[2], "02"); + fields.push("reused source"); TEST_EQ(fields[0], "reused source"); + } + TEST_EQ(retained.size(), 3U); TEST_EQ(retained[0], "2026"); + Array stolen; + stolen.push("replace me"); stolen.steal(retained); + TEST_EQ(retained.size(), 0U); TEST_EQ(stolen.size(), 3U); TEST_EQ(stolen[2], "02"); + retained.push("independent"); TEST_EQ(retained[0], "independent"); + TEST_EQ(stolen[0], "2026"); + #if __cplusplus >= 201103L + Array emptySource; + Array emptyMoved((Array&&)emptySource); + TEST_EQ(emptySource.size(), 0U); TEST_EQ(emptyMoved.size(), 0U); + emptySource.push("source"); emptyMoved.push("destination"); + TEST_EQ(emptySource[0], "source"); TEST_EQ(emptyMoved[0], "destination"); + Array populatedMoved((Array&&)stolen); + TEST_EQ(stolen.size(), 0U); TEST_EQ(populatedMoved.size(), 3U); + TEST_EQ(populatedMoved[0], "2026"); TEST_EQ(populatedMoved[2], "02"); + stolen.push("reused moved-from"); TEST_EQ(stolen[0], "reused moved-from"); + TEST_EQ(populatedMoved[0], "2026"); + #endif +} From abceb73178164c9b211fd69c4727d62ea4f9c661 Mon Sep 17 00:00:00 2001 From: pythonyx135793 Date: Thu, 22 Oct 2026 23:34:11 +0200 Subject: [PATCH 2/3] Match ReadConsoleW declaration to Windows SDK --- src/base/readline.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/base/readline.cpp b/src/base/readline.cpp index b034e3f..4229d43 100644 --- a/src/base/readline.cpp +++ b/src/base/readline.cpp @@ -7,7 +7,8 @@ extern "C" { #define STD_INPUT_HANDLE -10UL #include //for ReadConsoleW, WideCharToMultiByte __declspec(dllimport) void* __stdcall GetStdHandle(unsigned long nStdHandle); struct _OVERLAPPED; -__declspec(dllimport) int __stdcall ReadConsoleW(void* hInput, void* lpBuffer, unsigned long nNumberOfCharsToRead, unsigned long* lpNumberOfCharsRead, void* lpReserved); +struct _CONSOLE_READCONSOLE_CONTROL; +__declspec(dllimport) int __stdcall ReadConsoleW(void* hInput, void* lpBuffer, unsigned long nNumberOfCharsToRead, unsigned long* lpNumberOfCharsRead, struct _CONSOLE_READCONSOLE_CONTROL* pInputControl); __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int CodePage, unsigned long dwFlags, const wchar_t*, int, char*, int, const char*, int*); //__declspec(dllimport) int __stdcall ReadFile(void* hFile, void* lpBuffer, unsigned long nNumberOfBytesToRead, unsigned long* lpNumberOfBytesRead, struct _OVERLAPPED* lpOverlapped); #endif From bb5baea112f22414787c21b6bcddfdc3468d9936 Mon Sep 17 00:00:00 2001 From: pythonyx135793 Date: Thu, 22 Oct 2026 23:40:15 +0200 Subject: [PATCH 3/3] Fix Windows Clang build flags and propagate compile failures --- tests/make_test.bat | 70 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/tests/make_test.bat b/tests/make_test.bat index a2b8d77..07d83ef 100644 --- a/tests/make_test.bat +++ b/tests/make_test.bat @@ -34,7 +34,7 @@ if "%~1"=="x32" (set "ARCH_FLAG=-m32" & set "WL_ENTRY_FNAME=__start" & shift) set WARN_FLAGS=-Wall -Wno-misleading-indentation set FNO_FLAGS=-fno-exceptions -fno-rtti set FNO_FLAGS_WH=%FNO_FLAGS% -fwhole-program -if "%COMPILER%"=="CLANG" (set "FNO_FLAGS_WH=%FNO_FLAGS% -flto=full -fvisibility=hidden -Wl,/OPT:REF -Wl,/OPT:ICF") +if "%COMPILER%"=="CLANG" (set "FNO_FLAGS_WH=%FNO_FLAGS% -fvisibility=hidden") set OPT_FLAGS=-O2 -std=%STDCXX% %FNO_FLAGS_WH% set DBG_LNK_FLAGS=%ARCH_FLAG% -lws2_32 -lpsapi -liphlpapi @@ -73,17 +73,61 @@ set start_time=%TIME% if not "%gccpath%"=="" (cd /d "%gccpath%") -if "%mode%"=="LIB" echo Make via ncpp.a... & %CBIN% -D NCPP_LIB_USE %WARN_FLAGS% %OPT_FLAGS% %cppfile% -o %exefile% -L"%currCD%\..\lib" -lncpp %LNK_FLAGS% -if "%mode%"=="LIB_DLL" echo Make via ncpp.dll... & %CBIN% -D NCPP_LIB_USE %WARN_FLAGS% %OPT_FLAGS% %cppfile% -o %exefile% -L"%currCD%\..\lib" -lncpp %D_LNK_FLAGS% -if "%mode%"=="FAST" echo Make with -O3 -march=native... & %CBIN% %WARN_FLAGS% -O3 -std=$STDCXX %FNO_FLAGS_WH% %cppfile% -o %exefile% -march=native -mtune=native -flto -funroll-loops -fipa-cp-clone -ffast-math -fomit-frame-pointer %LNK_FLAGS% -if "%mode%"=="DBG" echo Make debug -g -Og... & %CBIN% %WARN_FLAGS% -g -Og -std=%STDCXX% %FNO_FLAGS_WH% %cppfile% -o %exefile% %DBG_LNK_FLAGS% -if "%mode%"=="SAN" echo Make using sanitizers... & %CBIN% %WARN_FLAGS% -g -Og -std=%STDCXX% %FNO_FLAGS_WH% %cppfile% -o %exefile% %D_LNK_FLAGS% -fsanitize=address,undefined -if "%mode%"=="GUI" echo Make for GUI... & %CBIN% -DUSE_GUI -DNOUSE_GL %WARN_FLAGS% %OPT_FLAGS% %cppfile% -o %exefile% %LNK_FLAGS% -lgdi32 -if "%mode%"=="GL" echo Make for GL... & %CBIN% -DUSE_GUI %WARN_FLAGS% %OPT_FLAGS% %cppfile% -o %exefile% %LNK_FLAGS% -lopengl32 -lgdi32 -if "%mode%"=="EXP" echo Make for Experimental... & %CBIN% -DUSE_GUI -DUSE_EXPERIMENTAL %WARN_FLAGS% %OPT_FLAGS% %cppfile% -o %exefile% %LNK_FLAGS% -lopengl32 %IMAGE_LIBS% %AUDIO_LIBS% -if "%mode%"=="NOCRT" echo Make NOCRT... & %CBIN% -DNCPP_NOCRT %WARN_FLAGS% -O2 -std=%STDCXX% %FNO_FLAGS% %cppfile% -o %exefile% %ARCH_FLAG% -Wl,--entry=%WL_ENTRY_FNAME% -s -static -nostdlib -lkernel32 -if "%mode%"=="DLNK" echo Make DLNK (Dynamic Lnk)... & %CBIN% %WARN_FLAGS% %OPT_FLAGS% %cppfile% -o %exefile% %D_LNK_FLAGS% -if "%mode%"=="" echo Make (default)... & %CBIN% %WARN_FLAGS% %OPT_FLAGS% %cppfile% -o %exefile% %LNK_FLAGS% +if "%mode%"=="LIB" ( + echo Make via ncpp.a... + %CBIN% -D NCPP_LIB_USE %WARN_FLAGS% %OPT_FLAGS% "%cppfile%" -o "%exefile%" -L"%currCD%\..\lib" -lncpp %LNK_FLAGS% + if errorlevel 1 exit /b 1 +) +if "%mode%"=="LIB_DLL" ( + echo Make via ncpp.dll... + %CBIN% -D NCPP_LIB_USE %WARN_FLAGS% %OPT_FLAGS% "%cppfile%" -o "%exefile%" -L"%currCD%\..\lib" -lncpp %D_LNK_FLAGS% + if errorlevel 1 exit /b 1 +) +if "%mode%"=="FAST" ( + echo Make with -O3 -march=native... + %CBIN% %WARN_FLAGS% -O3 -std=%STDCXX% %FNO_FLAGS_WH% "%cppfile%" -o "%exefile%" -march=native -mtune=native -flto -funroll-loops -fipa-cp-clone -ffast-math -fomit-frame-pointer %LNK_FLAGS% + if errorlevel 1 exit /b 1 +) +if "%mode%"=="DBG" ( + echo Make debug -g -Og... + %CBIN% %WARN_FLAGS% -g -Og -std=%STDCXX% %FNO_FLAGS_WH% "%cppfile%" -o "%exefile%" %DBG_LNK_FLAGS% + if errorlevel 1 exit /b 1 +) +if "%mode%"=="SAN" ( + echo Make using sanitizers... + %CBIN% %WARN_FLAGS% -g -Og -std=%STDCXX% %FNO_FLAGS_WH% "%cppfile%" -o "%exefile%" %D_LNK_FLAGS% -fsanitize=address,undefined + if errorlevel 1 exit /b 1 +) +if "%mode%"=="GUI" ( + echo Make for GUI... + %CBIN% -DUSE_GUI -DNOUSE_GL %WARN_FLAGS% %OPT_FLAGS% "%cppfile%" -o "%exefile%" %LNK_FLAGS% -lgdi32 + if errorlevel 1 exit /b 1 +) +if "%mode%"=="GL" ( + echo Make for GL... + %CBIN% -DUSE_GUI %WARN_FLAGS% %OPT_FLAGS% "%cppfile%" -o "%exefile%" %LNK_FLAGS% -lopengl32 -lgdi32 + if errorlevel 1 exit /b 1 +) +if "%mode%"=="EXP" ( + echo Make for Experimental... + %CBIN% -DUSE_GUI -DUSE_EXPERIMENTAL %WARN_FLAGS% %OPT_FLAGS% "%cppfile%" -o "%exefile%" %LNK_FLAGS% -lopengl32 %IMAGE_LIBS% %AUDIO_LIBS% + if errorlevel 1 exit /b 1 +) +if "%mode%"=="NOCRT" ( + echo Make NOCRT... + %CBIN% -DNCPP_NOCRT %WARN_FLAGS% -O2 -std=%STDCXX% %FNO_FLAGS% "%cppfile%" -o "%exefile%" %ARCH_FLAG% -Wl,--entry=%WL_ENTRY_FNAME% -s -static -nostdlib -lkernel32 + if errorlevel 1 exit /b 1 +) +if "%mode%"=="DLNK" ( + echo Make DLNK ^(Dynamic Lnk^)... + %CBIN% %WARN_FLAGS% %OPT_FLAGS% "%cppfile%" -o "%exefile%" %D_LNK_FLAGS% + if errorlevel 1 exit /b 1 +) +if "%mode%"=="" ( + echo Make ^(default^)... + %CBIN% %WARN_FLAGS% %OPT_FLAGS% "%cppfile%" -o "%exefile%" %LNK_FLAGS% + if errorlevel 1 exit /b 1 +) if not "%gccpath%"=="" (cd /d "%currCD%") @@ -95,4 +139,4 @@ set /A durationMS=endMS-startMS set /A durationS=durationMS/1000 set /A durationMS=durationMS%%1000 echo Build Time: %durationS%.%durationMS% sec. -pause \ No newline at end of file +exit /b 0 \ No newline at end of file