SConstruct for libtiff

The libtiff homepage is LibTIFF - TIFF Library and Utilities. Get the library itself here. This is setup to use MinGW by default. If you want to use another compiler or OS you may need to play with it a bit, but not much. This script uses features from Python 2.6 (print function and with statement). If you are using 2.5.x or below you will either need to upgrade or modify this file appropriately.

Code

   1 # $Id: SConstruct,v 1.2 2006/03/23 14:54:02 dron Exp $
   2 
   3 # Tag Image File Format (TIFF) Software
   4 #
   5 # Copyright (C) 2005, Andrey Kiselev <dron@ak4719.spb.edu>
   6 #
   7 # Permission to use, copy, modify, distribute, and sell this software and 
   8 # its documentation for any purpose is hereby granted without fee, provided
   9 # that (i) the above copyright notices and this permission notice appear in
  10 # all copies of the software and related documentation, and (ii) the names of
  11 # Sam Leffler and Silicon Graphics may not be used in any advertising or
  12 # publicity relating to the software without the specific, prior written
  13 # permission of Sam Leffler and Silicon Graphics.
  14 # 
  15 # THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  16 # EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  17 # WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  18 # 
  19 # IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  20 # ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  21 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22 # WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  23 # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  24 # OF THIS SOFTWARE.
  25 
  26 # This file contains rules to build software with the SCons tool
  27 # (see the http://www.scons.org/ for details on SCons).
  28 
  29 from __future__ import print_function
  30 import os
  31 
  32 def CheckSizeofInt(context):
  33     sizeof_int_test = '#include <stdio.h>\nint main() {printf("%d", sizeof(int)); return 0;}\n'
  34     context.Message('Checking sizeof(int)...')
  35     result = context.TryRun(sizeof_int_test, '.c')
  36     if not result[0]:
  37         context.Result(result[0])
  38         Exit(1)
  39     context.Result(result[1])
  40     return result[1]
  41 def CheckSizeofLong(context):
  42     sizeof_long_test = '#include <stdio.h>\nint main() {printf("%d", sizeof(long)); return 0;}\n'
  43     context.Message('Checking sizeof(long)...')
  44     result = context.TryRun(sizeof_long_test, '.c')
  45     if not result[0]:
  46         context.Result(result[0])
  47         Exit(1)
  48     context.Result(result[1])
  49     return result[1]
  50 def CheckTimeWithSysTime(context):
  51     time_with_sys_time_test = "#include <time.h>\n#include <sys/time.h>\nint main() {return 0;}\n"
  52     context.Message('Checking if you can safely include both <sys/time.h> and <time.h>...')
  53     result = context.TryCompile(time_with_sys_time_test, '.c')
  54     context.Result(result)
  55     return result
  56 def CheckTmInSysTime(context):
  57     tm_in_sys_time_test = "#include <sys/time.h>\nstruct tm t;\nint main() {return 0;}\n"
  58     context.Message("Checking if your <sys/time.h> declares `struct tm'...")
  59     result = context.TryCompile(tm_in_sys_time_test, '.c')
  60     context.Result(result)
  61     return result
  62 
  63 def GrokSettings(env):
  64     settings = {}
  65     
  66     settings['CCITT_SUPPORT']                = env['CCITT_SUPPORT']
  67     settings['CHECK_JPEG_YCBCR_SUBSAMPLING'] = env['CHECK_JPEG_YCBCR_SUBSAMPLING']
  68     settings['CXX_SUPPORT']                  = env['CXX_SUPPORT']
  69     settings['DEFAULT_EXTRASAMPLE_AS_ALPHA'] = env['DEFAULT_EXTRASAMPLE_AS_ALPHA']
  70     settings['HAVE_APPLE_OPENGL_FRAMEWORK']  = env['HAVE_APPLE_OPENGL_FRAMEWORK']
  71     settings['JPEG_SUPPORT']                 = env['JPEG_SUPPORT']
  72     settings['LOGLUV_SUPPORT']               = env['LOGLUV_SUPPORT']
  73     settings['LZW_SUPPORT']                  = env['LZW_SUPPORT']
  74     settings['MDI_SUPPORT']                  = env['MDI_SUPPORT']
  75     settings['NEXT_SUPPORT']                 = env['NEXT_SUPPORT']
  76     settings['OJPEG_SUPPORT']                = env['OJPEG_SUPPORT']
  77     settings['PACKBITS_SUPPORT']             = env['PACKBITS_SUPPORT']
  78     settings['PIXARLOG_SUPPORT']             = env['PIXARLOG_SUPPORT']
  79     settings['STRIPCHOP_DEFAULT']            = env['STRIPCHOP_DEFAULT'] and 'TIFF_STRIPCHOP' or False
  80     settings['STRIP_SIZE_DEFAULT']           = str(env['STRIP_SIZE_DEFAULT'])
  81     settings['SUBIFD_SUPPORT']               = env['SUBIFD_SUPPORT']
  82     settings['THUNDER_SUPPORT']              = env['THUNDER_SUPPORT']
  83     settings['X_DISPLAY_MISSING']            = env['X_DISPLAY_MISSING']
  84     settings['ZIP_SUPPORT']                  = env['ZIP_SUPPORT']
  85     
  86     settings['HAVE_IEEEFP'] = True
  87     settings['HAVE_INT16'] = False
  88     settings['HAVE_INT32'] = False
  89     settings['HAVE_INT8'] = False
  90     settings['HOST_BIGENDIAN'] = '0'
  91     settings['WORDS_BIGENDIAN'] = False # Define to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX).
  92     settings['HOST_FILLORDER'] = 'FILLORDER_LSB2MSB'
  93     settings['LT_OBJDIR'] = '".libs/"' # Define to the sub-directory in which libtool stores uninstalled libraries.
  94     settings['NO_MINUS_C_MINUS_O'] = False
  95     settings['PACKAGE'] = '"tiff"'
  96     settings['PACKAGE_BUGREPORT'] = '"tiff@lists.maptools.org"'
  97     settings['PACKAGE_NAME'] = '"LibTIFF Software"'
  98     settings['PACKAGE_STRING'] = '"LibTIFF Software 3.8.2"'
  99     settings['PACKAGE_TARNAME'] = '"tiff"'
 100     settings['PACKAGE_VERSION'] = '"3.8.2"'
 101     settings['VERSION'] ='"3.8.2"'
 102     settings['PTHREAD_CREATE_JOINABLE'] = False # Define to necessary symbol if this constant uses a non-standard name on your system.
 103     settings['STDC_HEADERS'] = True # Define to 1 if you have the ANSI C header files.
 104     settings['_FILE_OFFSET_BITS'] = False # Number of bits in a file offset, on hosts where this is settable.
 105     settings['_LARGE_FILES'] = False # Define for large files, on AIX-style hosts.
 106     settings['const'] = False # Define to empty if `const' does not conform to ANSI C.
 107     settings['inline'] = False # Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name.
 108     
 109     conf = Configure(env, custom_tests = {'CheckSizeofInt': CheckSizeofInt, 
 110                                           'CheckSizeofLong': CheckSizeofLong,
 111                                           'CheckTimeWithSysTime': CheckTimeWithSysTime,
 112                                           'CheckTmInSysTime': CheckTmInSysTime})
 113     
 114     settings['HAVE_ASSERT_H'] = conf.CheckCHeader('assert.h')
 115     settings['HAVE_DLFCN_H'] = conf.CheckCHeader('dlfcn.h')
 116     settings['HAVE_FCNTL_H'] = conf.CheckCHeader('fcntl.h')
 117     settings['HAVE_INTTYPES_H'] = conf.CheckCHeader('inttypes.h')
 118     settings['HAVE_LIMITS_H'] = conf.CheckCHeader('limits.h')
 119     settings['HAVE_MALLOC_H'] = conf.CheckCHeader('malloc.h')
 120     settings['HAVE_MEMORY_H'] = conf.CheckCHeader('memory.h')
 121     settings['HAVE_SEARCH_H'] = conf.CheckCHeader('search.h')
 122     settings['HAVE_STDINT_H'] = conf.CheckCHeader('stdint.h')
 123     settings['HAVE_STDLIB_H'] = conf.CheckCHeader('stdlib.h')
 124     settings['HAVE_STRINGS_H'] = conf.CheckCHeader('strings.h')
 125     settings['HAVE_STRING_H'] = conf.CheckCHeader('string.h')
 126     settings['HAVE_SYS_STAT_H'] = conf.CheckCHeader('sys/stat.h')
 127     settings['HAVE_SYS_TIME_H'] = conf.CheckCHeader('sys/time.h')
 128     settings['HAVE_SYS_TYPES_H'] = conf.CheckCHeader('sys/types.h')
 129     settings['HAVE_UNISTD_H'] = conf.CheckCHeader('unistd.h')
 130     settings['HAVE_WINDOWS_H'] = conf.CheckCHeader('windows.h')
 131     
 132     settings['HAVE_FLOOR'] = conf.CheckFunc('floor')
 133     settings['HAVE_GETOPT'] = conf.CheckFunc('getopt')
 134     settings['HAVE_ISASCII'] = conf.CheckFunc('isascii')
 135     settings['HAVE_LFIND'] = conf.CheckFunc('lfind')
 136     settings['HAVE_MEMMOVE'] = conf.CheckFunc('memmove')
 137     settings['HAVE_MEMSET'] = conf.CheckFunc('memset')
 138     settings['HAVE_MMAP'] = conf.CheckFunc('mmap')
 139     settings['HAVE_POW'] = conf.CheckFunc('pow')
 140     settings['HAVE_SQRT'] = conf.CheckFunc('sqrt')
 141     settings['HAVE_STRCASECMP'] = conf.CheckFunc('strcasecmp')
 142     settings['HAVE_STRCHR'] = conf.CheckFunc('strchr')
 143     settings['HAVE_STRRCHR'] = conf.CheckFunc('strrchr')
 144     settings['HAVE_STRSTR'] = conf.CheckFunc('strstr')
 145     settings['HAVE_STRTOL'] = conf.CheckFunc('strtol')
 146     settings['HAVE_STRTOUL'] = conf.CheckFunc('strtoul')
 147     
 148     settings['HAVE_LIBC'] = conf.CheckLib('c')
 149     settings['HAVE_LIBM'] = conf.CheckLib('m')
 150     
 151     settings['HAVE_PTHREAD'] = conf.CheckLibWithHeader('pthread', 'pthread.h', 'c')
 152     
 153     if settings['JPEG_SUPPORT'] and not conf.CheckLib('jpeg'):
 154         print("JPEG compression requires IJG JPEG library, which is not present.")
 155         Exit(1)
 156     
 157     if settings['PIXARLOG_SUPPORT'] and not conf.CheckLib('z'):
 158         print("Pixar log-format algorithm support requires Zlib, which is not present.")
 159         Exit(1)
 160     
 161     if settings['ZIP_SUPPORT'] and not conf.CheckLib('z'):
 162         print("Deflate compression support requires Zlib, which is not present.")
 163         Exit(1)
 164     
 165     settings['SIZEOF_INT'] = conf.CheckSizeofInt()
 166     settings['SIZEOF_LONG'] = conf.CheckSizeofLong()
 167     settings['TIME_WITH_SYS_TIME'] = conf.CheckTimeWithSysTime()
 168     settings['TM_IN_SYS_TIME'] = conf.CheckTmInSysTime()
 169     
 170     if conf.CheckType('off_t', '#include <sys/types.h>\n'):
 171        settings['off_t'] = False
 172     else:
 173        settings['off_t'] = 'long'
 174     
 175     if conf.CheckType('size_t', '#include <sys/types.h>\n'):
 176        settings['size_t'] = False
 177     else:
 178        settings['size_t'] = 'unsigned'
 179     
 180     env = conf.Finish()
 181     env['settings'] = settings
 182     return env
 183 
 184 def GenerateConfig(target, source, env):
 185     settings=env['settings']
 186     for t in target:
 187         print(t)
 188         with open(str(t), 'wt') as f:
 189             for key in settings.keys():
 190                 if isinstance(settings[key], str):
 191                     print("#define %s %s" % (key, settings[key]), file=f)
 192                 else:
 193                     if settings[key]:
 194                         print("#define %s 1" % (key,), file=f)
 195                     else:
 196                         print("/* #undef %s */" % (key,), file=f)
 197     return 0
 198 
 199 # Import globally defined options
 200 #Import([ 'env', 'idir_lib' ])
 201 
 202 opts = Variables()
 203 opts.Add(PathVariable('PREFIX',
 204                       'Directory to install under', 
 205                       'c:/mingw',
 206                       PathVariable.PathIsDir))
 207 opts.Add(BoolVariable('CCITT_SUPPORT', 
 208                       'Support CCITT Group 3 & 4 algorithms.',
 209                       1))
 210 opts.Add(BoolVariable('CHECK_JPEG_YCBCR_SUBSAMPLING', 
 211                       'Pick up YCbCr subsampling info from the JPEG data stream to support files '\
 212                       'lacking the tag (default enabled).',
 213                       1))
 214 opts.Add(BoolVariable('CXX_SUPPORT', 
 215                       'Support C++ stream API (requires C++ compiler).',
 216                       0))
 217 opts.Add(BoolVariable('DEFAULT_EXTRASAMPLE_AS_ALPHA', 
 218                       'Treat extra sample as alpha (default enabled). The RGBA interface will ' \
 219                       'treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many ' \
 220                       'packages produce RGBA files but don\'t mark the alpha properly.',
 221                       1))
 222 opts.Add(BoolVariable('HAVE_APPLE_OPENGL_FRAMEWORK', 
 223                       'Use the Apple OpenGL framework.',
 224                       0))
 225 opts.Add(BoolVariable('JPEG_SUPPORT',
 226                       'Support JPEG compression (requires IJG JPEG library).',
 227                       1))
 228 opts.Add(BoolVariable('LOGLUV_SUPPORT',
 229                       'Support LogLuv high dynamic range encoding.',
 230                       1))
 231 opts.Add(BoolVariable('LZW_SUPPORT',
 232                       'Support LZW algorithm.', 
 233                       1))
 234 opts.Add(BoolVariable('MDI_SUPPORT', 
 235                       'Support Microsoft Document Imaging format.', 
 236                       1))
 237 opts.Add(BoolVariable('NEXT_SUPPORT', 
 238                       'Support NeXT 2-bit RLE algorithm.',
 239                       1))
 240 opts.Add(BoolVariable('OJPEG_SUPPORT',
 241                       'Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation ' \
 242                       'fails with unpatched IJG JPEG library.',
 243                       0))
 244 opts.Add(BoolVariable('PACKBITS_SUPPORT', 'Support Macintosh PackBits algorithm.', 1))
 245 opts.Add(BoolVariable('PIXARLOG_SUPPORT', 'Support Pixar log-format algorithm (requires Zlib).', 1))
 246 opts.Add(BoolVariable('STRIPCHOP_DEFAULT',
 247                       'Support strip chopping (whether or not to convert single-strip uncompressed ' \
 248                       'images to mutiple strips of specified size to reduce memory usage)',
 249                       1))
 250 opts.Add('STRIP_SIZE_DEFAULT', 'Default size of the strip in bytes (when strip chopping enabled).', '8192')
 251 opts.Add(BoolVariable('SUBIFD_SUPPORT', 'Enable SubIFD tag (330) support.', 1))
 252 opts.Add(BoolVariable('THUNDER_SUPPORT', 'Support ThunderScan 4-bit RLE algorithm.', 1))
 253 opts.Add(BoolVariable('X_DISPLAY_MISSING', 'Define to 1 if the X Window System is missing or not being used.', 1))
 254 opts.Add(BoolVariable('ZIP_SUPPORT', 'Support Deflate compression.', 1))
 255 
 256 env = Environment(ENV=os.environ, variables=opts)
 257 Tool('mingw')(env)
 258 env.Replace(CCFLAGS="-O2 -march=i686")
 259 
 260 Help(opts.GenerateHelpText(env))
 261 
 262     
 263 idir_prefix = '$PREFIX'
 264 idir_lib    = '$PREFIX/lib'
 265 idir_bin    = '$PREFIX/bin'
 266 idir_inc    = '$PREFIX/include'
 267 idir_data   = '$PREFIX/share'
 268 Export('env idir_prefix idir_lib idir_bin idir_inc idir_data')
 269 
 270 
 271 VariantDir('bin', 'obj', duplicate=0)
 272 VariantDir('lib', 'obj', duplicate=0)
 273 VariantDir('obj', '.', duplicate=0)
 274 
 275 env = GrokSettings(env)
 276 
 277 env.AlwaysBuild(env.Command('tif_config.h', '', GenerateConfig))
 278 
 279 
 280 SRCS = [
 281         'tif_aux.c', 
 282         'tif_close.c', 
 283         'tif_codec.c', 
 284         'tif_color.c', 
 285         'tif_compress.c', 
 286         'tif_dir.c', 
 287         'tif_dirinfo.c', 
 288         'tif_dirread.c', 
 289         'tif_dirwrite.c', 
 290         'tif_dumpmode.c', 
 291         'tif_error.c', 
 292         'tif_extension.c', 
 293         'tif_fax3.c', 
 294         'tif_fax3sm.c', 
 295         'tif_flush.c', 
 296         'tif_getimage.c', 
 297         'tif_jpeg.c', 
 298         'tif_luv.c', 
 299         'tif_lzw.c', 
 300         'tif_next.c', 
 301         'tif_ojpeg.c', 
 302         'tif_open.c', 
 303         'tif_packbits.c', 
 304         'tif_pixarlog.c', 
 305         'tif_predict.c', 
 306         'tif_print.c', 
 307         'tif_read.c', 
 308         'tif_strip.c', 
 309         'tif_swab.c', 
 310         'tif_thunder.c', 
 311         'tif_tile.c', 
 312         #'tif_unix.c',
 313         'tif_version.c', 
 314         'tif_warning.c', 
 315         'tif_write.c', 
 316         'tif_zip.c' ]
 317 
 318 LIBS = []
 319 if env['JPEG_SUPPORT'] or env['OJPEG_SUPPORT']:
 320     LIBS.append('jpeg')
 321 if env['PIXARLOG_SUPPORT'] or env['ZIP_SUPPORT']:
 322     LIBS.append('z')
 323 
 324 INCS = []
 325 
 326 if env['PLATFORM'] in ['posix', 'cygwin', 'darwin', 'irix', 'sunos', 'hpux', 'aix']:
 327     SRCS.append('tif_unix.c')
 328 elif env['PLATFORM'] in ['win32', 'nt', 'ce']:
 329     SRCS.append('tif_win32.c')
 330     env.MergeFlags('-includewindows.h -mwindows')
 331 elif env['PLATFORM'] in ['mac']:
 332     SRCS.append('tif_apple.c')
 333 elif env['PLATFORM'] in ['riscos']:
 334     SRCS.append('tif_acorn.h')
 335 #elif env['PLATFORM'] in ['win16']:
 336 #    SRCS.append('tif_win3.c')
 337 #elif env['PLATFORM'] in ['msdos', 'dos']:
 338 #    SRCS.append('tif_msdos.h')
 339 #elif env['PLATFORM'] in ['atari']:
 340 #    SRCS.append('tif_atari.h')
 341 else:
 342      print("Platform '%s' not supported." % (env['PLATFORM'],))
 343      Exit(1)
 344 
 345 SRCS = ['obj/'+x for x in SRCS]
 346 
 347 libtiff = env.StaticLibrary('lib/tiff', SRCS, LIBS=LIBS)
 348 #env.SharedLibrary('bin/tiff', SRCS, LIBS=LIBS)
 349 
 350 Default(libtiff)
 351 
 352 Alias('install-lib', env.Install(idir_lib, libtiff))
 353 Alias('install-inc', env.Install(idir_inc, ['tiff.h', 'tiffconf.h', 'tiffio.h', 'tiffvers.h', 'tif_config.h']))
 354 env.Alias('install', ['install-lib', 'install-inc'])

Discussion

KenBull/libtiff (last edited 2008-12-24 19:38:48 by d38-58-133)