Skip to content

Commit

Permalink
[Build] Cleanup Makefile rules to avoid random build failures.
Browse files Browse the repository at this point in the history
When building the programs with LOC enabled (i.e. generated
files mode), ensure that the generated loc_filenames.c is the
1st file in the list-of-sources defined for each binary being
built. Otherwise, depending on `make` rules, we may end-up
compiling one of the test-sources before the loc.h fileis
generated.

This results in using LOC-ELF mode of LOC-ID, which causes the
link step to fail.

this commit resolves this issue by consistently applying the
rule that, e.g., SINGLE_FILE_CC_PROGRAM_GENSRC, is listed as
the 1st item in SINGLE_FILE_CC_PROGRAM_TESTSRC . And, so on for
other program binaries.
  • Loading branch information
gapisback committed Apr 11, 2024
1 parent 8a78ff9 commit 087eff6
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ help::
# Verbosity
#
ifndef BUILD_VERBOSE
BUILD_VERBOSE=0
BUILD_VERBOSE := 0
endif

# Setup echo formatting for messages.
ifeq "$(BUILD_VERBOSE)" "1"
ifeq ($(BUILD_VERBOSE), 1)
COMMAND=
PROLIX=@echo
BRIEF=@ >/dev/null echo
# Always print message describe step executed, even in verbose mode.
# BRIEF_FORMATTED=@ >/dev/null echo
BRIEF_FORMATTED=@printf
BRIEF_PARTIAL=@echo -n >/dev/null
else ifeq "$(BUILD_VERBOSE)" "0"
else ifeq ($(BUILD_VERBOSE), 0)
COMMAND=@
PROLIX=@ >/dev/null echo
BRIEF=@echo
Expand Down Expand Up @@ -264,9 +264,36 @@ clean:
####################################################################
# The main targets
#
all: all-tests all-test-code

all-tests: $(BINDIR)/unit_test
all-test-code: $(TEST_CODE_BINS)
all: all-tests all-test-code

ifeq ($(BUILD_VERBOSE), 1)
$(info ------ Debug ---------------------------------------------------------)
$(info $$TEST_CODE_SRC = [${TEST_CODE_SRC}])
$(info )

$(info $$TEST_CODE_OBJS = [${TEST_CODE_OBJS}])
$(info )

$(info $$TEST_CODE_BIN_SRC = [${TEST_CODE_BIN_SRC}])
$(info )

$(info $$TEST_CODE_BINS = [${TEST_CODE_BINS}])
$(info )

$(info $$UNIT_TESTSRC = [${UNIT_TESTSRC}])
$(info )

$(info $$GENERATED_OBJS = [${GENERATED_OBJS}])
$(info )

$(info $$UNIT_TESTOBJS = [${UNIT_TESTOBJS}])
$(info )

endif


# ###################################################################
# CFLAGS, LDFLAGS, ETC
Expand Down Expand Up @@ -337,6 +364,12 @@ $(BINDIR)/unit_test: $(UNIT_TESTOBJS)
# There can be more than one .o's linked to create test-code example
# program.

# -----------------------------------------------------------------------------
# You have to list the generated file 1st in the list, so it gets generated
# up-front. Otherwise, the core test-code/single-file-cpp-program/single-file-main.cpp
# file will get compiled first without the generated loc.h, thereby, #include'ing
# include/loc.h . This will cause builds (make all-test-code) to fail in normal
# build mode.
# -----------------------------------------------------------------------------
SINGLE_FILE_PROGRAM_TESTSRC := $(SINGLE_FILE_PROGRAM_GENSRC)
SINGLE_FILE_PROGRAM_TESTSRC += $(shell find $(TEST_CODE)/single-file-program -type f -name *.c -print)
Expand All @@ -346,23 +379,20 @@ SINGLE_FILE_PROGRAM_OBJS := $(SINGLE_FILE_PROGRAM_TESTSRC:%.c=$(OBJDIR)/%.o)
$(BINDIR)/$(TEST_CODE)/single-file-program: $(SINGLE_FILE_PROGRAM_OBJS)

# -----------------------------------------------------------------------------
TWO_FILES_PROGRAM_TESTSRC := $(shell find $(TEST_CODE)/two-files-program -type f -name *.c -print)
TWO_FILES_PROGRAM_TESTSRC += $(TWO_FILES_PROGRAM_GENSRC)
TWO_FILES_PROGRAM_TESTSRC := $(TWO_FILES_PROGRAM_GENSRC)
TWO_FILES_PROGRAM_TESTSRC += $(shell find $(TEST_CODE)/two-files-program -type f -name *.c -print)

TWO_FILES_PROGRAM_OBJS := $(TWO_FILES_PROGRAM_TESTSRC:%.c=$(OBJDIR)/%.o)

$(BINDIR)/$(TEST_CODE)/two-files-program: $(TWO_FILES_PROGRAM_OBJS)
$(BINDIR)/$(TEST_CODE)/single-file-program: $(OBJDIR)/$(TEST_CODE)/single-file-program/single-file-main.o

$(BINDIR)/$(TEST_CODE)/two-files-program: $(OBJDIR)/$(TEST_CODE)/two-files-program/two-files-main.o \
$(OBJDIR)/$(TEST_CODE)/two-files-program/two-files-file1.o

# -----------------------------------------------------------------------------
SINGLE_FILE_CPP_PROGRAM_TESTSRC := $(SINGLE_FILE_CPP_PROGRAM_GENSRC)
SINGLE_FILE_CPP_PROGRAM_TESTSRC += $(shell find $(TEST_CODE)/single-file-cpp-program -type f -name *.cpp -print)

SINGLE_FILE_CPP_PROGRAM_TMP := $(SINGLE_FILE_CPP_PROGRAM_TESTSRC:%.cpp=$(OBJDIR)/%.o)
SINGLE_FILE_CPP_PROGRAM_OBJS := $(SINGLE_FILE_CPP_PROGRAM_TMP:%.c=$(OBJDIR)/%.o)

$(BINDIR)/$(TEST_CODE)/single-file-cpp-program: $(SINGLE_FILE_CPP_PROGRAM_OBJS)

# -----------------------------------------------------------------------------
Expand All @@ -371,6 +401,7 @@ SINGLE_FILE_CC_PROGRAM_TESTSRC += $(shell find $(TEST_CODE)/single-file-cc-progr

SINGLE_FILE_CC_PROGRAM_TMP := $(SINGLE_FILE_CC_PROGRAM_TESTSRC:%.cc=$(OBJDIR)/%.o)
SINGLE_FILE_CC_PROGRAM_OBJS := $(SINGLE_FILE_CC_PROGRAM_TMP:%.c=$(OBJDIR)/%.o)

$(BINDIR)/$(TEST_CODE)/single-file-cc-program: $(SINGLE_FILE_CC_PROGRAM_OBJS)

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -417,17 +448,6 @@ $(BINDIR)/%: | $$(@D)/.

unit_test: $(BINDIR)/unit_test

ifeq "$(BUILD_VERBOSE)" "1"
@echo
$(info $$TEST_CODE_SRC = [${TEST_CODE_SRC}])
$(info $$TEST_CODE_OBJS = [${TEST_CODE_OBJS}])
$(info $$TEST_CODE_BIN_SRC = [${TEST_CODE_BIN_SRC}])
$(info $$TEST_CODE_BINS = [${TEST_CODE_BINS}])
$(info $$UNIT_TESTSRC = [${UNIT_TESTSRC}])
$(info $$GENERATED_OBJS = [${GENERATED_OBJS}])
$(info $$UNIT_TESTOBJS = [${UNIT_TESTOBJS}])
endif

# ###################################################################
# Testing
#
Expand Down

0 comments on commit 087eff6

Please sign in to comment.