#
# Makefile - Build the Fakefile libraries
#
# Copyright 2012 by Werner Almesberger
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#

CFLAGS = -Wall -g -Wextra -Wno-unused-parameter -fPIC
LDFLAGS = -L. -Wl,-rpath=$(shell pwd)
LDLIBS = -lfakefile

LIBFAKEFILE_OBJS = comm.o fakefile.o file.o launch.o
LIBFFSLAVE_OBJS = comm.o slave.o
TARGETS = libfakefile.so libfakefile_slave.so demo

CC_normal	:= $(CC)
LD_normal	:= $(LD)
DEPEND_normal	:= $(CPP) $(CFLAGS) -MM -MG

CC_quiet	= @echo "  CC       " $@ && $(CC_normal)
LD_quiet	= @echo "  LD       " $@ && $(LD_normal)
GEN_quiet	= @echo "  GENERATE " $@ &&
DEPEND_quiet	= @$(DEPEND_normal)

ifeq ($(V),1)
	CC	= $(CC_normal)
	LD	= $(LD_normal)
	GEN	=
	DEPEND	= $(DEPEND_normal)
else
	CC	= $(CC_quiet)
	LD	= $(LD_quiet)
	GEN	= $(GEN_quiet)
	DEPEND	= $(DEPEND_quiet)
endif

.PHONY:		all clean spotless

all:		$(TARGETS)

libfakefile.so:	$(LIBFAKEFILE_OBJS)
		$(LD) -shared -o $@ $^

libfakefile_slave.so: $(LIBFFSLAVE_OBJS)
		$(LD) -shared -o $@ $^ -ldl

clean:
		rm -f $(LIBFAKEFILE_OBJS) $(LIBFFSLAVE_OBJS)

spotless:	clean
		rm -f $(TARGETS)
