From a78c52265d755a2294a743e186ad5a6b5456d9f1 Mon Sep 17 00:00:00 2001 From: kartofen Date: Fri, 28 Apr 2023 20:39:42 +0300 Subject: testing structure done --- Makefile | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 4278311..544ff31 100644 --- a/Makefile +++ b/Makefile @@ -5,14 +5,13 @@ SRCD := src OBJD := obj BIND := bin -SRCS = $(shell find $(SRCD)/$(SUBD) -type f) -OBJS = $(SRCS:$(SRCD)/$(SUBD)/%.c=$(OBJD)/$(SUBD)/%.o) +FILES = $(shell find $(SRCD)/$(SUBD) -type f) -DAEMON_TARGET_NAME := daemon -CLIENT_TARGET_NAME := client -MODULE_TARGET_NAME := keylogger.ko -TESTS_TARGET_NAME := tests +CSRCS = $(filter %.c, $(FILES)) +HSRCS = $(filter %.h, $(FILES)) +COBJS = $(CSRCS:$(SRCD)/%.c=$(OBJD)/%.o) +MODULE_TARGET := keylogger.ko KERNEL_NAME := kernel-$(shell uname -r) INITFS_NAME := initramfs.img @@ -20,34 +19,38 @@ export all: daemon client module tests vm -daemon client module tests: - $(MAKE) $(BIND)/$($(shell echo $@ | tr '[:lower:]' '[:upper:]')_TARGET_NAME) SUBD=$@ - clean: rm -rf $(BIND) rm -rf $(OBJD) -# generic build -$(BIND)/%: $(OBJS) +daemon client module tests libs: + $(eval TARGET := $($(shell echo $@ | tr 'a-z' 'A-Z')_TARGET)) + $(MAKE) $(BIND)/$(if $(TARGET),$(TARGET),$@) SUBD=$@ + +# generic link +$(BIND)/%: $(COBJS) $(HSRCS) mkdir -p $(dir $@) $(CC) $(CFLAGS) $(SFLAGS) $^ -o $@ -$(OBJD)/$(SUBD)/%.o: $(SRCD)/$(SUBD)/%.c +# generic bulid +$(OBJD)/%.o: $(SRCD)/%.c mkdir -p $(dir $@) $(CC) $(CFLAGS) $(SFLAGS) -c $^ -o $@ + # build a module -$(BIND)/%.ko: $(SRCS) +$(BIND)/%.ko: $(CSRCS) $(HSRCS) mkdir -p $(dir $@); mkdir -p $(OBJD)/$(SUBD) make -C $(SRCD)/$(SUBD) name=$(@:$(BIND)/%.ko=%) mv $(SRCD)/$(SUBD)/*.o $(OBJD)/$(SUBD) mv $(SRCD)/$(SUBD)/*.ko $@ make -C $(SRCD)/$(SUBD) clean -# copy the test files -$(BIND)/tests: $(SRCS) - mkdir -p $(BIND) - cp -r $(SRCD)/$(SUBD) $(BIND) +# copy and build the testing files and other shared files (no .c files) +$(BIND)/tests: libs +$(BIND)/tests $(BIND)/libs: $(FILES) $(CSRCS:$(SRCD)/%.c=$(BIND)/%) + mkdir -p $(BIND)/$(SUBD) + find $(SRCD)/$(SUBD) -type f ! -name '*.c' -exec cp {} $(BIND)/$(SUBD) \; # VM things -- cgit v1.2.3