From: Keith M. <kei...@to...> - 2006-07-05 08:33:21
|
Rux Li wrote: > Makefile may have to switch between different platform. For > example, my MinGW have no readline library. But I want include > it on my Linux porting. You normally would use a configure script to achieve this; have it check for available libraries, and write an appropriate LIBS macro definition into the Makefile, then add $(LIBS) into the $(CC) command lines. I'd use Autoconf for this... <file name="configure.ac"> AC_INIT AC_PROG_CC AC_CKECK_LIBS([readline]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT </file> As developer, you run: $ autoconf which translates the above file into a configure script. You add *both* the above configure.ac, *and* the generated configure script to your packaged distribution. Additionally, you add a *template* for the Makefile, called Makefile.in; you *don't* supply any Makefile itself. <file name="Makefile.in"> : CC = @CC@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ EXEEXT = @EXEEXT@ : %$(EXEEXT): %.c <TAB>$(CC) -o $@ $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) $(LIBS) : </file> Now, your user first runs the configure script, which generates a Makefile, based on your Makefile.in, with appropriate @NAME@ substitution fields filled in, and $(LIBS) will represent those that you named in AC_CHECK_LIBS, and which are actually present on the user's system. He can then proceed with a normal `make' and `make install', as appropriate. Once learned, it really is very easy to achieve this sort of thing, but I appreciate that it may be intimidating for a newbie. HTH, Keith. |