-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel2exe.bat
150 lines (106 loc) · 2.61 KB
/
model2exe.bat
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
@setlocal
@setlocal enabledelayedexpansion
@set rootdir=%~dp0
@set target=%~1
@set vcvars=
@set platform=32
@set vsver=2019
@set "vsdir=%ProgramFiles(x86)%\Microsoft Visual Studio\%vsver%"
@for /D %%M in ("%vsdir%\*") do @(
@if exist "%%M\VC\Auxiliary\Build\vcvars%platform%.bat" (
@set "vcvars=%%M\VC\Auxiliary\Build\vcvars%platform%.bat"
goto use_vcvars
)
)
@set vsver=2022
@set "vsdir=%ProgramFiles%\Microsoft Visual Studio\%vsver%"
@for /D %%M in ("%vsdir%\*") do @(
@if exist "%%M\VC\Auxiliary\Build\vcvars%platform%.bat" (
@set "vcvars=%%M\VC\Auxiliary\Build\vcvars%platform%.bat"
goto use_vcvars
)
)
@echo.
@echo Failed to initialize MS build tools
@exit /b 1
:use_vcvars
@call "%vcvars%"
@set "MOD=%rootdir%mod\mod.exe"
@if not exist "%MOD%" (
@echo.
@echo Building mod...
@echo.
@if not exist "%rootdir%mod\obj\" (
@mkdir "%rootdir%mod\obj\"
)
cl "%rootdir%mod\*.c" /Fe:"%rootdir%mod\mod.exe" /Fo:"%rootdir%mod\obj/" /O2
@if %ERRORLEVEL% neq 0 (
@pause
@exit /b 1
)
@echo.
@echo ...done
)
@if not exist "%rootdir%sim\obj\" (
mkdir "%rootdir%sim\obj\"
)
@if "%target%" NEQ "" (
@for %%i in ("%target%") do @(
@set targetName=%%~ni
@set targetDir=%%~dpi
)
@set "target_c=!targetDir!!targetName!.c"
@set "target_exe=!targetDir!!targetName!.exe"
@if exist "!target_c!" (
@del "!target_c!"
)
"%MOD%" "%target%" "!target_c!"
@if not exist "!target_c!" (
@exit /b 1
)
@if exist "!target_exe!" (
@del "!target_exe!"
)
@call :sub_cl "!target_c!" "!target_exe!"
@if not exist "!target_exe!" (
@exit /b 1
)
@echo Created !target_exe!
@exit /b 0
)
@if not exist "%rootdir%out" (
mkdir "%rootdir%out"
)
@for /f %%M in ("%rootdir%target\*.model") do @(
@echo.
@echo Building sim for %%~nM...
@set "target_c=%rootdir%out\%%~nM.c"
@set "target_exe=%rootdir%out\%%~nM.exe"
@if exist "!target_c!" (
@del "!target_c!"
)
"%MOD%" "%rootdir%target\%%~nM.model" "!target_c!"
@if not exist "!target_c!" (
@echo.
@echo Failed to generate .c file for %%~nM
@exit /b 1
)
@echo ...compiling...
@if exist "!target_exe!" (
@del "!target_exe!"
)
@call :sub_cl "!target_c!" "!target_exe!"
@if not exist "!target_exe!" (
@echo.
@echo Failed to compile/link .c file for %%~nM
@exit /b 1
)
@echo.
@echo ...done...created %%~nM.exe
)
@exit /b 0
:sub_cl
@set "model_c=%1"
@set "model_exe=%2"
cl "%rootdir%sim\*.c" "%model_c%" gsl.lib /O2 /Fo:"%rootdir%sim\obj/" /Fe:"%model_exe%" /I"%rootdir%sim" /I"%rootdir%sim\gsl-2.7" /link /LIBPATH:"%rootdir%sim\gsl-2.7\.libs"
@exit /b