2017-04-25 14:41:48 +02:00
|
|
|
# You shouldn't need to edit this file, see the defs.mak file
|
|
|
|
|
|
|
|
|
|
module: lib${MODULE}.o
|
|
|
|
|
|
build: per-file automatic dependencies (.deps), retire the Depend/sed machinery
Replace the monolithic per-directory `Depend` file -- generated by a separate,
serial `make depend` pass (one `gcc -MM` over all sources) and post-processed by
sed -- with automake-style per-file dependency fragments produced as a side
effect of each compile.
rules.mak's %.o rule now adds, when the compiler supports it,
-MMD -MP -MF .deps/<stem>.d
so every object records the (non-system) headers it used. Those fragments are
`-include`d best-effort: absent on a first build, present and correct after.
Benefits:
* self-maintaining -- no explicit depend step; deps refresh on every compile;
* parallel -- generated during the (already parallel) compile, no barrier;
* -MMD already drops system headers (what the sed did) and -MP tolerates a
removed/renamed header, so the sed post-processing is gone;
* fixes out-of-tree incremental header tracking: with an absolute srcdir the
old sed stripped the now-absolute *local* header paths too, silently losing
them; the .d files keep them.
configure probes `-MMD -MP` (AUTODEP_FLAGS; empty and best-effort-skipped if the
compiler cannot). clean/distclean remove .deps (rm -r); .gitignore replaces the
obsolete */Depend with .deps/. `make depend` is kept as a no-op for callers that
still invoke it (e.g. the WASM build script).
Verified out-of-tree (--disable-ccache): 324 .d files, 0 Depend files, a header
touch recompiles its dependents, no-op rebuild is idle, clean clears .deps. (The
top-level depend phase still runs here as a no-op; removed next.)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 16:47:29 +02:00
|
|
|
# Dependencies are now generated automatically as a side effect of each compile
|
|
|
|
|
# (see the %.o rule below); "make depend" is a no-op kept only so scripts/habits
|
|
|
|
|
# that still invoke it do not error.
|
|
|
|
|
.PHONY: depend
|
|
|
|
|
depend:
|
|
|
|
|
|
|
|
|
|
# Compile a source into an object. When the compiler supports it
|
|
|
|
|
# (AUTODEP_FLAGS = "-MMD -MP"), also write .deps/<stem>.d listing the non-system
|
|
|
|
|
# headers this object used -- generated as a side effect of the compile, so there
|
|
|
|
|
# is no separate serial "make depend" pass and it parallelises for free. -MMD
|
|
|
|
|
# already drops system headers (the job the old sed did), and -MP adds a phony
|
|
|
|
|
# target per header so a later removed/renamed header does not break the build.
|
rules.mak: fix module Depend and build rules
The ../database/database.h dependency is already described (only when
necessary) inside the Depend file for the specific complication unit.
Not all objects are affected by database.h changes, so it doesn't need
to be forced as a dependency for all OBJS.
Depend itself was never rebuilt when a source file changed. This now
happens, however technically the superior MAKE process needs to restart
so it includes the new updated copy of Depend file we just updated.
However in practice when developing, modifying #include directives does
not happen often and doing 'make; make' will fix the issue performing
an incremental build both times. So a minor caveat.
Previously when a single source file was changed the entire module was
recompiled, but we have a Depends file to manage the incremental build
problem and we are not really using it (if we always recompile the entire
module due to any one file change, there would be no need for Depends).
Now when developing, a single *.c file change results in the Depends
being rebuilt, then the single file compiled, then the module relinked.
This is exactly the kind of incremental build speedup having a Depends
file is designed to achieve.
Additionally the use of a direct pipeline to create the file does not
manage error scenarios. MAKE itself is driven by file existance and
their timestamps for targets, so even if 'make depend' failed, it
would still create an output file that MAKE can not distunguish
between a well formed (possibly empty) Depend file and an incorrectly
created partial. So building in a *.tmp file first and only if all the
commands are successful then rename to target filename. This has the
effect of making 'make depend' able to fail now.
2024-10-16 11:49:46 +02:00
|
|
|
%.o: %.c
|
2017-04-25 14:41:48 +02:00
|
|
|
@echo --- compiling ${MODULE}/$*.o
|
build: per-file automatic dependencies (.deps), retire the Depend/sed machinery
Replace the monolithic per-directory `Depend` file -- generated by a separate,
serial `make depend` pass (one `gcc -MM` over all sources) and post-processed by
sed -- with automake-style per-file dependency fragments produced as a side
effect of each compile.
rules.mak's %.o rule now adds, when the compiler supports it,
-MMD -MP -MF .deps/<stem>.d
so every object records the (non-system) headers it used. Those fragments are
`-include`d best-effort: absent on a first build, present and correct after.
Benefits:
* self-maintaining -- no explicit depend step; deps refresh on every compile;
* parallel -- generated during the (already parallel) compile, no barrier;
* -MMD already drops system headers (what the sed did) and -MP tolerates a
removed/renamed header, so the sed post-processing is gone;
* fixes out-of-tree incremental header tracking: with an absolute srcdir the
old sed stripped the now-absolute *local* header paths too, silently losing
them; the .d files keep them.
configure probes `-MMD -MP` (AUTODEP_FLAGS; empty and best-effort-skipped if the
compiler cannot). clean/distclean remove .deps (rm -r); .gitignore replaces the
obsolete */Depend with .deps/. `make depend` is kept as a no-op for callers that
still invoke it (e.g. the WASM build script).
Verified out-of-tree (--disable-ccache): 324 .d files, 0 Depend files, a header
touch recompiles its dependents, no-op rebuild is idle, clean clears .deps. (The
top-level depend phase still runs here as a no-op; removed next.)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 16:47:29 +02:00
|
|
|
@test -z "${AUTODEP_FLAGS}" || mkdir -p .deps
|
2017-04-25 14:41:48 +02:00
|
|
|
${RM} $*.o
|
build: per-file automatic dependencies (.deps), retire the Depend/sed machinery
Replace the monolithic per-directory `Depend` file -- generated by a separate,
serial `make depend` pass (one `gcc -MM` over all sources) and post-processed by
sed -- with automake-style per-file dependency fragments produced as a side
effect of each compile.
rules.mak's %.o rule now adds, when the compiler supports it,
-MMD -MP -MF .deps/<stem>.d
so every object records the (non-system) headers it used. Those fragments are
`-include`d best-effort: absent on a first build, present and correct after.
Benefits:
* self-maintaining -- no explicit depend step; deps refresh on every compile;
* parallel -- generated during the (already parallel) compile, no barrier;
* -MMD already drops system headers (what the sed did) and -MP tolerates a
removed/renamed header, so the sed post-processing is gone;
* fixes out-of-tree incremental header tracking: with an absolute srcdir the
old sed stripped the now-absolute *local* header paths too, silently losing
them; the .d files keep them.
configure probes `-MMD -MP` (AUTODEP_FLAGS; empty and best-effort-skipped if the
compiler cannot). clean/distclean remove .deps (rm -r); .gitignore replaces the
obsolete */Depend with .deps/. `make depend` is kept as a no-op for callers that
still invoke it (e.g. the WASM build script).
Verified out-of-tree (--disable-ccache): 324 .d files, 0 Depend files, a header
touch recompiles its dependents, no-op rebuild is idle, clean clears .deps. (The
top-level depend phase still runs here as a no-op; removed next.)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 16:47:29 +02:00
|
|
|
${CC} ${CFLAGS} ${CPPFLAGS} ${DFLAGS} ${AUTODEP_FLAGS} $(if ${AUTODEP_FLAGS},-MF .deps/$*.d) -c $< -o $@
|
2017-04-25 14:41:48 +02:00
|
|
|
|
|
|
|
|
lib${MODULE}.o: ${OBJS}
|
|
|
|
|
@echo --- linking lib${MODULE}.o
|
|
|
|
|
${RM} lib${MODULE}.o
|
|
|
|
|
${LINK} ${OBJS} -o lib${MODULE}.o ${EXTERN_LIBS}
|
|
|
|
|
|
|
|
|
|
lib: lib${MODULE}.a
|
|
|
|
|
|
|
|
|
|
lib${MODULE}.a: ${OBJS} ${LIB_OBJS}
|
|
|
|
|
@echo --- archiving lib${MODULE}.a
|
|
|
|
|
${RM} lib${MODULE}.a
|
|
|
|
|
${AR} ${ARFLAGS} lib${MODULE}.a ${OBJS} ${LIB_OBJS}
|
|
|
|
|
${RANLIB} lib${MODULE}.a
|
|
|
|
|
|
|
|
|
|
${MODULE}: lib${MODULE}.o ${EXTRA_LIBS}
|
|
|
|
|
@echo --- building main ${MODULE}
|
|
|
|
|
${RM} ${MODULE}
|
|
|
|
|
${CC} ${CFLAGS} ${CPPFLAGS} ${DFLAGS} lib${MODULE}.o ${EXTRA_LIBS} -o ${MODULE} ${LIBS}
|
|
|
|
|
|
|
|
|
|
${DESTDIR}${BINDIR}/${MODULE}${EXEEXT}: ${MODULE}${EXEEXT}
|
|
|
|
|
${RM} ${DESTDIR}${BINDIR}/${MODULE}${EXEEXT}
|
|
|
|
|
${CP} ${MODULE}${EXEEXT} ${DESTDIR}${BINDIR}
|
|
|
|
|
|
2023-08-29 21:43:11 +02:00
|
|
|
.PHONY: clean
|
2017-04-25 14:41:48 +02:00
|
|
|
clean:
|
|
|
|
|
${RM} ${CLEANS}
|
build: per-file automatic dependencies (.deps), retire the Depend/sed machinery
Replace the monolithic per-directory `Depend` file -- generated by a separate,
serial `make depend` pass (one `gcc -MM` over all sources) and post-processed by
sed -- with automake-style per-file dependency fragments produced as a side
effect of each compile.
rules.mak's %.o rule now adds, when the compiler supports it,
-MMD -MP -MF .deps/<stem>.d
so every object records the (non-system) headers it used. Those fragments are
`-include`d best-effort: absent on a first build, present and correct after.
Benefits:
* self-maintaining -- no explicit depend step; deps refresh on every compile;
* parallel -- generated during the (already parallel) compile, no barrier;
* -MMD already drops system headers (what the sed did) and -MP tolerates a
removed/renamed header, so the sed post-processing is gone;
* fixes out-of-tree incremental header tracking: with an absolute srcdir the
old sed stripped the now-absolute *local* header paths too, silently losing
them; the .d files keep them.
configure probes `-MMD -MP` (AUTODEP_FLAGS; empty and best-effort-skipped if the
compiler cannot). clean/distclean remove .deps (rm -r); .gitignore replaces the
obsolete */Depend with .deps/. `make depend` is kept as a no-op for callers that
still invoke it (e.g. the WASM build script).
Verified out-of-tree (--disable-ccache): 324 .d files, 0 Depend files, a header
touch recompiles its dependents, no-op rebuild is idle, clean clears .deps. (The
top-level depend phase still runs here as a no-op; removed next.)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 16:47:29 +02:00
|
|
|
${RM} -r .deps
|
2017-04-25 14:41:48 +02:00
|
|
|
|
|
|
|
|
tags: ${SRCS} ${LIB_SRCS}
|
2026-07-22 14:33:37 +02:00
|
|
|
ctags $(addprefix $(srcdir)/,${SRCS} ${LIB_SRCS})
|
2017-04-25 14:41:48 +02:00
|
|
|
|
build: per-file automatic dependencies (.deps), retire the Depend/sed machinery
Replace the monolithic per-directory `Depend` file -- generated by a separate,
serial `make depend` pass (one `gcc -MM` over all sources) and post-processed by
sed -- with automake-style per-file dependency fragments produced as a side
effect of each compile.
rules.mak's %.o rule now adds, when the compiler supports it,
-MMD -MP -MF .deps/<stem>.d
so every object records the (non-system) headers it used. Those fragments are
`-include`d best-effort: absent on a first build, present and correct after.
Benefits:
* self-maintaining -- no explicit depend step; deps refresh on every compile;
* parallel -- generated during the (already parallel) compile, no barrier;
* -MMD already drops system headers (what the sed did) and -MP tolerates a
removed/renamed header, so the sed post-processing is gone;
* fixes out-of-tree incremental header tracking: with an absolute srcdir the
old sed stripped the now-absolute *local* header paths too, silently losing
them; the .d files keep them.
configure probes `-MMD -MP` (AUTODEP_FLAGS; empty and best-effort-skipped if the
compiler cannot). clean/distclean remove .deps (rm -r); .gitignore replaces the
obsolete */Depend with .deps/. `make depend` is kept as a no-op for callers that
still invoke it (e.g. the WASM build script).
Verified out-of-tree (--disable-ccache): 324 .d files, 0 Depend files, a header
touch recompiles its dependents, no-op rebuild is idle, clean clears .deps. (The
top-level depend phase still runs here as a no-op; removed next.)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 16:47:29 +02:00
|
|
|
# Per-file dependency fragments written by the %.o rule above. Best effort: none
|
|
|
|
|
# exist on a first build (everything compiles anyway); on later builds they cause
|
|
|
|
|
# a recompile when a used header changes. `-include` tolerates their absence and
|
|
|
|
|
# the `-MP` phony header targets tolerate a removed/renamed header.
|
|
|
|
|
-include $(wildcard .deps/*.d)
|