Code::Blocks Forums

User forums => Help => Topic started by: gammell on May 15, 2011, 09:45:04 pm

Title: Environment Configuration for Custom Makefile
Post by: gammell on May 15, 2011, 09:45:04 pm
Hi,
I'm working to make a template for ROS (http://www.ros.org/) projects in Code::Blocks. I've got it mostly figured out (and would be quite happy to share it), except for some misunderstandings about configuring the CB shell environment. ROS uses custom Makefiles that call cmake using the shell macro. The Makefile is:
Quote from: Makefile
include $(shell rospack find mk)/cmake.mk
This would normally return the path to the cmake template (i.e, something like "/opt/ros/ros/core/mk") with the /cmake.mk appended to the end of the path.

I enabled custom Makefiles in CB, but it doesn't work because the PATH variable does not include the directory for rospack. This is expected, as a traditional installation from source for ROS requires you to modify your ~/.bashrc as follows:
Quote from: ~/.bashrc
source /opt/ros/setup.bash
This is where I've run into problems. How do I do a similar configuration in the CB environment on a per-project level? I tried simply putting the "source ..." line into the pre-build steps, but that gives the error
Quote
/bin/sh: source: not found

All setup.bash does is some shell configuration (that is probably unnecessary for CB) and then calls setup.sh which is a file full of export commands to various shell variables (including PATH). I'd rather not copy the relevant variables out of the scripts however, as that results in a static solution that isn't very portable. The setup scripts are distributed as part of ROS, so using them would mean the template project would stay up-to-date with any configuration changes.

Can anyone provide any insight?
Thanks.
Title: Re: Environment Configuration for Custom Makefile
Post by: Jenna on May 15, 2011, 10:34:28 pm
Did you try to call the shell-script(s) directly in the prebuild steps (without the source) ?
Title: Re: Environment Configuration for Custom Makefile
Post by: gammell on May 15, 2011, 10:42:27 pm
Did you try to call the shell-script(s) directly in the prebuild steps (without the source) ?
The scripts do not have the execute bit set by default so I did not.

I could obviously chmod them, but I was hoping to find a solution that didn't require any modification to the base ROS install (no matter how trivial) so the project files would be portable.
Title: Re: Environment Configuration for Custom Makefile
Post by: stahta01 on May 16, 2011, 02:12:38 am
Use the shell name then redirect the script as input; it works at the Linux Prompt, no idea if it will work inside Code::Blocks.

Tim S.
Title: Re: Environment Configuration for Custom Makefile
Post by: gammell on May 16, 2011, 03:23:22 am
Use the shell name then redirect the script as input; it works at the Linux Prompt, no idea if it will work inside Code::Blocks.

Do you mean
Code
/bin/sh setup.sh
?

Yes, that runs the script without having an execute bit set; however, you're running a new shell inside the shell. All the shell variables and configuration belong to the child and disappear when the script finishes.
That or similar would work if there is a way to modify the default CB shell call, but I doubt that would be a project-level setting...

Does anyone know why the CB shell can't find source if it's /bin/sh?


Edit:
I don't think it matters, but I'm running Code::Blocks 10.05 on Ubuntu 10.04.2 LTS.
Title: Re: Environment Configuration for Custom Makefile
Post by: oBFusCATed on May 16, 2011, 08:46:07 am
Another option is to make a wrapper script distributed with you project which has the executable bit set and only calls the original script.
Title: Re: Environment Configuration for Custom Makefile
Post by: gammell on May 20, 2011, 06:07:19 pm
Another option is to make a wrapper script distributed with you project which has the executable bit set and only calls the original script.
Hm, maybe. But I think there may be scope issues again and regardless, it's not really a portable solution across projects.


I think i need more information about the shell embedded within CB. I've been thinking about it as essentially some sort of embedded OS shell, but that doesn't seem to be the case...