cleaner Makefile, separate dir for build and target

This commit is contained in:
2024-04-11 17:14:27 +02:00
parent 38813b42f2
commit d99a77f5c7
2 changed files with 57 additions and 47 deletions

57
Makefile Normal file
View File

@ -0,0 +1,57 @@
LDFLAGS="-L/usr/local/opt/flex/lib"
BUILD_DIR := ./build
TARGET_DIR := ./target
all: test bubble_sort automaton a_pow_b
automaton: $(BUILD_DIR)/ram $(TARGET_DIR)/ram.py
$(BUILD_DIR)/ram < src/stack.asm
mv machine.py $(TARGET_DIR)/automaton.py
echo "\n### automaton.py ###"
cat $(TARGET_DIR)/automaton.py
echo "### execution ###"
python $(TARGET_DIR)/automaton.py
bubble_sort: $(BUILD_DIR)/ram $(TARGET_DIR)/ram.py
$(BUILD_DIR)/ram < src/bubble_sort.asm
mv machine.py $(TARGET_DIR)/bubble_sort.py
echo "\n### machine.py ###"
cat $(TARGET_DIR)/bubble_sort.py
echo "### execution ###"
python $(TARGET_DIR)/bubble_sort.py
a_pow_b: $(BUILD_DIR)/ram $(TARGET_DIR)/ram.py
$(BUILD_DIR)/ram < src/a_pow_b.asm
mv machine.py $(TARGET_DIR)/a_pow_b.py
echo "\n### a_pow_b.py ###"
cat $(TARGET_DIR)/a_pow_b.py
echo "### execution ###"
python $(TARGET_DIR)/a_pow_b.py
test: $(BUILD_DIR)/ram $(TARGET_DIR)/ram.py
$(BUILD_DIR)/ram < src/test.asm
mv machine.py $(TARGET_DIR)/test.py
echo "\n### test.py ###"
cat $(TARGET_DIR)/test.py
echo "### execution ###"
python $(TARGET_DIR)/test.py
$(TARGET_DIR)/ram.py: src/ram.py
mkdir -p $(TARGET_DIR)
cp $< $@
$(BUILD_DIR)/ram: $(BUILD_DIR)/ram.yy.c $(BUILD_DIR)/ram.tab.c
gcc -o $@ $^ -ly -lfl
$(BUILD_DIR)/ram.tab.c: src/ram.y
mkdir -p $(BUILD_DIR)
bison -d --report=all -o $@ $<
$(BUILD_DIR)/ram.yy.c: src/ram.l
mkdir -p $(BUILD_DIR)
flex -o $@ $<
clean:
rm -rf $(BUILD_DIR)
rm -rf $(TARGET_DIR)