# Variables to define the source and output directories
SRC_DIR = db
OUT_DIR = out

# List of source files without extension
SOURCES = 0014 0022 0013 0001 0016 0017 0018 0023 0019 0002 0025

# Add directory and extension to the source filenames
SRC_FILES = $(SOURCES:%=$(SRC_DIR)/%.txt)

# Add directory and .md extension to the markdown filenames
MD_FILES = $(SOURCES:%=$(OUT_DIR)/%.md)

# Add .html extension for the HTML filenames
HTML_FILES = $(MD_FILES:.md=.html)

# Default target
all: Makefile $(HTML_FILES) $(OUT_DIR)/learning.html

Makefile: $(SRC_DIR)/0026.txt
	cmm print -f $< -S | sed "s/    `printf '    /\t/g'`" >$@

# Rule to create a markdown file from a source file
$(OUT_DIR)/%.md: $(SRC_DIR)/%.txt
	cmm print -f $< -a > $@

# Rule to create an HTML file from a markdown file
$(OUT_DIR)/%.html: $(OUT_DIR)/%.md
	python convert.py $<

$(OUT_DIR)/learning.html: $(SRC_DIR)/0015.txt
	cmm print -f $< -S | \
	awk "/LINKS_LINE/ { \
	    split(\"$(SOURCES)\", sources, \" \"); \
	    for (i = 1; i <= length(sources); i++) { \
		\"awk '/^# /{ sub(/^# /, \\\"\\\"); print \$0; }' db/\" sources[i] \".txt\" | getline NAME; \
		print \"	<li><a href=\\\"\" sources[i] \".html\\\">\" NAME \"</a></li>\"; \
	    } \
	} 1" > $@

# Target to clean the output directory
clean:
	rm -f $(OUT_DIR)/*

.PHONY: all clean
