114 lines
3.2 KiB
Makefile
114 lines
3.2 KiB
Makefile
#This program is free software: you can redistribute it and/or modify
|
|
#it under the terms of the GNU General Public License as published by
|
|
#the Free Software Foundation, either version 3 of the License, or
|
|
#(at your option) any later version.
|
|
|
|
#This program is distributed in the hope that it will be useful,
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
#GNU General Public License for more details.
|
|
|
|
#You should have received a copy of the GNU General Public License
|
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#Copyright 2018-2019 rexy712
|
|
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
WINDOWS=1
|
|
endif
|
|
|
|
SOURCE_DIRS:=src/raii src/matrix
|
|
OBJDIR:=obj
|
|
DEPDIR:=$(OBJDIR)/dep
|
|
INCLUDE_DIRS:=include
|
|
EXT:=cpp
|
|
MAIN_LIBRARY:=librmatrix.so
|
|
|
|
CXXFLAGS:=-g -std=c++17 -Wall -pedantic -Wextra -fPIC
|
|
|
|
ifneq ($(WINDOWS),1)
|
|
CXX:=g++
|
|
AR:=ar
|
|
RANLIB:=ranlib
|
|
LDFLAGS:=-shared
|
|
LDLIBS:=-lcurl -lrjp -lavformat -lavcodec -lavutil -lswresample -lswscale -lfreeimageplus
|
|
STRIP:=strip
|
|
else
|
|
CXX:=x86_64-w64-mingw32-g++
|
|
AR:=x86_64-w64-mingw32-ar
|
|
RANLIB:=x86_64-w64-mingw32-ranlib
|
|
LDFLAGS:=
|
|
LDLIBS:=-lcurl -lrjp -lavformat -lavcodec -lavutil -lswresample -lswscale -lfreeimageplus
|
|
STRIP:=x86_64-w64-mingw32-strip
|
|
endif
|
|
all: CXXFLAGS+=-O0
|
|
release: CXXFLAGS+=-O2
|
|
|
|
memchk:LDFLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
|
|
memchk:CXXFLAGS+=-O0 -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
mkdir=mkdir $(subst /,\,$(1)) > NUL 2>&1
|
|
rm=del /F $(1) > NUL 2>&1
|
|
rmdir=rd /s /q $(1) > NUL 2>&1
|
|
move=move /y $(subst /,\,$(1)) $(subst /,\,$(2)) > NUL 2>&1
|
|
MAIN_EXECUTABLE:=$(MAIN_EXECUTABLE).exe
|
|
LDLIBS:=-lglfw3 -lSOIL -lgl3w -lm -lopengl32 -lglu32 -lgdi32 -lkernel32
|
|
else
|
|
mkdir=mkdir -p $(1)
|
|
rm=rm -f $(1)
|
|
rmdir=rm -rf $(1)
|
|
move=mv $(1) $(2)
|
|
endif
|
|
|
|
INTERNAL_CXXFLAGS=-c $(foreach dir,$(INCLUDE_DIRS),-I"$(dir)") -MMD -MP -MF"$(DEPDIR)/$(notdir $(patsubst %.o,%.d,$@))"
|
|
SOURCES:=$(foreach source,$(SOURCE_DIRS),$(foreach ext,$(EXT),$(wildcard $(source)/*.$(ext))))
|
|
OBJECTS:=$(addprefix $(OBJDIR)/,$(subst \,.,$(subst /,.,$(addsuffix .o,$(SOURCES)))))
|
|
|
|
all: $(MAIN_LIBRARY)
|
|
.PHONY: memchk
|
|
memchk: all
|
|
.PHONY: release
|
|
release: all
|
|
.PHONY: utils
|
|
utils: matrix-send
|
|
tester: $(MAIN_LIBRARY) $(OBJDIR)/src.test.cpp.o
|
|
$(CXX) -L. -o "$@" $(OBJDIR)/src.test.cpp.o -lrmatrix -lpthread
|
|
|
|
matrix-send: $(MAIN_LIBRARY) $(OBJDIR)/util.matrix-send.cpp.o
|
|
$(CXX) -L. -o "$@" $(OBJDIR)/util.matrix-send.cpp.o -lrmatrix
|
|
|
|
$(MAIN_LIBRARY): $(OBJECTS)
|
|
$(CXX) -o "$@" $^ $(CXXFLAGS) $(LDFLAGS) $(LDLIBS)
|
|
|
|
define GENERATE_OBJECTS
|
|
|
|
$$(OBJDIR)/$(subst \,.,$(subst /,.,$(1))).%.o: $(1)/%
|
|
$$(CXX) $$(CXXFLAGS) $$(INTERNAL_CXXFLAGS) "$$<" -o "$$@"
|
|
|
|
endef
|
|
|
|
$(foreach dir,$(SOURCE_DIRS),$(eval $(call GENERATE_OBJECTS,$(dir))))
|
|
$(eval $(call GENERATE_OBJECTS,util))
|
|
$(eval $(call GENERATE_OBJECTS,src))
|
|
$(OBJECTS): | $(OBJDIR) $(DEPDIR)
|
|
|
|
$(OBJDIR):
|
|
$(call mkdir,"$@")
|
|
$(DEPDIR):
|
|
$(call mkdir,"$@")
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
$(call rmdir,"$(DEPDIR)")
|
|
$(call rmdir,"$(OBJDIR)")
|
|
$(call rm,"$(MAIN_LIBRARY)")
|
|
.PHONY: utilsclean
|
|
fullclean: clean
|
|
$(call rm,"matrix-send")
|
|
$(call rm,"tester")
|
|
|
|
-include $(wildcard $(DEPDIR)/*.d)
|
|
|