summaryrefslogtreecommitdiff
path: root/scripts/build_release.bat
blob: 4f9ce43e4fd2c7f509d9f72576ce395c648954c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
@echo off
REM ReiLua Release Build Script
REM Run this from w64devkit shell or CMD with MinGW in PATH

echo ================================
echo ReiLua - Release Build
echo ================================
echo.

REM Get script directory and navigate to project root
cd /d "%~dp0.."

REM Check if we're in the right directory
if not exist "CMakeLists.txt" (
    echo ERROR: Cannot find CMakeLists.txt in project root
    exit /b 1
)

REM Create and navigate to build directory
if not exist "build" mkdir build
cd build
if errorlevel 1 (
    echo ERROR: Cannot access build directory
    exit /b 1
)

REM ALWAYS clean build folder for fresh build
echo Cleaning build directory for fresh build...
del /Q /S * >nul 2>&1
for /d %%p in (*) do rmdir "%%p" /s /q >nul 2>&1
echo * Build directory cleaned
echo.

REM Clean old embedded files
echo Ready for fresh build...
del /Q embedded_main.h embedded_assets.h 2>nul

REM Auto-copy from game folder if it exists
echo.
if exist "..\game" (
    echo Found game/ folder - auto-copying ALL contents to build...
    
    REM Copy all files from game folder recursively, excluding LSP files
    xcopy /E /I /Y /EXCLUDE:..\game\ReiLua_API.lua+..\game\.luarc.json "..\game\*" . >nul 2>&1
    if exist "..\game\ReiLua_API.lua" del /Q "ReiLua_API.lua" 2>nul
    if exist "..\game\.luarc.json" del /Q ".luarc.json" 2>nul
    
    echo   * Copied ALL game files and folders
    echo   * All folder structures preserved ^(user-created folders included^)
    echo.
)

REM Check for Lua files
echo Checking for Lua files...
dir /b *.lua >nul 2>&1
if errorlevel 1 (
    echo.
    echo WARNING: No Lua files found in build directory!
    echo.
    if exist "..\game" (
        echo No Lua files found in game/ folder.
        echo Add your main.lua to game/ folder and try again.
    ) else (
        echo Tip: Create a game/ folder in project root and add main.lua there.
        echo Or manually copy files:
        echo   cd build
        echo   copy ..\your_game\*.lua .
    )
    echo.
    set /p CONTINUE="Do you want to continue anyway? (y/N): "
    if /i not "%CONTINUE%"=="y" exit /b 1
) else (
    echo Found Lua files:
    dir /b *.lua
)

REM Check for non-Lua data files (any folder, any file type)
echo.
echo Checking for data files to embed...
set DATA_COUNT=0
for /r %%f in (*) do (
    echo %%~nxf | findstr /i /v ".lua .exe .o .a CMake Makefile" >nul
    if not errorlevel 1 set /a DATA_COUNT+=1
)

if %DATA_COUNT% GTR 0 (
    echo Found data files to embed
    echo   ^(includes: images, sounds, config, data, and any other files^)
    set EMBED_ASSETS=ON
) else (
    echo No non-Lua files found ^(only Lua code will be embedded^)
    set EMBED_ASSETS=OFF
)

echo.
echo ================================
echo Build Configuration
echo ================================
echo Lua Embedding:    ON
echo Data Embedding:   %EMBED_ASSETS%
echo Build Type:       Release
echo ================================
echo.
pause

REM Clean CMake cache
echo.
echo Cleaning CMake cache...
del /Q CMakeCache.txt 2>nul
rmdir /S /Q CMakeFiles 2>nul

REM Configure with embedding enabled
echo.
echo Configuring CMake for release...
cmake -G "MinGW Makefiles" .. -DEMBED_MAIN=ON -DEMBED_ASSETS=%EMBED_ASSETS% -DCMAKE_BUILD_TYPE=Release

if errorlevel 1 (
    echo.
    echo ERROR: CMake configuration failed!
    pause
    exit /b 1
)

REM Build
echo.
echo Building ReiLua Release...
mingw32-make

if errorlevel 1 (
    echo.
    echo ERROR: Build failed!
    pause
    exit /b 1
)

REM Show summary
echo.
echo ================================
echo Embedded Files Summary
echo ================================

if exist "embedded_main.h" (
    echo.
    echo Embedded Lua files:
    findstr /C:"Embedded file:" embedded_main.h
)

if exist "embedded_assets.h" (
    echo.
    echo Embedded assets:
    findstr /C:"Embedded asset:" embedded_assets.h
)

echo.
echo ================================
echo Build Complete!
echo ================================
echo.
echo Executable: ReiLua.exe
echo Location:   %CD%\ReiLua.exe
echo.
echo Your game is ready for distribution!
echo.
echo To test the release build:
echo   ReiLua.exe --log  (with console)
echo   ReiLua.exe        (production mode)
echo.
echo To distribute:
echo   - Copy ReiLua.exe to your distribution folder
echo   - Rename it to your game name (optional)
echo   - That's it! Single file distribution!
echo.
pause