libswarm-ng

C implementation of BMT hasher, Swarmhash and Single Owner Chunk for swarm
git clone git://git.defalsify.org/libswarm-ng.git
Info | Log | Files | Refs | Submodules | README

Makefile.dev (8493B)


      1 KECCAK_DIR = ./aux/keccak-tiny
      2 SECP256K1_DIR = ./aux/secp256k1
      3 CHECK_DIR = ./aux/check
      4 INCLUDE = -I./src -I$(KECCAK_DIR) -I$(SECP256K1_DIR)/include -I$(CHECK_DIR)/src -I$(CHECK_DIR)
      5 LIBS += -L./build/
      6 CFLAGS += $(INCLUDE) $(LIBS)
      7 CFLAGS_CHECK = $(CFLAGS) -L./build/test -L./aux/check/src/.libs ./aux/secp256k1/.libs/libsecp256k1.a
      8 LD_LIBRARY_PATH = ./build/:./build/test:./aux/secp256k1/.libs:./aux/check/src/.libs
      9 prefix = /usr/local
     10 includedir = $(prefix)/include
     11 libdir = $(prefix)/lib
     12 wasm_cc = /usr/bin/clang
     13 wasm_libcdir = /opt/wasi-libc
     14 wasm_libdir = $(wasm_libcdir)/lib/wasm32-wasi
     15 wasm_target = wasm32-unknown-wasi
     16 wasm_cflags = -I./src/wasm -m32 --target=$(wasm_target) -Wl,--import-memory -Wl,--import-table -Wl,--allow-undefined -Wl,--no-entry -nostdlib -nostartfiles -DLIBSWARM_MALLOC
     17 wasm_cflags_stdlib = $(wasm_cflags) --sysroot $(wasm_libcdir)
     18 
     19 prep:
     20 	mkdir -vp build/lib build/include build/test build/wasm
     21 	
     22 build_keccak: prep
     23 	$(CC) -D"memset_s(W,WL,V,OL)=memset(W,V,OL)" $(CFLAGS) -O3 -march=native -std=c11 -Wextra -Wpedantic -Wall -rdynamic --shared $(KECCAK_DIR)/keccak-tiny.c -o build/libkeccak-tiny.so
     24 	$(CC) -D"memset_s(W,WL,V,OL)=memset(W,V,OL)" $(CFLAGS) -Os -march=native -std=c11 -Wextra -Wpedantic -Wall -rdynamic --shared $(KECCAK_DIR)/keccak-tiny.c -o build/libkeccak-tiny-small.so
     25 	$(CC) -D"memset_s(W,WL,V,OL)=memset(W,V,OL)" $(CFLAGS) -O3 -march=native -std=c11 -Wextra -Wpedantic -Wall $(KECCAK_DIR)/keccak-tiny.c -c -o build/libkeccak.o
     26 	$(CC) -D"memset_s(W,WL,V,OL)=memset(W,V,OL)" $(CFLAGS) -Os -march=native -std=c11 -Wextra -Wpedantic -Wall $(KECCAK_DIR)/keccak-tiny.c -c -o build/libkeccak-tiny-small.o
     27 	$(CC) -D"memset_s(W,WL,V,OL)=memset(W,V,OL)" $(CFLAGS) -Os -march=native -std=c11 -Wextra -Wpedantic -Wall --static $(KECCAK_DIR)/keccak-tiny.c -c -o build/libkeccak-tiny-small.a
     28 
     29 build_base: prep build_keccak
     30 	$(CC) -c -o build/bmt.o src/bmt.c $(CFLAGS) -lkeccak-tiny
     31 	$(CC) -c -o build/endian.o $(CFLAGS) src/endian.c
     32 	$(CC) -c -o build/swarmfile.o $(CFLAGS) src/swarmfile.c
     33 	$(CC) -c -o build/swarm.o $(CFLAGS) src/swarm.c
     34 	$(CC) -c -o build/chunk.o $(CFLAGS) src/chunk.c
     35 
     36 build_base_malloc: prep build_keccak
     37 	$(CC) -c -o build/bmt.o src/bmt.c $(CFLAGS) -DLIBSWARM_MALLOC -lkeccak-tiny
     38 	$(CC) -c -o build/endian.o $(CFLAGS) -DLIBSWARM_MALLOC src/endian.c
     39 	$(CC) -c -o build/swarmfile.o $(CFLAGS) -DLIBSWARM_MALLOC src/swarmfile.c
     40 	$(CC) -c -o build/swarm.o $(CFLAGS) -DLIBSWARM_MALLOC src/swarm.c
     41 	$(CC) -c -o build/chunk.o $(CFLAGS) -DLIBSWARM_MALLOC src/chunk.c
     42 
     43 
     44 build_secp256k1: prep
     45 
     46 build_keystore: prep build_keccak build_secp256k1
     47 	$(CC) -c -o build/keystore.o -I aux/secp256k1/include -L aux/secp256k1/.libs $(CFLAGS) src/keystore.c
     48 
     49 
     50 build_soc: prep build_keccak build_keystore
     51 	$(CC) -c -o build/soc.o src/soc.c $(CFLAGS) -lkeccak-tiny
     52 
     53 build: build_base
     54 
     55 build_check_common:
     56 	$(CC) -c -o build/hex.o $(CFLAGS) src/hex.c
     57 	$(CC) -c -o build/common.o $(CFLAGS) test/common.c
     58 	ar -rvs build/test/libtestcommon.a build/common.o build/hex.o 
     59 
     60 # TODO: should not be necessary to add -lsecp256k1 here
     61 build_check: build_base_malloc build_check_common
     62 	$(CC) -I./src -o build/test/check_bmt build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_bmt.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon 
     63 	$(CC) -I./src -o build/test/check_bmt_malloc build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_bmt_malloc.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon 
     64 	$(CC) -I./src -o build/test/check_file build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_file.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon
     65 	$(CC) -I./src -o build/test/check_chunk build/chunk.o build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_chunk.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon
     66 
     67 build_check_stack: build_base build_check_common
     68 	$(CC) -I./src -o build/test/check_bmt build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_bmt.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon  -lsecp256k1
     69 
     70 
     71 build_check_keystore: build_base_malloc build_keystore build_check_common
     72 	$(CC) -I./src -o build/test/check_keystore build/swarm.o build/keystore.o test/check_keystore.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon
     73 
     74 
     75 build_check_soc: build_check build_check_common build_soc
     76 	$(CC) -I./src -o build/test/check_soc build/keystore.o build/endian.o build/bmt.o build/chunk.o build/swarm.o build/soc.o test/check_soc.c -L./aux/secp256k1/.libs $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon -lsecp256k1
     77 
     78 build_lib: build
     79 	$(CC) -fPIC -rdynamic --shared -o build/lib/libswarm.so build/swarm.o build/swarmfile.o build/bmt.o build/endian.o
     80 	$(AR) -rvs build/lib/libswarm.a build/swarmfile.o build/swarm.o build/bmt.o build/endian.o build/libkeccak-tiny-small.o
     81 
     82 .PHONY: test clean
     83 
     84 check_bmt: build_check
     85 	LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no CFLAGS=-DLIBSWARM_MALLOC build/test/check_bmt_malloc
     86 
     87 check_bmt_stack: build_check_stack
     88 	LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no CFLAGS=-DLIBSWARM_MALLOC build/test/check_bmt
     89 
     90 check_chunk: build_check
     91 	LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no build/test/check_chunk
     92 
     93 check_file: build_check
     94 	LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no build/test/check_file
     95 
     96 check_base: check_bmt check_chunk check_file
     97 
     98 check_keystore: build_check_keystore
     99 	LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no build/test/check_keystore
    100 
    101 check_soc: build_check_soc
    102 	LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no build/test/check_soc
    103 
    104 # TODO: file test is flaky, check_base should be first instead
    105 check: check_keystore check_soc check_base
    106 
    107 test: check
    108 
    109 clean:
    110 	rm -vrf build/*
    111 
    112 install_prep: build_lib
    113 	cp -v src/bmt.h build/include/
    114 
    115 install:
    116 	install -vd $(includedir)
    117 	install -vd $(libdir)
    118 	install -vDm 0644 build/include/*.h $(includedir)/
    119 	install -vDm 0644 build/lib/*.a $(libdir)/
    120 	install -vDm 0644 build/lib/*.so $(libdir)/
    121 
    122 wasm_prep:
    123 	mkdir -vp build/wasm
    124 
    125 wasm_base: wasm_prep 
    126 	#clang $(CFLAGS) $(wasm_cflags_stdlib) -static -Wl,--export="bmt_hash" -Wl,--export="bmt_hash_heap_init" -Wl,--export="bmt_hash_heap_free" -o build/wasm/swarm.wasm src/wasm.c build/lib/libswarm.a
    127 	clang $(CFLAGS) $(wasm_cflags_stdlib) -c -Wl,--export-all -Os -o build/wasm/wasm_o.wasm src/wasm/wasm.c
    128 	clang $(CFLAGS) $(wasm_cflags_stdlib) -c -Wl,--export="bmt_sum" -Os  -Wl,--export="bmt_init_ptr" -Wl,--export="bmt_hash" -o build/wasm/bmt_o.wasm -c src/bmt.c
    129 	clang $(CFLAGS) $(wasm_cflags_stdlib) -c -Wl,--export="keccak_hash_btc" -Os -o build/wasm/swarm_o.wasm -c src/swarm.c
    130 	clang $(CFLAGS) $(wasm_cflags) -c -Wl,--export="to_endian" -Os -o build/wasm/endian_o.wasm src/endian.c
    131 	clang $(CFLAGS) $(wasm_cflags_stdlib) -c -D"memset_s(W,WL,V,OL)=memset(W,V,OL)" -Os -march=native -std=c11 -Wextra -Wpedantic -Wall -Wl,--export="keccak_hash_heap_init" -Wl,--export="keccak_hash" -o build/wasm/keccak_o.wasm aux/keccak-tiny/keccak-tiny.c
    132 
    133 wasm_libc: wasm_base
    134 	clang $(CFLAGS) $(wasm_cflags_stdlib) -D"memset_s(W,WL,V,OL)=memset(W,V,OL)" -Os -march=native -std=c11 -Wextra -Wpedantic -Wall -Wl,--export="keccak_hash_heap_init" -Wl,--export="keccak_hash_heap_free" -Wl,--export="keccak_hash" -o build/wasm/keccak.wasm build/wasm/keccak_o.wasm build/wasm/wasm_o.wasm  $(wasm_libdir)/libc.a
    135 	clang $(CFLAGS) $(wasm_cflags_stdlib) -D"memset_s(W,WL,V,OL)=memset(W,V,OL)" -Os -march=native -std=c11 -Wextra -Wpedantic -Wall -Wl,--export="bmt_hash"  -Wl,--export="bmt_hash_free" -Wl,--export="bmt_hash_heap" -o build/wasm/swarm.wasm build/wasm/endian_o.wasm build/wasm/keccak_o.wasm build/wasm/bmt_o.wasm build/wasm/swarm_o.wasm build/wasm/wasm_o.wasm $(wasm_libdir)/libc.a
    136 
    137 wasm_native: wasm_base
    138 	clang $(CFLAGS) $(wasm_cflags_stdlib) -c -Wl,--export-all -Os -o build/wasm/common_o.wasm src/wasm/common.c
    139 	clang $(CFLAGS) $(wasm_cflags_stdlib) -D"memset_s(W,WL,V,OL)=memset(W,V,OL)" -Os -march=native -std=c11 -Wextra -Wpedantic -Wall -Wl,--export="keccak_hash_heap_init" -Wl,--export="keccak_hash_heap_free" -Wl,--export="keccak_hash" -o build/wasm/keccak.wasm build/wasm/keccak_o.wasm build/wasm/wasm_o.wasm  build/wasm/common_o.wasm
    140 	clang $(CFLAGS) $(wasm_cflags_stdlib) -D"memset_s(W,WL,V,OL)=memset(W,V,OL)" -Os -march=native -std=c11 -Wextra -Wpedantic -Wall -Wl,--export="bmt_hash"  -Wl,--export="bmt_hash_free" -Wl,--export="bmt_hash_heap" -o build/wasm/swarm.wasm build/wasm/endian_o.wasm build/wasm/keccak_o.wasm build/wasm/bmt_o.wasm build/wasm/swarm_o.wasm build/wasm/wasm_o.wasm build/wasm/common_o.wasm