STAGINGDIR?=/
INSTALL?=install

-include $(STAGINGDIR)/usr/components.config
-include $(STAGINGDIR)/components.config

TARGET = mtk_advanced.so

OBJECTS = simple.o \
          advanced.o

CFLAGS += -fPIC -O2 -g -I. -Wall -Wextra -Werror -I$(STAGINGDIR)/include -I$(STAGINGDIR)/usr/include $(shell pkg-config --cflags sahtrace pcb mtk)
LDFLAGS += -L$(STAGINGDIR)/lib -L$(STAGINGDIR)/usr/lib $(shell pkg-config --libs sahtrace pcb mtk)

all: $(TARGET)

$(TARGET): $(OBJECTS)
	$(CC) -Wl,-soname,$(TARGET) -shared -fPIC -o $(@) $(OBJECTS) $(LDFLAGS)

-include $(OBJECTS:.o=.d)

%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<
	@$(CC) $(CFLAGS) -MM -MP -MT '$(@) $(@:.o=.d)' -MF $(@:.o=.d) $(<)

clean:
	rm -f $(TARGET) $(OBJECTS)
	rm -f *.d

.PHONY: install clean
