0

I have a simple program.

// test.c
#include <stdio.h>


int main()
{
    #ifdef HELLO
    printf("Hello ");
    #endif
    printf("World\n");
    return 0;    
}

I'd like to set up a makefile and either define HELLO or not in that Makefile and then either the program displays "World" or "Hello World" based on whether HELLO is defined. But I don't know where to define HELLO in the Makefile, whether to export it, and how to compile it using gcc. Makefile below.

all: run


test: test.c
	gcc test.c -o test

run: test
	./test

clean:
	rm *~ *.o test

Edited by VernonDozier: n/a

2
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by VernonDozier
1

Put it in your gcc invocation:

all: run
 
 
test: test.c
	gcc -D HELLO test.c -o test
 
run: test
	./test
 
clean:
	rm *~ *.o test
Votes + Comments
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.