SConstruct 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #
  2. # SConstruct (10.09.09)
  3. # SConscript for all components.
  4. #
  5. # Copyright (C) 2010-2013 Andrew Nayenko
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. import os
  21. import platform
  22. import SCons
  23. env = Environment(**ARGUMENTS)
  24. for var in ['PATH', 'SYSROOT']:
  25. if var in os.environ:
  26. env['ENV'][var] = os.environ[var]
  27. destdir = env.get('DESTDIR', '/sbin');
  28. libs = ['exfat']
  29. libfuse = 'fuse'
  30. if not env.GetOption('clean'):
  31. conf = Configure(env)
  32. if 'AR' in os.environ:
  33. conf.env.Replace(AR = os.environ['AR'])
  34. if 'RANLIB' in os.environ:
  35. conf.env.Replace(RANLIB = os.environ['RANLIB'])
  36. if 'CC' in os.environ:
  37. conf.env.Replace(CC = os.environ['CC'])
  38. if 'CCFLAGS' in os.environ:
  39. conf.env.Replace(CCFLAGS = os.environ['CCFLAGS'])
  40. # Set default CCFLAGS for known compilers
  41. if not conf.env['CCFLAGS']:
  42. if conf.env['CC'] == 'gcc':
  43. conf.env.Replace(CCFLAGS = '-Wall -O2 -ggdb -std=c99')
  44. elif conf.env['CC'] == 'clang':
  45. conf.env.Replace(CCFLAGS = '-Wall -O2 -g -std=c99')
  46. if 'CPPFLAGS' in os.environ:
  47. conf.env.Replace(CPPFLAGS = os.environ['CPPFLAGS'])
  48. conf.env.Append(CPPDEFINES = {'_FILE_OFFSET_BITS' : 64})
  49. conf.env.Append(CPPPATH = ['libexfat'])
  50. if 'LDFLAGS' in os.environ:
  51. conf.env.Append(LINKFLAGS = os.environ['LDFLAGS'])
  52. conf.env.Append(LIBPATH = ['libexfat'])
  53. # GNU/Linux requires _BSD_SOURCE define for vsyslog(), _XOPEN_SOURCE >= 500
  54. # for pread(), pwrite(), snprintf(), strdup(), etc. Everything needed is
  55. # enabled by _GNU_SOURCE.
  56. if platform.system() == 'Linux':
  57. conf.env.Append(CPPDEFINES = '_GNU_SOURCE');
  58. # Use 64-bit inode numbers (introduced in Mac OS X 10.5 Leopard). Require
  59. # OSXFUSE (http://osxfuse.github.com).
  60. if platform.system() == 'Darwin':
  61. conf.env.Append(CPPDEFINES = '_DARWIN_USE_64_BIT_INODE')
  62. conf.env.Append(CPPDEFINES = {'__DARWIN_UNIX03' : 1})
  63. conf.env.Append(CPPPATH = ['/usr/local/include/osxfuse'])
  64. conf.env.Append(CFLAGS = '-mmacosx-version-min=10.5')
  65. conf.env.Append(LINKFLAGS = '-mmacosx-version-min=10.5')
  66. libfuse = 'osxfuse_i64'
  67. # FreeBSD does not support block devices, only raw devices. Ublio is
  68. # required for unaligned I/O and caching.
  69. if platform.system() == 'FreeBSD':
  70. conf.env.Append(CPPDEFINES = 'USE_UBLIO')
  71. libs.append('ublio')
  72. conf.env.Append(CPPPATH = ['/usr/local/include'])
  73. conf.env.Append(LIBPATH = ['/usr/local/lib'])
  74. if not conf.CheckCC():
  75. print '''
  76. A working C compiler is needed very much.
  77. '''
  78. Exit(1)
  79. if not conf.CheckTypeSize('off_t', '#include <sys/types.h>', 'C', 8):
  80. print '''
  81. The size of off_t type must be 64 bits. File systems larger than
  82. 2 GB will be corrupted with 32-bit off_t.
  83. '''
  84. Exit(1)
  85. env = conf.Finish()
  86. def make_symlink(dir, target, link_name):
  87. workdir = os.getcwd()
  88. os.chdir(dir)
  89. try:
  90. os.remove(link_name)
  91. except OSError:
  92. pass
  93. os.symlink(target, link_name)
  94. os.chdir(workdir)
  95. symlink = SCons.Action.ActionFactory(make_symlink,
  96. lambda dir, target, link_name:
  97. 'make_symlink("%s", "%s", "%s")' % (dir, target, link_name))
  98. def program(pattern, output, alias, libs):
  99. sources = Glob(pattern)
  100. if not sources:
  101. return
  102. target = env.Program(output, sources, LIBS = libs)
  103. if alias:
  104. Clean(Alias('install', Install(destdir, target),
  105. symlink(destdir, os.path.basename(output), alias)),
  106. destdir + '/' + alias)
  107. else:
  108. Alias('install', Install(destdir, target))
  109. env.Library('libexfat/exfat', Glob('libexfat/*.c'))
  110. program('fuse/*.c', 'fuse/mount.exfat-fuse', 'mount.exfat', [libs + [libfuse]])
  111. program('dump/*.c', 'dump/dumpexfat', None, libs)
  112. program('fsck/*.c', 'fsck/exfatfsck', 'fsck.exfat', libs)
  113. program('mkfs/*.c', 'mkfs/mkexfatfs', 'mkfs.exfat', libs)
  114. program('label/*.c', 'label/exfatlabel', None, libs)