Here is a demo showing how to pass environment variables from the shell command line to a Makefile. Browse and download the Makefiles and the source code.
(Don't forget to download flag.mak, integer.mak, and string.mak!)
# Examples showing how to pass environment variables from 'make' to the C preprocessor through the -D compiler option.
# Check out each Makefile for how flags, integers and strings are treated.
# Examples:
# make DEBUG=1
# make MYINT=3
# make MYSTR='Hi there!'
includeflag.mak integer.mak string.mak
# Variables for compiler options.
CFLAGS =-g -ansi -pedantic -Wall -O2
TARGETS = hello
# Integers, strings and debug options.
all:
cc $(MYINT_CPP) $(MYSTR_CPP) $(DEBUG_CPP) $(CFLAGS) ${CPPFLAGS} $(TARGETS).c -o $(TARGETS) clean:
rm -rf $(TARGETS) $(TARGETS).exe *.o *~