1##
2# Makefile for net-snmp
3##
4
5# General project info
6Project		= net-snmp
7ProjectName	= net_snmp
8UserType	= Administration
9ToolType	= Commands
10Submission	= 143
11
12
13#
14# Settings for the net-snmp project.
15#
16########################
17#
18# NOTE: when shipping library updates instead of the full package, you must also ship the updated
19#       /usr/include/net-snmp/net-snmp-config.h
20#
21########################
22#
23# Justification for #defines:
24# CONFORMANCE is to avoid confusing configure
25# UNSTABLE is required to pick up some other required structs
26# PrivateHeaders is so IPv6 can define struct ifnet.
27###
28# Disabled while trying to get build stuff working
29###
30
31########################
32# Allow selecting the compiler to be used
33########################
34SDKROOT ?=/
35CC = xcrun -sdk $(SDKROOT) cc
36CXX = xcrun -sdk $(SDKROOT) c++
37CLFAGS += -isysroot $(SDKROOT)
38CXXFLAGS += -isysroot $(SDKROOT)
39########################
40# for bug 8862468
41CFLAGS += -DNETSNMP_NO_INLINE
42
43DEFINES			= -DBUILD=$(Submission) \
44			-DMACOSX_DEPLOYMENT_TARGET=$(MACOSX_DEPLOYMENT_TARGET)
45INCLUDES		= -F/System/Library/PrivateFrameworks/ -F/System/Library/Frameworks/
46
47# For Perl to build correctly, both CFLAGS (CC_Flags) and CCFLAGS (Cxx_Flags)
48# must be properly defined.
49Extra_CC_Flags		= $(DEFINES) $(INCLUDES)
50Extra_Cxx_Flags		= $(Extra_CC_Flags)
51# also need ARCHFLAGS
52Default_ARCHFLAGS = -arch i386  -arch x86_64
53ifneq "$(RC_CFLAGS)" ""
54	ARCHFLAGS=$(RC_CFLAGS)
55else
56	ARCHFLAGS=$(Default_ARCHFLAGS)
57endif
58
59Extra_Configure_Flags	= --sysconfdir=/etc \
60			--with-install-prefix=$(DSTROOT) \
61			--with-default-snmp-version=2 \
62			--with-persistent-directory=/var/db/net-snmp \
63			--with-defaults \
64			--without-rpm \
65			--with-sys-contact="postmaster@example.com" \
66			--with-mib-modules="host ucd-snmp/diskio ucd-snmp/loadave " \
67			--disable-static \
68			--enable-ipv6 \
69			--with-perl-modules \
70			--disable-perl-cc-checks \
71			--disable-embedded-perl  \
72			--without-kmem-usage
73
74# ucd-snmp/lmSensorsTables
75
76# Old / unused configure flags
77#			--enable-mini-agent \
78#			--with-mib-modules="hardware/memory hardware/cpu host ucd-snmp/diskio ucd-snmp/loadave ucd-snmp/memory" \
79#			--with-out-mib-modules="mibII/icmp host/hr_swrun" \
80#			--enable-ipv6 \
81#			--enable-developer
82#			--with-libwrap=/usr/lib/libwrap.dylib
83#			--disable-embedded-perl  \
84
85
86# The following are sometimes necessary if DESTDIR or --with-install-prefix
87# are not respected.
88#Extra_Install_Flags	= exec_prefix=$(DSTROOT)$(Install_Prefix) \
89#			bindir=$(DSTROOT)$(USRBINDIR) \
90#			sbindir=$(DSTROOT)$(USRSBINDIR) \
91#			sysconfdir=$(DSTROOT)/etc \
92#			datadir=$(DSTROOT)$(SHAREDIR) \
93#			includedir=$(DSTROOT)$(USRINCLUDEDIR)/net-snmp \
94#			libdir=$(DSTROOT)$(USRLIBDIR) \
95#			libexecdir=$(DSTROOT)$(LIBEXECDIR) \
96#			localstatedir=$(DSTROOT)$(SHAREDIR)
97
98# For some reason, the Perl modules Makefiles use the environment
99# version of CCFLAGS instead of the one defined by the Makefile. The
100# wacky "INC=" is to used but not defined by the Makefile, so it's
101# used here to point to the project's headers instead of those already
102# installed on the system (which are out of date).
103Extra_Environment	= AR="$(SRCROOT)/ar.sh" INC="-I../../include -I../../../include"
104GnuAfterInstall		= install-macosx install-mibs install-compat 
105#GnuAfterInstall         = install-macosx install-mibs	# do not include the compatibility libs
106
107# Temporarily set for development
108GnuNoInstallHeaders	= YES
109
110# Binaries to strip
111STRIPPED_BINS	= encode_keychange snmpbulkget snmpbulkwalk snmpdelta snmpdf \
112			snmpget snmpgetnext snmpinform snmpnetstat \
113			snmpset snmpstatus snmptable snmptest snmptranslate \
114			snmptrap snmpusm snmpvacm snmpwalk agentxtrap
115STRIPPED_SBINS	= snmpd snmptrapd
116#STRIPPED_SNMPTRAPD	= snmptrapd
117STRIPPED_LIBS	= libnetsnmp libnetsnmpagent libnetsnmphelpers libnetsnmpmibs libnetsnmptrapd
118
119# Binaries to Lipo
120LIPO_BINS = $(STRIPPED_BINS)
121LIPO_SBINS = $(STRIPPED_SBINS)
122
123# Binary to patch
124CONFIGTOOL	= $(USRBINDIR)/net-snmp-config
125
126# MIB files to install
127MIBFILES	:= $(wildcard mibs/*.txt)
128MIBDIR		= $(SHAREDIR)/snmp/mibs
129
130# full patch list 
131#AEP_Patches    = diskio.patch IPv6.patch universal_builds.patch \
132#                        cache.patch container.patch darwin-header.patch \
133#                        dir_utils.patch disk.patch host.patch 6581429.patch \
134#                        lmsensors.patch darwin-sensors.patch swinst.patch swrun.patch \
135#                        system.patch table.patch darwin64.patch perl-cc.patch
136
137# Automatic Extract & Patch
138AEP		= YES
139AEP_Version	= 5.6
140AEP_Patches    = diskio.patch IPv6.patch universal_builds.patch \
141			container.patch darwin-header.patch \
142			host.patch \
143			lmsensors.patch darwin-sensors.patch \
144			darwin64.patch perl-cc.patch 
145AEP_LaunchdConfigs	= org.net-snmp.snmpd.plist
146AEP_ConfigDir	= $(ETCDIR)/snmp
147AEP_ConfigFiles	= snmpd.conf
148
149
150# Local targets that must be defined before including the following
151# files to get the dependency order correct
152.PHONY: $(GnuAfterInstall)
153
154install::
155
156# Include common makefile targets for B&I
157include $(MAKEFILEPATH)/CoreOS/ReleaseControl/GNUSource.make
158include $(MAKEFILEPATH)/CoreOS/ReleaseControl/AEP.make
159
160# Override settings from above include
161ifndef MACOSX_DEPLOYMENT_TARGET
162	MACOSX_DEPLOYMENT_TARGET = $(shell sw_vers -productVersion | cut -d. -f1-2)
163endif
164DESTDIR	= $(DSTROOT)
165
166# This project must be built in the source directory because the real
167# project (with configure) is there.
168BuildDirectory	= $(Sources)
169
170# This needs to be overridden because the project properly uses DESTDIR
171# (and supports the configure flag "--with-install-prefix").
172Install_Flags	= DESTDIR="$(DSTROOT)"
173# This project does not support the default "install-strip" target.
174Install_Target	= install 
175
176
177#
178# Post-extract target
179#
180#extract-source::
181#	$(CP) $(SHAREDIR)/libtool/ltmain.sh $(Sources)
182
183#
184# Pre-build targets
185#
186ifneq ($(GnuNoInstallHeaders),YES)
187install_headers:: $(GNUConfigStamp)
188	@echo "Installing headers..."
189	$(_v) umask $(Install_Mask) ; $(MAKE) -C $(BuildDirectory) $(Environment) installheaders
190	$(_v) $(FIND) $(DSTROOT) $(Find_Cruft) | $(XARGS) $(RMDIR)
191	$(_v) $(FIND) $(SYMROOT) $(Find_Cruft) | $(XARGS) $(RMDIR)
192ifneq ($(GnuNoChown),YES)
193	$(_v)- $(CHOWN) -R $(Install_User):$(Install_Group) $(DSTROOT) $(SYMROOT)
194endif
195endif
196
197
198#
199# Post-install targets
200#
201install-macosx:
202	@echo "Reorganizing install for Mac OS X..."
203	if [ -d $(DSTROOT)/etc ]; then 				\
204		$(MKDIR) -m 755 $(DSTROOT)/private;		\
205		$(MV) $(DSTROOT)/etc $(DSTROOT)/private;	\
206	fi
207	if [ -d $(DSTROOT)/var ]; then 				\
208		$(MKDIR) -m 755 $(DSTROOT)/private;		\
209		$(MV) $(DSTROOT)/var $(DSTROOT)/private;	\
210	fi
211	$(MKDIR) -m 700 $(DSTROOT)/private/var/agentx
212	@echo "Unzipping man pages..."
213	$(_v) if [ -d $(DSTROOT)$(Install_Man) ]; then		\
214		$(FIND) $(DSTROOT)/$(Install_Man) -name '*.gz' -print -exec gunzip {} \; ;	\
215	fi
216	@echo "Removing pod files..."
217	$(_v) $(RM) $(DSTROOT)/System/Library/Perl/5.8.8/darwin-thread-multi-2level/perllocal.pod
218	@echo "Removing broken tools..."
219	$(_v) $(RM) $(DSTROOT)$(USRBINDIR)/snmpcheck \
220				$(DSTROOT)$(USRBINDIR)/ipf-mod.pl
221	@echo "Stripping unstripped binaries..."
222	if [ ! -d $(SYMROOT) ]; then \
223		$(MKDIR) -m 755 $(SYMROOT); \
224	fi
225	$(_v) for file in $(STRIPPED_BINS); \
226	do \
227		$(CP) $(DSTROOT)$(USRBINDIR)/$${file} $(SYMROOT); \
228		$(STRIP) $(DSTROOT)$(USRBINDIR)/$${file}; \
229	done
230	$(_v) for file in $(STRIPPED_SBINS); \
231	do \
232		$(CP) $(DSTROOT)$(USRSBINDIR)/$${file} $(SYMROOT); \
233		$(STRIP) $(DSTROOT)$(USRSBINDIR)/$${file}; \
234	done
235#	$(_v) for file in $(STRIPPED_SNMPTRAPD); \
236#	do \
237#		$(CP) $(DSTROOT)$(USRSBINDIR)/$${file} $(SYMROOT); \
238#		echo "_SyslogTrap" > $(DSTROOT)$(USRSBINDIR)/snmptrapd.exp; \
239#		echo "_dropauth" >> $(DSTROOT)$(USRSBINDIR)/snmptrapd.exp; \
240#		$(STRIP) -s $(DSTROOT)$(USRSBINDIR)/snmptrapd.exp $(DSTROOT)$(USRSBINDIR)/$${file}; \
241#		$(RM) $(DSTROOT)$(USRSBINDIR)/snmptrapd.exp; \
242#	done
243	$(_v) for file in $(STRIPPED_LIBS); \
244	do \
245		$(CP) $(DSTROOT)$(USRLIBDIR)/$${file}*.dylib $(SYMROOT); \
246		$(STRIP) -x $(DSTROOT)$(USRLIBDIR)/$${file}.dylib; \
247	done
248	$(_v)- $(FIND) $(DSTROOT)$(NSLIBRARYSUBDIR)/Perl -type f -name '*.bundle' -print -exec strip -S {} \;
249	@echo "Removing 32-bit executable code from binaries..."
250	$(_v) for file in $(LIPO_BINS); \
251	do \
252		$(LIPO) -thin x86_64 $(DSTROOT)$(USRBINDIR)/$${file} -output $(DSTROOT)$(USRBINDIR)/$${file}.64; \
253		$(RM) $(DSTROOT)$(USRBINDIR)/$${file};\
254		$(MV) $(DSTROOT)$(USRBINDIR)/$${file}.64 $(DSTROOT)$(USRBINDIR)/$${file}; \
255	done
256	$(_v) for file in $(LIPO_SBINS); \
257	do \
258		$(LIPO) -thin x86_64 $(DSTROOT)$(USRSBINDIR)/$${file} -output $(DSTROOT)$(USRSBINDIR)/$${file}.64; \
259		$(RM) $(DSTROOT)$(USRSBINDIR)/$${file};\
260		$(MV) $(DSTROOT)$(USRSBINDIR)/$${file}.64 $(DSTROOT)$(USRSBINDIR)/$${file}; \
261	done
262
263	@echo "Copying sensor data"
264	$(_v) $(INSTALL_FILE) $(SRCROOT)/SensorDat.xml $(DSTROOT)$(SHAREDIR)/snmp
265	@echo "Fixing permissions..."
266	$(_v) $(FIND) $(DSTROOT)$(USRINCLUDEDIR)/net-snmp -type f -exec chmod 644 {} \;
267	$(_v) $(FIND) $(DSTROOT)$(SHAREDIR)/snmp -type f -exec chmod 644 {} \;
268	$(_v) $(RM) $(DSTROOT)$(USRLIBDIR)/*.a $(DSTROOT)$(USRLIBDIR)/*.la
269	$(_v) $(FIND) $(DSTROOT)$(MANDIR) -type f -exec chmod 644 {} \;
270	@echo "setting up snmpd proxy"
271	$(_v) $(MKDIR) -p $(DSTROOT)/usr/libexec/
272	$(_v) $(MV) $(DSTROOT)$(USRSBINDIR)/snmpd $(DSTROOT)/usr/libexec/snmpd
273	$(_v) $(CP) $(SRCROOT)/snmpd-proxy $(DSTROOT)$(USRSBINDIR)/snmpd
274	$(_v) $(CHOWN) root:wheel $(DSTROOT)$(USRSBINDIR)/snmpd
275	@echo "Removing perllocal.pod..."
276	$(_v) $(RM) -rf "$(DSTROOT)/System/Library/Perl"
277	@echo "Eliminating architecture flags from $(CONFIGTOOL)..."
278	$(MV) $(DSTROOT)$(CONFIGTOOL) $(DSTROOT)$(CONFIGTOOL).old
279	$(SED) -Ee 's/-arch [-_a-z0-9]{3,10}//g' \
280		-e '/^NSC_INCLUDEDIR=/s/=.*/=\/usr\/local\/include/' \
281		-e '/^NSC_LIBDIR=/s/=.*/=" "/' $(DSTROOT)$(CONFIGTOOL).old > $(DSTROOT)$(CONFIGTOOL)
282	$(CHMOD) 755 $(DSTROOT)$(CONFIGTOOL)
283	$(RM) $(DSTROOT)$(CONFIGTOOL).old
284
285install-mibs:
286	$(_v) for file in $(MIBFILES); \
287	do \
288		$(INSTALL_FILE) $${file} $(DSTROOT)$(MIBDIR); \
289	done
290
291install-compat:
292	$(_v) $(TAR) -C $(DSTROOT)$(USRLIBDIR) -xzf $(SRCROOT)/libs-5.2.1.tar.gz
293	@echo "Fixing privs on libnetsnmp.5.dylib ref bug# 6877106"
294	$(_v) $(CHMOD) -h 755 $(DSTROOT)$(USRLIBDIR)/libnetsnmp.5.dylib
295	$(_v) $(TAR) -C $(DSTROOT)$(USRLIBDIR) -xzf $(SRCROOT)/libs-5.4.2.1.tar.gz
296	$(_v) $(CHMOD) -h 755 $(DSTROOT)$(USRLIBDIR)/libnetsnmp.15.dylib
297