aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2023-04-24 23:52:41 +0300
committerkartofen <mladenovnasko0@gmail.com>2023-04-24 23:52:41 +0300
commit9bf5719d4c59993c07113c089ebd5a92d692f785 (patch)
tree7310918ccac5bb3cfffc18861c286a6872554c01 /Makefile
parent2ca6677667af23ecb1e17479c5b5cc08efa53309 (diff)
skeleton done
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile52
1 files changed, 52 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a4a8911
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,52 @@
+CC := gcc
+CFLAGS = -std=c99 -Wall -Wextra -Wpedantic -g
+
+SRCD := src
+OBJD := obj
+BIND := bin
+
+SRCS = $(shell find $(SRCD)/$(SUBD) -type f)
+OBJS = $(SRCS:$(SRCD)/$(SUBD)/%.c=$(OBJD)/$(SUBD)/%.o)
+
+DAEMON_TARGET_NAME := daemon
+CLIENT_TARGET_NAME := client
+MODULE_TARGET_NAME := keylogger.ko
+
+KERNEL_NAME := kernel-$(shell uname -r)
+INITFS_NAME := initramfs.img
+
+export
+
+all: daemon client module
+
+daemon client module:
+ $(MAKE) $(BIND)/$($(shell echo $@ | tr '[:lower:]' '[:upper:]')_TARGET_NAME) SUBD=$@
+
+clean:
+ rm -rf $(BIND)
+ rm -rf $(OBJD)
+
+# generic build
+$(BIND)/%: $(OBJS)
+ mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(SFLAGS) $^ -o $@
+
+$(OBJD)/$(SUBD)/%.o: $(SRCD)/$(SUBD)/%.c
+ mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(SFLAGS) -c $^ -o $@
+
+# build a module
+$(BIND)/%.ko: $(SRCS)
+ 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
+
+# VM things
+vm: vm.sh $(BIND)/$(INITFS_NAME) $(BIND)/$(KERNEL_NAME)
+ ./vm.sh run
+$(BIND)/$(INITFS_NAME): $(SRCD)/initramfs-init.sh module
+ ./vm.sh initramfs $@ $^
+$(BIND)/$(KERNEL_NAME):
+ ./vm.sh kernel $@