Browse files

First attempt at shared library support.

  • Loading branch information...
1 parent 1328a8d commit 4e6288ddbb65dc9d96163db50e161138525ddfef @niklasso committed Dec 16, 2010
Showing with 35 additions and 8 deletions.
  1. +35 −8 Makefile
View
43 Makefile
@@ -10,14 +10,20 @@ MINISAT_RELSYMBOLS ?= -g
MINISAT_REL ?= -O3 -D NDEBUG $(MINISAT_RELSYMBOLS)
MINISAT_DEB ?= -O0 -D DEBUG
MINISAT_PRF ?= -O3 -D NDEBUG
+MINISAT_FPIC ?= -fpic
# Target file names
MINISAT ?= minisat # Name of MiniSat main executable.
MINISAT_CORE ?= minisat_core # Name of simplified MiniSat executable (only core solver support).
-MINISAT_SLIB ?= libminisat.a # Name of MiniSat library.
+MINISAT_SLIB ?= libminisat.a # Name of MiniSat static library.
+MINISAT_DLIB ?= libminisat.so# Name of MiniSat shared library.
## Configurable options end #######################################################################
+SOMAJOR=2
+SOMINOR=0
+SORELEASE=0
+
MINISAT_CXXFLAGS = -I. -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS -Wall -Wno-parentheses
MINISAT_LDFLAGS = -Wall $(MINISAT_RELSYMBOLS) -lz
@@ -27,24 +33,28 @@ SRCS = $(wildcard minisat/core/*.cc) $(wildcard minisat/simp/*.cc) $(w
HDRS = $(wildcard minisat/mtl/*.h) $(wildcard minisat/core/*.h)$ $(wildcard minisat/simp/*.h) $(wildcard minisat/utils/*.h)
OBJS = $(filter-out %Main.o, $(SRCS:.cc=.o))
-.PHONY: r d p cr cd cp lr ld lp
+.PHONY: r d p sh cr cd cp csh lr ld lp lsh
r: $(BUILD_DIR)/release/bin/$(MINISAT)
d: $(BUILD_DIR)/debug/bin/$(MINISAT)
p: $(BUILD_DIR)/profile/bin/$(MINISAT)
+sh: $(BUILD_DIR)/dynamic/bin/$(MINISAT)
cr: $(BUILD_DIR)/release/bin/$(MINISAT_CORE)
cd: $(BUILD_DIR)/debug/bin/$(MINISAT_CORE)
cp: $(BUILD_DIR)/profile/bin/$(MINISAT_CORE)
+csh: $(BUILD_DIR)/dynamic/bin/$(MINISAT_CORE)
lr: $(BUILD_DIR)/release/lib/$(MINISAT_SLIB)
ld: $(BUILD_DIR)/debug/lib/$(MINISAT_SLIB)
lp: $(BUILD_DIR)/profile/lib/$(MINISAT_SLIB)
+lsh: $(BUILD_DIR)/dynamic/lib/$(MINISAT_DLIB)
## Build-type Compile-flags:
$(BUILD_DIR)/release/%.o: MINISAT_CXXFLAGS +=$(MINISAT_REL)
$(BUILD_DIR)/debug/%.o: MINISAT_CXXFLAGS +=$(MINISAT_DEB) -g
$(BUILD_DIR)/profile/%.o: MINISAT_CXXFLAGS +=$(MINISAT_PRF) -pg
+$(BUILD_DIR)/dynamic/%.o: MINISAT_CXXFLAGS +=$(MINISAT_REL) $(MINISAT_FPIC)
## Build-type Link-flags:
$(BUILD_DIR)/profile/bin/$(MINISAT): MINISAT_LDFLAGS += -pg
@@ -54,33 +64,50 @@ $(BUILD_DIR)/release/bin/$(MINISAT): MINISAT_LDFLAGS += --static
$(BUILD_DIR)/release/bin/$(MINISAT): $(BUILD_DIR)/release/minisat/simp/Main.o $(BUILD_DIR)/release/lib/$(MINISAT_SLIB)
$(BUILD_DIR)/debug/bin/$(MINISAT): $(BUILD_DIR)/debug/minisat/simp/Main.o $(BUILD_DIR)/debug/lib/$(MINISAT_SLIB)
$(BUILD_DIR)/profile/bin/$(MINISAT): $(BUILD_DIR)/profile/minisat/simp/Main.o $(BUILD_DIR)/profile/lib/$(MINISAT_SLIB)
+# need the main-file be compiled with fpic?
+$(BUILD_DIR)/dynamic/bin/$(MINISAT): $(BUILD_DIR)/dynamic/minisat/simp/Main.o $(BUILD_DIR)/dynamic/lib/$(MINISAT_DLIB)
## Executable dependencies (core-version)
$(BUILD_DIR)/release/bin/$(MINISAT_CORE): $(BUILD_DIR)/release/minisat/core/Main.o $(BUILD_DIR)/release/lib/$(MINISAT_SLIB)
$(BUILD_DIR)/debug/bin/$(MINISAT_CORE): $(BUILD_DIR)/debug/minisat/core/Main.o $(BUILD_DIR)/debug/lib/$(MINISAT_SLIB)
$(BUILD_DIR)/profile/bin/$(MINISAT_CORE): $(BUILD_DIR)/profile/minisat/core/Main.o $(BUILD_DIR)/profile/lib/$(MINISAT_SLIB)
+# need the main-file be compiled with fpic?
+$(BUILD_DIR)/dynamic/bin/$(MINISAT_CORE): $(BUILD_DIR)/dynamic/minisat/core/Main.o $(BUILD_DIR)/dynamic/lib/$(MINISAT_DLIB)
## Library dependencies
$(BUILD_DIR)/release/lib/$(MINISAT_SLIB): $(foreach o,$(OBJS),$(BUILD_DIR)/release/$(o))
$(BUILD_DIR)/debug/lib/$(MINISAT_SLIB): $(foreach o,$(OBJS),$(BUILD_DIR)/debug/$(o))
$(BUILD_DIR)/profile/lib/$(MINISAT_SLIB): $(foreach o,$(OBJS),$(BUILD_DIR)/profile/$(o))
+$(BUILD_DIR)/dynamic/lib/$(MINISAT_DLIB).$(SOMAJOR).$(SOMINOR).$(SORELEASE): $(foreach o,$(OBJS),$(BUILD_DIR)/dynamic/$(o))
## Compile rule
-$(BUILD_DIR)/release/%.o $(BUILD_DIR)/debug/%.o $(BUILD_DIR)/profile/%.o: %.cc
+$(BUILD_DIR)/release/%.o $(BUILD_DIR)/debug/%.o $(BUILD_DIR)/profile/%.o $(BUILD_DIR)/dynamic/%.o : %.cc
mkdir -p $(dir $@) $(dir $(BUILD_DIR)/dep/$*.d)
$(CXX) $(CXXFLAGS) $(MINISAT_CXXFLAGS) -c -o $@ $< -MMD -MF $(BUILD_DIR)/dep/$*.d
-## Linking rule (release/debug)
-$(BUILD_DIR)/release/bin/$(MINISAT) $(BUILD_DIR)/debug/bin/$(MINISAT) $(BUILD_DIR)/profile/bin/$(MINISAT)\
-$(BUILD_DIR)/release/bin/$(MINISAT_CORE) $(BUILD_DIR)/debug/bin/$(MINISAT_CORE) $(BUILD_DIR)/profile/bin/$(MINISAT_CORE):
+## Linking rule
+$(BUILD_DIR)/release/bin/$(MINISAT) $(BUILD_DIR)/debug/bin/$(MINISAT) $(BUILD_DIR)/profile/bin/$(MINISAT) $(BUILD_DIR)/dynamic/bin/$(MINISAT)\
+$(BUILD_DIR)/release/bin/$(MINISAT_CORE) $(BUILD_DIR)/debug/bin/$(MINISAT_CORE) $(BUILD_DIR)/profile/bin/$(MINISAT_CORE) $(BUILD_DIR)/dynamic/bin/$(MINISAT_CORE):
mkdir -p $(dir $@)
$(CXX) $^ $(LDFLAGS) $(MINISAT_LDFLAGS) -o $@
-## Library rule (release/debug)
-%$(MINISAT_SLIB):
+## Static Library rule
+%/lib/$(MINISAT_SLIB):
mkdir -p $(dir $@)
$(AR) -rcsv $@ $^
+## Shared Library rule
+$(BUILD_DIR)/dynamic/lib/$(MINISAT_DLIB).$(SOMAJOR).$(SOMINOR).$(SORELEASE):
+ mkdir -p $(dir $@)
+ $(CXX) $(MINISAT_LDFLAGS) -o $@ -shared -Wl,-soname,$(MINISAT_DLIB).$(SOMAJOR) $^
+
+## Shared Library links
+$(BUILD_DIR)/dynamic/lib/$(MINISAT_DLIB).$(SOMAJOR): $(BUILD_DIR)/dynamic/lib/$(MINISAT_DLIB).$(SOMAJOR).$(SOMINOR).$(SORELEASE)
+ ln -sf -T $(notdir $^) $@
+
+$(BUILD_DIR)/dynamic/lib/$(MINISAT_DLIB): $(BUILD_DIR)/dynamic/lib/$(MINISAT_DLIB).$(SOMAJOR)
+ ln -sf -T $(notdir $^) $@
+
## Include generated dependencies
## NOTE: dependencies are assumed to be the same in all build modes at the moment!
-include $(foreach s, $(SRCS:.cc=.d), $(BUILD_DIR)/dep/$s)

0 comments on commit 4e6288d

Please sign in to comment.