libscgui/Makefile

116 lines
2.7 KiB
Makefile
Raw Normal View History

include premake.make
2020-10-23 12:43:47 +02:00
LIBNAME := $(shell basename $$(pwd))
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LINKERNAME := $(LIBNAME).dylib
SONAME := $(LIBNAME).$(MAJOR).dylib
REALNAME := $(LINKERNAME)
endif
ifeq ($(UNAME_S),OpenBSD)
REALNAME := $(LIBNAME).so.$(MAJOR).$(MINOR)
endif
ifeq ($(UNAME_S),Linux)
2020-10-23 12:43:47 +02:00
LINKERNAME := $(LIBNAME).so
SONAME := $(LINKERNAME).$(MAJOR)
REALNAME := $(SONAME).$(MINOR).$(PATCH)
2020-10-23 12:43:47 +02:00
endif
STATICLIB := $(LIBNAME).a
2020-10-23 12:43:47 +02:00
BUILDDIR := build/intermediates/
2020-10-23 12:43:47 +02:00
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
CONFIGDIR ?= $(PREFIX)/etc
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
DATADIR ?= $(PREFIX)/share
MANDIR ?= $(DATADIR)/man
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
SRCS := $(notdir $(wildcard src/*.cpp))
OBJS := $(SRCS:.cpp=.o)
DEPS := $(SRCS:.cpp=.d)
HDRS := $(wildcard src/*.hpp)
2020-10-23 12:43:47 +02:00
CXX ?= g++
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC
2020-10-23 12:43:47 +02:00
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
CONFIG := debug
2020-10-23 12:43:47 +02:00
else
CXXFLAGS += -D NDEBUG -O3
CONFIG := release
2020-10-23 12:43:47 +02:00
endif
OUTDIR := build/$(CONFIG)/
2020-10-23 12:43:47 +02:00
RM := /bin/rm -rf
2020-10-23 12:43:47 +02:00
INSTALL := /usr/bin/install -c
vpath %.cpp src
vpath %.d $(BUILDDIR)
vpath %.o $(BUILDDIR)
.PHONY: all clean install prebuild test
2020-10-23 12:43:47 +02:00
all: prebuild $(OUTDIR)$(REALNAME) $(OUTDIR)$(STATICLIB)
2020-10-23 12:43:47 +02:00
prebuild:
@mkdir -p $(BUILDDIR) $(OUTDIR)
$(OUTDIR)$(REALNAME): $(OBJS) $(DEPS)
2020-10-23 12:43:47 +02:00
ifeq ($(UNAME_S),Darwin)
$(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 $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
endif
ifeq ($(UNAME_S),Linux)
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
2020-10-23 12:43:47 +02:00
endif
2021-12-21 14:53:06 +01:00
%.o: %.cpp %.d
2020-10-23 12:43:47 +02:00
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
@mv $@ $*.d $(BUILDDIR)
2020-10-23 12:43:47 +02:00
-include $(BUILDDIR)*.d
2020-10-23 12:43:47 +02:00
%.d: ;
$(OUTDIR)$(STATICLIB): $(OBJS)
ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS))
2021-12-21 14:53:06 +01:00
ifeq ($(GENERATELIBHEADER),1)
2020-10-23 12:43:47 +02:00
$(LIBNAME).hpp: $(HDRS)
@echo updating build/$(LIBNAME).hpp
@cp /dev/null build/$(LIBNAME).hpp
2020-10-23 12:43:47 +02:00
@for h in $(HDRS); \
do \
cat $$h >> build/$(LIBNAME).hpp; \
2020-10-23 12:43:47 +02:00
done
2021-12-21 14:53:06 +01:00
HEADERSRCDIR := build
else
HEADERSRCDIR := src
endif
2020-10-23 12:43:47 +02:00
test:
$(MAKE) -C tests && tests/tests
2020-10-23 12:43:47 +02:00
clean:
$(RM) build
$(MAKE) -C tests clean
2020-10-23 12:43:47 +02:00
2021-12-21 15:02:54 +01:00
install: $(LIBNAME).hpp
2020-10-23 12:43:47 +02:00
$(INSTALL) -d $(LIBDIR)
$(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR)
2020-10-23 12:43:47 +02:00
$(INSTALL) -d $(INCLUDEDIR)
2021-12-21 14:53:06 +01:00
$(INSTALL) -m 644 $(HEADERSRCDIR)/$(LIBNAME).hpp $(INCLUDEDIR)
2020-10-23 12:43:47 +02:00
ifeq ($(UNAME_S),Darwin)
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
endif
ifeq ($(UNAME_S),Linux)
2020-10-23 12:43:47 +02:00
ldconfig
cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME)
endif