STAGINGDIR?=/
INSTALL?=install

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

TARGET = hello.so

OBJECTS = hello.o \

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

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) $(<)

install:
	$(INSTALL) -d $(STAGINGDIR)/usr/lib/tutorials/greeter
	$(INSTALL) -m 755 $(TARGET) $(STAGINGDIR)/usr/lib/tutorials/greeter
	$(INSTALL) -m 755 hello.odl $(STAGINGDIR)/usr/lib/tutorials/greeter
		
clean:
	rm -f $(TARGET) $(OBJECTS)
	rm -f *.d

.PHONY: install clean
