Skip to content
Snippets Groups Projects
Makefile 1.67 KiB
Newer Older
# SPDX-License-Identifier: LGPL-3.0-or-later
#
# Copyright (C) 2020 CERN

Federico Vaga's avatar
Federico Vaga committed
# If it exists includes Makefile.specific. In this Makefile, you should put
# specific Makefile code that you want to run before this. For example,
# build a particular environment.
-include Makefile.specific

GIT_VERSION := $(shell git describe --dirty --long --tags)
VERSION := $(shell git describe --tags --abbrev=0 | tr -d 'v')
SO_VERSION_XYZ := $(shell echo $(VERSION) | grep -o -E "[0-9]+\.[0-9]+\.[0-9]")
SO_VERSION_X := $(shell echo $(SO_VERSION_XYZ) | cut -d "." -f 1)

LIB = libfmc.a
LIBS = libfmc.so
LIBS_XYZ = $(LIBS).$(SO_VERSION_XYZ)
LOBJ := libfmc.o

CFLAGS = -Wall -Werror -ggdb -O2 -I. -I../include/uapi
CFLAGS += -fPIC
CFLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\""
CFLAGS +=  $(EXTRACFLAGS)

DESTDIR ?= /usr/local
CPPCHECK ?= cppcheck

all: lib

lib: $(LIB) $(LIBS_XYZ)

%: %.c $(LIB)
	$(CC) $(CFLAGS) $*.c $(LDFLAGS) -o $@

$(LIB): $(LOBJ)
	$(AR) r $@ $^

$(LIBS_XYZ): $(LIB)
	$(CC) -shared  -o $@ -Wl,--whole-archive,-soname,$@ $^ -Wl,--no-whole-archive

clean:
	rm -f $(LIB) $(LIBS_XYZ) .depend *.o *~

.depend: Makefile $(wildcard *.c *.h ../*.h)
	$(CC) $(CFLAGS) -M $(LOBJ:.o=.c) -o $@

install:
	install -d $(DESTDIR)/lib
	install -d $(DESTDIR)/include/fmc

	install -m 644 -D $(LIB) $(DESTDIR)/lib
	install -m 0755 $(LIBS_XYZ) $(DESTDIR)/lib
	install -m 644 -D libfmc.h $(DESTDIR)/include/fmc
	ln -sf $(LIBS_XYZ) $(DESTDIR)/lib/$(LIBS).$(SO_VERSION_X)
	ln -sf $(LIBS).$(SO_VERSION_X) $(DESTDIR)/lib/$(LIBS)

modules_install:

cppcheck:
	$(CPPCHECK) -q -I. -I../include -I../include/uapi --suppress=missingIncludeSystem --enable=warning,style,information,missingInclude *.c *.h

-include .depend

.PHONY=cppcheck