Unverified Commit 17c6203c authored by Ola Bini's avatar Ola Bini
Browse files

Fix makefiles for new naming and organization

parent fc23aa33
......@@ -9,11 +9,10 @@ MACHINE := $(shell uname -m)
# Many of them are mapped to build/obj right now, but could be split later.
# The non-build/obj directories are the public interface.
BUILD_OBJ = build/obj
BUILD_C = src/GENERATED/c
BUILD_H = src/GENERATED/c
BUILD_C = src/GEN
BUILD_PY = build/obj
BUILD_LIB = build/lib
BUILD_INC = src/GENERATED/include
BUILD_INC = src/public_include
BUILD_BIN = build/bin
BUILD_IBIN = build/obj/bin
......@@ -35,7 +34,7 @@ PYTHON ?= python
WARNFLAGS = -pedantic -Wall -Wextra -Werror -Wunreachable-code \
-Wmissing-declarations -Wunused-function -Wno-overlength-strings $(EXWARN)
INCFLAGS = -Isrc/include -I$(BUILD_INC) -I$(BUILD_H)
INCFLAGS = -Isrc -Isrc/include -I$(BUILD_INC)
PUB_INCFLAGS = -I$(BUILD_INC)
LANGFLAGS = -std=c99 -fno-strict-aliasing
LANGXXFLAGS = -fno-strict-aliasing
......@@ -71,15 +70,9 @@ SAGES= $(shell ls test/*.sage)
BUILDPYS= $(SAGES:test/%.sage=$(BUILD_PY)/%.py)
.PHONY: clean all test test_ct bench todo doc lib bat sage sagetest gen_code gen_code_static
.PRECIOUS: $(BUILD_C)/*/%.c $(BUILD_H)/*/%.h $(BUILD_H)/%.h $(BUILD_H)/%.hxx $(BUILD_H)/*/%.hxx $(BUILD_IBIN)/%
.PRECIOUS: $(BUILD_C)/%.c $(BUILD_IBIN)/%
HEADER_SRCS= $(shell find src/public_include -name "*.h*")
HEADER_PRIVATE_SRCS= $(shell find src/include -name "*.tmpl.h*")
GEN_CODE_0= $(HEADER_SRCS:src/public_include/%=$(BUILD_INC)/%)
GEN_CODE_0+= $(HEADER_PRIVATE_SRCS:src/include/%=$(BUILD_C)/%)
GEN_CODE_1= $(GEN_CODE_0:%.tmpl.h=%.h)
GEN_CODE= $(GEN_CODE_1:%.tmpl.hxx=%.hxx)
HEADERS= Makefile.custom $(shell find src test -name "*.h") $(BUILD_OBJ)/timestamp $(GEN_CODE)
HEADERS= Makefile.custom $(shell find src test -name "*.h") $(BUILD_OBJ)/timestamp
# components needed by the lib
LIBCOMPONENTS = $(BUILD_OBJ)/utils.o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/spongerng.o
......@@ -132,119 +125,38 @@ $(BUILD_OBJ)/timestamp:
$(PER_OBJ_DIRS) $(BUILD_C)/goldilocks
touch $@
$(BUILD_INC)/%: src/public_include/% $(BUILD_OBJ)/timestamp
cp -f $< $@
$(BUILD_INC)/%.h: src/public_include/%.tmpl.h src/generator/*
$(PYTHON) -B src/generator/template.py --per=global --guard=$(@:$(BUILD_INC)/%=%) -o $@ $<
$(BUILD_C)/%.h: src/include/%.tmpl.h src/generator/*
$(PYTHON) -B src/generator/template.py --per=global --guard=$(@:$(BUILD_C)/%=%) -o $@ $<
$(BUILD_INC)/%.hxx: src/public_include/%.tmpl.hxx src/generator/*
$(PYTHON) -B src/generator/template.py --per=global --guard=$(@:$(BUILD_INC)/%=%) -o $@ $<
$(BUILD_C)/%.hxx: src/include/%.tmpl.hxx src/generator/*
$(PYTHON) -B src/generator/template.py --per=global --guard=$(@:$(BUILD_C)/%=%) -o $@ $<
################################################################
# Per-field code: call with field, arch
################################################################
PER_FIELD_C = $(wildcard src/per_field/*.tmpl.c)
PER_FIELD_H = $(wildcard src/per_field/*.tmpl.h*)
define define_field
ARCH_FOR_$(1) ?= $(2)
COMPONENTS_OF_$(1) = $$(BUILD_OBJ)/$(1)/f_impl.o $$(BUILD_OBJ)/$(1)/f_arithmetic.o $$(BUILD_OBJ)/$(1)/f_generic.o
HEADERS_OF_$(1) = $(HEADERS) $$(BUILD_H)/$(1)/f_field.h
LIBCOMPONENTS += $$(COMPONENTS_OF_$(1))
GEN_CODE_FOR_$(1) = $$(patsubst src/per_field/%,$(BUILD_C)/$(1)/%,$(patsubst %.tmpl.c,%.c,$(PER_FIELD_C)))
GEN_CODE_FOR_$(1) += $$(patsubst src/per_field/%,$(BUILD_H)/$(1)/%,$(patsubst %.tmpl.h,%.h,$(PER_FIELD_H)))
GEN_CODE += $$(GEN_CODE_FOR_$(1))
PER_OBJ_DIRS += $$(BUILD_OBJ)/$(1)
$$(BUILD_C)/$(1)/%.c: src/per_field/%.tmpl.c src/generator/* Makefile.custom
$(PYTHON) -B src/generator/template.py --per=field --guard=$(1)/`basename $$@` --item=$(1) -o $$@ $$<
$$(BUILD_H)/$(1)/%.h: src/per_field/%.tmpl.h src/generator/* Makefile.custom
$(PYTHON) -B src/generator/template.py --per=field --guard=$(1)/`basename $$@` --item=$(1) -o $$@ $$<
$$(BUILD_OBJ)/$(1)/%.o: $$(BUILD_C)/$(1)/%.c $$(HEADERS_OF_$(1))
$$(CC) $$(CFLAGS) -I src/$(1) -I src/$(1)/$$(ARCH_FOR_$(1)) -I $(BUILD_H)/$(1) \
-I $(BUILD_H)/$(1)/$$(ARCH_FOR_$(1)) -I src/include/$$(ARCH_FOR_$(1)) \
-c -o $$@ $$<
$$(BUILD_OBJ)/$(1)/%.o: src/$(1)/%.c $$(HEADERS_OF_$(1))
$$(CC) $$(CFLAGS) -I src/$(1) -I src/$(1)/$$(ARCH_FOR_$(1)) -I $(BUILD_H)/$(1) \
-I $(BUILD_H)/$(1)/$$(ARCH_FOR_$(1)) -I src/include/$$(ARCH_FOR_$(1)) \
-c -o $$@ $$<
$$(BUILD_OBJ)/$(1)/%.o: src/$(1)/$$(ARCH_FOR_$(1))/%.c $$(HEADERS_OF_$(1))
$$(CC) $$(CFLAGS) -I src/$(1) -I src/$(1)/$$(ARCH_FOR_$(1)) -I $(BUILD_H)/$(1) \
-I $(BUILD_H)/$(1)/$$(ARCH_FOR_$(1)) -I src/include/$$(ARCH_FOR_$(1)) \
-c -o $$@ $$<
endef
################################################################
# Per-field, per-curve code: call with curve, field
################################################################
PER_CURVE_C = $(wildcard src/per_curve/*.tmpl.c)
define define_curve
LIBCOMPONENTS += $$(BUILD_OBJ)/$(1)/goldilocks.o $$(BUILD_OBJ)/$(1)/elligator.o $$(BUILD_OBJ)/$(1)/scalar.o \
$$(BUILD_OBJ)/$(1)/eddsa.o $$(BUILD_OBJ)/$(1)/decaf_tables.o
PER_OBJ_DIRS += $$(BUILD_OBJ)/$(1)
GLOBAL_HEADERS_OF_$(1) = $(BUILD_INC)/goldilocks/point_$(3).h $(BUILD_INC)/goldilocks/point_$(3).hxx \
$(BUILD_INC)/goldilocks/ed$(3).h $(BUILD_INC)/goldilocks/ed$(3).hxx
HEADERS_OF_$(1) = $$(HEADERS_OF_$(2)) $$(GLOBAL_HEADERS_OF_$(1))
HEADERS += $$(GLOBAL_HEADERS_OF_$(1))
GEN_CODE_FOR_$(1) = $$(patsubst src/per_curve/%,$(BUILD_C)/$(1)/%,$(patsubst %.tmpl.c,%.c,$(PER_CURVE_C)))
GEN_CODE_FOR_$(1) += $$(GLOBAL_HEADERS_OF_$(1))
GEN_CODE_P2 += $(BUILD_C)/$(1)/decaf_tables.c
GEN_CODE += $$(GEN_CODE_FOR_$(1))
$$(BUILD_C)/$(1)/%.c: src/per_curve/%.tmpl.c src/generator/* Makefile.custom
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$(1)/`basename $$@` -o $$@ $$<
$$(BUILD_H)/$(1)/%.h: src/per_curve/%.tmpl.h src/generator/* Makefile.custom
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$(1)/`basename $$@` -o $$@ $$<
$$(BUILD_INC)/goldilocks/point_$(3).%: src/per_curve/point.tmpl.% src/generator/* Makefile.custom
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$$(BUILD_INC)/goldilocks/ed$(3).%: src/per_curve/eddsa.tmpl.% src/generator/* Makefile.custom
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$$(BUILD_INC)/goldilocks/elligator_$(3).%: src/per_curve/elligator.tmpl.% src/generator/* Makefile.custom
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$$(BUILD_INC)/goldilocks/scalar_$(3).%: src/per_curve/scalar.tmpl.% src/generator/* Makefile.custom
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$$(BUILD_IBIN)/goldilocks_gen_tables_$(1): $$(BUILD_OBJ)/$(1)/goldilocks_gen_tables.o \
$$(BUILD_OBJ)/$(1)/goldilocks.o $$(BUILD_OBJ)/$(1)/scalar.o $$(BUILD_OBJ)/utils.o \
$$(COMPONENTS_OF_$(2))
$$(LD) $$(LDFLAGS) -o $$@ $$^
$$(BUILD_C)/$(1)/decaf_tables.c: $$(BUILD_IBIN)/goldilocks_gen_tables_$(1)
./$$< > $$@ || (rm $$@; exit 1)
$$(BUILD_OBJ)/$(1)/%.o: $$(BUILD_C)/$(1)/%.c $$(HEADERS_OF_$(1))
$$(CC) $$(CFLAGS) -c -o $$@ $$< \
-I build/obj/curve_$(1)/ -I src/$(2) -I src/$(2)/$$(ARCH_FOR_$(2)) -I src/include/$$(ARCH_FOR_$(2)) \
-I $(BUILD_H)/$(1) -I $(BUILD_H)/$(2) -I $(BUILD_H)/$(2)/$$(ARCH_FOR_$(2))
$$(BUILD_OBJ)/goldilocks_gen_tables_$(1).o: src/goldilocks_gen_tables.c $$(HEADERS_OF_$(1))
$$(CC) $$(CFLAGS) \
-I build/obj/curve_$(1) -I src/$(2) -I src/$(2)/$$(ARCH_FOR_$(2)) -I src/include/$$(ARCH_FOR_$(2)) \
-I $(BUILD_H)/$(1) -I $(BUILD_H)/$(2) -I $(BUILD_H)/$(2)/$$(ARCH_FOR_$(2)) \
-c -o $$@ $$<
endef
################################################################
# call code above to generate curves and fields
$(eval $(call define_field,p448,arch_x86_64))
$(eval $(call define_curve,ed448goldilocks,p448,448))
COMPONENTS_OF = $(BUILD_OBJ)/f_impl.o $(BUILD_OBJ)/f_arithmetic.o $(BUILD_OBJ)/f_generic.o
LIBCOMPONENTS += $COMPONENTS_OF
$(BUILD_OBJ)/%.o: src/%.c $(HEADERS)
$(CC) $(CFLAGS) -I src/arch_x86_64 -I src/include/arch_x86_64 \
-c -o $@ $<
LIBCOMPONENTS += $(BUILD_OBJ)/goldilocks.o $(BUILD_OBJ)/elligator.o $(BUILD_OBJ)/scalar.o \
$(BUILD_OBJ)/eddsa.o $(BUILD_OBJ)/decaf_tables.o
GLOBAL_HEADERS_OF = $(BUILD_INC)/goldilocks/point_448.h $(BUILD_INC)/goldilocks/point_448.hxx \
$(BUILD_INC)/goldilocks/ed448.h $(BUILD_INC)/goldilocks/ed448.hxx
HEADERS += $(GLOBAL_HEADERS_OF)
GEN_CODE = $(BUILD_C)/decaf_tables.c
$(BUILD_IBIN)/goldilocks_gen_tables: $(BUILD_OBJ)/goldilocks_gen_tables.o \
$(BUILD_OBJ)/goldilocks.o $(BUILD_OBJ)/scalar.o $(BUILD_OBJ)/utils.o \
$(COMPONENTS_OF)
$(LD) $(LDFLAGS) -o $@ $^
$(BUILD_C)/decaf_tables.c: $(BUILD_IBIN)/goldilocks_gen_tables
./$< > $@ || (rm $@; exit 1)
$(BUILD_OBJ)/%.o: $(BUILD_C)/%.c $(HEADERS)
$(CC) $(CFLAGS) -c -o $@ $< \
-I build/obj/ -I src/ -I src/arch_x86_64 -I src/include/arch_x86_64
$(BUILD_OBJ)/goldilocks_gen_tables.o: src/goldilocks_gen_tables.c $(HEADERS)
$(CC) $(CFLAGS) \
-I build/obj/ -I src -I src/arch_x86_64 -I src/include/arch_x86_64 \
-c -o $@ $<
# The shakesum utility is in the public bin directory.
$(BUILD_BIN)/shakesum: $(BUILD_OBJ)/shakesum.o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/utils.o
......@@ -300,15 +212,14 @@ $(BUILD_DOC)/timestamp:
mkdir -p `dirname $@`
touch $@
#
doc: Doxyfile $(BUILD_OBJ)/timestamp gen_code_static
doc: Doxyfile $(BUILD_OBJ)/timestamp
$(DOXYGEN) > /dev/null
gen_code_static: $(GEN_CODE)
gen_code: gen_code_static $(GEN_CODE_P2)
gen_code: $(GEN_CODE)
# Finds todo items in .h and .c files
TODO_TYPES ?= HACK TODO @todo FIXME BUG XXX PERF FUTURE REMOVE MAGIC UNIFY
TODO_LOCATIONS ?= src/*.c src/include src/p* src/generator test Makefile.custom Doxyfile
TODO_LOCATIONS ?= src/*.c src/include src/p* test Makefile.custom Doxyfile
todo::
@(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx' -or -name '*.py') | xargs egrep --color=auto -w \
`echo $(TODO_TYPES) | tr ' ' '|'`
......@@ -340,4 +251,4 @@ clean:
rm -fr build
clean_generated: clean
rm -fr $(BUILD_C)/* $(BUILD_H)/* $(BUILD_INC)/*
rm -fr $(BUILD_C)/*
include $(top_srcdir)/variables.am
noinst_PROGRAMS = goldilocks_gen_tables_ed448goldilocks
noinst_PROGRAMS = goldilocks_gen_tables
goldilocks_gen_tables_ed448goldilocks_SOURCES = utils.c \
GENERATED/c/ed448goldilocks/goldilocks_gen_tables.c \
p448/arch_x86_64/f_impl.c \
p448/f_arithmetic.c \
GENERATED/c/p448/f_generic.c \
GENERATED/c/ed448goldilocks/goldilocks.c \
GENERATED/c/ed448goldilocks/scalar.c
goldilocks_gen_tables_SOURCES = utils.c \
goldilocks_gen_tables.c \
arch_x86_64/f_impl.c \
f_arithmetic.c \
f_generic.c \
goldilocks.c \
scalar.c
goldilocks_gen_tables_ed448goldilocks_CFLAGS = $(AM_CFLAGS) $(LANGFLAGS) $(WARNFLAGS) $(INCFLAGS) $(INCFLAGS_448) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
goldilocks_gen_tables_ed448goldilocks_LDFLAGS = $(AM_LDFLAGS) $(XLDFLAGS)
goldilocks_gen_tables_CFLAGS = $(AM_CFLAGS) $(LANGFLAGS) $(WARNFLAGS) $(INCFLAGS) $(INCFLAGS_448) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
goldilocks_gen_tables_LDFLAGS = $(AM_LDFLAGS) $(XLDFLAGS)
GENERATED/c/ed448goldilocks/decaf_tables.c: goldilocks_gen_tables_ed448goldilocks
GEN/decaf_tables.c: goldilocks_gen_tables
./$< > $@ || (rm $@; exit 1)
noinst_LTLIBRARIES = libgoldilocks448.la
lib_LTLIBRARIES = libgoldilocks.la
libgoldilocks_la_SOURCES = utils.c \
shake.c \
spongerng.c
arch_x86_64/f_impl.c \
f_arithmetic.c \
f_generic.c \
goldilocks.c \
elligator.c \
scalar.c \
eddsa.c \
GEN/decaf_tables.c
libgoldilocks_la_CFLAGS = $(AM_CFLAGS) $(LANGFLAGS) $(WARNFLAGS) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
libgoldilocks_la_LDFLAGS = $(AM_LDFLAGS) $(XLDFLAGS)
libgoldilocks_la_LIBADD = libgoldilocks448.la
libgoldilocks448_la_SOURCES = p448/arch_x86_64/f_impl.c \
p448/f_arithmetic.c \
GENERATED/c/p448/f_generic.c \
GENERATED/c/ed448goldilocks/goldilocks.c \
GENERATED/c/ed448goldilocks/elligator.c \
GENERATED/c/ed448goldilocks/scalar.c \
GENERATED/c/ed448goldilocks/eddsa.c \
GENERATED/c/ed448goldilocks/decaf_tables.c
libgoldilocks448_la_CFLAGS = $(AM_CFLAGS) $(LANGFLAGS) $(WARNFLAGS) $(INCFLAGS) $(INCFLAGS_448) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
libgoldilocks448_la_LDFLAGS = $(AM_LDFLAGS) $(XLDFLAGS)
incsubdir = $(includedir)/goldilocks
incsub_HEADERS = GENERATED/include/goldilocks/common.h \
GENERATED/include/goldilocks/ed448.h \
GENERATED/include/goldilocks/ed448.hxx \
GENERATED/include/goldilocks/eddsa.hxx \
GENERATED/include/goldilocks/point_448.h \
GENERATED/include/goldilocks/point_448.hxx \
GENERATED/include/goldilocks/secure_buffer.hxx \
GENERATED/include/goldilocks/shake.h \
GENERATED/include/goldilocks/shake.hxx \
GENERATED/include/goldilocks/spongerng.h \
GENERATED/include/goldilocks/spongerng.hxx
include_HEADERS = GENERATED/include/goldilocks.h \
GENERATED/include/goldilocks.hxx
#pkginclude_HEADERS = GENERATED/include/
incsub_HEADERS = public_include/goldilocks/common.h \
public_include/goldilocks/ed448.h \
public_include/goldilocks/ed448.hxx \
public_include/goldilocks/eddsa.hxx \
public_include/goldilocks/point_448.h \
public_include/goldilocks/point_448.hxx \
public_include/goldilocks/secure_buffer.hxx \
public_include/goldilocks/shake.h \
public_include/goldilocks/shake.hxx \
public_include/goldilocks/spongerng.h \
public_include/goldilocks/spongerng.hxx
include_HEADERS = public_include/goldilocks.h \
public_include/goldilocks.hxx
#pkginclude_HEADERS = public_include/
#pkgconfigdir = $(libdir)/pkgconfig
#pkgconfig_DATA = libgoldilocks.pc
FIELD_NAME_448 = p448
CURVE_NAME_448 = ed448goldilocks
ARCH_NAME = arch_x86_64
BUILD_H = $(top_srcdir)/src/GENERATED/c
BUILD_INC = $(top_srcdir)/src/GENERATED/include
LANGFLAGS = -std=c99 -fno-strict-aliasing
WARNFLAGS = -pedantic -Wall -Wextra -Werror -Wunreachable-code \
......@@ -14,12 +9,9 @@ WARNFLAGS = -pedantic -Wall -Wextra -Werror -Wunreachable-code \
#WARNFLAGS += -Wgcc-compat
#endif
INCFLAGS = -I$(top_srcdir)/src/include -I$(BUILD_INC) -I$(BUILD_H)
INCFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/include -I$(top_srcdir)/src/public_include
INCFLAGS += -I$(top_srcdir)/src/$(ARCH_NAME)
INCFLAGS += -I$(top_srcdir)/src/include/$(ARCH_NAME)
INCFLAGS_448 = -I$(top_srcdir)/src/$(FIELD_NAME_448)/$(ARCH_NAME)
INCFLAGS_448 += -I$(top_srcdir)/src/GENERATED/c/$(FIELD_NAME_448)
INCFLAGS_448 += -I$(top_srcdir)/src/GENERATED/c/$(FIELD_NAME_448)/$(ARCH_NAME)
OFLAGS ?= -O2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment