Commit c85e516c authored by Dimitris Lampridis's avatar Dimitris Lampridis

sw: make Makefile more standard

parent 2870732e
......@@ -2,5 +2,5 @@
#
# SPDX-License-Identifier: LGPL-2.1-or-later
all clean:
all install clean:
make -C lib $@
......@@ -4,34 +4,91 @@
-include Makefile.ftdi
OBJS = $(LIBNAME).o usb-enum.o eeprom.o
CFLAGS += -fPIC -g
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
GIT_VERSION = $(shell git describe --dirty --tags --long)
GIT_VERSION = $(shell git describe --dirty --long --tags --always | tr -d "v")
VER_MAJOR=$(word 1,$(subst ., ,$(GIT_VERSION)))
VER_MINOR=$(word 2,$(subst ., ,$(GIT_VERSION)))
VER_PATCH=$(word 1,$(subst -, ,$(word 3,$(subst ., ,$(GIT_VERSION)))))
VERSION=$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)
SO_VERSION_XYZ=$(VERSION)
SO_VERSION_X=$(VER_MAJOR)
ifeq ($(SO_VERSION_X),)
SO_VERSION_X := 0
endif
DESTDIR ?=
prefix ?= /usr/local
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/bin
libdir ?= $(exec_prefix)/lib
includedir ?= $(prefix)/include
pythondir ?= $(libdir)/python
NAME = oattnusb
BINNAME = $(NAME)test
LIBNAME = lib$(NAME)
LIBSO = $(LIBNAME).so
LIBSO_XYZ = $(LIBSO).$(SO_VERSION_XYZ)
LIBSO_X = $(LIBSO).$(SO_VERSION_X)
LIB = $(LIBNAME).a
LOBJ = $(LIBNAME).o usb-enum.o eeprom.o
CFLAGS += -Wall -Werror -fPIC -g
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
CFLAGS += $(EXTRACFLAGS)
ARFLAGS = rcv
# intra2net does not seem to settle into any side of this
# dilemma, so we have to decide for them, see
# http://developer.intra2net.com/mailarchive/html/libftdi/2013/msg00372.html
#
LIBFTDI_CONFIG = $(shell command -v libftdi1-config)
ifeq ($(LIBFTDI_CONFIG),)
LIBFTDI_CONFIG = $(shell command -v libftdi-config)
endif
LIBFTDI_INC := $(shell $(LIBFTDI_CONFIG) --cflags)
LIBFTDI_LIBS := $(shell $(LIBFTDI_CONFIG) --libs)
CFLAGS += $(LIBFTDI_INC)
LDLIBS += $(LIBFTDI_LIBS)
LDLIBS += -ludev
CPPCHECK ?= cppcheck
all: lib doc
lib: $(LIBNAME).a $(LIBNAME).so
all: lib doc
lib: $(LIB) $(LIBSO) $(LIBSO_XYZ)
$(LIBNAME).a: $(OBJS)
ar rc $(LIBNAME).a $(OBJS)
$(LIBNAME).so: LDLIBS += -ludev
$(LIBNAME).so: $(OBJS)
$(CC) $(CFLAGS) -shared -o $@ $^ $(LDFLAGS) $(LDLIBS)
$(OBJS): $(LIBNAME).h $(LIBNAME)-i.h usb-enum.h
$(LIB): $(LOBJ)
$(AR) $(ARFLAGS) $@ $^
$(LIBSO_XYZ): $(LOBJ)
$(CC) -shared $^ -Wl,-soname,$(LIBSO_X) -o $@ $(LDFLAGS) $(LDLIBS)
$(LIBSO): $(LIBSO_XYZ)
ln -sf $< $@
doc:
doxygen oattn.doxy
clean:
rm -f *.a *.o *.so
rm -f $(LIB) $(LIBSO) $(LIBSO_XYZ) $(LOBJ) .depend *.a *.o *.so* *~
rm -rf html
rm -rf build pyoattnusb.egg-info
cppcheck:
$(CPPCHECK) -I. *.c *.h --error-exitcode=1 --suppress=missingIncludeSystem \
--enable=warning,style,performance,portability,information,missingInclude
-include Makefile.install
deploy deploy-$(LIBNAME): install
install: $(LIBSO) $(LIBSO_XYZ) $(LIB)
mkdir -m 0775 -p $(DESTDIR){$(libdir),$(includedir),$(pythondir),$(bindir)}
install -D -t $(DESTDIR)$(libdir) -m 0755 $(LIBSO_XYZ)
install -D -t $(DESTDIR)$(libdir) -m 0644 $(LIB)
install -D -t $(DESTDIR)$(includedir) -m 0644 $(LIBNAME).h usb-enum.h
cp -d $(LIBSO) $(DESTDIR)$(libdir)
install -D -t $(DESTDIR)$(bindir) -m 0755 $(BINNAME)
VERSION=$(VERSION) pip install . --target $(DESTDIR)$(pythondir)
.PHONY: install
# SPDX-FileCopyrightText: 2023 CERN (home.cern)
#
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# intra2net does not seem to settle into any side of this
# dilemma, so we have to decide for them, see
# http://developer.intra2net.com/mailarchive/html/libftdi/2013/msg00372.html
#
CONFIG = $(shell which libftdi1-config)
ifeq ($(CONFIG),)
CONFIG = $(shell which libftdi-config)
endif
LIBFTDI_INC := $(shell $(CONFIG) --cflags)
LIBFTDI_LIBS := $(shell $(CONFIG) --libs)
CFLAGS += $(LIBFTDI_INC)
LDLIBS += $(LIBFTDI_LIBS)
# SPDX-FileCopyrightText: 2023 CERN (home.cern)
#
# SPDX-License-Identifier: LGPL-2.1-or-later
VERSION = $(shell git describe --dirty --tags --long)
OATTN_ROOT = /acc/local/L867/drv/$(NAME)
INSTALL_ROOT = $(OATTN_ROOT)/$(VERSION)
install: $(LIBNAME).a $(LIBNAME).so $(NAME)test
install: $(LIBNAME).h usb-enum.h
install:
mkdir -p $(INSTALL_ROOT)/lib
mkdir -p $(INSTALL_ROOT)/include
mkdir -p $(INSTALL_ROOT)/bin
ln -sf . $(INSTALL_ROOT)/include/$(NAME)
install -m 0775 $(LIBNAME).a $(LIBNAME).so $(INSTALL_ROOT)/lib
install -m 0775 $(NAME)test $(INSTALL_ROOT)/bin
install -m 0775 $(LIBNAME).h usb-enum.h $(INSTALL_ROOT)/include
pip install . --target $(INSTALL_ROOT)/lib
......@@ -3,16 +3,12 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
from setuptools import setup, find_packages
import subprocess
try:
version = subprocess.check_output(['git', 'describe', '--tags']).decode().strip()
except Exception:
version = '0.0.0'
import os
setup(
name='pyoattnusb',
version=version,
version=os.environ.get('VERSION', "0.0.0"),
packages=find_packages(),
author='Dimitris Lampridis',
author_email='dimitris.lampridis@cern.ch',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment