source: pacpussensors/trunk/NewComponent.bat@ 13

Last change on this file since 13 was 13, checked in by Marek Kurdej, 11 years ago

[script] Update NewComponent.bat script.

File size: 3.1 KB
Line 
1@echo off
2setlocal ENABLEDELAYEDEXPANSION
3
4set DebugOutput=0
5set ExampleComponent=ExampleComponent
6
7:argc
8set argc=0
9for %%x in (%*) do set /A argc+=1
10
11:usage
12if %argC% lss 1 (
13 echo Usage:
14 echo %0 ^<componentName^>
15 goto:EOF
16)
17
18:args
19set _componentName=%1
20set _componentDir=%_componentName%Component
21call :UCase _componentDir _componentDirCaps
22if %DebugOutput%==1 (
23 echo _componentName=%_componentName%
24 echo _componentDir=%_componentDir%
25 echo _componentDirCaps=%_componentDirCaps%
26)
27
28:cmake
29::cmake %ExampleComponent% -DCOMPONENT_NAME:STRING=%_componentName%
30::if %ERRORLEVEL% GEQ 1 (
31:: echo CMake must be installed and added to PATH
32:: goto:EOF
33::)
34::goto:EOF
35
36:dir
37if exist %_componentDir% (
38 echo Directory %_componentDir% exists already!
39 echo Please delete it first and retry.
40 goto:EOF
41)
42mkdir %_componentDir%
43if not exist %_componentDir% (
44 echo Directory %_componentDir% could not be created!
45 goto:EOF
46)
47
48:copy
49::xcopy /S %ExampleComponent% %_componentDir%
50copy %ExampleComponent%\CMakeLists.txt %_componentDir%\CMakeLists.txt
51copy %ExampleComponent%\%ExampleComponent%.cpp %_componentDir%\%_componentDir%.cpp
52copy %ExampleComponent%\%ExampleComponent%.h %_componentDir%\%_componentDir%.h
53copy %ExampleComponent%\%ExampleComponent%Config.h %_componentDir%\%_componentDir%Config.h
54
55:substitute
56set SedFile=NewComponent.sed
57set _currentDate=%DATE%
58:: escape / character
59set _currentDate=!_currentDate:/=\/!
60:: take first 8 characters (without milliseconds)
61set _currentTime=%TIME:~0,8%
62set _userName=%USERNAME%
63
64echo s/${^<PROJECT_NAME^>}/%_componentDir%/g > %SedFile%
65echo s/${^<PROJECT_NAME_CAPS^>}/%_componentDirCaps%/g >> %SedFile%
66echo s/${^<CURRENT_DATE^>}/%_currentDate%/g >> %SedFile%
67echo s/${^<CURRENT_TIME^>}/%_currentTime%/g >> %SedFile%
68echo s/${^<CURRENT_DATETIME^>}/%_currentDate% %_currentTime%/g >> %SedFile%
69echo s/${^<USERNAME^>}/%_userName%/g >> %SedFile%
70
71for /r . %%f in (%_componentDir%\*) do (
72 if %DebugOutput%==1 (
73 echo %%f
74 )
75 sed -f %SedFile% %%f > %%f.tmp
76)
77
78for /r . %%f in (%_componentDir%\*.tmp) do (
79 if %DebugOutput%==1 (
80 echo %%f
81 )
82 mv %%f %%~pnf
83)
84
85::cmake-manual-changes
86echo NOTE:
87echo You have to add line:
88echo add_subdirectory(%_componentDir%)
89echo to the root CMakeLists.txt.
90
91goto:EOF
92
93:LCase
94:UCase
95:: Converts to upper/lower case variable contents
96:: Syntax: CALL :UCase _VAR1 _VAR2
97:: Syntax: CALL :LCase _VAR1 _VAR2
98:: _VAR1 = Variable NAME whose VALUE is to be converted to upper/lower case
99:: _VAR2 = NAME of variable to hold the converted value
100:: Note: Use variable NAMES in the CALL, not values (pass "by reference")
101
102set _UCase=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
103set _LCase=a b c d e f g h i j k l m n o p q r s t u v w x y z
104set _Lib_UCase_Tmp=!%1!
105if /I "%0"==":UCase" (
106 set _Abet=%_UCase%
107)
108if /I "%0"==":LCase" (
109 set _Abet=%_LCase%
110)
111for %%Z in (%_Abet%) do (
112 set _Lib_UCase_Tmp=!_Lib_UCase_Tmp:%%Z=%%Z!
113)
114set %2=%_Lib_UCase_Tmp%
115goto:EOF
Note: See TracBrowser for help on using the repository browser.