1

I have the following project structure:

/project
    /src_dirs
        /src_dir_1
        /...
    /include_dirs
        /inc_dir_1
        /...

/output
    SConstruct
        /Sconscripts
            lib1_sconscript
            lib2_sconscript
            /...
    objects/
        /...
    libs/
        /...   

The build process invoked from the output directory. so all the paths in the sconscripts, are relative to output directory. my sconscript files are auto generated. as you can see below, the paths to source files and to include files are relative paths. this is a demo sconscript file:

Import('libaEnv')
includes = ['../../project/include_dirs/inc_dir_1/be/cmn/inc', '../../project/include_dirs/inc_dir_1/be/be/cmn/api_inc']
directives = ['-CC','-c','-g']
code_switches = ['FAST_RUNG_MLK', 'EN_PRIORITY']
listDefines = code_switches
linkLibs = []

crt = libaEnv.Object(target='objects/crt.o', source='../../project/src_dirs/src_dir_1/crt.c', CPPDEFINES=listDefines, CPPFLAGS=directives, CPPPATH=includes)
ert = libaEnv.Object(target='objects/ert.o', source='../../project/src_dirs/src_dir_1/ert.c', CPPDEFINES=listDefines, CPPFLAGS=directives, CPPPATH=includes)
urt = libaEnv.Object(target='objects/urt.o', source='../../project/src_dirs/src_dir_1/urt.c', CPPDEFINES=listDefines, CPPFLAGS=directives, CPPPATH=includes)

liba = libaEnv.Library (target='libs/liba.a', source=[crt,ert,urt])
Return('liba')

I have seen that scons invokes the compiler with absolute paths to the source and the headers files. i have seen this by running scons with -verbose (i have also validate this by printing the command line in Action.py in the spawn method).

My scons version is: SCons 2.5.1 and i am running with python 2.7.

How can i force scons to invoke the compiler with relative paths only ?

Adam
  • 2,820
  • 1
  • 13
  • 33
  • Are you trying to build/add on to some package you've downloaded which uses SCons as it's build system? SCons should build with paths relative to the location of the SConstruct by default (though you can change the base dir using some command line flags). Also you're using an OLD version of SCons. Any chance you can use 4.0.1 and python 3.5+? – bdbaddog Aug 03 '20 at 19:00
  • @bdbaddog-the paths are generated relative to the sconscript files. and the compiler invoked successefully by scons. but all the commands invoked with absolute paths. scons take the paths and convert them to absolute. and i dont want this behavior. actually i have some complicated applications running with python 2.7 and scons 2.5.1 so this is not an option for the short term. – Adam Aug 03 '20 at 19:26
  • That's not default SCons behavior. default behavior is paths relative to the SConstruct's location. Any reason you can't use py3 only to run SCons 4.01? Are you modifying CCCOM or such variables? – bdbaddog Aug 03 '20 at 19:58

1 Answers1

1

One approach here is you can use top-relative addressing, as in:

includes = ['#project/include_dirs/inc_dir_1/be/cmn/inc', '#project/include_dirs/inc_dir_1/be/be/cmn/api_inc']

This still gets you absolute paths, but they'll be computed based on a valid starting point (# = "the directory containing the top-level SConsctruct", thus top-relative)

Mats Wichmann
  • 800
  • 6
  • 6