# where to install:
PREFIX=/usr/local
INCDIR=$(DESTDIR)$(inst_root)$(PREFIX)/include/libualloc
LIBDIR=$(DESTDIR)$(inst_root)$(PREFIX)/lib

CFLAGS = -Wall -g -I..

OBJSA=slab_impl.o slabap_impl.o stackd_impl.o stackdnp_impl.o stacks_impl.o mcache_impl.o acache_impl.o buddy_impl.o buddy_debug.o libualloc.o
LIBA=libualloc.a
PWD=`pwd`

all: $(LIBA)

slab_impl.o: slab_impl.c
	$(CC) $(CFLAGS) -c slab_impl.c -o slab_impl.o

slabap_impl.o: slabap_impl.c
	$(CC) $(CFLAGS) -c slabap_impl.c -o slabap_impl.o

stackd_impl.o: stackd_impl.c
	$(CC) $(CFLAGS) -c stackd_impl.c -o stackd_impl.o

stackdnp_impl.o: stackdnp_impl.c
	$(CC) $(CFLAGS) -c stackdnp_impl.c -o stackdnp_impl.o

stacks_impl.o: stacks_impl.c
	$(CC) $(CFLAGS) -c stacks_impl.c -o stacks_impl.o

mcache_impl.o: mcache_impl.c
	$(CC) $(CFLAGS) -c mcache_impl.c -o mcache_impl.o

acache_impl.o: acache_impl.c
	$(CC) $(CFLAGS) -c acache_impl.c -o acache_impl.o

buddy_impl.o: buddy_impl.c
	$(CC) $(CFLAGS) -c buddy_impl.c -o buddy_impl.o

buddy_debug.o: buddy_debug.c
	$(CC) $(CFLAGS) -c buddy_debug.c -o buddy_debug.o

$(LIBA): $(OBJSA) libualloc.o
	touch $(LIBA)
	rm $(LIBA)
	ar ru $(LIBA) $(OBJSA) libualloc.o

install_: $(LIBA)
	mkdir -p $(LIBDIR) $(INCDIR)
	$(CP) $(PWD)/libualloc.h            $(INCDIR)/libualloc.h
	$(CP) $(PWD)/libualloc_impl.h       $(INCDIR)/libualloc_impl.h
	$(CP) $(PWD)/slab_api.h             $(INCDIR)/slab_api.h
	$(CP) $(PWD)/slab_impl.h            $(INCDIR)/slab_impl.h
	$(CP) $(PWD)/slabap_api.h           $(INCDIR)/slabap_api.h
	$(CP) $(PWD)/slabap_impl.h          $(INCDIR)/slabap_impl.h
	$(CP) $(PWD)/stackd_api.h           $(INCDIR)/stackd_api.h
	$(CP) $(PWD)/stackd_impl.h          $(INCDIR)/stackd_impl.h
	$(CP) $(PWD)/stacks_api.h           $(INCDIR)/stacks_api.h
	$(CP) $(PWD)/stacks_impl.h          $(INCDIR)/stacks_impl.h
	$(CP) $(PWD)/mcache_api.h           $(INCDIR)/mcache_api.h
	$(CP) $(PWD)/mcache_impl.h          $(INCDIR)/mcache_impl.h
	$(CP) $(PWD)/acache_api.h           $(INCDIR)/acache_api.h
	$(CP) $(PWD)/acache_impl.h          $(INCDIR)/acache_impl.h
	$(CP) $(PWD)/buddy_api.h            $(INCDIR)/buddy_api.h
	$(CP) $(PWD)/buddy_impl.h           $(INCDIR)/buddy_impl.h
	$(CP) $(PWD)/buddy_debug.h          $(INCDIR)/buddy_debug.h
	$(CP) $(PWD)/$(LIBA)                $(LIBDIR)/$(LIBA)

uninstall:
	-rm $(INCDIR)/*_api.h $(INCDIR)/*_impl.h $(INCDIR)/libualloc.h $(LIBDIR)/$(LIBA)
	-rmdir $(INCDIR)

install:
	make install_ CP="cp"

linstall:
	make install_ CP="ln -s"

clean:
	-rm $(LIBA) $(OBJSA)

