help in simplification of code [string manipulation]

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    #1

    help in simplification of code [string manipulation]


    How could I simplify the code to get libs out of LDFLAGS
    or vice versa automatically in the following python/scons code?

    if sys.platform[:5] == 'linux':
    env.Append (CPPFLAGS = '-D__LINUX')
    env.Append (LDFLAGS = '-lglut -lGLU -lGL -lm')
    env.Append(CPPP ATH=['include', 'include/trackball'])
    libs = ['glut',
    'GLU',
    'GL',
    'm',]


    Thanks,
    --j

  • Kent Johnson

    #2
    Re: help in simplification of code [string manipulation]

    John wrote:[color=blue]
    > How could I simplify the code to get libs out of LDFLAGS
    > or vice versa automatically in the following python/scons code?
    >
    > if sys.platform[:5] == 'linux':
    > env.Append (CPPFLAGS = '-D__LINUX')
    > env.Append (LDFLAGS = '-lglut -lGLU -lGL -lm')
    > env.Append(CPPP ATH=['include', 'include/trackball'])
    > libs = ['glut',
    > 'GLU',
    > 'GL',
    > 'm',][/color]
    [color=blue][color=green][color=darkred]
    >>> LDFLAGS = '-lglut -lGLU -lGL -lm'
    >>> libs = [flag[2:] for flag in LDFLAGS.split()]
    >>> libs[/color][/color][/color]
    ['glut', 'GLU', 'GL', 'm']

    Kent

    Comment

    • Christophe

      #3
      Re: help in simplification of code [string manipulation]

      John a écrit :[color=blue]
      > How could I simplify the code to get libs out of LDFLAGS
      > or vice versa automatically in the following python/scons code?
      >
      > if sys.platform[:5] == 'linux':
      > env.Append (CPPFLAGS = '-D__LINUX')
      > env.Append (LDFLAGS = '-lglut -lGLU -lGL -lm')
      > env.Append(CPPP ATH=['include', 'include/trackball'])
      > libs = ['glut',
      > 'GLU',
      > 'GL',
      > 'm',]
      >
      >
      > Thanks,
      > --j
      >[/color]

      Why don't you use the LIBS var in the environment instead of the LDFLAGS
      ? And what use would be the libs var for you ?

      if sys.platform[:5] == 'linux':
      libs = ['glut',
      'GLU',
      'GL',
      'm',]
      env.Append (CPPFLAGS = '-D__LINUX')
      env.Append (LIBS = Split(libs))
      env.Append(CPPP ATH=['include', 'include/trackball'])

      Comment

      • John

        #4
        Re: help in simplification of code [string manipulation]


        Thanks for your replies...
        Solved my problem.
        --j

        Christophe wrote:[color=blue]
        > John a écrit :[color=green]
        > > How could I simplify the code to get libs out of LDFLAGS
        > > or vice versa automatically in the following python/scons code?
        > >
        > > if sys.platform[:5] == 'linux':
        > > env.Append (CPPFLAGS = '-D__LINUX')
        > > env.Append (LDFLAGS = '-lglut -lGLU -lGL -lm')
        > > env.Append(CPPP ATH=['include', 'include/trackball'])
        > > libs = ['glut',
        > > 'GLU',
        > > 'GL',
        > > 'm',]
        > >
        > >
        > > Thanks,
        > > --j
        > >[/color]
        >
        > Why don't you use the LIBS var in the environment instead of the LDFLAGS
        > ? And what use would be the libs var for you ?
        >
        > if sys.platform[:5] == 'linux':
        > libs = ['glut',
        > 'GLU',
        > 'GL',
        > 'm',]
        > env.Append (CPPFLAGS = '-D__LINUX')
        > env.Append (LIBS = Split(libs))
        > env.Append(CPPP ATH=['include', 'include/trackball'])[/color]

        Comment

        • Christophe

          #5
          Re: help in simplification of code [string manipulation]

          John a écrit :[color=blue]
          > Thanks for your replies...
          > Solved my problem.[/color]

          Even so, I made a big mistake here. The Split function is of no use
          because there is already a list of flags. Better do it like that :
          libs = Split('glut GLU GL m')
          env.Append (LIBS = libs)

          BTW, Split is a scons function.
          [color=blue]
          > Christophe wrote:
          >[color=green]
          >>John a écrit :
          >>[color=darkred]
          >>>How could I simplify the code to get libs out of LDFLAGS
          >>>or vice versa automatically in the following python/scons code?
          >>>
          >>>if sys.platform[:5] == 'linux':
          >>> env.Append (CPPFLAGS = '-D__LINUX')
          >>> env.Append (LDFLAGS = '-lglut -lGLU -lGL -lm')
          >>> env.Append(CPPP ATH=['include', 'include/trackball'])
          >>> libs = ['glut',
          >>> 'GLU',
          >>> 'GL',
          >>> 'm',]
          >>>
          >>>
          >>>Thanks,
          >>>--j
          >>>[/color]
          >>
          >>Why don't you use the LIBS var in the environment instead of the LDFLAGS
          >>? And what use would be the libs var for you ?
          >>
          >>if sys.platform[:5] == 'linux':
          >> libs = ['glut',
          >> 'GLU',
          >> 'GL',
          >> 'm',]
          >> env.Append (CPPFLAGS = '-D__LINUX')
          >> env.Append (LIBS = Split(libs))
          >> env.Append(CPPP ATH=['include', 'include/trackball'])[/color]
          >
          >[/color]

          Comment

          • John

            #6
            Re: help in simplification of code [string manipulation]


            But ur previous solution worked on my machine...
            although a friend tried it on his machine and the libraries
            were not found even if they existed! (Even the -lm was not found)

            Can you explain a bit why the previous solution worked?

            Thanks for ur help,
            --j

            Comment

            Working...