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