[IOT-1089] Merge remote-tracking branch 'origin/master' into generic-java
[platform/upstream/iotivity.git] / run.bat
1 @echo off
2 REM Helper script to build and run IoTivity on Windows
3 SETLOCAL ENABLEDELAYEDEXPANSION
4
5 if [%1]==[] goto USAGE
6
7 set IOTIVITY_DIR=%~dp0
8 set HOME=%USERPROFILE%
9
10 IF "%1" == "msys" (
11   set BUILD_MSYS="YES"
12   SHIFT
13 ) ELSE (
14   set BUILD_MSYS=
15 )
16
17 REM *** Default BUILD OPTIONS ***
18 set TARGET_OS=windows
19
20 if "%TARGET_ARCH%" == "" (
21   set TARGET_ARCH=amd64
22
23
24 if "%TEST%" == "" (
25   set TEST=1
26 )
27
28 if "%LOGGING%" == "" (
29   set LOGGING=0
30 )
31
32 if "%RELEASE%" == "" (
33   set RELEASE=0
34 )
35
36 set SECURED=1
37 set WITH_RD=1
38 set ROUTING=EP
39 set WITH_UPSTREAM_LIBCOAP=1
40
41 set RUN_ARG=%1
42 SHIFT
43
44 set DEBUG=
45
46 :processArgs
47 IF NOT "%1"=="" (
48   IF "%1"=="-arch" (
49     SET TARGET_ARCH=%2
50     SHIFT
51   )
52   IF "%1"=="-noTest" (
53     SET TEST=0
54   )
55   IF "%1"=="-logging" (
56     SET LOGGING=1
57   )    
58   IF "%1"=="-debugger" (
59     set DEBUG="%ProgramFiles(x86)%\Windows Kits\10\Debuggers\x64\cdb.exe" -2 -c "g" 
60   )
61   IF "%1"=="-release" (
62     SET RELEASE=1
63   )
64
65   SHIFT
66   GOTO :processArgs
67 )
68
69 REM We need to append the "PATH" so the octbstack.dll can be found by executables
70 IF "%BUILD_MSYS%" == "" (
71   set BUILD_DIR=out\windows\%TARGET_ARCH%\debug
72   set PATH=!PATH!;!IOTIVITY_DIR!!BUILD_DIR!;
73 ) ELSE (
74   set BUILD_DIR=out\msys_nt\x86_64\debug
75   set PATH=!PATH!;!BUILD_DIR!;C:\msys64\mingw64\bin
76 )
77
78 set BUILD_OPTIONS= TARGET_OS=%TARGET_OS% TARGET_ARCH=%TARGET_ARCH% RELEASE=%RELEASE% WITH_RA=0 TARGET_TRANSPORT=IP SECURED=%SECURED% WITH_TCP=0 BUILD_SAMPLE=ON LOGGING=%LOGGING% TEST=%TEST% WITH_RD=%WITH_RD% ROUTING=%ROUTING% WITH_UPSTREAM_LIBCOAP=%WITH_UPSTREAM_LIBCOAP%
79
80 REM Use MSVC_VERSION=12.0 for VS2013, or MSVC_VERSION=14.0 for VS2015.
81 REM If MSVC_VERSION has not been defined here, SCons chooses automatically a VS version.
82 IF NOT "%MSVC_VERSION%" == "" (
83   set BUILD_OPTIONS=%BUILD_OPTIONS% MSVC_VERSION=%MSVC_VERSION%
84 )
85
86 REM *** BUILD OPTIONS ***
87
88 if "!RUN_ARG!"=="server" (
89   cd %BUILD_DIR%\resource\examples
90   %DEBUG% simpleserver.exe
91 ) else if "!RUN_ARG!"=="client" (
92   cd %BUILD_DIR%\resource\examples
93   %DEBUG% simpleclient.exe
94 ) else if "!RUN_ARG!"=="serverhq" (
95   cd %BUILD_DIR%\resource\examples
96   %DEBUG% simpleserverHQ.exe
97 ) else if "!RUN_ARG!"=="clienthq" (
98   cd %BUILD_DIR%\resource\examples
99   %DEBUG% simpleclientHQ.exe
100 )else if "!RUN_ARG!"=="mediaclient" (
101   cd %BUILD_DIR%\resource\examples
102   %DEBUG% mediaclient.exe
103 ) else if "!RUN_ARG!"=="mediaserver" (
104   cd %BUILD_DIR%\resource\examples
105   %DEBUG% mediaserver.exe
106 ) else if "!RUN_ARG!"=="winuiclient" (
107   cd %BUILD_DIR%\resource\examples
108   %DEBUG% winuiclient.exe
109 ) else if "!RUN_ARG!"=="occlient" (
110   cd %BUILD_DIR%\resource\csdk\stack\samples\linux\SimpleClientServer
111   %DEBUG% occlientbasicops.exe -u 0 -t 3 -c 1
112 ) else if "!RUN_ARG!"=="ocserver" (
113   cd %BUILD_DIR%\resource\csdk\stack\samples\linux\SimpleClientServer
114   %DEBUG% ocserverbasicops.exe
115 ) else if "!RUN_ARG!"=="provclient" (
116   cd %BUILD_DIR%\resource\csdk\security\provisioning\sample
117   %DEBUG% provisioningclient.exe
118 ) else if "!RUN_ARG!"=="justworks" (
119   cd %BUILD_DIR%\resource\csdk\security\provisioning\sample
120   %DEBUG% sampleserver_justworks.exe
121 ) else if "!RUN_ARG!"=="test" (
122   %DEBUG% %BUILD_DIR%\resource\csdk\connectivity\test\catests.exe
123   %DEBUG% %BUILD_DIR%\resource\csdk\stack\test\stacktests.exe
124   %DEBUG% %BUILD_DIR%\resource\csdk\stack\test\cbortests.exe
125   %DEBUG% %BUILD_DIR%\resource\csdk\security\unittest\unittest.exe
126   %DEBUG% %BUILD_DIR%\resource\csdk\security\provisioning\unittest\unittest.exe
127   %DEBUG% %BUILD_DIR%\resource\c_common\ocrandom\test\randomtests.exe
128   %DEBUG% %BUILD_DIR%\resource\c_common\oic_malloc\test\malloctests.exe
129   %DEBUG% %BUILD_DIR%\resource\c_common\oic_string\test\stringtests.exe
130   %DEBUG% %BUILD_DIR%\resource\c_common\oic_time\test\timetests.exe
131   %DEBUG% %BUILD_DIR%\resource\unittests\unittests.exe
132 ) else if "!RUN_ARG!"=="build" (
133   echo Starting IoTivity build with these options:
134   echo   TARGET_OS=%TARGET_OS%
135   echo   TARGET_ARCH=%TARGET_ARCH%
136   echo   SECURED=%SECURED%
137   echo   RELEASE=%RELEASE%
138   echo   TEST=%TEST%
139   echo   LOGGING=%LOGGING%
140   echo   WITH_RD=%WITH_RD%
141   echo   ROUTING=%ROUTING%
142   echo   WITH_UPSTREAM_LIBCOAP=%WITH_UPSTREAM_LIBCOAP%
143   echo.scons VERBOSE=1 %BUILD_OPTIONS%
144   scons VERBOSE=1 %BUILD_OPTIONS%
145 ) else if "!RUN_ARG!"=="clean" (
146   scons VERBOSE=1 %BUILD_OPTIONS% -c clean
147   rd /s /q out
148   del .sconsign.dblite
149   del extlibs\gtest\gtest*.lib
150   del extlibs\gtest\gtest-1.7.0\src\gtest*.obj
151   erase /s *.obj
152   erase resource\c_common\iotivity_config.h
153   erase extlibs\libcoap\coap.lib
154   erase extlibs\libcoap\libcoap\include\coap\coap_config.h
155 ) else if "!RUN_ARG!"=="cleangtest" (
156   rd /s /q extlibs\gtest\gtest-1.7.0
157   del extlibs\gtest\gtest-1.7.0.zip
158 ) else (
159     echo %0 - Script requires a valid argument!
160     goto :EOF
161 )
162
163 cd %IOTIVITY_DIR%
164
165 echo Done!
166
167 goto EOF
168
169 :USAGE
170 echo %0 - Helper to build/test iotivity.  Requires an argument.
171 echo Installation: Drop this into your iotivity root directory to use it.
172 echo.
173 echo. Default buidl settings are: debug binaries run unittests and no logging
174 echo.
175 echo. Default build parameters can be overridden using the following arguments
176 echo. 
177 echo   -arch [x86 | amd64]    - Build either amd64 or x86 architecture binaries
178 echo.
179 echo   -noTest                - Don't run the unittests after building the binaries
180 echo.
181 echo   -logging               - Enable logging while building the binaries
182 echo.
183 echo   -debugger              - Debug the requested application
184 echo.
185 echo   -release               - Build release binaries
186 echo.
187 echo. Usage examples:
188 echo   Launch SimpleClient with debugger:
189 echo      %0 client -debugger
190 echo.
191 echo   Launch SimpleServer:
192 echo      %0 server
193 echo.
194 echo   Launch WinUIClient built in msys:
195 echo      %0 msys winuiclient
196 echo.
197 echo   Build amd64 debug binaries and run unit tests:
198 echo      %0 build
199 echo.
200 echo   Build amd64 release binaries w/o running tests:
201 echo      %0 build -arch amd64 -noTest -release
202 echo.
203 echo   Build x86 debug binaries and run unit tests:
204 echo      %0 build -arch x86
205 echo.
206 echo   Build amd64 release binaries with logging enabled:
207 echo      %0 build -arch amd64 -release -logging
208 echo.
209 echo   Run all tests:
210 echo      %0 test
211 echo.
212 echo   Clean:
213 echo      %0 clean
214
215 :EOF