views:

117

answers:

3

Hi,

In my c/c++ files, there are multiple #define. As an example:

#ifdef LIBVNCSERVER_HAVE_LIBZ
  /* some code */
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
  /* some more code */

Can you please tell me how can I modify my Makefile.in so that I have those #define in ALL files during compilation?

Thank you.

+5  A: 
-DLIBVNCSERVER_HAVE_LIBZ -DLIBVNCSERVER_HAVE_LIBJPEG

You could pass those in CPPFLAGS,

CPPFLAGS = -DLIBVNCSERVER_HAVE_LIBZ -DLIBVNCSERVER_HAVE_LIBJPEG

or make new variable

CUSTOMDEFINES = -DLIBVNCSERVER_HAVE_LIBZ -DLIBVNCSERVER_HAVE_LIBJPEG

and pass it to CPPFLAGS = -DEXISTINGFLAGS $(CUSTOMDEFINES)

Those are finally will pass to gcc/g++ -D...

$(CC) $(CPPFLAGS)
S.Mark
afaik preprocessor flags should actually go to `CPPFLAGS`
Christoph
You're right, I've overlooked tags as C C++, edited
S.Mark
@s.mark - dang, you hit the nail on the head there....That was what I was trying to figure out....my answer was close but not close enough :)
tommieb75
cpp refers to C preprocessor, CXX prefix is for C++
aaa
Doing this completely misses the point of using the autotools. The configure script should determine whether or not to set those variables, not the user.
William Pursell
+1  A: 

Add the line below, to your makefile:

DEFINES=LIBVNCSERVER_HAVE_LIBZ LIBVNCSERVER_HAVE_LIBJPEG
...
... further on in your makefile on the line where it says ....
...
    $(cc) -D$(DEFINES) .....
...
...

This is to serve as an example, you only add another define to the DEFINES variable which gets referenced on the line as shown $(cc) -D$(DEFINES) in which the make will automatically expand the variable and compile those that are #ifdefd.

Edit: Thanks to R Samuel Klatchko for pointing out a small amiss...this is specifically for GNU's make, you can use addprefix do properly do that ($(addprefix -D, $(DEFINES))).

Hope this helps, Best regards, Tom.

tommieb75
That will only add -D to the first define (so it will yield `-DLIBVNCSERVER_HAVE_LIBZ LIBVNCSERVER_HAVE_LIBJPEG`). If you have GNU make, you can use addprefix do properly do that (`$(addprefix -D, $(DEFINES))`).
R Samuel Klatchko
@R Samuel Klatchko: Edited the answer to reflect your comment! Cheers for the heads up! :)
tommieb75
Normally, $(CC) or ${CC} will have the CC in upper-case, not lower-case.
Jonathan Leffler
A: 

Don't modify your Makefile.in. (and consider using Automake and converting your Makefile.in to a much simpler Makefile.am). The whole point of those #defines is to let the configure script define them in config.h, and your source files should #include <config.h>. If you are maintaining the package, you will need to write tests in configure.ac to determine whether or not the system being used has libvncserver installed with jpeg and zlib support. If you modify Makefile.in to always define them, then you are making the assumption that your code is only being built on machines where those features are available. If you make that assumption, you should still add checks to configure.ac to confirm it, and have the configure script fail if the dependencies are not met.

William Pursell