aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-19 10:06:21 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-19 10:06:21 -0700
commit5a25f38de6d3e2506838191c55af94cb56c9f641 (patch)
tree5dc6b2678fc76502c148c87c419c158680c3c4c5 /bin
parentef512a454184bfbcdf3ac6b295e9fb5bf7e26841 (diff)
feat: quality of life scripts to initialize make rules
Diffstat (limited to 'bin')
-rwxr-xr-xbin/initmk54
-rwxr-xr-xbin/updateblddir (renamed from bin/update_dirs.py)9
2 files changed, 59 insertions, 4 deletions
diff --git a/bin/initmk b/bin/initmk
new file mode 100755
index 0000000..eb0098a
--- /dev/null
+++ b/bin/initmk
@@ -0,0 +1,54 @@
+#!/bin/python
+
+import sys
+
+NAME = "rules.mk"
+TEMPLATE = """# ---- Push on stack ----
+SP := $(SP).x
+DIRSTACK_$(SP) := $(d)
+d := $(DIR)
+
+# Iterate through subdirectory tree
+
+# Local sources
+SRCS_$(d) := $(wildcard $(d)/*.c)
+OBJS_$(d) := $(SRCS_$(d):.c=.o)
+OBJS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(OBJS_$(d)))
+DEPS_$(d) := $(OBJS_$(d):.o=.d)
+
+OBJS := $(OBJS) $(OBJS_$(d))
+DEPS := $(DEPS) $(DEPS_$(d))
+
+# Local targets
+LIBS_$(d) :=
+LIBS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(LIBS_$(d)))
+LIBS := $(LIBS) $(LIBS_$(d))
+
+BINS_$(d) :=
+BINS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(BINS_$(d)))
+BINS := $(BINS) $(BINS_$(d))
+
+# Local rules
+# $(LIBS_$(d)) := TGTFLAGS :=
+# $(LIBS_$(d)) := TGTINCS :=
+# $(LIBS_$(d)) := TGTLIBS :=
+
+$(LIBS_$(d)): $(OBJS_$(d))
+ $(ARCHIVE)
+
+$(BINS_$(d)): $(OBJ_DIR)/libn/test.o
+ $(LINK)
+
+# ---- Pop off stack ----
+-include $(DEPS_$(d))
+
+d := $(DIRSTACK_$(SP))
+SP := $(basename $(SP))"""
+
+if __name__ == "__main__":
+ try:
+ with open(NAME, 'x') as makefile:
+ makefile.write(f"{TEMPLATE}\n")
+ except:
+ print("rules.mk already present", file=sys.stderr)
+ exit(1)
diff --git a/bin/update_dirs.py b/bin/updateblddir
index 0f0e0f2..34f148d 100755
--- a/bin/update_dirs.py
+++ b/bin/updateblddir
@@ -2,13 +2,14 @@
import os
-ROOT = "sys"
+ROOT = "/home/nolln/root"
+SRC = "sys"
BUILD = "build"
-IGNORED = ["build", "include", "lib", "bin", ".git", "vendor", "obj", "dep"]
+IGNORED = ["build", "include", "lib", "bin", ".git", "vendor", "obj", "dep", ".generated"]
if __name__ == "__main__":
- for root, dirs, _ in os.walk(ROOT):
+ for root, dirs, _ in os.walk(f"{ROOT}/{SRC}"):
dirs[:] = [d for d in dirs if d not in IGNORED]
- blddir = f"{BUILD}/{root[len(ROOT)+1:]}"
+ blddir = f"{ROOT}/{BUILD}/{root[len(ROOT)+len(SRC)+2:]}"
if not os.path.exists(blddir):
os.mkdir(blddir)