SConstruct for SDL_image

The SDL_image homepage is 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. Because this is set to use static linking by default, you will need to link to libpng, libtiff, zlib and libjpeg (in that order) for any program built with the resulting library. Just make sure your program's lib list looks like showimage_LIBS and you'll be fine. After installation, the include file resides in "c:/mingw/include/SDL" by default, so use #include <SDL/SDL_image.h> in your code.

Code

   1 import os
   2 
   3 env = Environment(ENV=os.environ)
   4 Tool('mingw')(env)
   5 env.Replace(CCFLAGS="-O2 -march=i686")
   6 
   7 
   8 opts = Variables('SDL_image.conf')
   9 
  10 opts.Add(PathVariable('PREFIX', 'Directory to install under', 'c:/mingw', PathVariable.PathIsDir))
  11 opts.Add(BoolVariable('LOAD_JPG', 'support loading JPG images', 1))
  12 opts.Add(BoolVariable('LOAD_PNG', 'support loading PNG images', 1))
  13 opts.Add(BoolVariable('LOAD_TIF', 'support loading TIFF images', 1))
  14 opts.Add(BoolVariable('LOAD_BMP', 'support loading BMP images', 1))
  15 opts.Add(BoolVariable('LOAD_GIF', 'support loading GIF images', 1))
  16 opts.Add(BoolVariable('LOAD_LBM', 'support loading LBM images', 1))
  17 opts.Add(BoolVariable('LOAD_PCX', 'support loading PCX images', 1))
  18 opts.Add(BoolVariable('LOAD_PNM', 'support loading PNM images', 1))
  19 opts.Add(BoolVariable('LOAD_TGA', 'support loading TGA images', 1))
  20 opts.Add(BoolVariable('LOAD_XCF', 'support loading XCF images', 1))
  21 opts.Add(BoolVariable('LOAD_XPM', 'support loading XPM images', 1))
  22 opts.Add(BoolVariable('LOAD_XV', 'support loading XV images', 1))
  23 opts.Add('LOAD_JPG_DYNAMIC', 'dynamically load JPG support', 0)
  24 opts.Add('LOAD_PNG_DYNAMIC', 'dynamically load PNG support', 0)
  25 opts.Add('LOAD_TIF_DYNAMIC', 'dynamically load TIFF support', 0)
  26 
  27 opts.Update(env)
  28 opts.Save('SDL_image.conf', env)
  29 Help(opts.GenerateHelpText(env))
  30 
  31 if env['LOAD_TIF'] and not env['LOAD_TIF_DYNAMIC']:
  32    env['LOAD_JPG_DYNAMIC'] = 0
  33 
  34 if env['LOAD_JPG']: env.Append(CPPDEFINES={'LOAD_JPG': env['LOAD_JPG'] and 1 or 0})
  35 if env['LOAD_PNG']: env.Append(CPPDEFINES={'LOAD_PNG': env['LOAD_PNG'] and 1 or 0})
  36 if env['LOAD_TIF']: env.Append(CPPDEFINES={'LOAD_TIF': env['LOAD_TIF'] and 1 or 0})
  37 if env['LOAD_BMP']: env.Append(CPPDEFINES={'LOAD_BMP': env['LOAD_BMP'] and 1 or 0})
  38 if env['LOAD_GIF']: env.Append(CPPDEFINES={'LOAD_GIF': env['LOAD_GIF'] and 1 or 0})
  39 if env['LOAD_LBM']: env.Append(CPPDEFINES={'LOAD_LBM': env['LOAD_LBM'] and 1 or 0})
  40 if env['LOAD_PCX']: env.Append(CPPDEFINES={'LOAD_PCX': env['LOAD_PCX'] and 1 or 0})
  41 if env['LOAD_PNM']: env.Append(CPPDEFINES={'LOAD_PNM': env['LOAD_PNM'] and 1 or 0})
  42 if env['LOAD_TGA']: env.Append(CPPDEFINES={'LOAD_TGA': env['LOAD_TGA'] and 1 or 0})
  43 if env['LOAD_XCF']: env.Append(CPPDEFINES={'LOAD_XCF': env['LOAD_XCF'] and 1 or 0})
  44 if env['LOAD_XPM']: env.Append(CPPDEFINES={'LOAD_XPM': env['LOAD_XPM'] and 1 or 0})
  45 if env['LOAD_XV']:  env.Append(CPPDEFINES={'LOAD_XV': env['LOAD_XV'] and 1 or 0})
  46 if env['LOAD_JPG_DYNAMIC']: env.Append(CPPDEFINES={'LOAD_JPG_DYNAMIC': '"$LOAD_JPG_DYNAMIC"'})
  47 if env['LOAD_PNG_DYNAMIC']: env.Append(CPPDEFINES={'LOAD_PNG_DYNAMIC': '"$LOAD_PNG_DYNAMIC"'})
  48 if env['LOAD_TIF_DYNAMIC']: env.Append(CPPDEFINES={'LOAD_TIF_DYNAMIC': '"$LOAD_TIF_DYNAMIC"'})
  49 
  50 
  51 idir_prefix = '$PREFIX'
  52 idir_lib    = '$PREFIX/lib'
  53 idir_bin    = '$PREFIX/bin'
  54 idir_inc    = '$PREFIX/include'
  55 idir_data   = '$PREFIX/share'
  56 Export('env idir_prefix idir_lib idir_bin idir_inc idir_data')
  57 
  58 env.Append(CPPPATH=Dir(idir_inc+"/SDL"))
  59 
  60 
  61 VariantDir('bin', 'obj', duplicate=0)
  62 VariantDir('lib', 'obj', duplicate=0)
  63 VariantDir('obj', '.', duplicate=0)
  64 
  65 
  66 libSDL_image_SOURCES = ['IMG.c',
  67                         'IMG_bmp.c',
  68                         'IMG_gif.c',
  69                         'IMG_jpg.c',
  70                         'IMG_lbm.c',
  71                         'IMG_pcx.c',
  72                         'IMG_png.c',
  73                         'IMG_pnm.c',
  74                         'IMG_tga.c',
  75                         'IMG_tif.c',
  76                         'IMG_xcf.c',
  77                         'IMG_xpm.c',
  78                         'IMG_xv.c']
  79 
  80 libSDL_image_LIBS = ['SDL',]
  81 if env['LOAD_PNG']:
  82    libSDL_image_LIBS.append('png')
  83 if env['LOAD_TIF']:
  84    libSDL_image_LIBS.append('tiff')
  85 if env['LOAD_PNG'] or env['LOAD_TIF']:
  86    libSDL_image_LIBS.append('z')
  87 if env['LOAD_JPG'] or env['LOAD_TIF']:
  88    libSDL_image_LIBS.append('jpeg')
  89 
  90 libSDL_image = env.StaticLibrary('lib/SDL_image', ['obj/'+x for x in libSDL_image_SOURCES], LIBS=libSDL_image_LIBS)
  91 
  92 
  93 showimage_SOURCES = ['showimage.c']
  94 
  95 showimage_LIBS = ['mingw32', 'SDLmain', libSDL_image]+libSDL_image_LIBS
  96 
  97 showimage = env.Program('bin/showimage', ['obj/'+x for x in showimage_SOURCES], LIBS=showimage_LIBS)
  98 
  99 
 100 Default(libSDL_image)
 101 
 102 
 103 Alias('install-lib', env.Install(idir_lib, libSDL_image))
 104 Alias('install-inc', env.Install(idir_inc+"/SDL", ['SDL_image.h']))
 105 Alias('install-bin', env.Install(idir_bin, [showimage]))
 106 Alias('install', ['install-lib', 'install-inc', 'install-bin'])

Discussion

KenBull/SDL_image (last edited 2008-12-24 19:50:44 by d38-58-133)