-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
6,618 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
# paths | ||
PREFIX = /usr | ||
TARGET_PREFIX ?= $(PREFIX) | ||
|
||
TARGET_CC := $(CROSS_COMPILE)gcc | ||
TARGET_AR := $(CROSS_COMPILE)ar | ||
TARGET_CFLAGS := -Wvla -O2 -g -Wall -pedantic -Wextra -Iinclude -Iinclude/libcmt/ioctl | ||
CFLAGS := -Wvla -O2 -g -Wall -pedantic -Wextra -fsanitize=address,undefined -Iinclude -Iinclude/libcmt/mock | ||
|
||
ALL := ioctl.build mock.build tools.build docs.build tests.run | ||
all: $(ALL) | ||
|
||
#------------------------------------------------------------------------------- | ||
examples_SRC := \ | ||
doc/examples/io.c \ | ||
doc/examples/rollup.c | ||
|
||
examples_OBJDIR := .build/examples/ | ||
examples_OBJ := $(patsubst %.c,$(examples_OBJDIR)%.o,$(examples_SRC)) | ||
|
||
$(examples_OBJ): $(examples_OBJDIR)%.o: %.c | ||
@mkdir -p $(@D) | ||
$(CC) $(CFLAGS) -MT $@ -MMD -MP -MF $(@:.o=.d) -c -o $@ $< | ||
|
||
# no need to link, just ensure examples build correctly | ||
examples.build: $(examples_OBJ) | ||
|
||
#------------------------------------------------------------------------------- | ||
ioctl_SRC := \ | ||
src/buf.c \ | ||
src/abi.c \ | ||
src/keccak.c \ | ||
src/merkle.c \ | ||
src/merkle-table.c \ | ||
src/rollup.c \ | ||
src/ioctl/io.c | ||
|
||
ioctl_OBJDIR := .build/ioctl/ | ||
ioctl_OBJ := $(patsubst %.c,$(ioctl_OBJDIR)%.o,$(ioctl_SRC)) | ||
|
||
$(ioctl_OBJ): $(ioctl_OBJDIR)%.o: %.c | ||
@mkdir -p $(@D) | ||
$(TARGET_CC) $(TARGET_CFLAGS) -MT $@ -MMD -MP -MF $(@:.o=.d) -c -o $@ $< | ||
|
||
libcmt.a: $(ioctl_OBJ) | ||
$(TARGET_AR) rcs $@ $^ | ||
|
||
$(ioctl_OBJDIR)io_echo: src/tests/io_echo.c libcmt.a | ||
$(TARGET_CC) $(TARGET_CFLAGS) -o $@ $^ | ||
|
||
$(ioctl_OBJDIR)rollup: src/tests/rollup.c libcmt.a | ||
$(TARGET_CC) $(TARGET_CFLAGS) -o $@ $^ | ||
|
||
ioctl.build: libcmt.a $(ioctl_OBJDIR)io_echo $(ioctl_OBJDIR)rollup | ||
ioctl.install: libcmt.a | ||
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib | ||
cp -f $< $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib | ||
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/ | ||
cp -f include/libcmt/*.h $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/ | ||
cp -f include/libcmt/ioctl/*.h $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/ | ||
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig | ||
sed \ | ||
-e 's|@ARG_PREFIX@|$(TARGET_PREFIX)|g' \ | ||
tools/templates/libcmt.pc > $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig/libcmt.pc | ||
|
||
#------------------------------------------------------------------------------- | ||
mock_SRC := \ | ||
src/abi.c \ | ||
src/buf.c \ | ||
src/keccak.c \ | ||
src/merkle.c \ | ||
src/merkle-table.c \ | ||
src/rollup.c \ | ||
src/mock/io.c | ||
|
||
mock_OBJDIR := .build/mock/ | ||
mock_OBJ := $(patsubst %.c,$(mock_OBJDIR)%.o,$(mock_SRC)) | ||
|
||
$(mock_OBJ): $(mock_OBJDIR)%.o: %.c | ||
@mkdir -p $(@D) | ||
$(CC) $(CFLAGS) -MT $@ -MMD -MP -MF $(@:.o=.d) -c -o $@ $< | ||
|
||
libcmt_mock.a: $(mock_OBJ) | ||
$(AR) rcs $@ $^ | ||
|
||
$(mock_OBJDIR)io_echo: src/tests/io_echo.c libcmt_mock.a | ||
$(CC) $(CFLAGS) -o $@ $^ | ||
|
||
$(mock_OBJDIR)rollup: src/tests/rollup.c libcmt_mock.a | ||
$(CC) $(CFLAGS) -o $@ $^ | ||
|
||
mock.build: libcmt_mock.a $(mock_OBJDIR)io_echo $(mock_OBJDIR)rollup | ||
|
||
mock.install: libcmt_mock.a | ||
mkdir -p $(DESTDIR)$(PREFIX)/lib | ||
cp -f $< $(DESTDIR)$(PREFIX)/lib | ||
mkdir -p $(DESTDIR)$(PREFIX)/include/libcmt/mock | ||
cp -f include/libcmt/*.h $(DESTDIR)$(PREFIX)/include/libcmt/ | ||
cp -f include/libcmt/mock/*.h $(DESTDIR)$(PREFIX)/include/libcmt/mock/ | ||
mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig | ||
sed \ | ||
-e 's|@ARG_PREFIX@|$(PREFIX)|g' \ | ||
tools/templates/libcmt_mock.pc > $(DESTDIR)$(PREFIX)/lib/pkgconfig/libcmt_mock.pc | ||
|
||
#------------------------------------------------------------------------------- | ||
testdata: | ||
cast calldata "EvmAdvance(address,uint256,uint256,uint256,bytes)" \ | ||
`cast address-zero` 1 2 3 0xdeadbeef | xxd -r -p > dat/C.bin | ||
cast calldata "Voucher(address,bytes)" \ | ||
`cast address-zero` 0xdeadbeef | xxd -r -p > dat/C.v0.bin | ||
cast calldata "Notice(bytes)" \ | ||
0xdeadbeef | xxd -r -p > dat/C.n0.bin | ||
xxd -n advance -i dat/C.bin > dat/C.h | ||
xxd -n voucher -i dat/C.v0.bin > dat/C.v0.h | ||
xxd -n notice -i dat/C.n0.bin > dat/C.n0.h | ||
|
||
unittests_BINS := \ | ||
$(mock_OBJDIR)abi-multi \ | ||
$(mock_OBJDIR)abi-single \ | ||
$(mock_OBJDIR)keccak \ | ||
$(mock_OBJDIR)merkle \ | ||
|
||
$(mock_OBJDIR)abi-multi: src/tests/abi-multi.c libcmt_mock.a | ||
$(CC) $(CFLAGS) -o $@ $^ | ||
|
||
$(mock_OBJDIR)abi-single: src/tests/abi-single.c libcmt_mock.a | ||
$(CC) $(CFLAGS) -o $@ $^ | ||
|
||
$(mock_OBJDIR)keccak: src/tests/keccak.c libcmt_mock.a | ||
$(CC) $(CFLAGS) -o $@ $^ | ||
|
||
$(mock_OBJDIR)merkle: src/tests/merkle.c libcmt_mock.a | ||
$(CC) $(CFLAGS) -o $@ $^ | ||
|
||
tests.build: $(unittests_BINS) $(mock_OBJDIR)io_echo | ||
tests.run: tests.build | ||
$(foreach test,$(unittests_BINS),$(test) &&) true | ||
|
||
#------------------------------------------------------------------------------- | ||
tools_OBJDIR := .build/tools/ | ||
|
||
tools_BINS := \ | ||
$(tools_OBJDIR)funsel \ | ||
$(tools_OBJDIR)merkle-table | ||
|
||
$(tools_OBJDIR)funsel: src/tools/funsel.c libcmt_mock.a | ||
@mkdir -p $(@D) | ||
$(CC) $(CFLAGS) -o $@ $^ | ||
|
||
$(tools_OBJDIR)merkle-table: src/tools/merkle-table.c src/keccak.c | ||
@mkdir -p $(@D) | ||
$(CC) $(CFLAGS) -o $@ $^ | ||
|
||
# generated source code | ||
src/merkle.c: src/merkle-table.c | ||
src/merkle-table.c: $(tools_OBJDIR)merkle-table | ||
$< > $@ | ||
|
||
tools.build: $(tools_BINS) | ||
|
||
#------------------------------------------------------------------------------- | ||
|
||
help: | ||
@echo "Targets: (default: '*')" | ||
@echo "* all - $(ALL)" | ||
@echo " mock.build - Build a mocked version of the library, tools and examples; to run on the host system." | ||
@echo " mock.install - install the mocked version of the library and C headers; on the host system." | ||
@echo " Use DESTDIR and PREFIX to customize the installation." | ||
@echo " ioctl.build - Build ioctl version of the library, tools and examples; to run on the cartesi-machine." | ||
@echo " (requires the cartesi Linux headers to build)" | ||
@echo " tests.build - Build tests on top of the mocked library to run on the host system." | ||
@echo " tests.run - Execute the tests." | ||
@echo " tools.build - Build tools on top of the mocked library to run on the host system." | ||
@echo " docs.build - Build the documentation and API references as html." | ||
@echo " clean - remove the binaries and objects." | ||
|
||
doc/theme: | ||
git clone [email protected]:jothepro/doxygen-awesome-css.git $@ | ||
git -C doc/theme checkout 8cea9a073ecd50a5b2c0958a3df100292d6c7374 | ||
|
||
docs.build: doc/theme examples.build | ||
doxygen doc/Doxyfile | ||
|
||
OBJ := $(mock_OBJ) $(ioctl_OBJ) $(examples_OBJ) $(tools_OBJ) | ||
clean: | ||
rm -rf $(OBJ) $(unittests_BINS) $(tools_BINS) libcmt_mock.a libcmt.a | ||
|
||
-include $(OBJ:%.o=%.d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
High level | ||
|
||
- @ref libcmt\_rollup | ||
|
||
Utility | ||
|
||
- @ref libcmt\_abi | ||
- @ref libcmt\_buf | ||
- @ref libcmt\_merkle | ||
- @ref libcmt\_keccak | ||
|
||
Low level | ||
|
||
- @ref libcmt\_io\_driver | ||
|
||
Download the static library from [cartesi tools](https://github.com/cartesi/machine-emulator-tools/). |
Oops, something went wrong.