Refactored to tree structure; added OpenBSD support
This commit is contained in:
parent
f4a478f8e8
commit
19b082b7a9
78
Makefile
78
Makefile
@ -1,8 +1,6 @@
|
||||
LIBNAME := $(shell basename $$(pwd))
|
||||
MAJOR := 1
|
||||
MINOR := 0
|
||||
PATCH := 0
|
||||
include premake.make
|
||||
|
||||
LIBNAME := $(shell basename $$(pwd))
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
@ -18,69 +16,91 @@ ifeq ($(UNAME_S),Linux)
|
||||
SONAME := $(LINKERNAME).$(MAJOR)
|
||||
REALNAME := $(SONAME).$(MINOR).$(PATCH)
|
||||
endif
|
||||
STATICLIB := $(LIBNAME).a
|
||||
|
||||
BUILDDIR := build/intermediates/
|
||||
PREFIX ?= /usr/local
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
LIBDIR ?= $(PREFIX)/lib
|
||||
CONFIGDIR ?= $(PREFIX)/etc
|
||||
INCLUDEDIR ?= $(PREFIX)/include
|
||||
LIBDIR ?= $(PREFIX)/lib
|
||||
DATADIR ?= $(PREFIX)/share
|
||||
MANDIR ?= $(DATADIR)/man
|
||||
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
|
||||
|
||||
SRCS := $(wildcard *.cpp)
|
||||
OBJS := $(subst .cpp,.o,$(SRCS))
|
||||
DEPS := $(subst .cpp,.d,$(SRCS))
|
||||
HDRS := $(filter-out $(LIBNAME).hpp,$(wildcard *.hpp))
|
||||
SRCS := $(notdir $(wildcard src/*.cpp))
|
||||
OBJS := $(SRCS:.cpp=.o)
|
||||
DEPS := $(SRCS:.cpp=.d)
|
||||
HDRS := $(wildcard src/*.hpp)
|
||||
|
||||
CXX ?= g++
|
||||
|
||||
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -std=c++17 -fPIC
|
||||
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC
|
||||
ifeq ($(DEBUG),1)
|
||||
CXXFLAGS += -D DEBUG -O0
|
||||
CONFIG := debug
|
||||
else
|
||||
CXXFLAGS += -D NDEBUG -O3
|
||||
CONFIG := release
|
||||
endif
|
||||
OUTDIR := build/$(CONFIG)/
|
||||
|
||||
LDLIBS :=
|
||||
|
||||
RM := /bin/rm -f
|
||||
RM := /bin/rm -rf
|
||||
INSTALL := /usr/bin/install -c
|
||||
|
||||
all: $(REALNAME)
|
||||
vpath %.cpp src
|
||||
vpath %.d $(BUILDDIR)
|
||||
vpath %.o $(BUILDDIR)
|
||||
|
||||
$(REALNAME): $(OBJS) $(DEPS)
|
||||
.PHONY: all clean install prebuild test
|
||||
|
||||
all: prebuild $(OUTDIR)$(REALNAME) $(OUTDIR)$(STATICLIB)
|
||||
|
||||
prebuild:
|
||||
@mkdir -p $(BUILDDIR) $(OUTDIR)
|
||||
|
||||
$(OUTDIR)$(REALNAME): $(OBJS) $(DEPS)
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
$(CXX) -dynamiclib -o $(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(OBJS)
|
||||
$(CXX) -dynamiclib -o $(OUTDIR)$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
||||
endif
|
||||
ifeq ($(UNAME_S),OpenBSD)
|
||||
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(REALNAME) $(LDFLAGS) $(LDLIBS) $(OBJS)
|
||||
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
||||
endif
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(REALNAME) $(LDFLAGS) $(LDLIBS) $(OBJS)
|
||||
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
||||
endif
|
||||
|
||||
%.o: %.cpp %.d Makefile
|
||||
%.o: %.cpp %.d
|
||||
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
|
||||
@mv $@ $*.d $(BUILDDIR)
|
||||
|
||||
-include *.d
|
||||
-include $(BUILDDIR)*.d
|
||||
|
||||
%.d: ;
|
||||
|
||||
$(OUTDIR)$(STATICLIB): $(OBJS)
|
||||
ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS))
|
||||
|
||||
$(LIBNAME).hpp: $(HDRS)
|
||||
@echo updating $(LIBNAME).hpp
|
||||
@cp /dev/null $(LIBNAME).hpp
|
||||
@echo updating build/$(LIBNAME).hpp
|
||||
@cp /dev/null build/$(LIBNAME).hpp
|
||||
@for h in $(HDRS); \
|
||||
do \
|
||||
cat $$h >> $(LIBNAME).hpp; \
|
||||
done
|
||||
cat $$h >> build/$(LIBNAME).hpp; \
|
||||
done
|
||||
|
||||
.PHONY: clean install
|
||||
test:
|
||||
$(MAKE) -C tests && tests/tests
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) $(DEPS) $(REALNAME) $(LIBNAME).hpp
|
||||
$(RM) build
|
||||
$(MAKE) -C tests clean
|
||||
|
||||
install: $(REALNAME) $(LIBNAME).hpp
|
||||
$(INSTALL) -m 644 $(REALNAME) $(LIBDIR)
|
||||
$(INSTALL) -m 644 $(LIBNAME).hpp $(INCLUDEDIR)
|
||||
install: $(OUTDIR)$(REALNAME) $(LIBNAME).hpp
|
||||
$(INSTALL) -d $(LIBDIR)
|
||||
$(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR)
|
||||
$(INSTALL) -d $(INCLUDEDIR)
|
||||
$(INSTALL) -m 644 build/$(LIBNAME).hpp $(INCLUDEDIR)
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
||||
endif
|
||||
|
5
premake.make
Normal file
5
premake.make
Normal file
@ -0,0 +1,5 @@
|
||||
LDLIBS :=
|
||||
|
||||
MAJOR := 1
|
||||
MINOR := 0
|
||||
PATCH := 0
|
Loading…
x
Reference in New Issue
Block a user