Autoconf: How to get installation paths into config.h

前端 未结 4 596
囚心锁ツ
囚心锁ツ 2021-02-04 08:00

My program needs to load some files at run time, which will be installed into whatever folder is given to ./configure --datadir=/somewhere

As my program nee

4条回答
  •  情书的邮戳
    2021-02-04 08:06

    Your answer is the preferred way of doing it. The autoconf manual explains how to override various variables at "make install" time (which is very useful for packaging, for example). In doing so it says (in the section "Installation Directory Variables):

       A corollary is that you should not use these variables except in
    makefiles.  For instance, instead of trying to evaluate `datadir' in
    `configure' and hard-coding it in makefiles using e.g.,
    `AC_DEFINE_UNQUOTED([DATADIR], ["$datadir"], [Data directory.])', you
    should add `-DDATADIR='$(datadir)'' to your makefile's definition of
    `CPPFLAGS' (`AM_CPPFLAGS' if you are also using Automake).
    

    autotools, and build systems in general, are a convoluted business and nobody has yet come up with nice and neat ways of doing things that are general enough, which means that we have to read sections like this one and work it out fully. In any case your intuition was correct!

提交回复
热议问题