Skip to content

Instantly share code, notes, and snippets.

@TheBeachMaster
Created January 22, 2022 22:40
Show Gist options
  • Save TheBeachMaster/167bc80cef55c67c3f5d2e61c3f93eed to your computer and use it in GitHub Desktop.
Save TheBeachMaster/167bc80cef55c67c3f5d2e61c3f93eed to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define UNIVERSAL_CONSTANT 42
/**
* app.c is currently the world's most complex application.
* We'll never know, will we?
*/
int main(int argc, char const *argv[])
{
// The answer to life's most fundamental question:
printf("Well the answer is %i", UNIVERSAL_CONSTANT);
return 0;
}
#Barebones configuration
#Library('mandelbrot',['./lib/mandelbrot.cc'])
#Program('./src/app.cc', LIBS=['mandelbrot'], LIBPATH='.')
#Customize excecutable directory and add a Clean up function
#Library('mandelbrot',['./lib/mandelbrot.cc'])
#Program('dist/mandelbrot','./src/app.cc', LIBS=['mandelbrot'], LIBPATH='.')
#target = Program('dist/mandelbrot','./src/app.cc', LIBS=['mandelbrot'], LIBPATH='.')
#Clean(target,'./dist')
#Add build help
#Library('mandelbrot',['./lib/mandelbrot.cc'])
#Program('dist/mandelbrot','./src/app.cc', LIBS=['mandelbrot'], LIBPATH='.')
#target = Program('dist/mandelbrot','./src/app.cc', LIBS=['mandelbrot'], LIBPATH='.')
#Clean(target,'./dist')
#Help("""
#Usage: 'scons .' to build the mandelbrot application
# 'scons PNGSUPPORT' to add PNG support to the application
#""")
#import platform
#platform_ = platform.system()
#if platform_ == 'Linux':
# Help("\nType: 'scons linux' Build with native Linux support.\n")
#if platform_ == 'Windows':
# Help("\nType: 'scons win32' Build with native Windows support.\n")
# Add Custom Commandline targets
Help("""
Usage: 'scons .' to build the mandelbrot application
'scons -Q IMAGETYPE=PNG' to generate PNG output only, default is PPM
'scons -Q IMAGETYPE=ALL' to generate both PPM and PNG images
""")
import platform
platform_ = platform.system()
if platform_ == 'Linux':
Help("\nType: 'scons linux' Build with native Linux support.\n")
if platform_ == 'Windows':
Help("\nType: 'scons win32' Build with native Windows support.\n")
vars = Variables(None)
vars.Add(EnumVariable('IMAGETYPE', 'Set to PNG to build for PNG image output support or ALL to generate PNG and PPM', 'PPM' ,
allowed_values=('PNG','PPM','ALL')))
env = Environment(variables = vars,
CPPDEFINES={'IMAGETYPE' : '"${IMAGETYPE}"'})
# CCFLAGS='`-I/usr/include/ImageMagick-7 -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/ImageMagick-7 -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -lMagick++-7.Q16HDRI -lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI -lMagick++-7.Q16HDRI -lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI')
unknown = vars.UnknownVariables()
if unknown:
print("Unknown variables: %s"%unknown.keys())
Exit(1)
env.Append(CPPPATH = ['/usr/include', '/usr/local/include'])
# Check if we have some headers
test_assert_source_file = """
#include <assert.h>
int test_assert(int x)
{
assert(x <= 4);
return x;
}
int main()
{
test_assert(2);
return 0;
}
"""
def CheckForAssert(context):
context.Message('Checking for Assert header files... ')
result = context.TryLink(test_assert_source_file, '.c')
context.Result(result)
return result
conf = Configure(env, custom_tests = {'CheckForAssert' : CheckForAssert})
if not conf.CheckForAssert():
print 'Assert header files not found!'
Exit(1)
if not conf.CheckLib('png'):
print 'PNG Library not found'
Exit(1)
if not conf.CheckCHeader('stdlib.h'):
print 'CMath.h must be installed!'
Exit(1)
if not conf.CheckCXXHeader('math.h'):
print 'Math.h must be installed!'
Exit(1)
if not conf.CheckProg('xterm'):
print 'XTerm must be installed'
Exit(1)
env = conf.Finish()
# Build
Library('pngwriter',['./include/pngwriter/src/pngwriter.cc', './include/pngwriter/src/pngwriter.h'])
Library('mandelbrot',['./lib/mandelbrot.cc'])
env.Program('dist/mandelbrot','./src/app.cc', LIBS=['png', 'pngwriter', 'mandelbrot'], LIBPATH=['.'])
target = env.Program('dist/mandelbrot','./src/app.cc', LIBS=[ 'png', 'pngwriter', 'mandelbrot'], LIBPATH=['.'])
Clean(target,'./dist')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment