I have a few PDFLaTeX main files called ch*.tex with numbers replacing the asterick, a PDF file printed by compiling ch*.tex called ch*.pdf, and several LaTeX files input into each ch*.tex during compile that are saved into their respective ch*/ directories. With a Makefile I want my ch*.pdf files to be compiled by ch*.tex files, with TeX files in the ch* subdirectory as additional dependencies, without hardcoding each ch* instances.
However, in some cases the ch* subdirectory may not exist. This changes as my LaTeX projects develops, as some ch*.tex files may be split into subfiles while others may just be one big block file of code. So I want my Makefile to use ch* subdirectory files as dependencies if they exist, but not if they don't. Here are some failed trials:
%.pdf : %.tex %/*.tex
pdflatex $<
This trial successfully detects existing files in the ch* subdirectory, but fails to compile if there is no ch* directory at all.
%.pdf : %.tex $(wildcard %/*.tex)
pdflatex $<
This trial doesn't recognise $(wildcard %/*.tex) as a dependency and only uses ch*.tex.
How can I use files in the ch* subdirectory (without using files in other subdirectories) as dependencies for its respective ch*.pdf compilation?