OSDN Git Service

6f4e26f450c866fe5f695293f35a6e6cd356fe72
[android-x86/external-exfat.git] / SConstruct
1 #
2 #       SConstruct (10.09.09)
3 #       SConscript for all components.
4 #
5 #       Copyright (C) 2010-2012  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
21 import os
22 import platform
23 import SCons
24
25 env = Environment(**ARGUMENTS)
26 for var in ['PATH', 'SYSROOT']:
27         if var in os.environ:
28                 env['ENV'][var] = os.environ[var]
29
30 destdir = env.get('DESTDIR', '/sbin');
31 targets = []
32 libs = ['exfat']
33 libfuse = 'fuse'
34
35 if not env.GetOption('clean'):
36         conf = Configure(env)
37
38         if 'AR' in os.environ:
39                 conf.env.Replace(AR = os.environ['AR'])
40         if 'RANLIB' in os.environ:
41                 conf.env.Replace(RANLIB = os.environ['RANLIB'])
42         if 'CC' in os.environ:
43                 conf.env.Replace(CC = os.environ['CC'])
44         if 'CCFLAGS' in os.environ:
45                 conf.env.Replace(CCFLAGS = os.environ['CCFLAGS'])
46         # Set default CCFLAGS for known compilers
47         if not conf.env['CCFLAGS']:
48                 if conf.env['CC'] == 'gcc':
49                         conf.env.Replace(CCFLAGS = '-Wall -O2 -ggdb -std=c99')
50                 elif conf.env['CC'] == 'clang':
51                         conf.env.Replace(CCFLAGS = '-Wall -O2 -g -std=c99')
52         if 'CPPFLAGS' in os.environ:
53                 conf.env.Replace(CPPFLAGS = os.environ['CPPFLAGS'])
54         conf.env.Append(CPPDEFINES = {'_FILE_OFFSET_BITS' : 64})
55         conf.env.Append(CPPPATH = ['libexfat'])
56         if 'LDFLAGS' in os.environ:
57                 conf.env.Append(LINKFLAGS = os.environ['LDFLAGS'])
58         conf.env.Append(LIBPATH = ['libexfat'])
59
60         # GNU/Linux requires _BSD_SOURCE define for vsyslog(), _XOPEN_SOURCE >= 500
61         # for pread(), pwrite(), snprintf(), strdup(), etc. Everything needed is
62         # enabled by _GNU_SOURCE.
63         if platform.system() == 'Linux':
64                 conf.env.Append(CPPDEFINES = '_GNU_SOURCE');
65
66         # Use 64-bit inode numbers (introduced in Mac OS X 10.5 Leopard). Require
67         # OSXFUSE (http://osxfuse.github.com).
68         if platform.system() == 'Darwin':
69                 conf.env.Append(CPPDEFINES = '_DARWIN_USE_64_BIT_INODE')
70                 conf.env.Append(CPPDEFINES = {'__DARWIN_UNIX03' : 1})
71                 conf.env.Append(CPPPATH = ['/usr/local/include/osxfuse'])
72                 conf.env.Append(CFLAGS    = '-mmacosx-version-min=10.5')
73                 conf.env.Append(LINKFLAGS = '-mmacosx-version-min=10.5')
74                 libfuse = 'osxfuse_i64'
75
76         # FreeBSD does not support block devices, only raw devices. Ublio is
77         # required for unaligned I/O and caching.
78         if platform.system() == 'FreeBSD':
79                 conf.env.Append(CPPDEFINES = 'USE_UBLIO')
80                 libs.append('ublio')
81                 conf.env.Append(CPPPATH = ['/usr/local/include'])
82                 conf.env.Append(LIBPATH = ['/usr/local/lib'])
83
84         if not conf.CheckCC():
85                 print '''
86         A working C compiler is needed very much.
87 '''
88                 Exit(1)
89
90         if not conf.CheckTypeSize('off_t', '#include <sys/types.h>', 'C', 8):
91                 print '''
92         The size of off_t type must be 64 bits. File systems larger than
93         2 GB will be corrupted with 32-bit off_t.
94 '''
95                 Exit(1)
96
97         env = conf.Finish()
98
99
100
101 def make_symlink(dir, target, link_name):
102         workdir = os.getcwd()
103         os.chdir(dir)
104         try:
105                 os.remove(link_name)
106         except OSError:
107                 pass
108         os.symlink(target, link_name)
109         os.chdir(workdir)
110
111 symlink = SCons.Action.ActionFactory(make_symlink,
112                 lambda dir, target, link_name:
113                                 'make_symlink("%s", "%s", "%s")' % (dir, target, link_name))
114
115 def program(pattern, output, alias, libs):
116         sources = Glob(pattern)
117         if not sources:
118                 return
119         target = env.Program(output, sources, LIBS = libs)
120         if alias:
121                 Clean(Alias('install', Install(destdir, target),
122                                 symlink(destdir, os.path.basename(output), alias)),
123                                 destdir + '/' + alias)
124         else:
125                 Alias('install', Install(destdir, target))
126         targets.append(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)
135
136 Default(targets)