Autoconf check for program and fail if not foundChecking and compiling Protocol Buffers using GNU build toolsBoost and AutoconfIs there a standard way of checking for a named executable with autoconfHow to recursively find and list the latest modified files in a directory with subdirectories and times?Checking for header-only library in autoconfWhy does autoconf erroneously find a function which isn't available later?autoconf: Detect deprecated functions (in Glibc)Does autoconf discover header files present on system?cross compiling with autoconfAutoconf has trouble recognizing m4autoconf: check a specific library

QGIS Welcome page: What is 'pin to list' for?

Why isn't there research to build a standard lunar, or Martian mobility platform?

What is this welding tool I found in my attic?

How can one write good dialogue in a story without sounding wooden?

As a DM, how to avoid unconscious metagaming when dealing with a high AC character?

How did the Game Boy Advance stretch Game Boy games to widescreen?

Do native speakers use ZVE or CPU?

If a specific mass of air is polluted, will the pollution stick with it?

What is temperature on a quantum level

Is this floating-point optimization allowed?

Are randomly-generated passwords starting with "a" less secure?

Was adding milk to tea started to reduce employee tea break time?

Supporting developers who insist on using their pet language

Why are Hobbits so fond of mushrooms?

Grammy Winners Grading

Is Arc Length always irrational between two rational points?

Where is the USB2 OTG port on the RPi 4 Model B located?

How might the United Kingdom become a republic?

diff shows a file that does not exist

Why did my rum cake turn black?

Why does resistance reduce when a conductive fabric is stretched?

Steampunk helicopter

Is Trump personally blocking people on Twitter?

Optimising Table wrapping over a Select



Autoconf check for program and fail if not found


Checking and compiling Protocol Buffers using GNU build toolsBoost and AutoconfIs there a standard way of checking for a named executable with autoconfHow to recursively find and list the latest modified files in a directory with subdirectories and times?Checking for header-only library in autoconfWhy does autoconf erroneously find a function which isn't available later?autoconf: Detect deprecated functions (in Glibc)Does autoconf discover header files present on system?cross compiling with autoconfAutoconf has trouble recognizing m4autoconf: check a specific library






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








15















I'm creating a project and using GNU Autoconf tools to do the configuring and making. I've set up all my library checking and header file checking but can't seem to figure out how to check if an executable exists on the system and fail if it doesn't exist.



I've tried:



AC_CHECK_PROG(TEST,testprogram,testprogram,AC_MSG_ERROR(Cannot find testprogram.))


When I configure it runs and outputs:



Checking for testprogram... find: `testprogram. 15426 5 ': No such file or directory


but does not fail.










share|improve this question






























    15















    I'm creating a project and using GNU Autoconf tools to do the configuring and making. I've set up all my library checking and header file checking but can't seem to figure out how to check if an executable exists on the system and fail if it doesn't exist.



    I've tried:



    AC_CHECK_PROG(TEST,testprogram,testprogram,AC_MSG_ERROR(Cannot find testprogram.))


    When I configure it runs and outputs:



    Checking for testprogram... find: `testprogram. 15426 5 ': No such file or directory


    but does not fail.










    share|improve this question


























      15












      15








      15


      2






      I'm creating a project and using GNU Autoconf tools to do the configuring and making. I've set up all my library checking and header file checking but can't seem to figure out how to check if an executable exists on the system and fail if it doesn't exist.



      I've tried:



      AC_CHECK_PROG(TEST,testprogram,testprogram,AC_MSG_ERROR(Cannot find testprogram.))


      When I configure it runs and outputs:



      Checking for testprogram... find: `testprogram. 15426 5 ': No such file or directory


      but does not fail.










      share|improve this question
















      I'm creating a project and using GNU Autoconf tools to do the configuring and making. I've set up all my library checking and header file checking but can't seem to figure out how to check if an executable exists on the system and fail if it doesn't exist.



      I've tried:



      AC_CHECK_PROG(TEST,testprogram,testprogram,AC_MSG_ERROR(Cannot find testprogram.))


      When I configure it runs and outputs:



      Checking for testprogram... find: `testprogram. 15426 5 ': No such file or directory


      but does not fail.







      linux autoconf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 '11 at 8:00









      Brock Adams

      71.9k16 gold badges169 silver badges222 bronze badges




      71.9k16 gold badges169 silver badges222 bronze badges










      asked Sep 20 '11 at 19:52









      Adam MagalukAdam Magaluk

      1,09814 silver badges25 bronze badges




      1,09814 silver badges25 bronze badges






















          6 Answers
          6






          active

          oldest

          votes


















          10














          Try this which is what I just lifted from a project of mine, it looks for something called quantlib-config in the path:



          # borrowed from a check for gnome in GNU gretl: def. a check for quantlib-config
          AC_DEFUN(AC_PROG_QUANTLIB, [AC_CHECK_PROG(QUANTLIB,quantlib-config,yes)])
          AC_PROG_QUANTLIB
          if test x"$QUANTLIB" == x"yes" ; then
          # use quantlib-config for QL settings
          [.... more stuff omitted here ...]
          else
          AC_MSG_ERROR([Please install QuantLib before trying to build RQuantLib.])
          fi





          share|improve this answer























          • Thanks for help, I used it create a shorter version which suits my needs.

            – Adam Magaluk
            Sep 20 '11 at 20:49











          • Yes, sure that looks good if you just need to bail out if the binary is not found.

            – Dirk Eddelbuettel
            Sep 20 '11 at 21:01


















          24














          I found this to be the shortest approach.



          AC_CHECK_PROG(FFMPEG_CHECK,ffmpeg,yes)
          AS_IF([test x"$FFMPEG_CHECK" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before configuring.])])





          share|improve this answer




















          • 1





            I’m not sure if it makes any difference in practice, but note that M4sh documents the AS_IF construct as a portable version. This is how the conditional is expressed with AS_IF: AS_IF([test x"$PATH_XMLTO" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before installing.])])

            – Michael
            Feb 11 at 20:42



















          4














          Similar to the above, but has the advantage of also being able to interact with automake by exporting the condition variable



          AC_CHECK_PROG([ffmpeg],[ffmpeg],[yes],[no])
          AM_CONDITIONAL([FOUND_FFMPEG], [test "x$ffmpeg" = xyes])
          AM_COND_IF([FOUND_FFMPEG],,[AC_MSG_ERROR([required program 'ffmpeg' not found.])])





          share|improve this answer






























            2














            When using AC_CHECK_PROG, this is the most concise version that I've run across is:



            AC_CHECK_PROG(BOGUS,[bogus],[bogus],[no])
            test "$BOGUS" == "no" && AC_MSG_ERROR([Required program 'bogus' not found.])


            When the program is missing, this output will be generated:



            ./configure
            ...cut...
            checking for bogus... no
            configure: error: Required program 'bogus' not found.


            Or when coupled with the built-in autoconf program checks, use this instead:



            AC_PROG_YACC
            AC_PROG_LEX

            test "$YACC" == ":" && AC_MSG_ERROR([Required program 'bison' not found.])
            test "$LEX" == ":" && AC_MSG_ERROR([Required program 'flex' not found.])





            share|improve this answer






























              1














              Stumbled here while looking for this issue, I should note that if you want to have your program just looked in pathm a runtime test is enough:



              if ! which programname >/dev/null ; then
              AC_MSG_ERROR([Missing programname]
              fi





              share|improve this answer






























                1














                This is not exactly a short approach, it's rather a general purporse approach (although when there are dozens of programs to check it might be also the shortest approach). It's taken from a project of mine (the prefix NA_ stands for “Not Autotools”).



                A general purpose macro



                dnl ***************************************************************************
                dnl NA_REQ_PROGS(prog1, [descr1][, prog2, [descr2][, etc., [...]]])
                dnl
                dnl Checks whether one or more programs have been provided by the user or can
                dnl be retrieved automatically. For each program `progx` an uppercase variable
                dnl named `PROGX` containing the path where `progx` is located will be created.
                dnl If a program is not reachable and the user has not provided any path for it
                dnl an error will be generated. The program names given to this function will
                dnl be advertised among the `influential environment variables` visible when
                dnl launching `./configure --help`.
                dnl ***************************************************************************
                AC_DEFUN([NA_REQ_PROGS], [
                m4_if([$#], [0], [], [
                AC_ARG_VAR(m4_translit([$1], [a-z], [A-Z]), [$2])
                AS_IF([test "x@S|@]m4_translit([$1], [a-z], [A-Z])[" = x], [
                AC_PATH_PROG(m4_translit([$1], [a-z], [A-Z]), [$1])
                AS_IF([test "x@S|@]m4_translit([$1], [a-z], [A-Z])[" = x], [
                AC_MSG_ERROR([$1 utility not found])
                ])
                ])
                m4_if(m4_eval([$# + 1 >> 1]), [1], [], [NA_REQ_PROGS(m4_shift2($*))])
                ])
                ])


                Sample usage



                NA_REQ_PROGS(
                [find], [Unix find utility],
                [xargs], [Unix xargs utility],
                [customprogram], [Some custom program],
                [etcetera], [Et cetera]
                )


                So that within Makefile.am you can do



                $(XARGS)


                or



                $(CUSTOMPROGRAM)


                and so on.



                Features



                • It advertises the programs among the “influential environment variables” visible when the final user launches ./configure --help, so that an alternative path to the program can be provided

                • A bash variable named with the same name of the program, but upper case, containing the path where the program is located, is created

                • En error is thrown if any of the programs given have not been found and the user has not provided any alternative path for them

                • The macro can take infinite (couples of) arguments

                When you should use it



                1. When the programs to be tested are vital for compiling your project, so that the user must be able to provide an alternative path for them and an error must be thrown if at least one program is not available at all

                2. When condition #1 applies to more than one single program, in which case there is no need to write a general purpose macro and you should just use your own customized code





                share|improve this answer



























                  Your Answer






                  StackExchange.ifUsing("editor", function ()
                  StackExchange.using("externalEditor", function ()
                  StackExchange.using("snippets", function ()
                  StackExchange.snippets.init();
                  );
                  );
                  , "code-snippets");

                  StackExchange.ready(function()
                  var channelOptions =
                  tags: "".split(" "),
                  id: "1"
                  ;
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function()
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled)
                  StackExchange.using("snippets", function()
                  createEditor();
                  );

                  else
                  createEditor();

                  );

                  function createEditor()
                  StackExchange.prepareEditor(
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader:
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  ,
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  );



                  );













                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7490978%2fautoconf-check-for-program-and-fail-if-not-found%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  6 Answers
                  6






                  active

                  oldest

                  votes








                  6 Answers
                  6






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  10














                  Try this which is what I just lifted from a project of mine, it looks for something called quantlib-config in the path:



                  # borrowed from a check for gnome in GNU gretl: def. a check for quantlib-config
                  AC_DEFUN(AC_PROG_QUANTLIB, [AC_CHECK_PROG(QUANTLIB,quantlib-config,yes)])
                  AC_PROG_QUANTLIB
                  if test x"$QUANTLIB" == x"yes" ; then
                  # use quantlib-config for QL settings
                  [.... more stuff omitted here ...]
                  else
                  AC_MSG_ERROR([Please install QuantLib before trying to build RQuantLib.])
                  fi





                  share|improve this answer























                  • Thanks for help, I used it create a shorter version which suits my needs.

                    – Adam Magaluk
                    Sep 20 '11 at 20:49











                  • Yes, sure that looks good if you just need to bail out if the binary is not found.

                    – Dirk Eddelbuettel
                    Sep 20 '11 at 21:01















                  10














                  Try this which is what I just lifted from a project of mine, it looks for something called quantlib-config in the path:



                  # borrowed from a check for gnome in GNU gretl: def. a check for quantlib-config
                  AC_DEFUN(AC_PROG_QUANTLIB, [AC_CHECK_PROG(QUANTLIB,quantlib-config,yes)])
                  AC_PROG_QUANTLIB
                  if test x"$QUANTLIB" == x"yes" ; then
                  # use quantlib-config for QL settings
                  [.... more stuff omitted here ...]
                  else
                  AC_MSG_ERROR([Please install QuantLib before trying to build RQuantLib.])
                  fi





                  share|improve this answer























                  • Thanks for help, I used it create a shorter version which suits my needs.

                    – Adam Magaluk
                    Sep 20 '11 at 20:49











                  • Yes, sure that looks good if you just need to bail out if the binary is not found.

                    – Dirk Eddelbuettel
                    Sep 20 '11 at 21:01













                  10












                  10








                  10







                  Try this which is what I just lifted from a project of mine, it looks for something called quantlib-config in the path:



                  # borrowed from a check for gnome in GNU gretl: def. a check for quantlib-config
                  AC_DEFUN(AC_PROG_QUANTLIB, [AC_CHECK_PROG(QUANTLIB,quantlib-config,yes)])
                  AC_PROG_QUANTLIB
                  if test x"$QUANTLIB" == x"yes" ; then
                  # use quantlib-config for QL settings
                  [.... more stuff omitted here ...]
                  else
                  AC_MSG_ERROR([Please install QuantLib before trying to build RQuantLib.])
                  fi





                  share|improve this answer













                  Try this which is what I just lifted from a project of mine, it looks for something called quantlib-config in the path:



                  # borrowed from a check for gnome in GNU gretl: def. a check for quantlib-config
                  AC_DEFUN(AC_PROG_QUANTLIB, [AC_CHECK_PROG(QUANTLIB,quantlib-config,yes)])
                  AC_PROG_QUANTLIB
                  if test x"$QUANTLIB" == x"yes" ; then
                  # use quantlib-config for QL settings
                  [.... more stuff omitted here ...]
                  else
                  AC_MSG_ERROR([Please install QuantLib before trying to build RQuantLib.])
                  fi






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 20 '11 at 19:55









                  Dirk EddelbuettelDirk Eddelbuettel

                  289k40 gold badges535 silver badges621 bronze badges




                  289k40 gold badges535 silver badges621 bronze badges












                  • Thanks for help, I used it create a shorter version which suits my needs.

                    – Adam Magaluk
                    Sep 20 '11 at 20:49











                  • Yes, sure that looks good if you just need to bail out if the binary is not found.

                    – Dirk Eddelbuettel
                    Sep 20 '11 at 21:01

















                  • Thanks for help, I used it create a shorter version which suits my needs.

                    – Adam Magaluk
                    Sep 20 '11 at 20:49











                  • Yes, sure that looks good if you just need to bail out if the binary is not found.

                    – Dirk Eddelbuettel
                    Sep 20 '11 at 21:01
















                  Thanks for help, I used it create a shorter version which suits my needs.

                  – Adam Magaluk
                  Sep 20 '11 at 20:49





                  Thanks for help, I used it create a shorter version which suits my needs.

                  – Adam Magaluk
                  Sep 20 '11 at 20:49













                  Yes, sure that looks good if you just need to bail out if the binary is not found.

                  – Dirk Eddelbuettel
                  Sep 20 '11 at 21:01





                  Yes, sure that looks good if you just need to bail out if the binary is not found.

                  – Dirk Eddelbuettel
                  Sep 20 '11 at 21:01













                  24














                  I found this to be the shortest approach.



                  AC_CHECK_PROG(FFMPEG_CHECK,ffmpeg,yes)
                  AS_IF([test x"$FFMPEG_CHECK" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before configuring.])])





                  share|improve this answer




















                  • 1





                    I’m not sure if it makes any difference in practice, but note that M4sh documents the AS_IF construct as a portable version. This is how the conditional is expressed with AS_IF: AS_IF([test x"$PATH_XMLTO" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before installing.])])

                    – Michael
                    Feb 11 at 20:42
















                  24














                  I found this to be the shortest approach.



                  AC_CHECK_PROG(FFMPEG_CHECK,ffmpeg,yes)
                  AS_IF([test x"$FFMPEG_CHECK" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before configuring.])])





                  share|improve this answer




















                  • 1





                    I’m not sure if it makes any difference in practice, but note that M4sh documents the AS_IF construct as a portable version. This is how the conditional is expressed with AS_IF: AS_IF([test x"$PATH_XMLTO" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before installing.])])

                    – Michael
                    Feb 11 at 20:42














                  24












                  24








                  24







                  I found this to be the shortest approach.



                  AC_CHECK_PROG(FFMPEG_CHECK,ffmpeg,yes)
                  AS_IF([test x"$FFMPEG_CHECK" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before configuring.])])





                  share|improve this answer















                  I found this to be the shortest approach.



                  AC_CHECK_PROG(FFMPEG_CHECK,ffmpeg,yes)
                  AS_IF([test x"$FFMPEG_CHECK" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before configuring.])])






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 23 at 18:10









                  John Kugelman

                  257k57 gold badges417 silver badges469 bronze badges




                  257k57 gold badges417 silver badges469 bronze badges










                  answered Sep 20 '11 at 20:50









                  Adam MagalukAdam Magaluk

                  1,09814 silver badges25 bronze badges




                  1,09814 silver badges25 bronze badges







                  • 1





                    I’m not sure if it makes any difference in practice, but note that M4sh documents the AS_IF construct as a portable version. This is how the conditional is expressed with AS_IF: AS_IF([test x"$PATH_XMLTO" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before installing.])])

                    – Michael
                    Feb 11 at 20:42













                  • 1





                    I’m not sure if it makes any difference in practice, but note that M4sh documents the AS_IF construct as a portable version. This is how the conditional is expressed with AS_IF: AS_IF([test x"$PATH_XMLTO" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before installing.])])

                    – Michael
                    Feb 11 at 20:42








                  1




                  1





                  I’m not sure if it makes any difference in practice, but note that M4sh documents the AS_IF construct as a portable version. This is how the conditional is expressed with AS_IF: AS_IF([test x"$PATH_XMLTO" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before installing.])])

                  – Michael
                  Feb 11 at 20:42






                  I’m not sure if it makes any difference in practice, but note that M4sh documents the AS_IF construct as a portable version. This is how the conditional is expressed with AS_IF: AS_IF([test x"$PATH_XMLTO" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before installing.])])

                  – Michael
                  Feb 11 at 20:42












                  4














                  Similar to the above, but has the advantage of also being able to interact with automake by exporting the condition variable



                  AC_CHECK_PROG([ffmpeg],[ffmpeg],[yes],[no])
                  AM_CONDITIONAL([FOUND_FFMPEG], [test "x$ffmpeg" = xyes])
                  AM_COND_IF([FOUND_FFMPEG],,[AC_MSG_ERROR([required program 'ffmpeg' not found.])])





                  share|improve this answer



























                    4














                    Similar to the above, but has the advantage of also being able to interact with automake by exporting the condition variable



                    AC_CHECK_PROG([ffmpeg],[ffmpeg],[yes],[no])
                    AM_CONDITIONAL([FOUND_FFMPEG], [test "x$ffmpeg" = xyes])
                    AM_COND_IF([FOUND_FFMPEG],,[AC_MSG_ERROR([required program 'ffmpeg' not found.])])





                    share|improve this answer

























                      4












                      4








                      4







                      Similar to the above, but has the advantage of also being able to interact with automake by exporting the condition variable



                      AC_CHECK_PROG([ffmpeg],[ffmpeg],[yes],[no])
                      AM_CONDITIONAL([FOUND_FFMPEG], [test "x$ffmpeg" = xyes])
                      AM_COND_IF([FOUND_FFMPEG],,[AC_MSG_ERROR([required program 'ffmpeg' not found.])])





                      share|improve this answer













                      Similar to the above, but has the advantage of also being able to interact with automake by exporting the condition variable



                      AC_CHECK_PROG([ffmpeg],[ffmpeg],[yes],[no])
                      AM_CONDITIONAL([FOUND_FFMPEG], [test "x$ffmpeg" = xyes])
                      AM_COND_IF([FOUND_FFMPEG],,[AC_MSG_ERROR([required program 'ffmpeg' not found.])])






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 7 '13 at 20:43









                      waTeimwaTeim

                      7,6822 gold badges27 silver badges35 bronze badges




                      7,6822 gold badges27 silver badges35 bronze badges





















                          2














                          When using AC_CHECK_PROG, this is the most concise version that I've run across is:



                          AC_CHECK_PROG(BOGUS,[bogus],[bogus],[no])
                          test "$BOGUS" == "no" && AC_MSG_ERROR([Required program 'bogus' not found.])


                          When the program is missing, this output will be generated:



                          ./configure
                          ...cut...
                          checking for bogus... no
                          configure: error: Required program 'bogus' not found.


                          Or when coupled with the built-in autoconf program checks, use this instead:



                          AC_PROG_YACC
                          AC_PROG_LEX

                          test "$YACC" == ":" && AC_MSG_ERROR([Required program 'bison' not found.])
                          test "$LEX" == ":" && AC_MSG_ERROR([Required program 'flex' not found.])





                          share|improve this answer



























                            2














                            When using AC_CHECK_PROG, this is the most concise version that I've run across is:



                            AC_CHECK_PROG(BOGUS,[bogus],[bogus],[no])
                            test "$BOGUS" == "no" && AC_MSG_ERROR([Required program 'bogus' not found.])


                            When the program is missing, this output will be generated:



                            ./configure
                            ...cut...
                            checking for bogus... no
                            configure: error: Required program 'bogus' not found.


                            Or when coupled with the built-in autoconf program checks, use this instead:



                            AC_PROG_YACC
                            AC_PROG_LEX

                            test "$YACC" == ":" && AC_MSG_ERROR([Required program 'bison' not found.])
                            test "$LEX" == ":" && AC_MSG_ERROR([Required program 'flex' not found.])





                            share|improve this answer

























                              2












                              2








                              2







                              When using AC_CHECK_PROG, this is the most concise version that I've run across is:



                              AC_CHECK_PROG(BOGUS,[bogus],[bogus],[no])
                              test "$BOGUS" == "no" && AC_MSG_ERROR([Required program 'bogus' not found.])


                              When the program is missing, this output will be generated:



                              ./configure
                              ...cut...
                              checking for bogus... no
                              configure: error: Required program 'bogus' not found.


                              Or when coupled with the built-in autoconf program checks, use this instead:



                              AC_PROG_YACC
                              AC_PROG_LEX

                              test "$YACC" == ":" && AC_MSG_ERROR([Required program 'bison' not found.])
                              test "$LEX" == ":" && AC_MSG_ERROR([Required program 'flex' not found.])





                              share|improve this answer













                              When using AC_CHECK_PROG, this is the most concise version that I've run across is:



                              AC_CHECK_PROG(BOGUS,[bogus],[bogus],[no])
                              test "$BOGUS" == "no" && AC_MSG_ERROR([Required program 'bogus' not found.])


                              When the program is missing, this output will be generated:



                              ./configure
                              ...cut...
                              checking for bogus... no
                              configure: error: Required program 'bogus' not found.


                              Or when coupled with the built-in autoconf program checks, use this instead:



                              AC_PROG_YACC
                              AC_PROG_LEX

                              test "$YACC" == ":" && AC_MSG_ERROR([Required program 'bison' not found.])
                              test "$LEX" == ":" && AC_MSG_ERROR([Required program 'flex' not found.])






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Apr 3 '16 at 19:00









                              sellasella

                              1411 silver badge6 bronze badges




                              1411 silver badge6 bronze badges





















                                  1














                                  Stumbled here while looking for this issue, I should note that if you want to have your program just looked in pathm a runtime test is enough:



                                  if ! which programname >/dev/null ; then
                                  AC_MSG_ERROR([Missing programname]
                                  fi





                                  share|improve this answer



























                                    1














                                    Stumbled here while looking for this issue, I should note that if you want to have your program just looked in pathm a runtime test is enough:



                                    if ! which programname >/dev/null ; then
                                    AC_MSG_ERROR([Missing programname]
                                    fi





                                    share|improve this answer

























                                      1












                                      1








                                      1







                                      Stumbled here while looking for this issue, I should note that if you want to have your program just looked in pathm a runtime test is enough:



                                      if ! which programname >/dev/null ; then
                                      AC_MSG_ERROR([Missing programname]
                                      fi





                                      share|improve this answer













                                      Stumbled here while looking for this issue, I should note that if you want to have your program just looked in pathm a runtime test is enough:



                                      if ! which programname >/dev/null ; then
                                      AC_MSG_ERROR([Missing programname]
                                      fi






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Apr 4 '14 at 7:37









                                      AlarAlar

                                      6353 silver badges11 bronze badges




                                      6353 silver badges11 bronze badges





















                                          1














                                          This is not exactly a short approach, it's rather a general purporse approach (although when there are dozens of programs to check it might be also the shortest approach). It's taken from a project of mine (the prefix NA_ stands for “Not Autotools”).



                                          A general purpose macro



                                          dnl ***************************************************************************
                                          dnl NA_REQ_PROGS(prog1, [descr1][, prog2, [descr2][, etc., [...]]])
                                          dnl
                                          dnl Checks whether one or more programs have been provided by the user or can
                                          dnl be retrieved automatically. For each program `progx` an uppercase variable
                                          dnl named `PROGX` containing the path where `progx` is located will be created.
                                          dnl If a program is not reachable and the user has not provided any path for it
                                          dnl an error will be generated. The program names given to this function will
                                          dnl be advertised among the `influential environment variables` visible when
                                          dnl launching `./configure --help`.
                                          dnl ***************************************************************************
                                          AC_DEFUN([NA_REQ_PROGS], [
                                          m4_if([$#], [0], [], [
                                          AC_ARG_VAR(m4_translit([$1], [a-z], [A-Z]), [$2])
                                          AS_IF([test "x@S|@]m4_translit([$1], [a-z], [A-Z])[" = x], [
                                          AC_PATH_PROG(m4_translit([$1], [a-z], [A-Z]), [$1])
                                          AS_IF([test "x@S|@]m4_translit([$1], [a-z], [A-Z])[" = x], [
                                          AC_MSG_ERROR([$1 utility not found])
                                          ])
                                          ])
                                          m4_if(m4_eval([$# + 1 >> 1]), [1], [], [NA_REQ_PROGS(m4_shift2($*))])
                                          ])
                                          ])


                                          Sample usage



                                          NA_REQ_PROGS(
                                          [find], [Unix find utility],
                                          [xargs], [Unix xargs utility],
                                          [customprogram], [Some custom program],
                                          [etcetera], [Et cetera]
                                          )


                                          So that within Makefile.am you can do



                                          $(XARGS)


                                          or



                                          $(CUSTOMPROGRAM)


                                          and so on.



                                          Features



                                          • It advertises the programs among the “influential environment variables” visible when the final user launches ./configure --help, so that an alternative path to the program can be provided

                                          • A bash variable named with the same name of the program, but upper case, containing the path where the program is located, is created

                                          • En error is thrown if any of the programs given have not been found and the user has not provided any alternative path for them

                                          • The macro can take infinite (couples of) arguments

                                          When you should use it



                                          1. When the programs to be tested are vital for compiling your project, so that the user must be able to provide an alternative path for them and an error must be thrown if at least one program is not available at all

                                          2. When condition #1 applies to more than one single program, in which case there is no need to write a general purpose macro and you should just use your own customized code





                                          share|improve this answer





























                                            1














                                            This is not exactly a short approach, it's rather a general purporse approach (although when there are dozens of programs to check it might be also the shortest approach). It's taken from a project of mine (the prefix NA_ stands for “Not Autotools”).



                                            A general purpose macro



                                            dnl ***************************************************************************
                                            dnl NA_REQ_PROGS(prog1, [descr1][, prog2, [descr2][, etc., [...]]])
                                            dnl
                                            dnl Checks whether one or more programs have been provided by the user or can
                                            dnl be retrieved automatically. For each program `progx` an uppercase variable
                                            dnl named `PROGX` containing the path where `progx` is located will be created.
                                            dnl If a program is not reachable and the user has not provided any path for it
                                            dnl an error will be generated. The program names given to this function will
                                            dnl be advertised among the `influential environment variables` visible when
                                            dnl launching `./configure --help`.
                                            dnl ***************************************************************************
                                            AC_DEFUN([NA_REQ_PROGS], [
                                            m4_if([$#], [0], [], [
                                            AC_ARG_VAR(m4_translit([$1], [a-z], [A-Z]), [$2])
                                            AS_IF([test "x@S|@]m4_translit([$1], [a-z], [A-Z])[" = x], [
                                            AC_PATH_PROG(m4_translit([$1], [a-z], [A-Z]), [$1])
                                            AS_IF([test "x@S|@]m4_translit([$1], [a-z], [A-Z])[" = x], [
                                            AC_MSG_ERROR([$1 utility not found])
                                            ])
                                            ])
                                            m4_if(m4_eval([$# + 1 >> 1]), [1], [], [NA_REQ_PROGS(m4_shift2($*))])
                                            ])
                                            ])


                                            Sample usage



                                            NA_REQ_PROGS(
                                            [find], [Unix find utility],
                                            [xargs], [Unix xargs utility],
                                            [customprogram], [Some custom program],
                                            [etcetera], [Et cetera]
                                            )


                                            So that within Makefile.am you can do



                                            $(XARGS)


                                            or



                                            $(CUSTOMPROGRAM)


                                            and so on.



                                            Features



                                            • It advertises the programs among the “influential environment variables” visible when the final user launches ./configure --help, so that an alternative path to the program can be provided

                                            • A bash variable named with the same name of the program, but upper case, containing the path where the program is located, is created

                                            • En error is thrown if any of the programs given have not been found and the user has not provided any alternative path for them

                                            • The macro can take infinite (couples of) arguments

                                            When you should use it



                                            1. When the programs to be tested are vital for compiling your project, so that the user must be able to provide an alternative path for them and an error must be thrown if at least one program is not available at all

                                            2. When condition #1 applies to more than one single program, in which case there is no need to write a general purpose macro and you should just use your own customized code





                                            share|improve this answer



























                                              1












                                              1








                                              1







                                              This is not exactly a short approach, it's rather a general purporse approach (although when there are dozens of programs to check it might be also the shortest approach). It's taken from a project of mine (the prefix NA_ stands for “Not Autotools”).



                                              A general purpose macro



                                              dnl ***************************************************************************
                                              dnl NA_REQ_PROGS(prog1, [descr1][, prog2, [descr2][, etc., [...]]])
                                              dnl
                                              dnl Checks whether one or more programs have been provided by the user or can
                                              dnl be retrieved automatically. For each program `progx` an uppercase variable
                                              dnl named `PROGX` containing the path where `progx` is located will be created.
                                              dnl If a program is not reachable and the user has not provided any path for it
                                              dnl an error will be generated. The program names given to this function will
                                              dnl be advertised among the `influential environment variables` visible when
                                              dnl launching `./configure --help`.
                                              dnl ***************************************************************************
                                              AC_DEFUN([NA_REQ_PROGS], [
                                              m4_if([$#], [0], [], [
                                              AC_ARG_VAR(m4_translit([$1], [a-z], [A-Z]), [$2])
                                              AS_IF([test "x@S|@]m4_translit([$1], [a-z], [A-Z])[" = x], [
                                              AC_PATH_PROG(m4_translit([$1], [a-z], [A-Z]), [$1])
                                              AS_IF([test "x@S|@]m4_translit([$1], [a-z], [A-Z])[" = x], [
                                              AC_MSG_ERROR([$1 utility not found])
                                              ])
                                              ])
                                              m4_if(m4_eval([$# + 1 >> 1]), [1], [], [NA_REQ_PROGS(m4_shift2($*))])
                                              ])
                                              ])


                                              Sample usage



                                              NA_REQ_PROGS(
                                              [find], [Unix find utility],
                                              [xargs], [Unix xargs utility],
                                              [customprogram], [Some custom program],
                                              [etcetera], [Et cetera]
                                              )


                                              So that within Makefile.am you can do



                                              $(XARGS)


                                              or



                                              $(CUSTOMPROGRAM)


                                              and so on.



                                              Features



                                              • It advertises the programs among the “influential environment variables” visible when the final user launches ./configure --help, so that an alternative path to the program can be provided

                                              • A bash variable named with the same name of the program, but upper case, containing the path where the program is located, is created

                                              • En error is thrown if any of the programs given have not been found and the user has not provided any alternative path for them

                                              • The macro can take infinite (couples of) arguments

                                              When you should use it



                                              1. When the programs to be tested are vital for compiling your project, so that the user must be able to provide an alternative path for them and an error must be thrown if at least one program is not available at all

                                              2. When condition #1 applies to more than one single program, in which case there is no need to write a general purpose macro and you should just use your own customized code





                                              share|improve this answer















                                              This is not exactly a short approach, it's rather a general purporse approach (although when there are dozens of programs to check it might be also the shortest approach). It's taken from a project of mine (the prefix NA_ stands for “Not Autotools”).



                                              A general purpose macro



                                              dnl ***************************************************************************
                                              dnl NA_REQ_PROGS(prog1, [descr1][, prog2, [descr2][, etc., [...]]])
                                              dnl
                                              dnl Checks whether one or more programs have been provided by the user or can
                                              dnl be retrieved automatically. For each program `progx` an uppercase variable
                                              dnl named `PROGX` containing the path where `progx` is located will be created.
                                              dnl If a program is not reachable and the user has not provided any path for it
                                              dnl an error will be generated. The program names given to this function will
                                              dnl be advertised among the `influential environment variables` visible when
                                              dnl launching `./configure --help`.
                                              dnl ***************************************************************************
                                              AC_DEFUN([NA_REQ_PROGS], [
                                              m4_if([$#], [0], [], [
                                              AC_ARG_VAR(m4_translit([$1], [a-z], [A-Z]), [$2])
                                              AS_IF([test "x@S|@]m4_translit([$1], [a-z], [A-Z])[" = x], [
                                              AC_PATH_PROG(m4_translit([$1], [a-z], [A-Z]), [$1])
                                              AS_IF([test "x@S|@]m4_translit([$1], [a-z], [A-Z])[" = x], [
                                              AC_MSG_ERROR([$1 utility not found])
                                              ])
                                              ])
                                              m4_if(m4_eval([$# + 1 >> 1]), [1], [], [NA_REQ_PROGS(m4_shift2($*))])
                                              ])
                                              ])


                                              Sample usage



                                              NA_REQ_PROGS(
                                              [find], [Unix find utility],
                                              [xargs], [Unix xargs utility],
                                              [customprogram], [Some custom program],
                                              [etcetera], [Et cetera]
                                              )


                                              So that within Makefile.am you can do



                                              $(XARGS)


                                              or



                                              $(CUSTOMPROGRAM)


                                              and so on.



                                              Features



                                              • It advertises the programs among the “influential environment variables” visible when the final user launches ./configure --help, so that an alternative path to the program can be provided

                                              • A bash variable named with the same name of the program, but upper case, containing the path where the program is located, is created

                                              • En error is thrown if any of the programs given have not been found and the user has not provided any alternative path for them

                                              • The macro can take infinite (couples of) arguments

                                              When you should use it



                                              1. When the programs to be tested are vital for compiling your project, so that the user must be able to provide an alternative path for them and an error must be thrown if at least one program is not available at all

                                              2. When condition #1 applies to more than one single program, in which case there is no need to write a general purpose macro and you should just use your own customized code






                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Mar 29 at 23:45

























                                              answered Mar 26 at 1:18









                                              madmurphymadmurphy

                                              1861 silver badge7 bronze badges




                                              1861 silver badge7 bronze badges



























                                                  draft saved

                                                  draft discarded
















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid


                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.

                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7490978%2fautoconf-check-for-program-and-fail-if-not-found%23new-answer', 'question_page');

                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                                  Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                                                  Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript