.PHONY: build clean

# 头文件
INCS += -I.
INCS += -I../swapi
INCS += -I./include

# 源文件
SRCS += $(filter-out ../swapi/testLib.c, $(wildcard ../swapi/*.c))
SRCS += takephoto.c

# .o文件
OBJS := $(SRCS:.c=.o)

# 编译器
CC := gcc
CFLAGS := -Wall -fPIC -O2 -g
DEFINS := -D_GNU_SOURCE

target ?= x86_64
ifeq ($(target),armv7hf)
  CC := arm-linux-gnueabihf-gcc
	AR := arm-linux-gnueabihf-ar
endif

# 库文件
LIBS += -Wl,-Bdynamic -lc -lm -ldl -lpthread
ifeq ($(target),armv7hf)
  LIBS += ./lib/armv7hf/./libMvCameraControl.so.4.5.0.3
else
  LIBS += ./lib/x86_64/64/libMvCameraControl.so.4.5.0.3
endif

# 编译和清理
build : libhk_takephoto.a takephoto_test.out hkcam_reset.out

%.o : %.c
	$(CC) $(DEFINS) $(CFLAGS) -c $< $(INCS) -o $@

libhk_takephoto.a : $(OBJS)
	$(AR) -cr $@ $(OBJS)

hkcam_reset.out : $(OBJS) hkcam_reset.c
	$(CC) $(DEFINS) $(CFLAGS) $(OBJS) hkcam_reset.c $(INCS) $(LIBS) -o $@

takephoto_test.out : $(OBJS) takephoto_test.c
	$(CC) $(DEFINS) $(CFLAGS) $(OBJS) takephoto_test.c $(INCS) $(LIBS) -o $@

clean :
	rm -rf $(OBJS) *.out *.a *.jpg *.bmp *.png *.tif config/ log/ status/ var/ MvSdkLog/
