simplify my Makefile by writing the build stuff in Python
I'm going to move all of the .scad files into subdirectories and I couldn't figure out how to recurse properly in make, so... do it the easy way make is hard, let's go shopping Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
de0fcfd160
commit
2ed9b12ed3
12
Makefile
12
Makefile
@ -1,9 +1,5 @@
|
||||
EXCLUDES = components parameters
|
||||
OBJECTS := $(filter-out $(EXCLUDES),$(patsubst src/%.scad,%,$(wildcard src/*.scad)))
|
||||
dir_guard=@mkdir -p ./build
|
||||
|
||||
all: $(OBJECTS)
|
||||
$(dir_guard)
|
||||
all:
|
||||
python build.py
|
||||
mkdir -p ./build/docs
|
||||
cp ./docs/README-objects.md ./build/README.md
|
||||
cp ./docs/assembly-and-tips.md ./build/docs/assembly-and-tips.md
|
||||
@ -11,9 +7,5 @@ all: $(OBJECTS)
|
||||
cp ./LICENSE ./build/LICENSE
|
||||
pushd ./build; zip ./buildable-stick-system-`git describe --dirty`-stls.zip . -r; popd
|
||||
|
||||
$(OBJECTS):
|
||||
$(dir_guard)
|
||||
openscad -o build/$@.stl src/$@.scad
|
||||
|
||||
clean:
|
||||
rm -rf ./build
|
||||
|
47
build.py
Normal file
47
build.py
Normal file
@ -0,0 +1,47 @@
|
||||
"""Compile all OpenSCAD files into a build directory and package it with docs.
|
||||
|
||||
(a.k.a.: "make is hard"
|
||||
|
||||
SPDX-FileCopyrightText: © 2024 Brian S. Stephan <bss@incorporeal.org>
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""
|
||||
import os
|
||||
import os.path
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
PROJECT_ROOT = os.path.abspath(os.getcwd())
|
||||
BUILD_DIR = os.path.join(PROJECT_ROOT, 'build/')
|
||||
SOURCE_DIR = os.path.join(PROJECT_ROOT, 'src/')
|
||||
|
||||
EXCLUDES = ['components.scad', 'parameters.scad']
|
||||
|
||||
# set up our environment to point openscad at the right stuff
|
||||
os.environ['OPENSCADPATH'] = SOURCE_DIR
|
||||
|
||||
# track processes to wait on
|
||||
processes = []
|
||||
|
||||
os.chdir(SOURCE_DIR)
|
||||
for root, dirs, files in os.walk('.'):
|
||||
print(f"{root} {dirs} {files}")
|
||||
# make the current directory so that openscad can write stuff into it
|
||||
os.makedirs(os.path.join(BUILD_DIR, root))
|
||||
|
||||
input_dir = os.path.join(SOURCE_DIR, root)
|
||||
output_dir = os.path.join(BUILD_DIR, root)
|
||||
for file in files:
|
||||
if not re.match(r'.*\.scad$', file):
|
||||
continue
|
||||
if file in EXCLUDES:
|
||||
continue
|
||||
|
||||
stl_file = re.sub(r'\.scad$', '.stl', file)
|
||||
input_ = os.path.join(input_dir, file)
|
||||
output = os.path.join(output_dir, stl_file)
|
||||
cmd = f'openscad -o {output} {input_}'
|
||||
print(cmd)
|
||||
processes.append(subprocess.Popen(cmd.split(' ')))
|
||||
|
||||
for process in processes:
|
||||
process.wait()
|
Loading…
Reference in New Issue
Block a user