You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SConstruct 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. # This file is part of Netsukuku
  2. # (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
  3. #
  4. # This source code is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Public License as published
  6. # by the Free Software Foundation; either version 2 of the License,
  7. # or (at your option) any later version.
  8. #
  9. # This source code is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. # Please refer to the GNU Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Public License along with
  15. # this source code; if not, write to:
  16. # Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. import sys
  18. import os
  19. NTK_VERSION="0.0.9b"
  20. #
  21. # Sources and libs
  22. #
  23. sources_common = Split('xmalloc.c log.c misc.c buffer.c endianness.c')
  24. sources_qspn = Split('qspn-empiric.c') + sources_common
  25. sources_netsukuku = Split("""accept.c llist.c ipv6-gmp.c inet.c request.c map.c
  26. gmap.c bmap.c pkts.c radar.c hook.c rehook.c tracer.c qspn.c
  27. hash.c daemon.c crypto.c snsd_cache.c
  28. andna_cache.c andna.c andns_lib.c err_errno.c
  29. dnslib.c andns.c andns_net.c andns_snsd.c
  30. ll_map.c libnetlink.c if.c krnl_route.c krnl_rule.c
  31. iptunnel.c route.c conf.c dns_wrapper.c igs.c mark.c
  32. libiptc/libip4tc.c libping.c netsukuku.c""") + sources_common
  33. sources_ntkresolv = sources_common + Split("""andns_lib.c ntkresolv.c andns_net.c
  34. crypto.c snsd_cache.c inet.c
  35. ll_map.c libnetlink.c
  36. err_errno.c""")
  37. libs = ['gmp', 'pthread', 'crypto', 'z']
  38. #
  39. # Command line options and help
  40. #
  41. opts = Options('build.conf')
  42. opts.AddOptions(('CONF_DIR', """Directory where the Netsukuku configuration files will be installed""",
  43. '/etc/netsukuku'),
  44. ('DATA_DIR', 'Directory to install data files',
  45. '/usr/share/netsukuku'),
  46. ('MAN_DIR', 'Where the manuals will be installed',
  47. '/usr/man'),
  48. ('BIN_DIR' , 'Directory to install the binaries',
  49. '/usr/bin'),
  50. ('PID_DIR', 'Specify location of ntkd.pid file',
  51. '/var/run'),
  52. ('destdir', 'SCons will copy all the files under destdir during installation',
  53. '/'),
  54. EnumOption('debug', 'build the debug code', 'no',
  55. allowed_values=('yes', 'no', '1', '0'), map={},
  56. ignorecase=0),
  57. EnumOption('static', 'build statically the binaries', 'no',
  58. allowed_values=('yes', 'no', '1', '0'), map={},
  59. ignorecase=0))
  60. opts.Add('CC', 'The C compiler.')
  61. opts.Add('CXX', 'The C++ compiler.')
  62. env = Environment(options = opts, ENV = os.environ, CCFLAGS = ' -Wall')
  63. if ("yes" in env['debug']) or ("1" in env['debug']):
  64. debug = 1
  65. env.Append(CPPDEFINES={'DEBUG' : '${debug}'}, CCFLAGS = ' -ggdb -Wall', CXXFLAGS = '-g')
  66. #CCFLAGS = ' -ggdb -Wall -DDMALLOC_FUNC_CHECK'
  67. # libs+=['dmalloc', 'dmallocth']
  68. os.system("echo Cscoping and ctagging...; cscope -b; ctags *")
  69. else:
  70. debug = 0
  71. if ("yes" in env['static']) or ("1" in env['static']):
  72. static = 1
  73. env.Append(CCFLAGS = ' -static', CXXFLAGS = '-static')
  74. else:
  75. static = 0
  76. if (env['destdir'] == "/"):
  77. env['destdir']=""
  78. opts.Save('build.conf', env)
  79. if os.path.exists("conf/netsukuku.conf") and env.GetOption('clean'):
  80. Execute(Delete('conf/netsukuku.conf'))
  81. if os.path.exists("config.h") and env.GetOption('clean'):
  82. Execute(Delete('config.h'))
  83. if os.path.exists("config.log") and env.GetOption('clean'):
  84. Execute(Delete('config.log'))
  85. Help("""
  86. *** Usage
  87. 'scons' to build the ntkd binary,
  88. 'scons debug=yes' to build the debug version.
  89. 'scons install' to install it in the system.
  90. *** General options
  91. """ + opts.GenerateHelpText(env))
  92. if ARGUMENTS.get('install'):
  93. print "you aren't root"
  94. #
  95. # Configure
  96. #
  97. if not os.path.exists("config.log") and not env.GetOption('clean'):
  98. print 'Configuring... '
  99. conf = Configure(env)
  100. if not conf.CheckLib('gmp'):
  101. print 'Did not find libgmp.a or gmp.lib, exiting!'
  102. Execute(Delete('config.log'))
  103. Exit(1)
  104. if not conf.CheckCHeader([ "gmp.h" ]):
  105. print 'Did not find the gmp headers, exiting!'
  106. Execute(Delete('config.log'))
  107. Exit(1)
  108. if not conf.CheckCHeader([ "zlib.h" ]):
  109. print 'Did not find the zlib headers, exiting!'
  110. Execute(Delete('config.log'))
  111. Exit(1)
  112. if not conf.CheckLib('pthread'):
  113. print 'Did not find pthread.a or pthread.lib, exiting!'
  114. Execute(Delete('config.log'))
  115. Exit(1)
  116. if not conf.CheckLib('crypto'):
  117. print 'Did not find the openssl libcrypto.a or libcrypto.lib, exiting!'
  118. Execute(Delete('config.log'))
  119. Exit(1)
  120. if not conf.CheckCHeader([ "openssl/bio.h", "openssl/evp.h",
  121. "openssl/crypto.h", "openssl/x509.h",
  122. "openssl/engine.h", "openssl/err.h", "openssl/rand.h",
  123. "openssl/rsa.h", "openssl/pem.h" ]):
  124. print 'Did not find the openssl headers, exiting!'
  125. Execute(Delete('config.log'))
  126. Exit(1)
  127. env = conf.Finish()
  128. def conf_build(target, source, env):
  129. conf_defines = {
  130. "CONF_DIR": env["CONF_DIR"],
  131. "DATA_DIR": env["DATA_DIR"],
  132. "PID_DIR": env["PID_DIR"],
  133. "VERSION": NTK_VERSION,
  134. "debug": debug # this is an int. 1 for true, 0 for false
  135. }
  136. conf = file(str(target), "w")
  137. conf_in = file(str(source), "r")
  138. conf.write(conf_in.read() % conf_defines)
  139. conf_in.close()
  140. conf.close()
  141. def build_config_files(target = None, source = None, env = None):
  142. if not os.path.exists("config.h") and not env.GetOption('clean'):
  143. print 'Generating config.h from config_scons.h.in'
  144. conf_build('config.h', 'config_scons.h.in', env)
  145. conf = file("config.h", "a")
  146. if sys.platform == 'linux2' or sys.platform == 'linux-i386':
  147. conf.write("#define GNU_LINUX\n")
  148. elif sys.platform == 'darwin':
  149. conf.write("#define DARWIN\n")
  150. elif string.find (sys.platform, 'sunos') != -1:
  151. conf.write("#define SUNOS\n")
  152. elif sys.platform=='openbsd3':
  153. conf.write("#define OPEN_BSD\n")
  154. elif string.find (sys.platform, 'irix') != -1:
  155. conf.write("#define IRIX\n")
  156. conf.close()
  157. if not os.path.exists("conf/netsukuku.conf") and not env.GetOption('clean'):
  158. print 'Generating conf/netsukuku.conf from conf/ntk_scons.conf.in'
  159. conf_build('conf/netsukuku.conf', 'conf/ntk_scons.conf.in', env)
  160. return 0
  161. build_config_files(env = env)
  162. #
  163. # Build
  164. #
  165. ntkd = env.Program('ntkd', sources_netsukuku, LIBS = libs, CPPPATH = '.')
  166. qspn = env.Program('qspn-empiric', sources_qspn, LIBS = libs, CPPPATH = '.')
  167. ntkresolv = env.Program('ntk-resolv', sources_ntkresolv, LIBS = libs, CPPPATH = '.')
  168. Default(ntkd, ntkresolv)
  169. #
  170. # Install
  171. #
  172. SConscript(['man/SConscript', 'scripts/SConscript', 'conf/SConscript'], 'env')
  173. # Here are our installation paths:
  174. idir_bin = '$destdir' + '$BIN_DIR'
  175. idir_data = '$destdir' + '$DATA_DIR'
  176. idir_conf = '$destdir' + '$CONF_DIR'
  177. idir_pid = '$destdir' + '$PID_DIR'
  178. env.Install(idir_bin, [ntkd])
  179. env.Install(idir_bin, [ntkresolv])
  180. env.Alias('install', [idir_bin, idir_conf])
  181. #Dirty hack ;( Why GetOption("install") doesn't work?
  182. #if not os.path.exists(env["DATA_DIR"]) and os.path.exists(env["CONF_DIR"]):
  183. # Execute(Mkdir(env["DATA_DIR"]))