Make swift over UDP compilable.
[swifty.git] / src / libswift_udp / SConstruct
1 # Written by Victor Grishchenko, Arno Bakker \r
2 # see LICENSE.txt for license information\r
3 #\r
4 # Requirements:\r
5 #  - scons: Cross-platform build system    http://www.scons.org/\r
6 #  - libevent2: Event driven network I/O   http://www.libevent.org/\r
7 #    * Install in \build\libevent-2.0.14-stable\r
8 # For debugging:\r
9 #  - googletest: Google C++ Test Framework http://code.google.com/p/googletest/\r
10 #       * Install in \build\gtest-1.4.0\r
11 #\r
12 \r
13 \r
14 import os\r
15 import re\r
16 import sys\r
17 \r
18 DEBUG = True\r
19 \r
20 TestDir='tests'\r
21 \r
22 target = 'swift'\r
23 source = [ 'bin.cpp', 'binmap.cpp','binheap.cpp', 'sha1.cpp','hashtree.cpp',\r
24            'transfer.cpp', 'channel.cpp', 'sendrecv.cpp', 'send_control.cpp', \r
25            'compat.cpp','avgspeed.cpp', 'availability.cpp']\r
26 \r
27 \r
28 env = Environment()\r
29 if sys.platform == "win32":\r
30     #libevent2path = '\\build\\libevent-2.0.14-stable'\r
31     libevent2path = '\\build\\ttuki\\libevent-2.0.15-arno-http'\r
32 \r
33     # "MSVC works out of the box". Sure.\r
34     # Make sure scons finds cl.exe, etc.\r
35     env.Append ( ENV = { 'PATH' : os.environ['PATH'] } )\r
36 \r
37     # Make sure scons finds std MSVC include files\r
38     if not 'INCLUDE' in os.environ:\r
39         print "swift: Please run scons in a Visual Studio Command Prompt"\r
40         sys.exit(-1)\r
41         \r
42     include = os.environ['INCLUDE']\r
43     include += libevent2path+'\\include;'\r
44     include += libevent2path+'\\WIN32-Code;'\r
45     if DEBUG:\r
46         include += '\\build\\gtest-1.4.0\\include;'\r
47     \r
48     env.Append ( ENV = { 'INCLUDE' : include } )\r
49     \r
50     if 'CXXPATH' in os.environ:\r
51         cxxpath = os.environ['CXXPATH']\r
52     else:\r
53         cxxpath = ""\r
54     cxxpath += include\r
55     if DEBUG:\r
56         env.Append(CXXFLAGS="/Zi /MTd")\r
57         env.Append(LINKFLAGS="/DEBUG")\r
58     env.Append(CXXPATH=cxxpath)\r
59     env.Append(CPPPATH=cxxpath)\r
60 \r
61     # getopt for win32\r
62     source += ['getopt.c','getopt_long.c']\r
63  \r
64      # Set libs to link to\r
65      # Advapi32.lib for CryptGenRandom in evutil_rand.obj\r
66     libs = ['ws2_32','libevent','Advapi32'] \r
67     if DEBUG:\r
68         libs += ['gtestd']\r
69         \r
70     # Update lib search path\r
71     libpath = os.environ['LIBPATH']\r
72     libpath += libevent2path+';'\r
73     if DEBUG:\r
74         libpath += '\\build\\gtest-1.4.0\\msvc\\gtest\\Debug;'\r
75 \r
76     # Somehow linker can't find uuid.lib\r
77     libpath += 'C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\Lib;'\r
78     \r
79     # TODO: Make the swift.exe a Windows program not a Console program\r
80     if not DEBUG:\r
81         env.Append(LINKFLAGS="/SUBSYSTEM:WINDOWS")\r
82     \r
83     APPSOURCE=['swift.cpp','httpgw.cpp','statsgw.cpp','cmdgw.cpp','getopt.c','getopt_long.c']\r
84     \r
85 else:\r
86     libevent2path = '/usr/local/'\r
87 \r
88     # Enable the user defining external includes\r
89     if 'CPPPATH' in os.environ:\r
90         cpppath = os.environ['CPPPATH']\r
91     else:\r
92         cpppath = ""\r
93         print "To use external libs, set CPPPATH environment variable to list of colon-separated include dirs"\r
94     cpppath += libevent2path+'/include:'\r
95     env.Append(CPPPATH=".:"+cpppath)\r
96     #env.Append(LINKFLAGS="--static")\r
97 \r
98     #if DEBUG:\r
99     #    env.Append(CXXFLAGS="-g")\r
100 \r
101     # Large-file support always\r
102     env.Append(CXXFLAGS="-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE")\r
103 \r
104     # Set libs to link to\r
105     libs = ['stdc++','libevent','pthread']\r
106     if 'LIBPATH' in os.environ:\r
107           libpath = os.environ['LIBPATH']\r
108     else:\r
109         libpath = ""\r
110         print "To use external libs, set LIBPATH environment variable to list of colon-separated lib dirs"\r
111     libpath += libevent2path+'/lib:'\r
112 \r
113     linkflags = '-Wl,-rpath,'+libevent2path+'/lib'\r
114     env.Append(LINKFLAGS=linkflags);\r
115 \r
116 \r
117     APPSOURCE=['swift.cpp','httpgw.cpp','statsgw.cpp','cmdgw.cpp']\r
118 \r
119 if DEBUG:\r
120     env.Append(CXXFLAGS="-DDEBUG")\r
121 \r
122 env.StaticLibrary (\r
123     target='libswift',\r
124     source = source,\r
125     LIBS=libs,\r
126     LIBPATH=libpath )\r
127 \r
128 env.Program(\r
129    target='swift',\r
130    source=APPSOURCE,\r
131    #CPPPATH=cpppath,\r
132    LIBS=[libs,'libswift'],\r
133    LIBPATH=libpath+':.')\r
134    \r
135 Export("env")\r
136 Export("libs")\r
137 Export("libpath")\r
138 Export("DEBUG")\r
139 # Arno: uncomment to build tests\r
140 SConscript('tests/SConscript')\r