11
11
PREFIX_USR? =/usr
12
12
endif
13
13
14
- ifeq (i686 ,$(TARGET_CPU ) )
15
- CFLAGS+ =-m32
16
- LDFLAGS+ =-m32
17
- endif
18
- ifeq (x86_64 ,$(TARGET_CPU ) )
14
+ ifeq (x86_64 ,$(RPM_ARCH ) )
15
+ ABI_BITS =64
16
+ LIB_BITS =64
17
+ else
18
+ ifneq ( ,$(wildcard /lib64 ) )
19
19
ABI_BITS =64
20
- CFLAGS+ =-m64
21
- LDFLAGS+ =-m64
20
+ LIB_BITS =64
21
+ endif
22
22
endif
23
23
24
- ifeq (,$(TARGET_CPU ) )
25
- _HAS_LIB64: =$(wildcard /lib64)
26
- ifneq (,$(_HAS_LIB64 ) )
27
- ABI_BITS =64
28
- ABI_FLAGS =-m64
24
+ # 'gmake ABI_BITS=64' for 64-bit build (recommended on all 64-bit platforms)
25
+ ifeq (64,$(ABI_BITS ) )
26
+ ifeq ($(OSNAME ) ,Linux)
27
+ ABI_FLAGS =-m64
28
+ endif
29
+ ifeq ($(OSNAME ) ,AIX)
30
+ AR+ =-X64
31
+ ABI_FLAGS =-maix64
29
32
endif
33
+ ifeq ($(OSNAME ) ,HP-UX)
34
+ ABI_FLAGS =-mlp64
30
35
endif
36
+ ifeq ($(OSNAME ) ,SunOS)
37
+ ABI_FLAGS =-m64
38
+ endif
39
+ endif
40
+
41
+ ifneq (,$(RPM_OPT_FLAGS ) )
42
+ CFLAGS+ =$(RPM_OPT_FLAGS ) -std=c99
43
+ LDFLAGS+ =$(RPM_OPT_FLAGS )
44
+ else
45
+ CC =gcc -pipe
46
+ CFLAGS+ =-Wall -Winline -pedantic -ansi -std=c99 -O3 -g $(ABI_FLAGS )
47
+ LDFLAGS+ =$(ABI_FLAGS )
48
+ endif
49
+
50
+ # Thread-safety (e.g. for thread-specific errno)
51
+ # (vendor compilers might need additional compiler flags, e.g. Sun Studio -mt)
52
+ CFLAGS+ =-D_THREAD_SAFE
31
53
32
- CC =gcc -pipe
33
- CFLAGS+ =$(ABI_FLAGS ) -Wall -Winline -pedantic -ansi -std=c99 -D_THREAD_SAFE -O3
34
- CFLAGS+ =-g -D_FORTIFY_SOURCE=2 -fstack-protector
35
- LDFLAGS+ =-Wl,-O,1 -Wl,--hash-style,gnu -Wl,-z,relro,-z,now $(ABI_FLAGS )
36
54
# To disable uint32 and nointr C99 inline functions:
37
55
# -DNO_C99INLINE
38
56
# Another option to smaller binary is -Os instead of -O3, and remove -Winline
39
57
58
+ OSNAME: =$(shell /bin/uname -s)
59
+ ifeq ($(OSNAME ) ,Linux)
60
+ ifneq (,$(strip $(filter-out /usr,$(PREFIX))))
61
+ RPATH = -Wl,-rpath,$(PREFIX ) /lib$(LIB_BITS )
62
+ endif
63
+ ifeq (,$(RPM_OPT_FLAGS))
64
+ CFLAGS+=-D_FORTIFY_SOURCE =2 -fstack-protector
65
+ endif
66
+ LDFLAGS+ =-Wl,-O,1 -Wl,--hash-style,gnu -Wl,-z,relro,-z,now
67
+ mcdbctl nss_mcdbctl t/testmcdbmake t/testmcdbrand t/testzero : \
68
+ LDFLAGS+ =-Wl,-z,noexecstack
69
+ endif
70
+ ifeq ($(OSNAME ) ,AIX)
71
+ ifneq (,$(strip $(filter-out /usr,$(PREFIX))))
72
+ RPATH = -Wl,-b,libpath:$(PREFIX ) /lib$(LIB_BITS )
73
+ endif
74
+ # -lpthreads (AIX) for pthread_mutex_{lock,unlock}() in mcdb.o and nss_mcdb.o
75
+ libmcdb.so lib32/libmcdb.so libnss_mcdb.so.2 lib32/libnss_mcdb.so.2 \
76
+ mcdbctl nss_mcdbctl t/testmcdbrand : \
77
+ LDFLAGS+ =-lpthreads
78
+ endif
79
+ ifeq ($(OSNAME ) ,HP-UX)
80
+ ifneq (,$(strip $(filter-out /usr,$(PREFIX))))
81
+ RPATH = -Wl,+b,$(PREFIX ) /lib$(LIB_BITS )
82
+ endif
83
+ endif
84
+ ifeq ($(OSNAME ) ,SunOS)
85
+ ifneq (,$(strip $(filter-out /usr,$(PREFIX))))
86
+ RPATH = -Wl,-R,$(PREFIX ) /lib$(LIB_BITS )
87
+ endif
88
+ CFLAGS+ =-D_POSIX_PTHREAD_SEMANTICS
89
+ # -lsocket -lnsl for inet_pton() in nss_mcdb_netdb.o and nss_mcdb_netdb_make.o
90
+ libnss_mcdb.so.2 lib32/libnss_mcdb.so.2 nss_mcdbctl : \
91
+ LDFLAGS+ =-lsocket -lnsl
92
+ # -lrt for fdatasync() in mcdb_make.o
93
+ libmcdb.so lib32/libmcdb.so mcdbctl nss_mcdbctl : \
94
+ LDFLAGS+ =-lrt
95
+ endif
96
+
40
97
# heavy handed dependencies
41
98
_DEPENDENCIES_ON_ALL_HEADERS_Makefile: = $(wildcard * .h) Makefile
42
99
@@ -46,72 +103,75 @@ _DEPENDENCIES_ON_ALL_HEADERS_Makefile:= $(wildcard *.h) Makefile
46
103
nss_mcdb.o : CFLAGS+=-DNSS_MCDB_PATH='"$(PREFIX ) /etc/mcdb/"'
47
104
lib32/nss_mcdb.o : CFLAGS+=-DNSS_MCDB_PATH='"$(PREFIX ) /etc/mcdb/"'
48
105
49
- PIC_OBJS: = mcdb.o mcdb_make.o mcdb_makefmt.o mcdb_makefn.o \
50
- nointr .o uint32 .o nss_mcdb.o nss_mcdb_acct .o nss_mcdb_netdb.o
106
+ PIC_OBJS: = mcdb.o mcdb_make.o mcdb_makefmt.o mcdb_makefn.o nointr.o uint32.o \
107
+ nss_mcdb .o nss_mcdb_acct .o nss_mcdb_authn .o nss_mcdb_netdb.o
51
108
$(PIC_OBJS ) : CFLAGS+= -fpic
52
109
53
110
# (nointr.o, uint32.o need not be included when fully inlined; adds 10K to .so)
54
- libnss_mcdb.so.2 : mcdb.o nss_mcdb.o nss_mcdb_acct.o nss_mcdb_netdb.o
55
- $(CC ) -o $@ -shared -fpic -Wl,-soname,$(@F ) \
56
- -Wl,--version-script,nss_mcdb.map \
57
- $(LDFLAGS) \
58
- $^
111
+ ifeq ($(OSNAME ) ,Linux)
112
+ libnss_mcdb.so.2 : LDFLAGS+=-Wl,-soname,$(@F ) -Wl,--version-script,nss_mcdb.map
113
+ endif
114
+ libnss_mcdb.so.2 : mcdb.o \
115
+ nss_mcdb.o nss_mcdb_acct.o nss_mcdb_authn.o nss_mcdb_netdb.o
116
+ $(CC) -o $@ -shared -fpic $(LDFLAGS) $^
59
117
118
+ ifeq ($(OSNAME ) ,Linux)
119
+ libmcdb.so : LDFLAGS+=-Wl,-soname,mcdb
120
+ endif
60
121
libmcdb.so : mcdb.o mcdb_make.o mcdb_makefmt.o mcdb_makefn.o nointr.o uint32.o
61
- $(CC ) -o $@ -shared -fpic -Wl,-soname,mcdb \
62
- $(LDFLAGS) \
63
- $^
122
+ $(CC ) -o $@ -shared -fpic $(LDFLAGS ) $^
64
123
65
124
libmcdb.a : mcdb.o mcdb_error.o mcdb_make.o mcdb_makefmt.o mcdb_makefn.o \
66
125
nointr.o uint32.o
67
126
$(AR) -r $@ $^
68
127
69
- libnss_mcdb.a : nss_mcdb.o nss_mcdb_acct.o nss_mcdb_netdb.o
128
+ libnss_mcdb.a : nss_mcdb.o nss_mcdb_acct.o nss_mcdb_authn.o nss_mcdb_netdb.o
70
129
$(AR ) -r $@ $^
71
130
72
- libnss_mcdb_make.a : nss_mcdb_make.o nss_mcdb_acct_make.o nss_mcdb_netdb_make.o
131
+ libnss_mcdb_make.a : nss_mcdb_make.o nss_mcdb_acct_make.o nss_mcdb_authn_make.o \
132
+ nss_mcdb_netdb_make.o
73
133
$(AR) -r $@ $^
74
134
75
135
mcdbctl : mcdbctl.o libmcdb.a
76
- $(CC ) -o $@ $(LDFLAGS ) -Wl,-z,noexecstack $^
136
+ $(CC ) -o $@ $(LDFLAGS ) $^
77
137
78
138
t/% .o : CFLAGS+=-I$(CURDIR )
79
139
80
140
t/testmcdbmake : t/testmcdbmake.o libmcdb.a
81
- $(CC ) -o $@ $(LDFLAGS ) -Wl,-z,noexecstack $^
141
+ $(CC ) -o $@ $(LDFLAGS ) $^
82
142
83
143
t/testmcdbrand : t/testmcdbrand.o libmcdb.a
84
- $(CC ) -o $@ $(LDFLAGS ) -Wl,-z,noexecstack $^
144
+ $(CC ) -o $@ $(LDFLAGS ) $^
85
145
86
146
t/testzero : t/testzero.o libmcdb.a
87
- $(CC ) -o $@ $(LDFLAGS ) -Wl,-z,noexecstack $^
147
+ $(CC ) -o $@ $(LDFLAGS ) $^
88
148
89
149
nss_mcdbctl : nss_mcdbctl.o libnss_mcdb_make.a libmcdb.a
90
- $(CC ) -o $@ $(LDFLAGS ) -Wl,-z,noexecstack $^
150
+ $(CC ) -o $@ $(LDFLAGS ) $^
91
151
92
- $(PREFIX ) /lib$(ABI_BITS ) $(PREFIX ) /sbin :
152
+ $(PREFIX ) /lib$(LIB_BITS ) $(PREFIX ) /sbin :
93
153
/bin/mkdir -p -m 0755 $@
94
- ifneq (,$(ABI_BITS ) )
154
+ ifneq (,$(LIB_BITS ) )
95
155
$(PREFIX ) /lib $(PREFIX_USR ) /lib :
96
156
/bin/mkdir -p -m 0755 $@
97
157
endif
98
158
ifneq ($(PREFIX_USR ) ,$(PREFIX ) )
99
- $(PREFIX_USR ) /lib$(ABI_BITS ) $(PREFIX_USR ) /bin :
159
+ $(PREFIX_USR ) /lib$(LIB_BITS ) $(PREFIX_USR ) /bin :
100
160
/bin/mkdir -p -m 0755 $@
101
- $(PREFIX_USR ) /lib$(ABI_BITS ) /libnss_mcdb.so.2 : \
102
- $(PREFIX)/lib$(ABI_BITS )/libnss_mcdb.so.2 $(PREFIX_USR)/lib$(ABI_BITS )
161
+ $(PREFIX_USR ) /lib$(LIB_BITS ) /libnss_mcdb.so.2 : \
162
+ $(PREFIX)/lib$(LIB_BITS )/libnss_mcdb.so.2 $(PREFIX_USR)/lib$(LIB_BITS )
103
163
[ -L $@ ] || /bin/ln -s ../../lib/$(<F) $@
104
164
endif
105
165
106
166
# (update library atomically (important to avoid crashing running programs))
107
167
# (could use /usr/bin/install if available)
108
- $(PREFIX ) /lib$(ABI_BITS ) /libnss_mcdb.so.2 : libnss_mcdb.so.2 \
109
- $(PREFIX)/lib$(ABI_BITS )
168
+ $(PREFIX ) /lib$(LIB_BITS ) /libnss_mcdb.so.2 : libnss_mcdb.so.2 \
169
+ $(PREFIX)/lib$(LIB_BITS )
110
170
/bin/cp -f $< $@.$$$$ \
111
171
&& /bin/mv -f $@.$$$$ $@
112
172
113
- $(PREFIX_USR ) /lib$(ABI_BITS ) /libmcdb.so : libmcdb.so \
114
- $(PREFIX_USR)/lib$(ABI_BITS )
173
+ $(PREFIX_USR ) /lib$(LIB_BITS ) /libmcdb.so : libmcdb.so \
174
+ $(PREFIX_USR)/lib$(LIB_BITS )
115
175
/bin/cp -f $< $@.$$$$ \
116
176
&& /bin/mv -f $@.$$$$ $@
117
177
@@ -133,41 +193,44 @@ install-doc: CHANGELOG COPYING FAQ INSTALL NOTES README
133
193
/bin/mkdir -p -m 0755 $(PREFIX_USR ) /share/doc/mcdb
134
194
umask 333; \
135
195
/bin/cp -f --preserve=timestamps $^ $(PREFIX_USR ) /share/doc/mcdb
136
- install : $(PREFIX ) /lib$(ABI_BITS ) /libnss_mcdb.so.2 \
137
- $(PREFIX_USR)/lib$(ABI_BITS )/libnss_mcdb.so.2 \
138
- $(PREFIX_USR)/lib$(ABI_BITS )/libmcdb.so \
196
+ install : $(PREFIX ) /lib$(LIB_BITS ) /libnss_mcdb.so.2 \
197
+ $(PREFIX_USR)/lib$(LIB_BITS )/libnss_mcdb.so.2 \
198
+ $(PREFIX_USR)/lib$(LIB_BITS )/libmcdb.so \
139
199
$(PREFIX_USR)/bin/mcdbctl $(PREFIX)/sbin/nss_mcdbctl \
140
200
install-headers
141
201
/bin/mkdir -p -m 0755 $(PREFIX)/etc/mcdb
142
202
143
203
144
204
# also create 32-bit libraries for /lib on systems with /lib and /lib64
145
- ifeq (,$(TARGET_CPU ) )
146
- ifneq (,$(_HAS_LIB64 ) )
147
- ifneq (,$(ABI_BITS ) )
205
+ ifeq (,$(RPM_ARCH ) )
206
+ ifeq (64,$(LIB_BITS ) )
148
207
ifeq (,$(wildcard lib32) )
149
208
$(shell mkdir lib32)
150
209
endif
151
210
lib32/% .o : % .c $(_DEPENDENCIES_ON_ALL_HEADERS_Makefile )
152
211
$(CC ) -o $@ $(CFLAGS ) -c $<
153
212
154
213
LIB32_PIC_OBJS: = $(addprefix lib32/,$(PIC_OBJS ) )
155
- $(LIB32_PIC_OBJS ) : ABI_BITS =32
214
+ $(LIB32_PIC_OBJS ) : LIB_BITS =32
156
215
$(LIB32_PIC_OBJS ) : ABI_FLAGS=-m32
157
216
$(LIB32_PIC_OBJS ) : CFLAGS+= -fpic
217
+
218
+ ifeq ($(OSNAME ) ,Linux)
219
+ lib32/libnss_mcdb.so.2 : \
220
+ LDFLAGS+ =-Wl,-soname,$(@F ) -Wl,--version-script,nss_mcdb.map
221
+ endif
158
222
lib32/libnss_mcdb.so.2 : ABI_FLAGS=-m32
159
223
lib32/libnss_mcdb.so.2 : $(addprefix lib32/, \
160
- mcdb.o nss_mcdb.o nss_mcdb_acct.o nss_mcdb_netdb.o)
161
- $(CC ) -o $@ -shared -fpic -Wl,-soname,$(@F ) \
162
- -Wl,--version-script,nss_mcdb.map \
163
- $(LDFLAGS) \
164
- $^
224
+ mcdb.o nss_mcdb.o nss_mcdb_acct.o nss_mcdb_authn.o nss_mcdb_netdb.o)
225
+ $(CC ) -o $@ -shared -fpic $(LDFLAGS ) $^
226
+
227
+ ifeq ($(OSNAME ) ,Linux)
228
+ lib32/libmcdb.so : LDFLAGS+=-Wl,-soname,mcdb
229
+ endif
165
230
lib32/libmcdb.so : ABI_FLAGS=-m32
166
231
lib32/libmcdb.so : $(addprefix lib32/, \
167
232
mcdb.o mcdb_make.o mcdb_makefmt.o mcdb_makefn.o nointr.o uint32.o)
168
- $(CC ) -o $@ -shared -fpic -Wl,-soname,mcdb \
169
- $(LDFLAGS) \
170
- $^
233
+ $(CC ) -o $@ -shared -fpic $(LDFLAGS ) $^
171
234
172
235
ifneq ($(PREFIX_USR ) ,$(PREFIX ) )
173
236
$(PREFIX_USR ) /lib/libnss_mcdb.so.2 : $(PREFIX ) /lib/libnss_mcdb.so.2 \
@@ -183,13 +246,12 @@ $(PREFIX_USR)/lib/libmcdb.so: lib32/libmcdb.so $(PREFIX_USR)/lib
183
246
/bin/cp -f $< $@ .$$$$ \
184
247
&& /bin/mv -f $@ .$$$$ $@
185
248
186
- all : lib32/libnss_mcdb.so.2
249
+ all : lib32/libnss_mcdb.so.2 lib32/libmcdb.so
187
250
188
251
install : $(PREFIX ) /lib/libnss_mcdb.so.2 $(PREFIX_USR ) /lib/libnss_mcdb.so.2 \
189
252
$(PREFIX_USR)/lib/libmcdb.so
190
253
endif
191
254
endif
192
- endif
193
255
194
256
195
257
.PHONY : test test64
@@ -211,7 +273,7 @@ endif
211
273
212
274
.PHONY : clean
213
275
clean :
214
- ! [ " $$ ($( usr_bin_id) -u)" = " 0" ]
276
+ [ " $$ ($( usr_bin_id) -u)" ! = " 0" ]
215
277
$(RM ) * .o t/* .o
216
278
$(RM ) -r lib32
217
279
$(RM ) libmcdb.a libnss_mcdb.a libnss_mcdb_make.a
0 commit comments