## Copyright 2016 Ian Jauslin ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. ## You may obtain a copy of the License at ## ## http://www.apache.org/licenses/LICENSE-2.0 ## ## Unless required by applicable law or agreed to in writing, software ## distributed under the License is distributed on an "AS IS" BASIS, ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## See the License for the specific language governing permissions and ## limitations under the License. # whether to compile only the static library, only the dynamic library, or both # if static=0 then compile both # if static=2 then compile the dynamic library # if static=1 then compile the static library STATIC=0 VERSION=1.0.1 # products of the compilation PROJECT_SO=libinum.so.$(VERSION) PROJECT_LIBS=libinum.a PROJECT_DOCS=libinum-doc.html # debug and optimization flags #DB= -ggdb OPT= -O3 # warning flags WARNINGS= -Wall -Wextra -Wno-strict-overflow -std=c99 -pedantic # installation dirs PREFIX=/usr LIBDIR=$(PREFIX)/lib INCLUDEDIR=$(PREFIX)/include DOCDIR=$(PREFIX)/share/doc/libinum # compiler CC=/usr/bin/gcc LD=$(CC) AR=/usr/bin/ar # directories INCLUDE = LIB = # flags override LDFLAGS +=$(LIB) override CFLAGS +=$(INCLUDE)$(DB) $(OPT) $(WARNINGS) # build directories BUILDDIR=./build SRCDIR=./src OBJDIR=./objs # objects LIBINUM_OBJS = $(addprefix $(OBJDIR)/, array.o integral.o utils.o polynomial.o polynomialMV.o root.o) ifeq ($(STATIC),1) # compile libinum.a PREREQ=static # install static lib INSTALLLIB=install-static else ifeq ($(STATIC),2) # compile libinum.so.$(VERSION) PREREQ=shared # install shared lib INSTALLLIB=install-shared else # compile both PREREQ=shared static # install both INSTALLLIB=install-shared install-static endif all: init $(PREREQ) # create dirs init: @[ -d $(OBJDIR) ] || /bin/mkdir $(OBJDIR) @[ -d $(BUILDDIR) ] || /bin/mkdir $(BUILDDIR) # static library static: $(PROJECT_LIBS) # shared library shared: $(PROJECT_SO) libinum.a: $(LIBINUM_OBJS) $(AR) -rc $(BUILDDIR)/$@ $^ libinum.so.$(VERSION): $(LIBINUM_OBJS) $(LD) -shared -lm -lmpfr -lgmp -lpthread $(LDFLAGS) -o $(BUILDDIR)/$@ $^ ln -fs ./libinum.so.$(VERSION) $(BUILDDIR)/libinum.so %.o : ../$(SRCDIR)/%.c $(CC) -c $(CFLAGS) -fPIC $< -o $@ install: $(INSTALLLIB) all mkdir -p $(MANDIR) $(DOCDIR) $(INCLUDEDIR)/libinum cp -rL include/libinum/* $(INCLUDEDIR)/libinum/ install -Dm644 include/libinum.h $(INCLUDEDIR)/ cp -r doc/libinum-examples $(DOCDIR)/ install -Dm644 $(addprefix doc/,$(PROJECT_DOCS)) $(DOCDIR)/ install-static: all mkdir -p $(LIBDIR) install -Dm755 $(addprefix $(BUILDDIR)/,$(PROJECT_LIBS)) $(LIBDIR)/ install-shared: all mkdir -p $(LIBDIR) install -Dm755 $(addprefix $(BUILDDIR)/,$(PROJECT_SO)) $(LIBDIR)/ for lib in $(PROJECT_SO); do ln -fs ./$$lib $(LIBDIR)/$${lib%.so.*}.so; done clean: @rm -rf $(OBJDIR) @rm -rf $(BUILDDIR)