help in simplification of code [string manipulation]

J

John

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(CPPPATH=['include', 'include/trackball'])
libs = ['glut',
'GLU',
'GL',
'm',]


Thanks,
--j
 
K

Kent Johnson

John said:
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(CPPPATH=['include', 'include/trackball'])
libs = ['glut',
'GLU',
'GL',
'm',]
>>> LDFLAGS = '-lglut -lGLU -lGL -lm'
>>> libs = [flag[2:] for flag in LDFLAGS.split()]
>>> libs
['glut', 'GLU', 'GL', 'm']

Kent
 
C

Christophe

John a écrit :
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(CPPPATH=['include', 'include/trackball'])
libs = ['glut',
'GLU',
'GL',
'm',]


Thanks,
--j

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(CPPPATH=['include', 'include/trackball'])
 
J

John

Thanks for your replies...
Solved my problem.
--j
John a écrit :
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(CPPPATH=['include', 'include/trackball'])
libs = ['glut',
'GLU',
'GL',
'm',]


Thanks,
--j

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(CPPPATH=['include', 'include/trackball'])
 
C

Christophe

John a écrit :
Thanks for your replies...
Solved my problem.

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.
Christophe said:
John a écrit :
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(CPPPATH=['include', 'include/trackball'])
libs = ['glut',
'GLU',
'GL',
'm',]


Thanks,
--j

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(CPPPATH=['include', 'include/trackball'])
 
J

John

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top