rewrite Makefile

dev
MITSUNARI Shigeo 9 years ago
parent 2b11833edb
commit 6ad5944973
  1. 119
      common.mk
  2. 23
      sample/Makefile
  3. 59
      src/Makefile
  4. 31
      test/Makefile

@ -1,119 +0,0 @@
GCC_VER=$(shell $(PRE)$(CC) -dumpversion)
UNAME_S=$(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS=Linux
endif
ifneq ($(UNAME_S),Darwin)
LDFLAGS += -lrt
endif
CP = cp -f
AR = ar r
MKDIR=mkdir -p
RM=rm -fr
CFLAGS_OPT+=-fomit-frame-pointer -DNDEBUG
ifeq ($(CXX),clang++)
CFLAGS_OPT+=-O3
else
ifeq ($(shell expr $(GCC_VER) \> 4.6.0),1)
CFLAGS_OPT+=-Ofast
else
CFLAGS_OPT+=-O3
endif
endif
CFLAGS_WARN=-Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith
CFLAGS+= -g
CFLAGS+=$(CFLAGS_WARN)
BIT?=64
ifeq ($(BIT),32)
CPU?=x86
else
ifeq ($(BIT),64)
CPU?=x64
endif
endif
ifeq ($(BIT),0)
BIT_OPT=
else
BIT_OPT=-m$(BIT)
endif
ifeq ($(MARCH),)
ifeq ($(shell expr $(GCC_VER) \> 4.2.1),1)
CFLAGS+=-march=native
endif
else
CFLAGS+=$(MARCH)
endif
DEBUG=0
ifeq ($(DEBUG),1)
DEBUG=1
endif
ifeq ($(DEBUG),0)
CFLAGS+=$(CFLAGS_OPT)
OBJDIR=release
OBJSUF=
else
ifeq ($(OS),Linux)
# LDFLAGS+=-rdynamic
endif
OBJDIR=debug
OBJSUF=d
endif
####################################################
LIB=$(TOPDIR)lib/libmcl$(OBJSUF).a
LDFLAGS += -lpthread -m$(BIT) -lgmp -lgmpxx -lcrypto
ifeq ($(MARCH),)
ifeq ($(BIT),64)
# CFLAGS += -DMCL_USE_XBYAK
endif
endif
CFLAGS += -DMCL_USE_LLVM
####################################################
TOPDIR:=$(realpath $(dir $(lastword $(MAKEFILE_LIST))))/
PARENTDIR:=$(realpath $(TOPDIR)../)/
EXTDIR:=$(PARENTDIR)cybozulib_ext/
CFLAGS+= -I$(TOPDIR)include -I$(PARENTDIR)cybozulib/include/ -I$(PARENTDIR)xbyak/ $(BIT_OPT) $(INC_DIR)
#LDFLAGS+= -L$(TOPDIR)lib $(BIT_OPT) -Wl,-rpath,'$$ORIGIN/../lib' $(LD_DIR)
LDFLAGS+= $(BIT_OPT)
MKDEP = sh -ec '$(PRE)$(CC) -MM $(CFLAGS) $< | sed "s@\($*\)\.o[ :]*@$(OBJDIR)/\1.o $@ : @g" > $@; [ -s $@ ] || rm -f $@; touch $@'
CLEAN=$(RM) $(TARGET) $(OBJDIR)
define UNIT_TEST
sh -ec 'for i in $(TARGET); do $$i|grep "ctest:name"; done' > result.txt
grep -v "ng=0, exception=0" result.txt || echo "all unit tests are ok"
endef
define SAMPLE_TEST
sh -ec 'for i in $(TARGET); do $$i; done'
endef
.SUFFIXES: .cpp .d .exe
$(OBJDIR)/%.o: %.cpp
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS)
$(OBJDIR)/%.o: %.s
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS)
$(OBJDIR)/%.d: %.cpp $(OBJDIR)
@$(MKDEP)
$(TOPDIR)bin/%$(OBJSUF).exe: $(OBJDIR)/%.o $(LIB)
$(PRE)$(CXX) $< -o $@ $(LIB) $(LDFLAGS)
OBJ=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o))
DEPEND_FILE=$(addprefix $(OBJDIR)/, $(SRC:.cpp=.d))
TEST_FILE=$(addprefix $(TOPDIR)bin/, $(SRC:.cpp=$(OBJSUF).exe))
.PHONY: test

@ -1,23 +0,0 @@
include ../common.mk
TARGET=$(TEST_FILE)
LIBS=
SRC=bench.cpp ecdh.cpp random.cpp vote.cpp rawbench.cpp
all: $(TARGET)
#test: $(TARGET)
# @$(SAMPLE_TEST)
$(OBJDIR):
@$(MKDIR) $(OBJDIR)
clean:
$(CLEAN)
$(LIBS):
$(MAKE) -C ../src
-include $(DEPEND_FILE)

@ -1,59 +0,0 @@
include ../common.mk
VER=-3.6
LLC=llc$(VER)
OPT=opt$(VER)
DIS=llvm-dis$(VER)
ASM=llvm-as$(VER)
OPT_LLC= $(OPT) -O3 -o - | $(LLC) -O3 -o -
SRC_TXT = once.txt all.txt long.txt short.txt mul.txt
SRC=fp.cpp
OBJ=$(OBJDIR)/fp.o $(OBJDIR)/x64.o
#TARGET=x64.s x86.s arm.s arm64.s
TARGET=$(TOPDIR)lib/libmcl$(OBJSUF).a
HAS_BMI2=$(shell cat "/proc/cpuinfo" | grep bmi2 >/dev/null && echo "1")
ifeq ($(HAS_BMI2),1)
AFLAGS=-mattr=bmi2
endif
all: $(TARGET)
$(TARGET): $(OBJ)
$(MKDIR) ../lib
$(AR) $@ $(OBJ)
$(OBJDIR):
@$(MKDIR) $(OBJDIR)
base64.ll: gen.py $(SRC_TXT)
python gen.py 64
base32.ll: gen.py $(SRC_TXT)
python gen.py 32
x64: base64.ll
$(LLC) base64.ll -o - -x86-asm-syntax=intel
x86: base32.ll
$(LLC) base32.ll -o - -x86-asm-syntax=intel -march=x86
arm64: base64.ll
$(LLC) base64.ll -o - -march=aarch64
arm: base32.ll
$(LLC) base32.ll -o - -march=arm
opt: base64.ll
cat base64.ll|$(OPT_LLC) -x86-asm-syntax=intel $(AFLAGS)
x64.s: base64.ll
cat base64.ll|$(OPT_LLC) $(AFLAGS) > x64.s
x86.s: base32.ll
cat base32.ll|$(OPT_LLC) $(AFLAGS) -march=x86 > x86.s
arm.s: base32.ll
cat base32.ll|$(OPT_LLC) -march=arm > arm.s
arm64.s: base32.ll
cat base64.ll|$(OPT_LLC) -march=aarch64 > arm64.s
clean:
rm -rf base*.ll *.s
$(CLEAN)
-include $(DEPEND_FILE)

@ -1,31 +0,0 @@
include ../common.mk
TARGET=$(TEST_FILE)
SRC=fp_test.cpp ec_test.cpp fp_util_test.cpp window_method_test.cpp elgamal_test.cpp fp_tower_test.cpp
ifeq ($(CPU),x64)
SRC+=fp_generator_test.cpp mont_fp_test.cpp
endif
all: $(TARGET)
test: $(TARGET)
@$(UNIT_TEST)
$(OBJDIR):
@$(MKDIR) $(OBJDIR)
clean:
$(CLEAN)
$(LIB):
$(MAKE) -C ../src
-include $(DEPEND_FILE)
ifeq ($(USE_LLVM),1)
$(ASM_OBJ): $(ASM_SRC)
$(CXX) $< -o $@ -c
endif
.PHONY: $(LIB)
Loading…
Cancel
Save