Skip to content

Commit

Permalink
Merge pull request #469 from jtraglia/improve-makefile
Browse files Browse the repository at this point in the history
Fix Makefile dependencies
  • Loading branch information
asn-d6 authored Aug 5, 2024
2 parents 17cf3d5 + c833fca commit 387685e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
37 changes: 22 additions & 15 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,21 @@ BLST_BUILDSCRIPT_FLAGS = -D__BLST_PORTABLE__
# Libraries to build with.
LIBS = $(BLST_LIBRARY)

# List of individual implementation files.
IMPL_FILES = common.c eip4844.c eip7594.c setup.c
# Create file lists.
SOURCE_FILES := $(shell find . -name '*.c' | sed 's|^\./||' | sort)
HEADER_FILES := $(patsubst %.c, %.h, $(SOURCE_FILES))
OBJECT_FILES := $(patsubst %.c, %.o, $(SOURCE_FILES))

# There is no tests header file.
HEADER_FILES := $(filter-out tests.h, $(HEADER_FILES))
# We don't want to format this and it is not expected to change.
HEADER_FILES := $(filter-out tinytest.h, $(HEADER_FILES))

###############################################################################
# Core
###############################################################################

all: ckzg.o test
all: $(OBJECT_FILES) test

$(BLST_BUILDSCRIPT):
@git submodule update --init
Expand All @@ -61,8 +68,8 @@ $(BLST_LIBRARY): $(BLST_BUILDSCRIPT)
blst: $(BLST_LIBRARY)

tests: CFLAGS += -O0
tests: tests.c $(BLST_LIBRARY)
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
tests: $(SOURCE_FILES) $(HEADER_FILES) $(BLST_LIBRARY)
@$(CC) $(CFLAGS) -o $@ tests.c $(LIBS)

.PHONY: test
test: tests
Expand All @@ -73,17 +80,17 @@ test: tests
###############################################################################

tests_cov: CFLAGS += -O0 -fprofile-instr-generate -fcoverage-mapping
tests_cov: tests.c ckzg.c
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
tests_cov: $(SOURCE_FILES) $(HEADER_FILES) $(BLST_LIBRARY)
@$(CC) $(CFLAGS) -o $@ tests.c $(LIBS)

.PHONY: coverage
coverage: tests_cov
@LLVM_PROFILE_FILE="ckzg.profraw" ./$<
@$(XCRUN) llvm-profdata merge --sparse ckzg.profraw -o ckzg.profdata
@$(XCRUN) llvm-cov show --instr-profile=ckzg.profdata --format=html \
$< $(IMPL_FILES) > coverage.html
$< $(SOURCE_FILES) > coverage.html
@$(XCRUN) llvm-cov report --instr-profile=ckzg.profdata \
--show-functions $< $(IMPL_FILES)
--show-functions $< $(SOURCE_FILES)

###############################################################################
# Profile
Expand All @@ -95,8 +102,8 @@ ifeq ($(PLATFORM),Darwin)
tests_prof: CFLAGS += -L$(shell brew --prefix gperftools)/lib
tests_prof: CFLAGS += -I$(shell brew --prefix gperftools)/include
endif
tests_prof: tests.c
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
tests_prof: $(SOURCE_FILES) $(HEADER_FILES) $(BLST_LIBRARY)
@$(CC) $(CFLAGS) -o $@ tests.c $(LIBS)

.PHONY: run_profiler
run_profiler: tests_prof
Expand Down Expand Up @@ -126,9 +133,9 @@ profile: \

.PHONY: sanitize_%
sanitize_%: CFLAGS += -O0 -fsanitize=$*
sanitize_%: tests.c
sanitize_%: $(SOURCE_FILES) $(HEADER_FILES) $(BLST_LIBRARY)
@echo Running sanitize=$*...
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
@$(CC) $(CFLAGS) -o $@ tests.c $(LIBS)
@ASAN_OPTIONS=allocator_may_return_null=1 \
LSAN_OPTIONS=allocator_may_return_null=1 \
./$@; rm $@
Expand All @@ -151,7 +158,7 @@ endif
###############################################################################

.PHONY: analyze
analyze: $(IMPL_FILES)
analyze: $(SOURCE_FILES) $(HEADER_FILES)
@$(CC) --analyze -Xanalyzer -analyzer-output=html \
-o analysis-report $(CFLAGS) -c $<
@[ -d analysis-report ] && exit 1 || exit 0
Expand All @@ -162,7 +169,7 @@ analyze: $(IMPL_FILES)

.PHONY: format
format:
@clang-format -i --sort-includes common.* eip4844.* eip7594.* setup.* debug.* ckzg.* tests.c
@clang-format -i --sort-includes $(SOURCE_FILES) $(HEADER_FILES)

.PHONY: clean
clean:
Expand Down
2 changes: 2 additions & 0 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "debug.h"

#include <stdio.h>

void print_bytes32(const Bytes32 *bytes) {
for (size_t i = 0; i < 32; i++) {
printf("%02x", bytes->bytes[i]);
Expand Down
4 changes: 3 additions & 1 deletion src/eip4844.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

#include "blst.h"

#include <assert.h>
#include <assert.h> /* For assert */
#include <stdlib.h> /* For NULL */
#include <string.h> /* For memcpy */

////////////////////////////////////////////////////////////////////////////////////////////////////
// Macros
Expand Down
5 changes: 3 additions & 2 deletions src/eip7594.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
#include "blst.h"
#include "common.h"

#include <inttypes.h>
#include <stdio.h>
#include <assert.h> /* For assert */
#include <stdlib.h> /* For NULL */
#include <string.h> /* For memcpy */

////////////////////////////////////////////////////////////////////////////////////////////////////
// Constants
Expand Down
6 changes: 6 additions & 0 deletions src/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "eip4844.h"
#include "eip7594.h"

#include <assert.h> /* For assert */
#include <inttypes.h> /* For SCNu64 */
#include <stdio.h> /* For FILE */
#include <stdlib.h> /* For NULL */
#include <string.h> /* For memcpy */

////////////////////////////////////////////////////////////////////////////////////////////////////
// Macros
////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 387685e

Please sign in to comment.