Author Topic: Environment Configuration for Custom Makefile  (Read 7590 times)

Offline gammell

  • Single posting newcomer
  • *
  • Posts: 4
Environment Configuration for Custom Makefile
« on: May 15, 2011, 09:45:04 pm »
Hi,
I'm working to make a template for ROS 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.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Environment Configuration for Custom Makefile
« Reply #1 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) ?

Offline gammell

  • Single posting newcomer
  • *
  • Posts: 4
Re: Environment Configuration for Custom Makefile
« Reply #2 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.
« Last Edit: May 15, 2011, 10:44:13 pm by gammell »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7786
    • My Best Post
Re: Environment Configuration for Custom Makefile
« Reply #3 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.
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline gammell

  • Single posting newcomer
  • *
  • Posts: 4
Re: Environment Configuration for Custom Makefile
« Reply #4 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.
« Last Edit: May 16, 2011, 04:01:48 am by gammell »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Environment Configuration for Custom Makefile
« Reply #5 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline gammell

  • Single posting newcomer
  • *
  • Posts: 4
Re: Environment Configuration for Custom Makefile
« Reply #6 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...