Skip to content

Commit

Permalink
Ensure that library dependencies work across Makefiles
Browse files Browse the repository at this point in the history
Since the main Makefile doesn't know the dependencies for the nolibc and
openlibm libraries, create intermediate phony targets.
That scheme ensures, even when one library already exists, that:
- when building a target that depend on that library, a recursive make
  is invoked to check that it is up-to-date,
- if the recursive make doesn't update the library, the dependency on
  the library is not a reason to rebuild the target.
  • Loading branch information
shym committed May 6, 2024
1 parent bfd0096 commit 0289971
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@ LIBS := openlibm/libopenlibm.a nolibc/libnolibc.a
LIB_CFLAGS=-I$(TOP)/nolibc/include -include _solo5/overrides.h

# NOLIBC
# Use a phony target indirection, so that nolibc/Makefile is always checked to
# see whether the library should be rebuilt while avoiding useless rebuild if
# nolibc/libnolibc.a was up-to-date
NOLIBC_CFLAGS=$(LIB_CFLAGS) -I$(TOP)/openlibm/src -I$(TOP)/openlibm/include
nolibc/libnolibc.a:
nolibc/libnolibc.a: phony-nolibc

.PHONY: phony-nolibc
phony-nolibc:
$(MAKE) -C nolibc libnolibc.a \
"CC=$(MAKECONF_TOOLCHAIN)-cc" \
"FREESTANDING_CFLAGS=$(NOLIBC_CFLAGS)"

# OPENLIBM
openlibm/libopenlibm.a:
# See NOLIBC for explanations of the phony target
openlibm/libopenlibm.a: phony-openlibm

.PHONY: phony-openlibm
phony-openlibm:
$(MAKE) -C openlibm libopenlibm.a \
"CC=$(MAKECONF_TOOLCHAIN)-cc" \
"CPPFLAGS=$(LIB_CFLAGS)"
Expand Down

0 comments on commit 0289971

Please sign in to comment.