0

I have a project where there are several helper scripts that call the main executable with different command-line options. Right now, the scripts assume the executable is in the same directory, so the calls to the executable in the script look like ./my_program. This, however, is not very flexible. What if the program is installed in the /usr/bin directory, and is not in the current directory?

Is there a way, using automake or autoconf, to generate these scripts, and substitute the calls to the executable with either ./my_program or just my_program, depending on whether or not the executable is already installed?

Nick
  • 499
  • 5
  • 13

1 Answers1

2

Sure. IMO the simplest solution with autotools would be:

  • create new m4 macro under m4/ folder that finds a path of your program, and sets it to a variable.

    For example, you created a macro:

    MY_PROGRAM_PATH_CHECK([action-if-found], [action-if-not-found])
    

    This macro creates MY_PROGRAM_PATH variable if path is found.

    configure.ac

    MY_PROGRAM_PATH_CHECK(,[AC_MSG_ERROR([my_program path not found, woot?])
    AC_SUBST(MY_PROGRAM_PATH)
    
    AC_CONFIG_FILES([src/script1.sh], [chmod +x src/script1.sh])
    AC_CONFIG_FILES([src/script2.sh], [chmod +x src/script2.sh])
    
  • convert your scripts to .in files, so the substitution would happen:

    src/Makefile.am

    bin_SCRIPTS = script1.sh script2.sh
    

    src/script1.sh

    @MY_PROGRAM_PATH@/my_program --option1
    

    src/script2.sh

    @MY_PROGRAM_PATH@/my_program --option2    
    
Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95