Home | History | Annotate | Download | only in projects
      1 @echo off
      2 rem ***************************************************************************
      3 rem *                                  _   _ ____  _
      4 rem *  Project                     ___| | | |  _ \| |
      5 rem *                             / __| | | | |_) | |
      6 rem *                            | (__| |_| |  _ <| |___
      7 rem *                             \___|\___/|_| \_\_____|
      8 rem *
      9 rem * Copyright (C) 2014 - 2017, Steve Holme, <steve_holme (a] hotmail.com>.
     10 rem *
     11 rem * This software is licensed as described in the file COPYING, which
     12 rem * you should have received as part of this distribution. The terms
     13 rem * are also available at https://curl.haxx.se/docs/copyright.html.
     14 rem *
     15 rem * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     16 rem * copies of the Software, and permit persons to whom the Software is
     17 rem * furnished to do so, under the terms of the COPYING file.
     18 rem *
     19 rem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     20 rem * KIND, either express or implied.
     21 rem *
     22 rem ***************************************************************************
     23 
     24 :begin
     25   rem Check we are running on a Windows NT derived OS
     26   if not "%OS%" == "Windows_NT" goto nodos
     27 
     28   rem Set our variables
     29   setlocal ENABLEEXTENSIONS
     30   set VERSION=ALL
     31   set MODE=GENERATE
     32 
     33   rem Check we are not running on a network drive
     34   if "%~d0."=="\\." goto nonetdrv
     35 
     36   rem Switch to this batch file's directory
     37   cd /d "%~0\.." 1>NUL 2>&1
     38 
     39   rem Check we are running from a curl git repository
     40   if not exist ..\GIT-INFO goto norepo
     41 
     42 :parseArgs
     43   if "%~1" == "" goto start
     44 
     45   if /i "%~1" == "pre" (
     46     set VERSION=PRE
     47   ) else if /i "%~1" == "vc6" (
     48     set VERSION=VC6
     49   ) else if /i "%~1" == "vc7" (
     50     set VERSION=VC7
     51   ) else if /i "%~1" == "vc7.1" (
     52     set VERSION=VC7.1
     53   ) else if /i "%~1" == "vc8" (
     54     set VERSION=VC8
     55   ) else if /i "%~1" == "vc9" (
     56     set VERSION=VC9
     57   ) else if /i "%~1" == "vc10" (
     58     set VERSION=VC10
     59   ) else if /i "%~1" == "vc11" (
     60     set VERSION=VC11
     61   ) else if /i "%~1" == "vc12" (
     62     set VERSION=VC12
     63   ) else if /i "%~1" == "vc14" (
     64     set VERSION=VC14
     65   ) else if /i "%~1" == "vc15" (
     66     set VERSION=VC15
     67   ) else if /i "%~1" == "-clean" (
     68     set MODE=CLEAN
     69   ) else if /i "%~1" == "-?" (
     70     goto syntax
     71   ) else if /i "%~1" == "-h" (
     72     goto syntax
     73   ) else if /i "%~1" == "-help" (
     74     goto syntax
     75   ) else (
     76     goto unknown
     77   )
     78 
     79   shift & goto parseArgs
     80 
     81 :start
     82   if exist ..\buildconf.bat (
     83     if "%MODE%" == "GENERATE" (
     84       call ..\buildconf
     85     ) else if "%VERSION%" == "PRE" (
     86       call ..\buildconf -clean
     87     ) else if "%VERSION%" == "ALL" (
     88       call ..\buildconf -clean
     89     )
     90   )
     91   if "%VERSION%" == "PRE" goto success
     92   if "%VERSION%" == "VC6" goto vc6
     93   if "%VERSION%" == "VC7" goto vc7
     94   if "%VERSION%" == "VC7.1" goto vc71
     95   if "%VERSION%" == "VC8" goto vc8
     96   if "%VERSION%" == "VC9" goto vc9
     97   if "%VERSION%" == "VC10" goto vc10
     98   if "%VERSION%" == "VC11" goto vc11
     99   if "%VERSION%" == "VC12" goto vc12
    100   if "%VERSION%" == "VC14" goto vc14
    101   if "%VERSION%" == "VC15" goto vc15
    102 
    103 :vc6
    104   echo.
    105 
    106   if "%MODE%" == "GENERATE" (
    107     echo Generating VC6 project files
    108     call :generate dsp Windows\VC6\src\curl.tmpl Windows\VC6\src\curl.dsp
    109     call :generate dsp Windows\VC6\lib\libcurl.tmpl Windows\VC6\lib\libcurl.dsp
    110   ) else (
    111     echo Removing VC6 project files
    112     call :clean Windows\VC6\src\curl.dsp
    113     call :clean Windows\VC6\lib\libcurl.dsp
    114   )
    115 
    116   if not "%VERSION%" == "ALL" goto success
    117 
    118 :vc7
    119   echo.
    120 
    121   if "%MODE%" == "GENERATE" (
    122     echo Generating VC7 project files
    123     call :generate vcproj1 Windows\VC7\src\curl.tmpl Windows\VC7\src\curl.vcproj
    124     call :generate vcproj1 Windows\VC7\lib\libcurl.tmpl Windows\VC7\lib\libcurl.vcproj
    125   ) else (
    126     echo Removing VC7 project files
    127     call :clean Windows\VC7\src\curl.vcproj
    128     call :clean Windows\VC7\lib\libcurl.vcproj
    129   )
    130 
    131   if not "%VERSION%" == "ALL" goto success
    132 
    133 :vc71
    134   echo.
    135 
    136   if "%MODE%" == "GENERATE" (
    137     echo Generating VC7.1 project files
    138     call :generate vcproj1 Windows\VC7.1\src\curl.tmpl Windows\VC7.1\src\curl.vcproj
    139     call :generate vcproj1 Windows\VC7.1\lib\libcurl.tmpl Windows\VC7.1\lib\libcurl.vcproj
    140   ) else (
    141     echo Removing VC7.1 project files
    142     call :clean Windows\VC7.1\src\curl.vcproj
    143     call :clean Windows\VC7.1\lib\libcurl.vcproj
    144   )
    145 
    146   if not "%VERSION%" == "ALL" goto success
    147 
    148 :vc8
    149   echo.
    150 
    151   if "%MODE%" == "GENERATE" (
    152     echo Generating VC8 project files
    153     call :generate vcproj2 Windows\VC8\src\curl.tmpl Windows\VC8\src\curl.vcproj
    154     call :generate vcproj2 Windows\VC8\lib\libcurl.tmpl Windows\VC8\lib\libcurl.vcproj
    155   ) else (
    156     echo Removing VC8 project files
    157     call :clean Windows\VC8\src\curl.vcproj
    158     call :clean Windows\VC8\lib\libcurl.vcproj
    159   )
    160 
    161   if not "%VERSION%" == "ALL" goto success
    162 
    163 :vc9
    164   echo.
    165 
    166   if "%MODE%" == "GENERATE" (
    167     echo Generating VC9 project files
    168     call :generate vcproj2 Windows\VC9\src\curl.tmpl Windows\VC9\src\curl.vcproj
    169     call :generate vcproj2 Windows\VC9\lib\libcurl.tmpl Windows\VC9\lib\libcurl.vcproj
    170   ) else (
    171     echo Removing VC9 project files
    172     call :clean Windows\VC9\src\curl.vcproj
    173     call :clean Windows\VC9\lib\libcurl.vcproj
    174   )
    175 
    176   if not "%VERSION%" == "ALL" goto success
    177 
    178 :vc10
    179   echo.
    180 
    181   if "%MODE%" == "GENERATE" (
    182     echo Generating VC10 project files
    183     call :generate vcxproj Windows\VC10\src\curl.tmpl Windows\VC10\src\curl.vcxproj
    184     call :generate vcxproj Windows\VC10\lib\libcurl.tmpl Windows\VC10\lib\libcurl.vcxproj
    185   ) else (
    186     echo Removing VC10 project files
    187     call :clean Windows\VC10\src\curl.vcxproj
    188     call :clean Windows\VC10\lib\libcurl.vcxproj
    189   )
    190 
    191   if not "%VERSION%" == "ALL" goto success
    192 
    193 :vc11
    194   echo.
    195 
    196   if "%MODE%" == "GENERATE" (
    197     echo Generating VC11 project files
    198     call :generate vcxproj Windows\VC11\src\curl.tmpl Windows\VC11\src\curl.vcxproj
    199     call :generate vcxproj Windows\VC11\lib\libcurl.tmpl Windows\VC11\lib\libcurl.vcxproj
    200   ) else (
    201     echo Removing VC11 project files
    202     call :clean Windows\VC11\src\curl.vcxproj
    203     call :clean Windows\VC11\lib\libcurl.vcxproj
    204   )
    205 
    206   if not "%VERSION%" == "ALL" goto success
    207 
    208 :vc12
    209   echo.
    210 
    211   if "%MODE%" == "GENERATE" (
    212     echo Generating VC12 project files
    213     call :generate vcxproj Windows\VC12\src\curl.tmpl Windows\VC12\src\curl.vcxproj
    214     call :generate vcxproj Windows\VC12\lib\libcurl.tmpl Windows\VC12\lib\libcurl.vcxproj
    215   ) else (
    216     echo Removing VC12 project files
    217     call :clean Windows\VC12\src\curl.vcxproj
    218     call :clean Windows\VC12\lib\libcurl.vcxproj
    219   )
    220 
    221   if not "%VERSION%" == "ALL" goto success
    222 
    223 :vc14
    224   echo.
    225 
    226   if "%MODE%" == "GENERATE" (
    227     echo Generating VC14 project files
    228     call :generate vcxproj Windows\VC14\src\curl.tmpl Windows\VC14\src\curl.vcxproj
    229     call :generate vcxproj Windows\VC14\lib\libcurl.tmpl Windows\VC14\lib\libcurl.vcxproj
    230   ) else (
    231     echo Removing VC14 project files
    232     call :clean Windows\VC14\src\curl.vcxproj
    233     call :clean Windows\VC14\lib\libcurl.vcxproj
    234   )
    235 
    236   if not "%VERSION%" == "ALL" goto success
    237 
    238 :vc15
    239   echo.
    240 
    241   if "%MODE%" == "GENERATE" (
    242     echo Generating VC15 project files
    243     call :generate vcxproj Windows\VC15\src\curl.tmpl Windows\VC15\src\curl.vcxproj
    244     call :generate vcxproj Windows\VC15\lib\libcurl.tmpl Windows\VC15\lib\libcurl.vcxproj
    245   ) else (
    246     echo Removing VC15 project files
    247     call :clean Windows\VC15\src\curl.vcxproj
    248     call :clean Windows\VC15\lib\libcurl.vcxproj
    249   )
    250 
    251   goto success
    252 
    253 rem Main generate function.
    254 rem
    255 rem %1 - Project Type (dsp for VC6, vcproj1 for VC7 and VC7.1, vcproj2 for VC8 and VC9
    256 rem      or vcxproj for VC10, VC11, VC12, VC14 and VC15)
    257 rem %2 - Input template file
    258 rem %3 - Output project file
    259 rem
    260 :generate
    261   if not exist %2 (
    262     echo.
    263     echo Error: Cannot open %2
    264     exit /B
    265   )
    266 
    267   if exist %3 (
    268     del %3
    269   )
    270 
    271   echo * %CD%\%3
    272   for /f "usebackq delims=" %%i in (`"findstr /n ^^ %2"`) do (
    273     set "var=%%i"
    274     setlocal enabledelayedexpansion
    275     set "var=!var:*:=!"
    276 
    277     if "!var!" == "CURL_SRC_C_FILES" (
    278       for /f "delims=" %%c in ('dir /b ..\src\*.c') do call :element %1 src "%%c" %3
    279     ) else if "!var!" == "CURL_SRC_H_FILES" (
    280       for /f "delims=" %%h in ('dir /b ..\src\*.h') do call :element %1 src "%%h" %3
    281     ) else if "!var!" == "CURL_SRC_RC_FILES" (
    282       for /f "delims=" %%r in ('dir /b ..\src\*.rc') do call :element %1 src "%%r" %3
    283     ) else if "!var!" == "CURL_SRC_X_C_FILES" (
    284       call :element %1 lib "strtoofft.c" %3
    285       call :element %1 lib "nonblock.c" %3
    286       call :element %1 lib "warnless.c" %3
    287       call :element %1 lib "curl_ctype.c" %3
    288     ) else if "!var!" == "CURL_SRC_X_H_FILES" (
    289       call :element %1 lib "config-win32.h" %3
    290       call :element %1 lib "curl_setup.h" %3
    291       call :element %1 lib "strtoofft.h" %3
    292       call :element %1 lib "nonblock.h" %3
    293       call :element %1 lib "warnless.h" %3
    294       call :element %1 lib "curl_ctype.h" %3
    295     ) else if "!var!" == "CURL_LIB_C_FILES" (
    296       for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
    297     ) else if "!var!" == "CURL_LIB_H_FILES" (
    298       for /f "delims=" %%h in ('dir /b ..\include\curl\*.h') do call :element %1 include\curl "%%h" %3
    299       for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3
    300     ) else if "!var!" == "CURL_LIB_RC_FILES" (
    301       for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3
    302     ) else if "!var!" == "CURL_LIB_VAUTH_C_FILES" (
    303       for /f "delims=" %%c in ('dir /b ..\lib\vauth\*.c') do call :element %1 lib\vauth "%%c" %3
    304     ) else if "!var!" == "CURL_LIB_VAUTH_H_FILES" (
    305       for /f "delims=" %%h in ('dir /b ..\lib\vauth\*.h') do call :element %1 lib\vauth "%%h" %3
    306     ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" (
    307       for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3
    308     ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" (
    309       for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3
    310     ) else (
    311       echo.!var!>> %3
    312     )
    313 
    314     endlocal
    315   )
    316   exit /B
    317 
    318 rem Generates a single file xml element.
    319 rem
    320 rem %1 - Project Type (dsp for VC6, vcproj1 for VC7 and VC7.1, vcproj2 for VC8 and VC9
    321 rem      or vcxproj for VC10, VC11, VC12, VC14 and VC15)
    322 rem %2 - Directory (src, lib, lib\vauth or lib\vtls)
    323 rem %3 - Source filename
    324 rem %4 - Output project file
    325 rem
    326 :element
    327   set "SPACES=    "
    328   if "%2" == "lib\vauth" (
    329     set "TABS=				"
    330   ) else if "%2" == "lib\vtls" (
    331     set "TABS=				"
    332   ) else (
    333     set "TABS=			"
    334   )
    335 
    336   call :extension %3 ext
    337 
    338   if "%1" == "dsp" (
    339     echo # Begin Source File>> %4
    340     echo.>> %4
    341     echo SOURCE=..\..\..\..\%2\%~3>> %4
    342     echo # End Source File>> %4
    343   ) else if "%1" == "vcproj1" (
    344     echo %TABS%^<File>> %4
    345     echo %TABS%	RelativePath="..\..\..\..\%2\%~3"^>>> %4
    346     echo %TABS%^</File^>>> %4
    347   ) else if "%1" == "vcproj2" (
    348     echo %TABS%^<File>> %4
    349     echo %TABS%	RelativePath="..\..\..\..\%2\%~3">> %4
    350     echo %TABS%^>>> %4
    351     echo %TABS%^</File^>>> %4
    352   ) else if "%1" == "vcxproj" (
    353     if "%ext%" == "c" (
    354       echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
    355     ) else if "%ext%" == "h" (
    356       echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4
    357     ) else if "%ext%" == "rc" (
    358       echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
    359     )
    360   )
    361 
    362   exit /B
    363 
    364 rem Returns the extension for a given filename.
    365 rem
    366 rem %1 - The filename
    367 rem %2 - The return value
    368 rem
    369 :extension
    370   set fname=%~1
    371   set ename=
    372 :loop1
    373   if "%fname%"=="" (
    374     set %2=
    375     exit /B
    376   )
    377 
    378   if not "%fname:~-1%"=="." (
    379     set ename=%fname:~-1%%ename%
    380     set fname=%fname:~0,-1%
    381     goto loop1
    382   )
    383 
    384   set %2=%ename%
    385   exit /B
    386 
    387 rem Removes the given project file.
    388 rem
    389 rem %1 - The filename
    390 rem
    391 :clean
    392   echo * %CD%\%1
    393 
    394   if exist %1 (
    395     del %1
    396   )
    397 
    398   exit /B
    399 
    400 :syntax
    401   rem Display the help
    402   echo.
    403   echo Usage: generate [what] [-clean]
    404   echo.
    405   echo What to generate:
    406   echo.
    407   echo pre       - Prerequisites only
    408   echo vc6       - Use Visual Studio 6
    409   echo vc7       - Use Visual Studio .NET
    410   echo vc7.1     - Use Visual Studio .NET 2003
    411   echo vc8       - Use Visual Studio 2005
    412   echo vc9       - Use Visual Studio 2008
    413   echo vc10      - Use Visual Studio 2010
    414   echo vc11      - Use Visual Studio 2012
    415   echo vc12      - Use Visual Studio 2013
    416   echo vc14      - Use Visual Studio 2015
    417   echo vc15      - Use Visual Studio 2017
    418   echo.
    419   echo -clean    - Removes the project files
    420   goto error
    421 
    422 :unknown
    423   echo.
    424   echo Error: Unknown argument '%1'
    425   goto error
    426 
    427 :nodos
    428   echo.
    429   echo Error: Only a Windows NT based Operating System is supported
    430   goto error
    431 
    432 :nonetdrv
    433   echo.
    434   echo Error: This batch file cannot run from a network drive
    435   goto error
    436 
    437 :norepo
    438   echo.
    439   echo Error: This batch file should only be used from a curl git repository
    440   goto error
    441 
    442 :seterr
    443   rem Set the caller's errorlevel.
    444   rem %1[opt]: Errorlevel as integer.
    445   rem If %1 is empty the errorlevel will be set to 0.
    446   rem If %1 is not empty and not an integer the errorlevel will be set to 1.
    447   setlocal
    448   set EXITCODE=%~1
    449   if not defined EXITCODE set EXITCODE=0
    450   echo %EXITCODE%|findstr /r "[^0-9\-]" 1>NUL 2>&1
    451   if %ERRORLEVEL% EQU 0 set EXITCODE=1
    452   exit /b %EXITCODE%
    453 
    454 :error
    455   if "%OS%" == "Windows_NT" endlocal
    456   exit /B 1
    457 
    458 :success
    459   endlocal
    460   exit /B 0
    461