Modernized Makefile
This commit is contained in:
parent
79fb2b2944
commit
0ffb1498f2
36
Makefile
36
Makefile
@ -1,10 +1,6 @@
|
|||||||
include premake.make
|
include premake.make
|
||||||
|
|
||||||
LIBNAME := $(shell basename $$(pwd))
|
LIBNAME := $(shell basename $$(pwd))
|
||||||
MAJOR ?= 1
|
|
||||||
MINOR ?= 0
|
|
||||||
PATCH ?= 0
|
|
||||||
|
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
|
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
@ -25,21 +21,20 @@ STATICLIB := $(LIBNAME).a
|
|||||||
BUILDDIR := build/intermediates/
|
BUILDDIR := build/intermediates/
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
BINDIR ?= $(PREFIX)/bin
|
BINDIR ?= $(PREFIX)/bin
|
||||||
|
MANDIR ?= $(PREFIX)/man
|
||||||
CONFIGDIR ?= $(PREFIX)/etc
|
CONFIGDIR ?= $(PREFIX)/etc
|
||||||
INCLUDEDIR ?= $(PREFIX)/include
|
INCLUDEDIR ?= $(PREFIX)/include
|
||||||
LIBDIR ?= $(PREFIX)/lib
|
LIBDIR ?= $(PREFIX)/lib
|
||||||
DATADIR ?= $(PREFIX)/share
|
DATADIR ?= $(PREFIX)/share
|
||||||
MANDIR ?= $(DATADIR)/man
|
|
||||||
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
|
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
|
||||||
|
|
||||||
SRCS := $(notdir $(wildcard src/*.cpp))
|
SRCS := $(notdir $(wildcard src/*.cpp))
|
||||||
OBJS := $(SRCS:.cpp=.o)
|
OBJS := $(SRCS:.cpp=.o)
|
||||||
DEPS := $(SRCS:.cpp=.d)
|
HDRS ?= $(wildcard src/*.hpp)
|
||||||
HDRS := $(wildcard src/*.hpp)
|
|
||||||
|
|
||||||
CXX ?= g++
|
CXX ?= g++
|
||||||
|
|
||||||
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC
|
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -std=c++17 -fPIC
|
||||||
ifeq ($(DEBUG),1)
|
ifeq ($(DEBUG),1)
|
||||||
CXXFLAGS += -D DEBUG -O0
|
CXXFLAGS += -D DEBUG -O0
|
||||||
CONFIG := debug
|
CONFIG := debug
|
||||||
@ -63,7 +58,7 @@ all: prebuild $(OUTDIR)$(REALNAME) $(OUTDIR)$(STATICLIB)
|
|||||||
prebuild:
|
prebuild:
|
||||||
@mkdir -p $(BUILDDIR) $(OUTDIR)
|
@mkdir -p $(BUILDDIR) $(OUTDIR)
|
||||||
|
|
||||||
$(OUTDIR)$(REALNAME): $(OBJS) $(DEPS)
|
$(OUTDIR)$(REALNAME): $(OBJS)
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
$(CXX) -dynamiclib -o $(OUTDIR)$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
$(CXX) -dynamiclib -o $(OUTDIR)$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
||||||
endif
|
endif
|
||||||
@ -74,24 +69,27 @@ ifeq ($(UNAME_S),Linux)
|
|||||||
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
%.o: %.cpp %.d Makefile
|
%.o %.d: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
|
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
|
||||||
@mv $@ $*.d $(BUILDDIR)
|
@mv $@ $*.d $(BUILDDIR)
|
||||||
|
|
||||||
-include $(BUILDDIR)*.d
|
-include $(BUILDDIR)$(SRCS:.cpp=.d)
|
||||||
|
|
||||||
%.d: ;
|
|
||||||
|
|
||||||
$(OUTDIR)$(STATICLIB): $(OBJS)
|
$(OUTDIR)$(STATICLIB): $(OBJS)
|
||||||
ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS))
|
ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS))
|
||||||
|
|
||||||
|
ifeq ($(GENERATELIBHEADER),1)
|
||||||
$(LIBNAME).hpp: $(HDRS)
|
$(LIBNAME).hpp: $(HDRS)
|
||||||
@echo updating build/$(LIBNAME).hpp
|
@echo updating build/$(LIBNAME).hpp
|
||||||
@cp /dev/null build/$(LIBNAME).hpp
|
@cp /dev/null build/$(LIBNAME).hpp
|
||||||
@for h in $(HDRS); \
|
@for h in $(HDRS); \
|
||||||
do \
|
do \
|
||||||
cat $$h >> build/$(LIBNAME).hpp; \
|
sed '/@exclude/d' $$h >> build/$(LIBNAME).hpp; \
|
||||||
done
|
done
|
||||||
|
HEADERSRCDIR := build
|
||||||
|
else
|
||||||
|
HEADERSRCDIR := src
|
||||||
|
endif
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(MAKE) -C tests && tests/tests
|
$(MAKE) -C tests && tests/tests
|
||||||
@ -100,11 +98,15 @@ clean:
|
|||||||
$(RM) build
|
$(RM) build
|
||||||
$(MAKE) -C tests clean
|
$(MAKE) -C tests clean
|
||||||
|
|
||||||
install: $(OUTDIR)$(REALNAME) $(LIBNAME).hpp
|
ifeq ($(GENERATELIBHEADER),1)
|
||||||
|
install: $(LIBNAME).hpp
|
||||||
|
else
|
||||||
|
install:
|
||||||
|
endif
|
||||||
$(INSTALL) -d $(LIBDIR)
|
$(INSTALL) -d $(LIBDIR)
|
||||||
$(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR)
|
$(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR)
|
||||||
$(INSTALL) -d $(INCLUDEDIR)
|
$(INSTALL) -d $(INCLUDEDIR)/$(LIBNAME)
|
||||||
$(INSTALL) -m 644 build/$(LIBNAME).hpp $(INCLUDEDIR)
|
$(INSTALL) -m 644 $(HEADERSRCDIR)/$(LIBNAME).hpp $(INCLUDEDIR)
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
||||||
endif
|
endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user