Building relative to src/ directory with SCons -


i have app following (i have thought quite common) directory hierarchy:

/src     subdir1/  # subdirs more source files.         more.c         sconscript     foo.c     # source files.     foo.h     sconscript /other        # other top-level directories no source code. /stuff        # however, there other assets may want build. readme        # other top-level files. sconstruct 

the problem when run scons top-level directory, calls gcc directory without cding src, this:

gcc -o src/foo.o src/foo.c 

this problematic several reasons:

  1. within program, #include files giving path relative src directory. example, more.c include foo.h #include "foo.h". fails because gcc run parent directory. don't want change includes #include "src/foo.h".
  2. i use __file__ special macro things logging. when built top-level directory, gcc puts "src/" @ front of filenames, since path given compile. may seem picky, don't want that, because think of source tree being relative src directory.

(edit: should add #1 can fixed adding -isrc flag gcc, seems more hacks around main issue.)

how can make scons cd src directory before calling gcc?

  • i don't want rid of src directory , move up, because there lots of other (non-code) files @ top level.
  • i don't want scons cd every subdirectory. should cd src , build files in hierarchy there.
  • i solve moving sconscript inside src directory , running there, perhaps using makefile @ top level. seems quite hacky, , want use scons build (non-code) assets in other directories src.

i've read can make custom builder , make change directories. however, not want write whole new builder c/c++. there way modify behaviour of existing builder without writing 1 scratch? also, on 1 forum, said changing directories within builder break parallel builds since change directory other tasks building from. true?

this behavior how scons works, , not possible avoid/change. i've been looking supporting documentation in favor, , havent found any. ive become used to.

as mention, include paths simple fix. harder part __file__ macro. hadnt ever noticed until mentioned it. unfortunately, think way around strip path in logger, rather ugly fix.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -