-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_makefile.py
112 lines (100 loc) · 3.99 KB
/
generate_makefile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!python
import re
"""This script generates the Makefile for the Openflexure Microscope.
It is intended to be run whenever you need a new makefile. The makefile lives in
the repository and is versioned, so most people never need to run this script.
"""
def part_versions(part_name, versions):
"""Given a part name and a dictionary of versions, list all the possible part names.
For example::
>>> part_versions("body_{}", {"a":{}, "b":{}})
"body_a body_b"
"""
return " ".join(part_name.format(n) for n in versions.keys())
def openscad_recipe(**kwargs):
"""Create a makefile recipe to compile an openscad file with given options."""
output = "\t" + "openscad -o $@"
for name, value in kwargs.iteritems():
try:
float(value)
except ValueError:
# numbers and booleans are OK, but strings need to be double-quoted on the command line.
if value not in ["true", "false"]:
value = '"{}"'.format(value)
if type(value) == type(True): #need to convert boolean values
value = "true" if value else "false"
output += " -D '{name}={value}'".format(name=name, value=str(value))
output += " $<\n"
return output
body_versions = {
"fibre_stage_1mm":{
"beam_height":75,
"xy_lever":10,
"z_lever":10,
"breadboard_lugs":"diagonal",
"fixed_stage":True,
},
"micromanipulator_2mm":{
"beam_height":85,
"xy_lever":20,
"z_lever":20,
"breadboard_lugs":"atsides",
"fixed_stage":False,
},
}
accessory_versions = {
"CPS532_to_top_plate":{},
"LED_to_top_plate":{},
"rms_to_top_plate":{},
"microscope_module":{},
}
if __name__ == "__main__":
with open("Makefile","w") as makefile:
def M(line):
makefile.write(line + "\n")
M("# Makefile for the openflexure block stage")
M("# Generated by generate_makefile.py")
M(".PHONY: all cleanstl")
M("")
M("SOURCE = openscad")
M("OUTPUT = builds")
M("")
M("BODIES := " + part_versions("main_body_{}", body_versions))
M("BASES := " + part_versions("base_{}", body_versions))
M("TOOLS := actuator_assembly_tools")
M("ACCESSORIES := " + part_versions("accessories/{}", accessory_versions))
M("COMMONPARTS := gears small_gears moving_platform")
M("ALLPARTS := $(COMMONPARTS) $(TOOLS) $(BODIES) $(BASES) $(ACCESSORIES)")
M("ALLSTLFILES := $(ALLPARTS:%=$(OUTPUT)/%.stl)")
M("")
M("parameters_file := $(SOURCE)/parameters.scad")
M("utilities_file := $(SOURCE)/utilities.scad")
M("all_deps := $(parameters_file) $(utilities_file) #All targets depend on these")
M("")
M("all: $(ALLSTLFILES)")
M("")
M("cleanstl:")
M("\t"+"rm $(STLFILES)")
M("")
M("#parameter and utilities files affect everything")
M("$(OUTPUT)/%.stl: $(all_deps)")
M("")
M("main_body_dep_names := compact_nut_seat fibre_stage_three_legs")
M("main_body_deps := $(main_body_dep_names:%=$(SOURCE)/%.scad)")
for version, parameters in body_versions.items():
M("$(OUTPUT)/main_body_" + version + ".stl: $(SOURCE)/main_body.scad $(main_body_deps)")
M(openscad_recipe(**parameters))
M(" ")
M("$(OUTPUT)/base_" + version + ".stl: $(SOURCE)/base.scad $(main_body_deps)")
M(openscad_recipe(**parameters))
M("")
M("$(OUTPUT)/actuator_assembly_tools.stl: $(SOURCE)/actuator_assembly_tools.scad")
M(openscad_recipe(foot_height=26))
M("")
for version, parameters in accessory_versions.items():
M("$(OUTPUT)/accessories/" + version + ".stl: $(SOURCE)/accessories/" + version + ".scad")
M(openscad_recipe(**parameters))
M("")
M("$(OUTPUT)/%.stl: $(SOURCE)/%.scad $(all_deps)")
M(openscad_recipe())
M("")