File size: 3,954 Bytes
fd49381 |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
SHELL = bash
MAKEFLAGS += --warn-undefined-variables
.DEFAULT_GOAL = all
.SUFFIXES:
# ===============================================================================
# LOCAL ENVIRONMENT
# ===============================================================================
# shell script snippet:
define find_moses_root
d=$$(pwd);
while [[ ! -e $$d/Jamroot && $$d != "/" ]] ; do
d=$$(dirname $$d);
done;
echo $$d
endef
MOSES_ROOT := $(shell $(find_moses_root))
$(info MOSES_ROOT=${MOSES_ROOT})
# ===============================================================================
# COMPILATION PREFERENCES
# ===============================================================================
# CCACHE: if set to ccache, use ccache to speed up compilation
# OPTI: optimization level
# PROF: profiler switches
# compiler command
compiler ?= g++
variant ?= runtime
link ?= static
CXX = $(shell which ccache) $(compiler)
CXXFLAGS += -DMAX_NUM_FACTORS=4
CXXFLAGS += -DKENLM_MAX_ORDER=5
CXXFLAGS += -DWITH_THREADS
CXXFLAGS += -DNO_MOSES
# CXXFLAGS += -DMMT
CXXFLAGS += -I$(dir ${MOSES_ROOT})mmt-only
CXXFLAGS += -I${MOSES_ROOT} -I. -I${MOSES_ROOT}/opt/include
ifeq ($(variant),debug)
CXXFLAGS += -ggdb -O0
else ifeq ($(variant),profile)
CXXFLAGS += -g -pg -O3
else ifeq ($(variant),syntax)
CXXFLAGS += -fsyntax-only
endif
LDFLAGS = -L${MOSES_ROOT}/opt/lib -L./lib/
# WDIR = build/$(variant)/${HOSTTYPE}/${KERNEL}
WDIR = build/$(variant)
# ===============================================================================
# COMPILATION 'LOCALIZATION'
HOST ?= $(shell hostname)
HOSTTYPE ?= $(shell uname -m)
KERNEL = $(shell uname -r)
nil:
# libraries required
BOOSTLIBS := program_options iostreams thread system filesystem
BOOSTLIBS := $(addprefix -lboost_,${BOOSTLIBS})
ifeq ($(BOOSTLIBTAG),"")
BOOSTLIBS := $(addsuffix ${BOOSTLIBTAG},${BOOSTLIBS})
endif
STATIC_LIBS = m bz2 z dl rt
DYNAMIC_LIBS = pthread
#DYNAMIC_LIBS += tcmalloc
LIBS = -Wl,-B$(link)
LIBS += -L${MOSES_ROOT}/opt/lib ${BOOSTLIBS}
LIBS += $(addprefix -l,${STATIC_LIBS})
LIBS += -Wl,-Bdynamic
LIBS += $(addprefix -l,${DYNAMIC_LIBS})
cc2obj = $(addsuffix .o,$(patsubst ${MOSES_ROOT}%,$(WDIR)%,\
$(patsubst .%,$(WDIR)%,$(basename $1))))
cc2exe = $(addprefix ./bin/$(variant)/,$(basename $(notdir $1)))
cc2trg = $(basename $(notdir $1))
define compile
DEP += $(basename $(call cc2obj,$1)).d
$(call cc2obj,$1): $1
@echo -e "COMPILING $1"
@mkdir -p $$(@D)
${CXX} ${CXXFLAGS} -MD -MP -c $$< -o $$@
endef
define build
$(call cc2trg,$1): $(call cc2exe,$1)
$(call cc2exe,$1): $(call cc2obj,$1) $(LIBOBJ)
ifneq ($(variant),syntax)
@echo -e "LINKING $$@"
@mkdir -p $${@D}
${CXX} ${CXXFLAGS} -o $$@ $$< $(LIBOBJ) ${LIBS}
endif
endef
# list files here that you want explicitly excluded from compilation
skip = sim-pe.cc
skip += mtt.count.cc
skip += try-align2.cc
skip += spe-check-coverage3.cc
skip += mmsapt.cpp
skip += ug_stringdist.cc
skip += ug_splice_arglist.cc
# skip += ug_lexical_reordering.cc
# objects from elsewhere in the moses tree that are needed
extra = ${MOSES_ROOT}/util/exception.cc
extra += ${MOSES_ROOT}/util/integer_to_string.cc
$(foreach f,$(skip),$(eval broken+=$(shell find -name $f)))
broken += $(wildcard ./mm/stashed/*)
$(info SCANNING DIRECTORY TREE FOR FILES)
find_cfiles = find -name '*.cc' -or -name '*.cpp'
CFILES = $(filter-out $(broken), $(shell $(find_cfiles)))
PROGRAMS := $(shell $(find_cfiles) | xargs grep -lP '^(int +)?main')
PROGRAMS := $(filter-out $(broken),$(PROGRAMS))
ALLOBJ = $(call cc2obj,$(CFILES) $(extra))
LIBOBJ = $(call cc2obj,$(filter-out $(PROGRAMS),$(CFILES) $(extra)))
$(foreach f,$(CFILES) $(extra),$(eval $(call compile,$f)))
$(foreach p,$(PROGRAMS),$(eval $(call build,$p)))
ifeq ($(filter relink,$(MAKECMDGOALS)),relink)
.PHONY: relink
$(foreach p,$(PROGRAMS),$(eval .PHONY: $(call cc2exe,$p)))
relink: $(filter-out relink,$(MAKECMDGOALS))
endif
-include $(DEP)
|