2

I would like to source /opt/something/somescript.com before running the Makefile in the Netbeans environment (v8.2). There seems to be answers about this only for Ant and Java, and not for generic C++.

There are only 2 files to play with in Netbeans:

  1. The Makefile, which is useless for this purpose
  2. The configurations.xml file, which maybe is the way to do this.

However, one looks in that configuration file, and there doesn't seem to be anything about running scripts, and I can't find any manual online that explains what XML tags are available.

So my question is: How can I configure Netbeans to source a shell script before building?

Community
  • 1
  • 1
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189

2 Answers2

1

(Assuming GNU Make)

  • The very link you provide that you claim proves that Makefile would be useless actually contains at least one recipe of "sourcing" a script into your build: call out to shell (using the shell builtin) to:

    • source your script (redirecting all output to /dev/null, probably)
    • call env and massage the output to emit VAR:=VALUE and export VAR for every variable
    • (optional) write the result into a file

    Then, if the result went into a file -- include that file; otherwise just eval the output of shell.

  • Another possibility is tweaking the magic SHELL variable to source your script before running whatever Make wants it to run. This might become noticeable if your script is heavy, but probably OK if it just sets some environment variables (I know nothing about Netbeans so can't say).

Here's a sample recipe for the first approach (don't actually indent everything by 4 spaces, that's just me struggling with StackOverflow):

    # Somewhere at the beginning of the Makefile
    define emit-sourced-env
      $(shell . $1 > /dev/null && env | sed -e 's/=/:=/' -e 's/^/export /' > $(notdir $1).mk)
    endef
    $(call emit-sourced-env,/opt/something/somescript.com)
    include somescript.com.mk
Michael Livshin
  • 401
  • 3
  • 4
  • You're making suggestions that are not in the frame of Netbeans building scheme. I don't understand anything of what you said (sorry) because it all is not possible in Netbeans. All I can do is modify that make file. Would you provide a recipe that would solve the problem in the Makefile, or alternatively provide the recipe to make this work on Netbeans? – The Quantum Physicist Jan 28 '17 at 11:43
  • added a working GNU Make sample to the answer, hope it helps – Michael Livshin Jan 28 '17 at 12:24
0

You can use project properties for that:

Netbeans Pop-up

(This is valid for projects with existing sources)

HEKTO
  • 3,876
  • 2
  • 24
  • 45
  • Actually this doesn't work. Try to source something there and see what happens. It gives an error that `source` doesn't exist. – The Quantum Physicist Jan 26 '17 at 19:32
  • @TheQuantumPhysicist - the line `/bin/bash -c "source ${HOME}/somescript"` will work (on Unix). Of course, all you can do in this script will be limited by the Unix processes design – HEKTO Jan 26 '17 at 20:21
  • This doesn't preserve the environment for make. Once bash exits, the environment variables go with it. – The Quantum Physicist Jan 26 '17 at 20:26
  • Yes, sure. I normally use a bunch of `make` include files to import everything I need into all makefiles I use – HEKTO Jan 26 '17 at 20:29
  • Actually you can't import environment variables through makefiles. Thanks for the effort. Sorry it didn't work out. – The Quantum Physicist Jan 26 '17 at 20:46