Created
June 14, 2013 21:08
-
-
Save catalan42/5785281 to your computer and use it in GitHub Desktop.
Makefile to demonstrate make dependencies using the "touch" command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################################################### | |
# Default target (must be first target in file) | |
.PHONY : all | |
all : dog | |
###################################################################### | |
# Constants | |
SHELL = /bin/sh | |
CC = g++ | |
CXX = g++ | |
LINK = ${CXX} ${LDFLAGS} | |
# Default value is blank, unless set on commmand line | |
CFLAGS = | |
LDFLAGS = | |
vpath %.h /usr/include | |
# Delete all built-in suffixes, then make our own list | |
.SUFFIXES: | |
.SUFFIXES: .cpp .o .h | |
###################################################################### | |
# clean | |
define doClean | |
rm -f *.o *.exe | |
endef | |
.PHONY : clean | |
clean : | |
${doClean} | |
###################################################################### | |
# dog | |
dogCpp := dog.cpp dogSays.cpp | |
dogObj := $(patsubst %.cpp,%.o,${dogCpp}) | |
dog.exe : ${dogObj} | |
${LINK} $^ -o $@ | |
.PHONY : dog | |
dog : dog.exe | |
@echo | |
$< | |
@echo | |
###################################################################### | |
# Generic build rules | |
%.o : %.cpp | |
${CXX} ${CFLAGS} -c $< | |
# Dependency specifications created automatically by Depend.groovy | |
include depSpecs.mk | |
###################################################################### | |
# Fail-safe dependency injection: all source files depend on all include files. | |
# If any include file changes, touch each corresponding source file to force | |
# recompilation of any dependent targets (i.e. objects & executables). | |
# | |
# $(wildcard *.cpp) : $(wildcard *.h) | |
# touch $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment