meankondo/Makefile

162 lines
4.8 KiB
Makefile
Raw Normal View History

2015-06-14 00:52:45 +00:00
## Copyright 2015 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 link dynamically
# if static=0 then link dynamically
# if static=2 then link statically
# if static=1 then link libkondo statically but other libraries dynamically
STATIC=1
VERSION=1.2.1
2015-06-14 00:52:45 +00:00
# products of the compilation
PROJECT_BINS= meankondo numkondo meantools kondo_preprocess meantools-convert
PROJECT_SO=libkondo.so.$(VERSION)
PROJECT_LIBS=libkondo.a
PROJECT_MANS=meankondo.1 numkondo.1 meantools.1 meantools-convert.1 kondo_preprocess.1
PROJECT_SCRIPTS=config_functions.sh
PROJECT_DOCS=meankondo-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
BINDIR=$(PREFIX)/bin
LIBDIR=$(PREFIX)/lib
MANDIR=$(PREFIX)/share/man/man1
SCRIPTDIR=$(PREFIX)/share/meankondo/scripts
DOCDIR=$(PREFIX)/share/doc/meankondo-doc
# 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
LIBKONDO_OBJS = $(addprefix $(OBJDIR)/,array.o cli_parser.o coefficient.o fields.o grouped_polynomial.o idtable.o istring.o number.o parse_file.o polynomial.o rational_float.o rational_int.o rcc.o tools.o)
MEANKONDO_OBJS = $(addprefix $(OBJDIR)/,meankondo.o mean.o)
NUMKONDO_OBJS = $(addprefix $(OBJDIR)/,numkondo.o flow.o)
MEANTOOLS_OBJS = $(addprefix $(OBJDIR)/,meantools.o meantools_exp.o meantools_deriv.o meantools_eval.o)
KONDO_PP_OBJS = $(addprefix $(OBJDIR)/,kondo_preprocess.o kondo.o)
# flags which depend on whether to link statically or dynamically
# lib flag for libkondo
LIBKONDO_FLAG=-lkondo
# additional library required for static linking
XTRA_LIBS=
ifeq ($(STATIC),1)
# compile libkondo.a
PREREQ=static
# libkondo is linked against libm
XTRA_LIBS=-lm
# link binaries using the static library
LIBKONDO_FLAG=-l:libkondo.a
# install static lib
INSTALLLIB=install-static
else ifeq ($(STATIC),2)
# compile libkondo.a
PREREQ=static
# libkondo is linked against libm
XTRA_LIBS=-lm
# link binaries statically
override LDFLAGS += -static
INSTALLLIB=install-static
else
# compile libkondo.so.$(VERSION)
PREREQ=shared
# required flag for subsequent dynamic linking
override CFLAGS += -fPIC
INSTALLLIB=install-shared
endif
all: init $(PREREQ)
# create dirs
init:
@[ -d $(OBJDIR) ] || /bin/mkdir $(OBJDIR)
@[ -d $(BUILDDIR) ] || /bin/mkdir $(BUILDDIR)
@[ -d $(BUILDDIR)/bin ] || /bin/mkdir $(BUILDDIR)/bin
@[ -d $(BUILDDIR)/lib ] || /bin/mkdir $(BUILDDIR)/lib
# static library
static: $(PROJECT_LIBS) $(PROJECT_BINS)
# shared library
shared: $(PROJECT_SO) $(PROJECT_BINS)
libkondo.a: $(LIBKONDO_OBJS)
$(AR) -rc $(BUILDDIR)/lib/$@ $^
libkondo.so.$(VERSION): $(LIBKONDO_OBJS)
$(LD) -shared -lm $(LDFLAGS) -o $(BUILDDIR)/lib/$@ $^
ln -fs ./libkondo.so.$(VERSION) $(BUILDDIR)/lib/libkondo.so
meankondo: $(MEANKONDO_OBJS)
$(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) -lpthread $(XTRA_LIBS)
numkondo: $(NUMKONDO_OBJS)
$(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) -lm $(XTRA_LIBS)
meantools: $(MEANTOOLS_OBJS)
$(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) $(XTRA_LIBS)
meantools-convert:
cp scripts/meantools-convert $(BUILDDIR)/bin/
kondo_preprocess: $(KONDO_PP_OBJS)
$(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) $(XTRA_LIBS)
%.o : ../$(SRCDIR)/%.c
$(CC) -c $(CFLAGS) $< -o $@
install: $(INSTALLLIB) all
mkdir -p $(BINDIR) $(MANDIR) $(SCRIPTDIR) $(DOCDIR)
install -Dm755 $(addprefix $(BUILDDIR)/bin/,$(PROJECT_BINS)) $(BINDIR)/
install -Dm644 $(addprefix man/,$(PROJECT_MANS)) $(MANDIR)/
gzip $(addprefix $(MANDIR)/,$(PROJECT_MANS))
install -Dm644 $(addprefix scripts/,$(PROJECT_SCRIPTS)) $(SCRIPTDIR)/
install -Dm644 $(addprefix doc/,$(PROJECT_DOCS)) $(DOCDIR)/
install-static: all
mkdir -p $(LIBDIR)
install -Dm755 $(addprefix $(BUILDDIR)/lib/,$(PROJECT_LIBS)) $(LIBDIR)/
install-shared: all
mkdir -p $(LIBDIR)
install -Dm755 $(addprefix $(BUILDDIR)/lib/,$(PROJECT_SO)) $(LIBDIR)/
for lib in $(PROJECT_SO); do ln -fs ./$$lib $(LIBDIR)/$${lib%.so.*}.so; done
clean:
@rm -rf $(OBJDIR)
@rm -rf $(BUILDDIR)