include defs.mk

LIBNAME = $(shell echo $(basename $(SONAME)) | sed -e 's/^lib//')
HTARGET = $(prefix)/include/$(LIBNAME)/
LIBTARGET = $(prefix)/lib/

CFLAGS += -static -fpic $(shell pkg-config --cflags glib-2.0 gobject-2.0 mono) $(EXTRAINCLUDES) -I.

ifdef bundle
EXTRAOBJS = bundle.o
CFLAGS += -DCILC_BUNDLE
EXTRATARGETS = bundle.h
endif

ifndef prefix
prefix = $(CWD)
endif

all: $(SONAME)

$(SONAME): $(EXTRAOBJS) $(OBJS)
	gcc -Wall -fpic -shared `pkg-config --libs glib-2.0 gobject-2.0 mono` -lpthread $(EXTRAOBJS) $(OBJS) $(EXTRALIBS) -o $(SONAME)

$(LIBNAME).o: $(EXTRATARGETS)

bundle.o bundle.h: $(ASSEMBLY)
	mkbundle -c -o bundle.c.tmp -oo bundle.o $(ASSEMBLY)
	rm -f xx*
	csplit bundle.c.tmp /mono_main/
	mv xx00 bundle.h
	rm -f xx*
	rm -f bundle.c.tmp

install_libs: $(SONAME)
	mkdir -p $(LIBTARGET)
	install -s $(SONAME) $(LIBTARGET)

install_headers: *.h
	mkdir -p $(HTARGET)
	install *.h $(HTARGET)

install: install_libs install_headers

clean:
	rm -rf core *~ *.o *.so bundle.h

