.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   GNU Make question (http://forums.bots-united.com/showthread.php?t=4175)

Rick 02-07-2005 21:06

GNU Make question
 
I thought this was obvious...but meh
Here is what I want: I simply want to set a macro when the target 'server' is being build. That way a clean ded server can be build.
Here is what I have now, and doesn't work :-/
Code:

server: $(SERVER_OBJS)
        $(CXX) $(CXXFLAGS) -DSTANDALONE -o cube_bot_fbsd-server $(SERVER_OBJS) $(SERVER_LIBS)

For same reason the macro 'STANDALONE' is not set.

Can somebody please help me? :)

Lazy 02-07-2005 23:51

Re: GNU Make question
 
Are you using the right macro?
Because this works for me...

dtest.c
Code:

#include <stdio.h>

int main( void ) {
        #ifdef _SERVER_
        printf( "Server started!\n" );
        #else
        printf( "Client started!\n" );
        #endif

        return 0;
}

Makefile
Code:

CC=gcc
CFLAGS=-O2
CLFILE=client.exe
SVFILE=server.exe

server:
        $(CC) $(CFLAGS) -o $(SVFILE) -D_SERVER_ dtest.c

client:
        $(CC) $(CFLAGS) -o $(CLFILE) dtest.c

clean:
        rm client.exe
        rm server.exe
        rm dtest.o


Rick 03-07-2005 12:44

Re: GNU Make question
 
OK got it to work, thanks :)

I guess its the way of compiling...it works if I do it simulair to yours:
Code:

server:
        $(CXX) $(CXXFLAGS) -o cube_bot_fbsd-server -DSTANDALONE $(SERVER_FILES) $(SERVER_LIBS)

Where SERVER_FILES are the actual source files instead of the object files.

mirv 04-07-2005 10:30

Re: GNU Make question
 
Not entirely sure if this is right...but I think the defines really only work compiling the source files direct, not on the object files - though header files are sometimes used when linking, so it could have an effect there.
I could be completely wrong - someone please correct me if I am!

Rick 04-07-2005 13:12

Re: GNU Make question
 
I'm not sure about linking header files(never saw that happen), but you're right about the other part. Unfortunaly this way of compiling doesn't leave any .o files and thus you have to recompile everything each time.


All times are GMT +2. The time now is 18:20.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.