summaryrefslogtreecommitdiff
path: root/win32/msvcbuild.bat
blob: 9f8b1b77dd770695be60820b474a3e62abe9bd52 (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
@echo off

@rem Script to build libnet with MSVC.
@rem Dependencies are:
@rem Npcap SDK in ..\npcap-sdk
@rem
@rem Helpful links for non-Windows users:
@rem https://github.com/microsoft/vswhere/wiki/Find-VC#batch
@rem https://renenyffenegger.ch/notes/Windows/dirs/Program-Files-x86/Microsoft-Visual-Studio/version/edition/Common7/Tools/VsDevCmd_bat
@rem https://renenyffenegger.ch/notes/Windows/development/Visual-Studio/environment-variables/index

:start
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -nologo`) do (
  set InstallDir=%%i
)
if not exist "%InstallDir%\Common7\Tools\VsDevCmd.bat" (goto fail)

@if "%1" == "" goto x86
@setlocal
@set userinput=%1
@if not "%1"=="x86" @if not "%1"=="x64" @if not "%1"=="x86_x64" goto usage
@if "%1"=="x86"  goto x86
@if "%1"=="x64" goto x86_x64
@if "%1"=="x86_x64" goto x86_x64
@endlocal

:x86
call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -arch=x86
goto msvcbuild32

:x64
call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -arch=x64
goto msvcbuild64

:x86_x64
call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -arch=amd64
goto msvcbuild64

:msvcbuild32
@echo on
@setlocal
@set MYCOMPILE=cl /nologo /MD /O2 /W4 /c /D_CRT_SECURE_NO_DEPRECATE /Fowin32\
@set MYLINK=link /nologo
@set MYMT=mt /nologo
@set VERSION=1.2

@rem relative to C code in src/
@set NPCAP=..\..\npcap-sdk

if not exist "src\win32\" mkdir "src\win32\"

if not exist "lib\x86\" mkdir "lib\x86\"

copy win32\libnet.h include\
copy win32\stdint.h include\libnet\
copy win32\config.h include\
copy win32\getopt.h include\

cd src
%MYCOMPILE% /I..\include /I%NPCAP%\Include libnet_a*.c libnet_build_*.c libnet_c*.c libnet_dll.c libnet_error.c libnet_i*.c libnet_link_win32.c libnet_p*.c libnet_raw.c libnet_resolve.c libnet_version.c libnet_write.c
%MYLINK% /DLL /libpath:%NPCAP%\Lib  /out:..\lib\x86\libnet%VERSION%.dll win32\*.obj Advapi32.lib
if exist libnet.dll.manifest^
  %MYMT% -manifest libnet.dll.manifest -outputresource:libnet.dll;2
cd ..

exit /b %errorlevel%

:msvcbuild64
@echo on
@setlocal
@set MYCOMPILE=cl /nologo /MD /O2 /W4 /c /D_CRT_SECURE_NO_DEPRECATE /Fowin64\
@set MYLINK=link /nologo
@set MYMT=mt /nologo
@set VERSION=1.2

@rem relative to C code in src/
@set NPCAP=..\..\npcap-sdk

if not exist "src\win64\" mkdir "src\win64\"

if not exist "lib\x64\" mkdir "lib\x64\"

copy win32\libnet.h include\
@rem copy win32\stdint.h include\libnet\
copy win32\config.h include\
copy win32\getopt.h include\

cd src
%MYCOMPILE% /I..\include /I%NPCAP%\Include libnet_a*.c libnet_build_*.c libnet_c*.c libnet_dll.c libnet_error.c libnet_i*.c libnet_link_win32.c libnet_p*.c libnet_raw.c libnet_resolve.c libnet_version.c libnet_write.c
dir .\win64\
%MYLINK% /DLL /libpath:%NPCAP%\Lib\x64  /out:..\lib\x64\libnet%VERSION%.dll win64\*.obj Advapi32.lib
dir ..\lib\x64\
if exist libnet.dll.manifest^
  %MYMT% -manifest libnet.dll.manifest -outputresource:libnet.dll;2
cd ..

exit /b %errorlevel%

:usage
echo Invalid option "%*". The correct usage is:
echo     %0 [option]
echo :
echo where [option] is: x86 ^| x64 ^| x86_x64
echo :
echo The script will verify and set the appropriate environment variables.
echo If no options are provided, x86 is assumed.
echo :
echo Usage examples:
echo     %0 x86
echo     %0 x64
echo     %0 x86_x64
echo :
echo If your build computer is 32-bit and you want to build for 64-bit 
echo (aka Cross), choose "x86_x64"
echo :
echo Please make sure Visual Studio or the C++ Build SKU is installed,
echo and that this script is executed from a Developer Command Prompt.
echo :
goto end

:fail
echo Visual Studio or the C++ Build SKU do not seem to be installed.
echo Please Install either of them or try to executed this script
echo from a Developer Command Prompt.
goto end

:end