-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
63 lines (49 loc) · 2.13 KB
/
Copy pathMakefile
File metadata and controls
63 lines (49 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
CC ?= cc
CFLAGS := -O2 -march=native+crypto -Wall -Wextra -std=gnu11
SODIUM_CFLAGS := $(shell pkg-config --cflags libsodium 2>/dev/null)
SODIUM_LIBS := $(shell pkg-config --libs libsodium 2>/dev/null)
ifeq ($(SODIUM_LIBS),)
SODIUM_CFLAGS := -I/opt/homebrew/include -I/usr/local/include
SODIUM_LIBS := -L/opt/homebrew/lib -L/usr/local/lib -lsodium
endif
CFLAGS += $(SODIUM_CFLAGS)
LIBS = -lpthread -lm $(SODIUM_LIBS)
SRCS = src/main.c src/base58.c src/sha256_arm.c src/net.c
OBJS = $(SRCS:.c=.o)
# Metal GPU support (opt-in: make ENABLE_METAL=1)
ifdef ENABLE_METAL
CFLAGS += -DENABLE_METAL
OBJS += src/metal_grind.o
LIBS += -framework Metal -framework Foundation
endif
vain: $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
# Embed Metal shader sources as C byte arrays
src/metal_shader_src.h: src/grind_seed.metal
@echo "Embedding seed shader..."
@echo 'static const unsigned char grind_seed_metal_src[] = {' > $@
@xxd -i < src/grind_seed.metal >> $@
@echo ', 0x00 };' >> $@
src/metal_keypair_shader_src.h: src/grind_keypair.metal src/ed25519_base_table.h
@echo "Embedding keypair shader (with ed25519 table)..."
@sed '/#include "ed25519_base_table.h"/r src/ed25519_base_table.h' src/grind_keypair.metal | sed '/#include "ed25519_base_table.h"/d' > /tmp/keypair_combined.metal
@echo 'static const unsigned char grind_keypair_metal_src[] = {' > $@
@xxd -i < /tmp/keypair_combined.metal >> $@
@echo ', 0x00 };' >> $@
src/metal_grind.o: src/metal_grind.m src/metal_grind.h src/metal_shader_src.h src/metal_keypair_shader_src.h
$(CC) $(CFLAGS) -fobjc-arc -c -o $@ $<
# Dependencies
src/main.o: src/main.c src/base58.h src/sha256_arm.h src/net.h
src/net.o: src/net.c src/net.h
src/base58.o: src/base58.c src/base58.h
src/sha256_arm.o: src/sha256_arm.c src/sha256_arm.h
test: test.o src/base58.o src/sha256_arm.o src/net.o
$(CC) $(CFLAGS) -o test_vain $^ $(LIBS)
./test_vain
test.o: test.c src/base58.h src/sha256_arm.h src/net.h
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f $(OBJS) src/metal_grind.o src/metal_shader_src.h src/metal_keypair_shader_src.h test.o test_vain vain
.PHONY: clean