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