diff --git a/Makefile/Makefile b/Makefile/Makefile index 0a68850..39f865b 100644 --- a/Makefile/Makefile +++ b/Makefile/Makefile @@ -1,24 +1,40 @@ # Preproc options -# -MMD is used to generate .d files for header dependencies +# -MMD is used to generate .d files for user header dependencies (use -MD for system and user header instead) CPPFLAGS = -MMD # main compilation CFLAGS ?= -Werror -Wall #$(pkg-config --cflags sdl) +# C++ flags +CXXFLAGS = #Linker flags LDFLAGS = #Linker path LDLIBS = #$(pkg-config --libs sdl) -program = test +bin = main +cxxbin = cxxmain sources = $(wildcard *.c) objects = $(sources:%.c=%.o) depends = $(sources:%.c=%.d) -$(program): $(objects) +# Do not have same file prefix between C and C++ (e.g. main.c and main.cpp) +cxx_sources = $(wildcard *.cpp) +cxx_objects = $(cxx_sources:%.cpp=%.o) +cxx_depends = $(cxx_sources:%.cpp=%.d) + +$(bin): $(objects) + +$(cxxbin) : $(cxx_objects) + + +# C++ compilation (Use implicit LINK.CC) +$(cxxbin): + $(LINK.cc) $^ $(LDLIBS) -o $@ .PHONY: clean clean: - $(RM) $(program) $(objects) $(depends) + $(RM) $(bin) $(objects) $(depends) $(cxxbin) $(cxx_objects) $(cxx_depends) ifneq ($(MAKECMDGOALS),clean) -include $(depends) +-include $(cxx_depends) endif