### Copyright (c) 2003 by Scott Lystig Fritchie, ### See the file "LICENSE" for full license terms. import os import sys ### ### CHANGEME ### top_dir -- Define to fit your local environment. Delete the ### print statements and the sys.exit call. ### print "\nPlease set the variable 'top_dir' to be the full path to" print "the SConstruct file, then re-run scons. Search for the" print "text string 'CHANGEME'.\n" print "Exiting!\n" sys.exit(1) #Examples: #top_dir = "/home/slf/wrk/exp/build" #top_dir = "/user/fritchie/tmp/c/exp/build/mylib" ### ### Reminder: ### The SConstruct file must be "above" both the source and ### build directories, or else ... things just won't work. ### ### ### NOTE: Because I don't have experience with building software on ### non-UNIX systems, these examples are not paranoid about ### how file paths are created and manipulated. If I were ### truly paranoid, I would use the os.path.* functions ### religiously. But I'm not. Sorry! ### if 0: # CHANGEME: edit this line and the next if Mylib.py not in current dir. sys.path = ["/path/to/directory/containing/Mylib.py"] + sys.path import Mylib ### ### Here is where we create custom builders. ### ### StaticLibMerge -- Create a static library whose object files ### are found in several different directories. See the comments ### in Mylib.py for CreateMergedStaticLibrary() for more details. ### ### IDL -- An example IDL compiler builder. IDL compilers have ### wide range of command-line flags and file output behavior. ### You'll almost certainly have to modify the builder's action ### string as well as the Mylib.Emitter_IDL function to fit your ### IDL compiler's behavior. ### B_StaticLibMerge = Builder(generator = Mylib.Gen_StaticLibMerge) B_IDL = Builder( action = ["$IDL $__XFLAGS $IDLFLAGS $_CPPINCFLAGS --output-dir $__OUTPUT_DIR $SOURCE"], emitter = Mylib.Emitter_IDL) builders = Environment().Dictionary('BUILDERS') builders["StaticLibMerge"] = B_StaticLibMerge builders["CompileIDL"] = B_IDL top_env = Environment( platform = "posix", BUILDERS = builders, ENV = {"PATH" : os.environ["PATH"]}) ### ### The boilerplate used in the SConscript files end up creating a ### lot of copies of environments so they can change their environment ### without adversely affecting someone else's environment. However, ### it's nice to be able to keep a reference to the original ### environment dictionary, just in case. ### top_env["TopEnv"] = top_env ### ### Add other things to the top-level environment that we know all ### flavors of build (different debugging levels, optimization levels, ### cross-platform, cross-operating system) are going to require. ### top_env["IDL"] = str(Dir(".")) + "/fake-bin/fake-idl-compiler" ### ### Example usage of BuildDir. Notice that that we tell Mylib.Subdirs ### to use build_dir_WHATEVER, *not* "src". ### ### The Mylib function Subdirs() is the only Mylib function that ### does *not* take an environment dict as its first argument. It ### has a wacky assumption that the environment that you will pass ### to the subdirectory's SConscript file is in the variable "env". ### This is the reason why we *only* use a variable named "env" ### immediately before calling Mylib.Subdirs(). ### ### I wish I knew enough Python magic to be able to pass this ### variable as a normal argument. {sigh} ### build_dir_normal = top_dir + "/build-normal" build_dir_debug = top_dir + "/build-debug" src_dir = top_dir + "/src" # # Set up the first of two build directories, the "normal" one. # BuildDir(build_dir_normal, src_dir, 1) env = top_env.Copy() # # Define environment vars for various directories. See the comments # in Mylib.py for ExportHeader, ExportStaticLibrary, InstallBin, and # others for details on how EXPORT_INCLUDE, EXPORT_LIB, and # INSTALL_BIN (and others) are used. # env["EXPORT_INCLUDE"] = top_dir + "/export-normal/include" env["EXPORT_LIB"] = top_dir + "/export-normal/lib" env["INSTALL_BIN"] = top_dir + "/install-normal/bin" Mylib.AddIncludeDirs(env, env["EXPORT_INCLUDE"]) Mylib.AddIncludeDirs(env, "/path/to/lib1/include") # Add as many as necessary Mylib.AddLibDirs(env, env["EXPORT_LIB"]) Mylib.AddLibDirs(env, "/path/to/lib1/lib") # Add as many as you need # Whew! Go for it. Mylib.Subdirs(build_dir_normal) # # Do the same thing for the debug directory. # BuildDir(build_dir_debug, src_dir, 1) env = top_env.Copy() Mylib.AddCFlags(env, "-g -D__TOP_LEVEL_DEBUG") env["EXPORT_INCLUDE"] = top_dir + "/export-debug/include" env["EXPORT_LIB"] = top_dir + "/export-debug/lib" env["INSTALL_BIN"] = top_dir + "/install-debug/bin" Mylib.AddIncludeDirs(env, env["EXPORT_INCLUDE"]) Mylib.AddIncludeDirs(env, "/path/to/lib1/include") # Add as many as necessary Mylib.AddLibDirs(env, env["EXPORT_LIB"]) Mylib.AddLibDirs(env, "/path/to/lib1/lib") # Add as many as you need # Go for it Mylib.Subdirs(build_dir_debug) # # Simple example for a cross-platform build directory. # #build_dir_mips9900 = top_dir + "/build-mips9900" #BuildDir(build_dir_mips9900, src_dir, 1) #env = top_env.Copy() #env["AR"] = "/path/to/mips9900/ar" #env["CC"] = "/path/to/mips9900/cc" #env["CXX"] = "/path/to/mips9900/c++" #env["LINK"] = "/path/to/mips9900/ld" #env["RANLIB"] = "/path/to/mips9900/ranlib" #env["SHCC"] = "/path/to/mips9900/cc-shared" #env["SHCXX"] = "/path/to/mips9900/c++-shared" #Mylib.AddCFlags(env, "-DACME_MIPS_9900") #env["EXPORT_INCLUDE"] = top_dir + "/export-mips9900/include" #env["EXPORT_LIB"] = top_dir + "/export-mips9900/lib" #env["INSTALL_BIN"] = top_dir + "/install-mips9900/bin" #Mylib.AddIncludeDirs(env, env["EXPORT_INCLUDE"]) #Mylib.AddIncludeDirs(env, "/path/to/lib1/include") # Add as many as necessary #Mylib.AddLibDirs(env, env["EXPORT_LIB"]) #Mylib.AddLibDirs(env, "/path/to/lib1/lib") # Add as many as you need ## Go for it #Mylib.Subdirs(build_dir_mips9900) ### ### Example of building in the "src" dir directly. Doing things this way ### reduces SCon's flexibility, e.g. to build multiple variations of ### the same library: one with debugging symbols and one without. ### #env = env.Copy() #Mylib.Subdirs("src")