2017-06-12 14:29:01 +02:00
|
|
|
# Preproc options
|
2017-06-12 14:56:49 +02:00
|
|
|
# -MMD is used to generate .d files for user header dependencies (use -MD for system and user header instead)
|
2017-06-12 14:29:01 +02:00
|
|
|
CPPFLAGS = -MMD
|
|
|
|
# main compilation
|
2017-06-12 14:34:04 +02:00
|
|
|
CFLAGS ?= -Werror -Wall #$(pkg-config --cflags sdl)
|
2017-06-12 14:56:49 +02:00
|
|
|
# C++ flags
|
|
|
|
CXXFLAGS =
|
2017-06-12 14:29:01 +02:00
|
|
|
#Linker flags
|
|
|
|
LDFLAGS =
|
|
|
|
#Linker path
|
2017-06-12 14:34:04 +02:00
|
|
|
LDLIBS = #$(pkg-config --libs sdl)
|
2016-10-05 16:02:13 +02:00
|
|
|
|
2017-06-12 14:56:49 +02:00
|
|
|
bin = main
|
|
|
|
cxxbin = cxxmain
|
2017-06-12 15:18:51 +02:00
|
|
|
lib = libexample.so
|
|
|
|
|
|
|
|
#Will be compiled with -fpic
|
|
|
|
lib_src = lib.c
|
|
|
|
lib_obj = $(lib_src:%.c=%.o)
|
|
|
|
lib_dep = $(lib_src:%.c=%.d)
|
|
|
|
$(info $$lib_obj is ${lib_obj})
|
|
|
|
|
|
|
|
sources = $(filter-out $(lib_src), $(wildcard *.c))
|
2016-10-05 16:02:13 +02:00
|
|
|
objects = $(sources:%.c=%.o)
|
|
|
|
depends = $(sources:%.c=%.d)
|
|
|
|
|
2017-06-12 14:56:49 +02:00
|
|
|
# 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 $@
|
2016-10-05 16:02:13 +02:00
|
|
|
|
2017-06-12 15:18:51 +02:00
|
|
|
$(lib): CFLAGS += -fpic
|
|
|
|
$(lib): $(lib_obj)
|
|
|
|
|
|
|
|
%.so:
|
|
|
|
$(LINK.c) -shared $^ $(LDLIBS) -o $@
|
|
|
|
|
2016-10-05 16:02:13 +02:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2017-06-12 15:18:51 +02:00
|
|
|
$(RM) $(bin) $(objects) $(depends) $(cxxbin) $(cxx_objects) $(cxx_depends) $(lib) $(lib_obj) $(lib_dep)
|
2016-10-05 16:02:13 +02:00
|
|
|
|
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
|
|
-include $(depends)
|
2017-06-12 14:56:49 +02:00
|
|
|
-include $(cxx_depends)
|
2017-06-12 15:18:51 +02:00
|
|
|
-include $(lib_dep)
|
2016-10-05 16:02:13 +02:00
|
|
|
endif
|