Index: generic.py
===================================================================
--- generic.py	(revision 489397)
+++ generic.py	(working copy)
@@ -504,6 +504,42 @@
 		return ''
 	return os.popen("which %s 2>/dev/null" % prog).read().strip()
 
+#HELPER - write a header file with information if a lib is available or not
+#         and stop if the package is mandatory
+
+def write_lib_header(lenv, libname, test_result, mandatory=False, headername='',addcontent=''):
+	
+	lib = libname.lower()
+	
+	if lib[0:3] != 'lib':
+		lib = 'lib'+lib
+
+	CACHED_LIB = 'CACHED_'+lib[3:].upper()
+	HAVE_LIB = 'HAVE_'+lib.upper()
+
+	if not test_result:
+		if mandatory:
+			pprint ( lenv, 'RED', lib + ' not found (mandatory).' )
+			lenv.Exit(1)
+		else:
+			pprint ( lenv, 'YELLOW', lib + ' not found.' )
+
+	if headername == '':
+		headername = 'config-'+lib+'.h'
+
+	dest=open(lenv.join(lenv['_BUILDDIR_'], headername), 'w')
+	dest.write('/* '+lib+' configuration created by bksys */\n')
+	if test_result:
+		dest.write('#define '+HAVE_LIB+' 1\n')
+   if addcontent: dest.write(addcontent);
+		lenv['_CONFIG_H_'].append(lib)
+		lenv[CACHED_LIB] = 1
+	else:
+		dest.write('/* #undef '+HAVE_LIB+' */\n')
+
+	dest.close()
+
+
 ## Scons-specific function, do not remove
 def exists(env):
 	return true
@@ -1093,6 +1129,7 @@
 	SConsEnvironment.find_program=find_program
 	SConsEnvironment.find_program_using_which=find_program_using_which
 	SConsEnvironment.getInstDirForResType=getInstDirForResType
+	SConsEnvironment.write_lib_header=write_lib_header
 
 	if env.has_key('GENCXXFLAGS'):   env.AppendUnique( CPPFLAGS  = env['GENCXXFLAGS'] )
 	if env.has_key('GENCCFLAGS'):    env.AppendUnique( CCFLAGS   = env['GENCCFLAGS'] )
Index: libjpeg.py
===================================================================
--- libjpeg.py	(revision 489397)
+++ libjpeg.py	(working copy)
@@ -64,10 +64,12 @@
 	opts.Save(optionFile, env)
 
 	if not env['HELP'] and (env['_CONFIGURE_'] or not env.has_key('CACHED_JPEG')):
+
 		conf = env.Configure(custom_tests =	 { 'Check_libjpeg' : Check_libjpeg} )
-		if not conf.Check_libjpeg():
-			print 'libjpeg not found (mandatory).'
-			
+		have_jpeg = conf.Check_libjpeg()
 		env = conf.Finish()
+
+		env.write_lib_header( 'libjpeg', have_jpeg, True )
+
 		opts.Save(optionFile, env)
 	
