Makefile 6.62 KB
Newer Older
1

2
CC   := gcc
3
CXX  := g++
4
AR   := ar
5 6
LD   := $(CXX)

Alan Mishchenko committed
7
MSG_PREFIX ?=
8
ABCSRC = .
Alan Mishchenko committed
9 10 11

$(info $(MSG_PREFIX)Using CC=$(CC))
$(info $(MSG_PREFIX)Using CXX=$(CXX))
12
$(info $(MSG_PREFIX)Using AR=$(AR))
Alan Mishchenko committed
13
$(info $(MSG_PREFIX)Using LD=$(LD))
Alan Mishchenko committed
14 15

PROG := abc
16
OS := $(shell uname -s)
Alan Mishchenko committed
17

Alan Mishchenko committed
18
MODULES := \
19
	$(wildcard src/ext*) \
20
	src/base/abc src/base/abci src/base/cmd src/base/io src/base/main src/base/exor \
21
	src/base/ver src/base/wlc src/base/wln src/base/acb src/base/bac src/base/cba src/base/pla src/base/test \
22
	src/map/mapper src/map/mio src/map/super src/map/if \
Alan Mishchenko committed
23
	src/map/amap src/map/cov src/map/scl src/map/mpm \
24 25
	src/misc/extra src/misc/mvc src/misc/st src/misc/util src/misc/nm \
	src/misc/vec src/misc/hash src/misc/tim src/misc/bzlib src/misc/zlib \
26
	src/misc/mem src/misc/bar src/misc/bbl src/misc/parse \
27
	src/opt/cut src/opt/fxu src/opt/fxch src/opt/rwr src/opt/mfs src/opt/sim \
28
	src/opt/ret src/opt/fret src/opt/res src/opt/lpk src/opt/nwk src/opt/rwt \
29
	src/opt/cgt src/opt/csw src/opt/dar src/opt/dau src/opt/dsc src/opt/sfm src/opt/sbd \
30
	src/sat/bsat src/sat/xsat src/sat/satoko src/sat/csat src/sat/msat src/sat/psat src/sat/cnf src/sat/bmc src/sat/glucose src/sat/glucose2 \
31 32
	src/bool/bdc src/bool/deco src/bool/dec src/bool/kit src/bool/lucky \
	src/bool/rsb src/bool/rpo \
33
	src/proof/pdr src/proof/abs src/proof/live src/proof/ssc src/proof/int \
34
	src/proof/cec src/proof/acec src/proof/dch src/proof/fraig src/proof/fra src/proof/ssw \
35
	src/aig/aig src/aig/saig src/aig/gia src/aig/ioa src/aig/ivy src/aig/hop \
36
	src/aig/miniaig
Alan Mishchenko committed
37

38
all: $(PROG)
Alan Mishchenko committed
39
default: $(PROG)
Alan Mishchenko committed
40

41 42 43 44
ARCHFLAGS_EXE ?= ./arch_flags

$(ARCHFLAGS_EXE) : arch_flags.c
	$(CC) arch_flags.c -o $(ARCHFLAGS_EXE)
45

46
INCLUDES += -I$(ABCSRC)/src
47

48 49 50 51 52 53 54
# Use C99 stdint.h header for platform-dependent types
ifdef ABC_USE_STDINT_H
    ARCHFLAGS ?= -DABC_USE_STDINT_H=1
else
    ARCHFLAGS ?= $(shell $(CC) $(ABCSRC)/arch_flags.c -o $(ARCHFLAGS_EXE) && $(ARCHFLAGS_EXE))
endif

55 56
ARCHFLAGS := $(ARCHFLAGS)

57
OPTFLAGS  ?= -g -O
Alan Mishchenko committed
58

59
CFLAGS    += -Wall -Wno-unused-function -Wno-write-strings -Wno-sign-compare $(ARCHFLAGS)
60 61 62
ifneq ($(findstring arm,$(shell uname -m)),)
	CFLAGS += -DABC_MEMALIGN=4
endif
63

64
# compile ABC using the C++ compiler and put everything in the namespace $(ABC_NAMESPACE)
65
ifdef ABC_USE_NAMESPACE
66
  CFLAGS += -DABC_NAMESPACE=$(ABC_USE_NAMESPACE) -fpermissive -x c++
67 68 69 70 71
  CC := $(CXX)
  $(info $(MSG_PREFIX)Compiling in namespace $(ABC_NAMESPACE))
endif

# compile CUDD with ABC
72
ifndef ABC_USE_NO_CUDD
73 74 75 76 77
  CFLAGS += -DABC_USE_CUDD=1
  MODULES += src/bdd/cudd src/bdd/extrab src/bdd/dsd src/bdd/epd src/bdd/mtr src/bdd/reo src/bdd/cas src/bdd/bbr src/bdd/llb
  $(info $(MSG_PREFIX)Compiling with CUDD)
endif

78 79 80 81 82 83 84
ABC_READLINE_INCLUDES ?=
ABC_READLINE_LIBRARIES ?= -lreadline

# whether to use libreadline
ifndef ABC_USE_NO_READLINE
  CFLAGS += -DABC_USE_READLINE $(ABC_READLINE_INCLUDES)
  LIBS += $(ABC_READLINE_LIBRARIES)
85 86 87 88
  ifeq ($(OS), FreeBSD)
    CFLAGS += -I/usr/local/include
    LDFLAGS += -L/usr/local/lib
  endif
89 90 91
  $(info $(MSG_PREFIX)Using libreadline)
endif

92
# whether to compile with thread support
Alan Mishchenko committed
93
ifndef ABC_USE_NO_PTHREADS
94 95 96 97 98
  CFLAGS += -DABC_USE_PTHREADS
  LIBS += -lpthread
  $(info $(MSG_PREFIX)Using pthreads)
endif

99 100
# whether to compile into position independent code
ifdef ABC_USE_PIC
101
  CFLAGS += -fPIC
102 103 104 105 106 107 108 109 110 111 112
  LIBS += -fPIC
  $(info $(MSG_PREFIX)Compiling position independent code)
endif

# whether to echo commands while building
ifdef ABC_MAKE_VERBOSE
  VERBOSE=
else
  VERBOSE=@
endif

113 114 115 116
# Set -Wno-unused-bug-set-variable for GCC 4.6.0 and greater only
ifneq ($(or $(findstring gcc,$(CC)),$(findstring g++,$(CC))),)
empty:=
space:=$(empty) $(empty)
117

118 119 120 121
GCC_VERSION=$(shell $(CC) -dumpversion)
GCC_MAJOR=$(word 1,$(subst .,$(space),$(GCC_VERSION)))
GCC_MINOR=$(word 2,$(subst .,$(space),$(GCC_VERSION)))

Alan Mishchenko committed
122
$(info $(MSG_PREFIX)Found GCC_VERSION $(GCC_VERSION))
123
ifeq ($(findstring $(GCC_MAJOR),0 1 2 3),)
124 125
ifeq ($(GCC_MAJOR),4)
$(info $(MSG_PREFIX)Found GCC_MAJOR==4)
126
ifeq ($(findstring $(GCC_MINOR),0 1 2 3 4 5),)
Alan Mishchenko committed
127
$(info $(MSG_PREFIX)Found GCC_MINOR>=6)
128
CFLAGS += -Wno-unused-but-set-variable
129
endif
130 131 132 133
else
$(info $(MSG_PREFIX)Found GCC_MAJOR>=5)
CFLAGS += -Wno-unused-but-set-variable
endif
134 135 136
endif

endif
137

138
# LIBS := -ldl -lrt
139 140 141 142 143
LIBS += -lm
ifneq ($(OS), FreeBSD)
  LIBS += -ldl
endif

144 145 146
ifneq ($(findstring Darwin, $(shell uname)), Darwin)
   LIBS += -lrt
endif
Alan Mishchenko committed
147

148 149 150 151
ifdef ABC_USE_LIBSTDCXX
   LIBS += -lstdc++
   $(info $(MSG_PREFIX)Using explicit -lstdc++)
endif
152

Alan Mishchenko committed
153
$(info $(MSG_PREFIX)Using CFLAGS=$(CFLAGS))
154
CXXFLAGS += $(CFLAGS)
155

156
SRC  :=
157
GARBAGE := core core.* *.stackdump ./tags $(PROG) arch_flags
Alan Mishchenko committed
158

159
.PHONY: all default tags clean docs cmake_info
Alan Mishchenko committed
160

161
include $(patsubst %, $(ABCSRC)/%/module.make, $(MODULES))
Alan Mishchenko committed
162 163 164

OBJ := \
	$(patsubst %.cc, %.o, $(filter %.cc, $(SRC))) \
Alan Mishchenko committed
165
	$(patsubst %.cpp, %.o, $(filter %.cpp, $(SRC))) \
Alan Mishchenko committed
166
	$(patsubst %.c, %.o,  $(filter %.c, $(SRC)))  \
167
	$(patsubst %.y, %.o,  $(filter %.y, $(SRC)))
Alan Mishchenko committed
168

169 170
LIBOBJ := $(filter-out src/base/main/main.o,$(OBJ))

Alan Mishchenko committed
171 172 173 174
DEP := $(OBJ:.o=.d)

# implicit rules

175
%.o: %.c
176
	@echo "$(MSG_PREFIX)\`\` Compiling:" $(LOCAL_PATH)/$<
177
	$(VERBOSE)$(CC) -c $(OPTFLAGS) $(INCLUDES) $(CFLAGS) $< -o $@
178 179

%.o: %.cc
180
	@echo "$(MSG_PREFIX)\`\` Compiling:" $(LOCAL_PATH)/$<
181
	$(VERBOSE)$(CXX) -c $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< -o $@
182

183 184
%.o: %.cpp
	@echo "$(MSG_PREFIX)\`\` Compiling:" $(LOCAL_PATH)/$<
185
	$(VERBOSE)$(CXX) -c $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< -o $@
186

Alan Mishchenko committed
187
%.d: %.c
188
	@echo "$(MSG_PREFIX)\`\` Generating dependency:" $(LOCAL_PATH)/$<
189
	$(VERBOSE)$(ABCSRC)/depends.sh "$(CC)" `dirname $*.c` $(OPTFLAGS) $(INCLUDES) $(CFLAGS) $< > $@
Alan Mishchenko committed
190 191

%.d: %.cc
192
	@echo "$(MSG_PREFIX)\`\` Generating dependency:" $(LOCAL_PATH)/$<
193
	$(VERBOSE)$(ABCSRC)/depends.sh "$(CXX)" `dirname $*.cc` $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< > $@
Alan Mishchenko committed
194

195 196
%.d: %.cpp
	@echo "$(MSG_PREFIX)\`\` Generating dependency:" $(LOCAL_PATH)/$<
197
	$(VERBOSE)$(ABCSRC)/depends.sh "$(CXX)" `dirname $*.cpp` $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< > $@
198

199
ifndef ABC_MAKE_NO_DEPS
Alan Mishchenko committed
200
-include $(DEP)
201
endif
Alan Mishchenko committed
202 203 204 205 206

# Actual targets

depend: $(DEP)

207
clean:
208
	@echo "$(MSG_PREFIX)\`\` Cleaning up..."
209
	$(VERBOSE)rm -rvf $(PROG) lib$(PROG).a $(OBJ) $(GARBAGE) $(OBJ:.o=.d)
Alan Mishchenko committed
210 211

tags:
212
	etags `find . -type f -regex '.*\.\(c\|h\)'`
Alan Mishchenko committed
213 214

$(PROG): $(OBJ)
215
	@echo "$(MSG_PREFIX)\`\` Building binary:" $(notdir $@)
216
	$(VERBOSE)$(LD) -o $@ $^ $(LDFLAGS) $(LIBS)
Alan Mishchenko committed
217

218
lib$(PROG).a: $(LIBOBJ)
219
	@echo "$(MSG_PREFIX)\`\` Linking:" $(notdir $@)
220
	$(VERBOSE)$(AR) rsv $@ $?
Alan Mishchenko committed
221

222 223 224 225
lib$(PROG).so: $(LIBOBJ)
	@echo "$(MSG_PREFIX)\`\` Linking:" $(notdir $@)
	$(VERBOSE)$(CXX) -shared -o $@ $^ $(LIBS)

Alan Mishchenko committed
226
docs:
227
	@echo "$(MSG_PREFIX)\`\` Building documentation." $(notdir $@)
228
	$(VERBOSE)doxygen doxygen.conf
229 230 231

cmake_info:
	@echo SEPARATOR_CFLAGS $(CFLAGS) SEPARATOR_CFLAGS
232
	@echo SEPARATOR_CXXFLAGS $(CXXFLAGS) SEPARATOR_CXXFLAGS
233 234
	@echo SEPARATOR_LIBS $(LIBS) SEPARATOR_LIBS
	@echo SEPARATOR_SRC $(SRC) SEPARATOR_SRC