obj-$(CONFIG_SECURITY_CTFORGE) := ctforge_lsm.o ctforge_main.o \
	ctforge_record.o ctforge_proc.o ctforge_netlink.o \
	ctforge_sec.o \

obj-$(CONFIG_CTK_DATA_PROTECT) += ctk_data_protect/
obj-$(CONFIG_CRYPTO_DEV_NAQU_SEC) += naqu_sec/
obj-$(CONFIG_SECURITY_CTMAC) += ctmac/

ARCH  = $(shell uname -m)
PHONY := default


default: help

PHONY += help
help:
	@echo "all            build all target"
	@echo "install        install all target"
	@echo "uninstall      remove all target"


PHONY += genvmlinuxh
genvmlinuxh:
	@if [ -e ../../vmlinux ]; then \
		cp ../../vmlinux vmlinux ; \
		tar -xf tools/$(ARCH)/bpftool.tar.gz ; \
		tar -xf tools/$(ARCH)/pahole.tar.gz ; \
		./pahole -J vmlinux ; \
		./bpftool btf dump file vmlinux format c > include/vmlinux.h ; \
		mkdir -p tools/$(ARCH) ; \
		cd include && tar -zcvf ../tools/$(ARCH)/vmlinux.tar.gz vmlinux.h ; \
	else \
		echo "vmlinux not found! try unpack vmlinux.tar.gz" ; \
		tar -xvf tools/$(ARCH)/vmlinux.tar.gz -C include ; \
	fi
	ls -alh include/vmlinux.h
	@rm -f bpftool pahole vmlinux


PHONY += all
all: genvmlinuxh
	cd libbpf        &&  make rebuild
	cd ctforged      &&  make
	cd ebpf_payload  &&  make
	cd ebpf_tests    &&  make
	@echo "-> All ok! All success!"


PHONY += install
install:
	cd libbpf       &&  make install DESTDIR=${DESTDIR}
	cd ctforged     &&  make install DESTDIR=${DESTDIR}
	cd ebpf_payload &&  make install DESTDIR=${DESTDIR}
	cd ebpf_tests   &&  make install DESTDIR=${DESTDIR}
	cd tools        &&  make install DESTDIR=${DESTDIR}
	# minimal or complete vmlinux.h
	cp -a tools/$(ARCH)/vmlinux.tar.gz $(DESTDIR)/usr/share/ctforge/tools/${ARCH}/
	@echo "-> All ok! All success!"


PHONY += uninstall
uninstall:
	cd libbpf       &&  make uninstall DESTDIR=${DESTDIR}
	cd ctforged     &&  make uninstall DESTDIR=${DESTDIR}
	cd ebpf_payload &&  make uninstall DESTDIR=${DESTDIR}
	cd ebpf_tests   &&  make uninstall DESTDIR=${DESTDIR}
	cd tools        &&  make uninstall DESTDIR=${DESTDIR}
	@echo "-> All ok! All success!"


.PHONY: $(PHONY)

