mirror of
https://github.com/ervanalb/keygen.git
synced 2025-12-16 13:25:25 +00:00
trying to make auto-dependencies work
This commit is contained in:
12
Makefile
12
Makefile
@@ -25,13 +25,15 @@ POLYFLAGS =
|
||||
SCADFLAGS =
|
||||
|
||||
# Targets
|
||||
all: all_stl
|
||||
all: stl
|
||||
poly: $(POLY_OBJ)
|
||||
$(STL_DIR)/key_blanks.d:
|
||||
BUILD_DIR=$(STL_DIR) bin/parse.py $(SCAD_SRC)
|
||||
$(STL_DIR)/%.d: $(SCAD_DIR)/%.scad
|
||||
BUILD_DIR=$(STL_DIR) bin/parse.py $<
|
||||
clean:
|
||||
-rm -f $(POLY_DIR)/*.gen.scad $(STL_DIR)/*.stl
|
||||
-rm -f $(POLY_DIR)/*.gen.scad $(STL_DIR)/*.stl $(STL_DIR)/*.d
|
||||
$(POLY_DIR)/%.gen.scad: $(SVG_DIR)/%.svg
|
||||
$(POLY) $(POLYFLAGS) --fname $@ $<
|
||||
|
||||
include $(STL_DIR)/key_blanks.d
|
||||
include $(patsubst $(SCAD_DIR)/%.scad,$(STL_DIR)/%.d,$(SCAD_SRC))
|
||||
|
||||
stl: $(STL_OBJ)
|
||||
|
||||
60
bin/parse.py
60
bin/parse.py
@@ -7,43 +7,45 @@ import json
|
||||
import string
|
||||
import itertools
|
||||
|
||||
def handle(fn):
|
||||
with open(fn) as f:
|
||||
scad_text = f.read()
|
||||
build_dir = os.environ.get("BUILD_DIR", "")
|
||||
|
||||
poly_reqs = re.findall(r'<(.+\.gen\.scad)>', scad_text)
|
||||
fn = sys.argv[1]
|
||||
|
||||
modules = re.findall(r"module\s+([^\s\(]+)\s*\("
|
||||
r".+"
|
||||
r"outlines_k\s*=\s*(\[[^\]]+\])"
|
||||
r".+"
|
||||
r"wardings_k\s*=\s*(\[[^\]]+\])"
|
||||
, scad_text, flags=re.S)
|
||||
with open(fn) as f:
|
||||
scad_text = f.read()
|
||||
|
||||
modules_parsed = [(n, json.loads(o), json.loads(w)) for (n, o, w) in modules]
|
||||
poly_reqs = re.findall(r'<(.+\.gen\.scad)>', scad_text)
|
||||
|
||||
def sanitize(s):
|
||||
return "".join([c for c in s.lower() if c in string.ascii_lowercase + string.digits])
|
||||
modules = re.findall(r"module\s+([^\s\(]+)\s*\("
|
||||
r".+"
|
||||
r"outlines_k\s*=\s*(\[[^\]]+\])"
|
||||
r".+"
|
||||
r"wardings_k\s*=\s*(\[[^\]]+\])"
|
||||
, scad_text, flags=re.S)
|
||||
|
||||
all_keys = [(n, o, w) for (n, os, ws) in modules_parsed for o in os for w in ws]
|
||||
modules_parsed = [(n, json.loads(o), json.loads(w)) for (n, o, w) in modules]
|
||||
|
||||
def stl_filename(n, o, w):
|
||||
return "$(STL_DIR)/{n}_{o_s}_{w_s}.stl".format(n=n, o=o, w=w, o_s=sanitize(o), w_s=sanitize(w))
|
||||
def sanitize(s):
|
||||
return "".join([c for c in s.lower() if c in string.ascii_lowercase + string.digits])
|
||||
|
||||
all_keys_makefile = ["{stl_fn}: {scad_fn} {deps}\n\t$(SCAD) $(SCADFLAGS) -D 'outline=\"{o}\"' -D 'warding=\"{w}\"' {scad_fn} -o $@"
|
||||
.format(n=n, o=o, w=w,
|
||||
scad_fn=fn, stl_fn=stl_filename(n, o, w), deps=" ".join(["$(POLY_DIR)/{}".format(r) for r in poly_reqs]))
|
||||
for (n, o, w) in all_keys]
|
||||
all_stl = [stl_filename(n, o, w) for (n, o, w) in all_keys]
|
||||
all_keys_makefile.append("all_stl: {}".format(" \\\n ".join(all_stl)))
|
||||
all_keys = [(n, o, w) for (n, os, ws) in modules_parsed for o in os for w in ws]
|
||||
|
||||
return all_keys, all_keys_makefile
|
||||
def stl_filename(n, o, w):
|
||||
return "$(STL_DIR)/{n}_{o_s}_{w_s}.stl".format(n=n, o=o, w=w, o_s=sanitize(o), w_s=sanitize(w))
|
||||
|
||||
all_keys, all_keys_makefile = (list(itertools.chain.from_iterable(e)) for e in zip(*[handle(fn) for fn in sys.argv[1:]]))
|
||||
all_keys_makefile = ["{stl_fn}: {scad_fn} {deps}\n\t$(SCAD) $(SCADFLAGS) -D 'outline=\"{o}\"' -D 'warding=\"{w}\"' {scad_fn} -o $@"
|
||||
.format(n=n, o=o, w=w,
|
||||
scad_fn=fn, stl_fn=stl_filename(n, o, w), deps=" ".join(["$(POLY_DIR)/{}".format(r) for r in poly_reqs]))
|
||||
for (n, o, w) in all_keys]
|
||||
all_stl = [stl_filename(n, o, w) for (n, o, w) in all_keys]
|
||||
all_keys_makefile.append("STL_OBJ += {}".format(" \\\n ".join(all_stl)))
|
||||
|
||||
d = os.environ.get("BUILD_DIR", "")
|
||||
def stripfn(fn):
|
||||
fn = os.path.basename(fn)
|
||||
if fn.endswith(".scad"):
|
||||
fn = fn[:-5]
|
||||
return fn
|
||||
|
||||
with open(os.path.join(d, "key_blanks.d"), "w") as f:
|
||||
print("\n".join(all_keys_makefile), file=f)
|
||||
with open(os.path.join(d, "key_blanks.json"), "w") as f:
|
||||
print(json.dumps(all_keys), file=f)
|
||||
with open(os.path.join(build_dir, "{}.d".format(stripfn(fn))), "w") as f:
|
||||
print("\n".join(all_keys_makefile), file=f
|
||||
)
|
||||
|
||||
@@ -5,6 +5,8 @@ module schlage_classic(bitting="",
|
||||
outline_name="5-pin",
|
||||
warding_name="C") {
|
||||
|
||||
name = "Schlage Classic";
|
||||
|
||||
outlines_k = ["5-pin",
|
||||
"6-pin"];
|
||||
outlines_v = [[outline_5pin_points, outline_5pin_paths,
|
||||
|
||||
Reference in New Issue
Block a user