Makefile: C++ compilation

This commit is contained in:
Mathieu Maret 2017-06-12 14:56:49 +02:00
parent 3f6fd7ddb0
commit 3fcfdb6720

View File

@ -1,24 +1,40 @@
# Preproc options # 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 CPPFLAGS = -MMD
# main compilation # main compilation
CFLAGS ?= -Werror -Wall #$(pkg-config --cflags sdl) CFLAGS ?= -Werror -Wall #$(pkg-config --cflags sdl)
# C++ flags
CXXFLAGS =
#Linker flags #Linker flags
LDFLAGS = LDFLAGS =
#Linker path #Linker path
LDLIBS = #$(pkg-config --libs sdl) LDLIBS = #$(pkg-config --libs sdl)
program = test bin = main
cxxbin = cxxmain
sources = $(wildcard *.c) sources = $(wildcard *.c)
objects = $(sources:%.c=%.o) objects = $(sources:%.c=%.o)
depends = $(sources:%.c=%.d) 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 .PHONY: clean
clean: clean:
$(RM) $(program) $(objects) $(depends) $(RM) $(bin) $(objects) $(depends) $(cxxbin) $(cxx_objects) $(cxx_depends)
ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),clean)
-include $(depends) -include $(depends)
-include $(cxx_depends)
endif endif