summaryrefslogtreecommitdiff
path: root/makefiles/gmake/libs.mk
blob: ada98531605cc895f396e77060d1fcefdff3fac2 (plain)
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
# provides explicit library rules
#
# requires:
# - STATIC_LIB: name of the static library
# - DYNAMIC_LIB: soname and versions of the shared library
# - DYNAMIC_MODULE: loadable module (for dlopen)
#
# - all others like OBJS, CPP_OBJS, LIBS, SH_OBJS, SHPP_OBJS, LDFLAGS
#
# provides:
# - targets to build the static and dynamic version of the project's library
# - targets to build the loadable module (no soname and funny installation
#   rules here)
#

# the soname of the shared library
ifneq "$(DYNAMIC_LIB)" ""
SONAME=$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR)
endif

# SONAME_FLAGS to indicate to the platform linker, we want to fiddle in the
# ELF header (more plaform/linker dependant than compiler dependant)

ifeq "$(PLATFORM)" "LINUX"
SONAME_FLAGS=-Wl,-soname,$(SONAME)
endif

ifeq "$(PLATFORM)" "SUNOS"
ifeq "$(COMPILER)" "gcc"  
SONAME_FLAGS=-Wl,-h,$(SONAME)
endif
ifeq "$(COMPILER)" "spro"
SONAME_FLAGS=-h $(SONAME)
endif
endif

ifeq "$(PLATFORM)" "FREEBSD"
SONAME_FLAGS=-Wl,-x,-soname,$(SONAME)
endif

ifeq "$(PLATFORM)" "OPENBSD"
SONAME_FLAGS=-Wl,-soname,$(SONAME)
endif

ifeq "$(PLATFORM)" "NETBSD"
SONAME_FLAGS=-Wl,-soname,$(SONAME)
endif

ifeq "$(PLATFORM)" "CYGWIN"
SONAME_FLAGS=-Wl,-soname,$(SONAME)
endif

# no soname and versioning for loadable modules, just dynamic linking
ifneq "$(DYNAMIC_MODULE)" ""
SONAME_FLAGS=
endif

# indicate we want to link shared, depends actually on the compiler more
# than on the platform
ifeq "$(COMPILER)" "gcc"
SO_LIB_FLAGS = -shared $(SONAME_FLAGS)
SO_MOD_FLAGS = -shared
endif
ifeq "$(COMPILER)" "spro"
SO_LIB_FLAGS = -G $(SONAME_FLAGS)
SO_MOD_FLAGS = -G
endif

ifneq "$(STATIC_LIB)" ""
$(STATIC_LIB) : $(OBJS) $(CPP_OBJS)
	$(AR) cr $@ $(OBJS) $(CPP_OBJS)
else
$(STATIC_LIB) :
endif

ifneq "$(DYNAMIC_LIB)" ""
$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH) : $(SH_OBJS) $(SHPP_OBJS)
	$(CXX_LINK) $(SO_LIB_FLAGS) -o $@ $(ALL_LDFLAGS) $(SH_OBJS) $(SHPP_OBJS) $(LIBS)
$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR) : $(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH)
	@test -z "$(DYNAMIC_LIB)" || ( \
		rm -f "$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR)" && \
		ln -s "$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH)" \
			"$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR)" )
$(DYNAMIC_LIB) : $(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH)
	@test -z "$(DYNAMIC_LIB)" || ( \
		rm -f "$(DYNAMIC_LIB)" && \
		ln -s "$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH)" \
			"$(DYNAMIC_LIB)" )	
else
$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH) :
endif

ifneq "$(DYNAMIC_MODULE)" ""
$(DYNAMIC_MODULE) : $(SH_OBJS) $(SHPP_OBJS)
	$(CXX_LINK) $(SO_MOD_FLAGS) -o $@ $(ALL_LDFLAGS) $(SH_OBJS) $(SHPP_OBJS) $(LIBS)
else
$(DYNAMIC_MODULE) :
endif