-PRE_SRCS = $(patsubst ./%, %, \
- $(wildcard $(patsubst %, %/*.hs, . $(ALL_DIRS))) \
- $(wildcard $(patsubst %, %/*.lhs, . $(ALL_DIRS))) \
- $(wildcard $(patsubst %, %/*.y, . $(ALL_DIRS))) \
- $(wildcard $(patsubst %, %/*.c, . $(ALL_DIRS))) \
- $(wildcard $(patsubst %, %/*.prl, . $(ALL_DIRS))) \
- $(wildcard $(patsubst %, %/*.lprl, . $(ALL_DIRS))) \
- $(wildcard $(patsubst %, %/*.lit, . $(ALL_DIRS))) \
- $(wildcard $(patsubst %, %/*.verb, . $(ALL_DIRS))) \
- $(wildcard $(patsubst %, %/*.hsc, . $(ALL_DIRS))) \
- )
+# NB. use := rather than = here, otherwise the wildcard will get re-computed
+# every time PRE_SRCS is expanded (this happens a lot).
+PRE_SRCS := $(wildcard $(patsubst ./%, %, \
+ $(patsubst %,%/*.hs, . $(ALL_DIRS)) \
+ $(patsubst %,%/*.lhs, . $(ALL_DIRS)) \
+ $(patsubst %,%/*.y, . $(ALL_DIRS)) \
+ $(patsubst %,%/*.c, . $(ALL_DIRS)) \
+ $(patsubst %,%/*.hc, . $(ALL_DIRS)) \
+ $(patsubst %,%/*.S, . $(ALL_DIRS)) \
+ $(patsubst %,%/*.prl, . $(ALL_DIRS)) \
+ $(patsubst %,%/*.lprl, . $(ALL_DIRS)) \
+ $(patsubst %,%/*.lit, . $(ALL_DIRS)) \
+ $(patsubst %,%/*.verb, . $(ALL_DIRS)) \
+ $(patsubst %,%/*.hsc, . $(ALL_DIRS)) \
+ ))
+
+PRE_HS_SRCS = $(filter %.hs, $(PRE_SRCS))
+PRE_LHS_SRCS = $(filter %.lhs, $(PRE_SRCS))