CC = /home/black/raspberry/toolchain/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc $(SYSROOT_FLAG)
SYSROOT = /home/black/raspberry/sysroot
SYSROOT_FLAG = --sysroot=$(SYSROOT)
CFLAGS += -L$(SYSROOT)/usr/lib/arm-linux-gnueabihf/ -lconfig
TARGET = libconfig-test

BUILD_DIR = build

#vpath %.o /home/black/Elektronik/Projects/Hausbus/Server-raspberry/sysroot/usr/lib/arm-linux-gnueabihf/

C_INCLUDES = \
	-I$(SYSROOT)/usr/include/ \
	-I$(SYSROOT)/usr/lib/arm-linux-gnueabihf/
#substitute all *.c with $(BUILD_DIR)/*.o
OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(wildcard *.c))

all: $(OBJS) 
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$(TARGET) $(OBJS)

$(BUILD_DIR)/main.o: main.c main.h | $(BUILD_DIR)
	$(CC) $(C_INCLUDES) -c $< -o $@

$(BUILD_DIR):
	mkdir $@

.PHONY: clean
clean:
	#rm $(BUILD_DIR)/$(TARGET) $(OBJS)
	rm -rf $(BUILD_DIR)