include ../Makefile.inc

SUBLIBDIR=printer usb

SRCS=$(wildcard */*.c)
OBJS=$(SRCS:%.c=%.o)
LIBRARY=lib$(LIBNAME).so.$(SHLIB_MAJOR)
STATIC_LIBRARY=lib$(LIBNAME).a

.PHONY: all clean install remoteinstall $(SUBLIBDIR)

all: $(SUBLIBDIR) $(LIBRARY) $(STATIC_LIBRARY)

$(SUBLIBDIR):
	$(MAKE) -C $@ $(MAKECMDGOALS)

$(LIBRARY): $(SUBLIBDIR)
	-rm -f $@
	$(CC) -Wl,-soname,$(LIBRARY),--no-undefined -shared -o $@ $(OBJS) $(LIBS)

$(STATIC_LIBRARY): $(SUBLIBDIR)
	-rm -f $@
	$(AR) -rcs $@ $(OBJS)

clean:
	-rm -f *.o
	-rm -f $(LIBRARY)
	-rm -f lib$(LIBNAME).so

install:
	install -Dm755 $(LIBRARY) $(INSTALLDIR)/$(libdir)/$(LIBRARY)
	ln -sf $(LIBRARY) $(INSTALLDIR)/$(libdir)/lib$(LIBNAME).so
	install -Dm 755 $(STATIC_LIBRARY) $(INSTALLDIR)/$(libdir)/$(STATIC_LIBRARY) ;

remoteinstall:
	install -Dm755 $(LIBRARY) $(INSTALLDIR)/$(libdir)/$(LIBRARY)
ifndef NOSTRIP
	$(STRIP) $(INSTALLDIR)/$(libdir)/$(LIBRARY)
endif
