aboutsummaryrefslogtreecommitdiff
path: root/src/Makefile
blob: 48e21f2f5f23a26520844573619cb79a87dc3e26 (plain) (blame)
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
64
65
66
67
####
#
# ecgen, tool for generating Elliptic curve domain parameters
# Copyright (C) 2017 J08nY
#
####

CC ?= gcc
GP2C = gp2c

CFLAGS = -O3 -Wall
LDFLAGS = -L../lib

GP_CFLAGS = -O3 -Wall -fomit-frame-pointer -fno-strict-aliasing -fPIC
GPFLAGS = -g -i4

INCLUDES = -I. -I../lib
LIBS = -lrt -lpari -lparson

####

VPATH = cm:invalid:io:exhaustive:math

GP =
GPC = $(addsuffix .c, $(GP))
GPO = $(addsuffix .o, $(GP))
GPH = $(addsuffix .h, $(GP))

SRC = ecgen.c $(wildcard */*.c)
OBJ = $(patsubst %.c,%.o, $(SRC))
HDR = $(wildcard *.h) $(wildcard */*.h)

####

all: ecgen

ecgen: ecgen.o $(GPO) $(OBJ)
	$(CC) $(CFLAGS) $(INCLUDES) -o $@ $^ $(LDFLAGS) $(LIBS)
	mv ecgen ..

gp2c: $(GPC) $(GPH)

$(GPO): $(GPC) $(GPH)
	$(CC) $(GP_CFLAGS) $(INCLUDES) -c -o $@ $< $(LDFLAGS) $(LIBS)

%.o: %.c $(GPH)
	$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<

%.h %.c: %.gp
	$(GP2C) $(GPFLAGS) gp/$*.gp  2>/dev/null | clang-format | awk 'BEGIN{print "#ifndef GP_H" > "gp.h"; print "#define GP_H" >> "gp.h";} { if(found) print >> "gp.c"; else print >> "gp.h"} /End of prototype/{found=1; print "#include \"gp.h\"" > "gp.c"; print "#endif //GP_H" >> "gp.h"}'

####

clean-all: clean clean-gp

clean:
	find . -type f -name '*.o' -exec rm {} +

clean-gp:
	rm -f $(GPH)
	rm -f $(GPC)

format:
	clang-format -i $(SRC)
	clang-format -i $(HDR)

.PHONY: all gp2c clean-all clean clean-gp format