1#########################################################################
2# Uptime Client v5.0b8
3# $Id: Makefile,v 1.58 2003/05/26 22:29:23 carstenklapp Exp $
4#
5# Logs system uptime and statistics with Uptimes Project servers
6#
7# Copyright (C) 1999-2002 Martijn Broenland, Alex C. de Haas, Carsten Klapp
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22#
23# Carsten Klapp <carstenklapp@users.sourceforge.net>
24# Alex C. de Haas <alex@uptimes.net>
25# Martijn Broenland <tgm@uptimes.net>
26#
27#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
28# Makefile
29#
30# Disclaimer: This Makefile needs a lot of work. Help!!
31#
32# Please report problems and suggestions(!) about this new Makefile to
33# Carsten at the above address.
34#
35  PROGRAMNAME = UpClient
36# UPCLIENT_VERSION = "5.0b8"
37  UPCLIENT_VERSION = `sed -n 's/"//g;/\#define UPCLIENT_VERSION /s///p' version.h`
38#########################################################################
39
40
41binname = upclient
42
43# Uptimes Server
44uptimes_server = uptimes.hostingwired.com
45
46OPTIMIZATION_CFLAGS=-O3
47
48# System directories
49prefix = /usr/local
50#prefix = /sw
51#prefix = /opt/${binname}
52#prefix = /tmp/upclient
53
54mandir = ${prefix}/share/man
55#mandir = ${prefix}/man
56
57exec_prefix = ${prefix}
58sbindir = ${exec_prefix}/sbin
59datadir = ${prefix}/share
60sysconfdir = ${prefix}/etc
61#sysconfdir = /etc
62#localstatedir = ${prefix}/var
63localstatedir = /var
64destdir=
65
66
67# Further Reading
68# Filesystem Hierarchy Standard 2.2 May 24, 2001
69# http://www.pathname.com/fhs/
70#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
71# Uncomment the lines for your system if you want to use Gettext
72# localization. Included languages: Deutsch, Fran�ais
73
74LANGUAGES=de es fr it nl
75
76## generic
77#localedir = ${datadir}/locale
78#LOCALEFLAGS = -DLOCALEPATH=\"$(localedir)\"
79#LOCALELIBS = -lintl
80
81## [x86] Linux 2.4 (Debian 2.2)
82## [x86] Linux 2.4 (Redhat 7.3)
83## [Alpha] Linux 2.4 (Debian 3.0)
84## [PPC - RS/6000]  Linux 2.2 (Debian 3.0)
85## [CerfCube SA1110] Linux 2.4 (Debian 3.0)
86## [PPC - 601] MkLinux (DR3)
87#localedir = ${datadir}/locale
88#LOCALEFLAGS = -DLOCALEPATH=\"$(localedir)\"
89#LOCALELIBS =
90
91## [x86] FreeBSD (4.7-RC)
92## assumes gettext installed in /usr/local
93localedir = ${datadir}/locale
94LOCALEFLAGS = -DLOCALEPATH=\"$(localedir)\" -I/usr/local/include
95LOCALELIBS = -L/usr/local/lib -lintl
96
97## [Sparc - R220] Sun Solaris (5.8)
98## not sure whether this locale dir is correct
99#localedir = ${prefix}/lib/locale
100#LOCALEFLAGS = -DLOCALEPATH=\"$(localedir)\"
101#LOCALELIBS = -lintl
102
103## [PPC] Darwin-fink
104#localedir = /sw/share/locale
105#LOCALEFLAGS = -DLOCALEPATH=\"$(localedir)\"
106#LOCALELIBS = -lintl
107
108#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
109# -DPARANOID prevents any data from being transmitted!
110# -DDBUG gives extra messages.
111#DEBUGFLAGS=-g3 -DDEBUG
112#DEBUGFLAGS=-g3 -DDEBUG -DPARANOID
113
114WARNINGFLAGS=-Wpointer-arith -Wbad-function-cast -Wcast-qual		\
115 -Wcast-align -Wconversion -Wstrict-prototypes -Wmissing-prototypes	\
116 -Wmissing-declarations -Wnested-externs -Wformat-security -Wformat	\
117 -Wcomment -Wchar-subscripts -Wunused -Wbad-function-cast -Wconversion
118#########################################################################
119# No user serviceable parts below
120
121MAKEFLAGS=$(MFLAGS)
122
123# compiler files
124SOURCES = stats-bsd.c stats-uxw.c stats-ult.c stats-sol.c stats-lnx.c	\
125 stats-mach.c stats-aix.c stats-beos.c stats-w2k.c network.c base64.c	\
126 options.c uplog.c transmit.c upclient.c
127OBJECTS = stats-bsd.o stats-uxw.o stats-ult.o stats-sol.o stats-lnx.o	\
128 stats-mach.o stats-aix.o stats-beos.o stats-w2k.o network.o base64.o	\
129 options.o uplog.o transmit.o upclient.o
130
131OBJECTSDIR=objects
132PRODUCTSDIR=products
133
134# our files
135MANFILE = $(binname).8
136DOCS = AUTHORS INSTALL README TODO COPYING HISTORY HISTORY-BETA FAQ	\
137 "Uptimes Protocol 5" TODO-splint TODO-flawfinder
138DOCDIR = ${datadir}/doc/$(binname)
139
140# more of our files
141CONFIGFILE = $(binname).conf
142CONFIGPATH = ${sysconfdir}/$(CONFIGFILE)
143#DEBUGCONFIGPATH=./upclient.conf
144PIDFILE = ${binname}.pid
145PIDPATH = ${localstatedir}/run/$(PIDFILE)
146PATHFLAGS = -DCONFIGFILE=\"$(CONFIGPATH)\" -DPIDFILE=\"$(PIDPATH)\"
147
148# install commands (not used for install-solaris)
149INSTALL_PROGRAM = install -m 750
150INSTALL_DATA = install -m 644
151INSTALL_CONFIG = install -m 600
152
153#########################################################################
154# targets
155
156nothing-specified:
157	       #########################################################################
158	@echo ""
159	@echo "BUILD:"
160	@echo "To compile with gettext you must first edit the Makefile."
161	@echo "Please specify the system which you want to compile for:"
162	@echo "make bsd         OpenBSD, FreeBSD, NetBSD"
163	@echo "make darwin      Darwin, Mac OS X"
164	@echo "make solaris     Solaris, SunOS"
165	@echo "make linux       Linux"
166	@echo "make irix        Irix"
167	@echo "make ultrix      Ultrix"
168	@echo "make unixware    UnixWare"
169	@echo "make aix         AIX"
170	@echo "make beos        BeOS"
171	@echo "make winnt       Windows NT4/2000"
172	@echo ""
173	@echo "INSTALL:"
174	@echo "make install            use generic 'install' program (GNU)"
175	@echo "make install-solaris"
176	@echo "or make install-irix    if using Solaris/SunOS 'install' program"
177	@echo ""
178	@echo "LOCALIZED INSTALL:"
179	@echo "make install-locales            generic 'install' with gettext"
180	@echo "make install-locales-solaris"
181	@echo "make install-locales-irix       Solaris/SunOS with gettext"
182	@echo ""
183	@echo "PREVIEW:"
184	@echo "make pathcheck    preview paths used for compile & install,"
185	@echo "                  (nothing compiled)"
186	@echo ""
187	@echo "make uninstall    uninstalls all but config file"
188	@echo ""
189	       #########################################################################
190
191pathcheck:
192	@echo "prefix        = ${prefix}"
193	@echo "exec_prefix   = ${exec_prefix}"
194	@echo "datadir       = ${datadir}"
195	@echo "mandir        = ${mandir}"
196	@echo "docdir        = ${docdir}"
197	@echo "sysconfdir    = ${sysconfdir}"
198	@echo "localstatedir = ${localstatedir}"
199	@echo "localedir     = ${localedir}"
200	@echo "destdir       = ${destdir}"
201
202bsd:
203	$(MAKE) $(MAKEFLAGS) CC="cc"		\
204		LDFLAGS='$(LDFLAGS) -lkvm'	\
205		PLATFORMFLAG='-DPLATFORM_BSD'	\
206		all
207
208darwin:
209	$(MAKE) $(MAKEFLAGS) CC=cc			\
210		LDFLAGS='$(LDFLAGS) -lkvm -prebind'	\
211		CFLAGS='$(CFLAGS) -prebind'		\
212		PLATFORMFLAG='-DPLATFORM_BSD'		\
213		all
214
215darwin-fink:
216	$(MAKE) $(MAKEFLAGS) CC=cc			\
217		prefix=/sw mandir=/sw/share/man		\
218		LDFLAGS='$(LDFLAGS) -prebind -lkvm'	\
219		CFLAGS='$(CFLAGS) -prebind'		\
220		PLATFORMFLAG='-DPLATFORM_BSD'		\
221		all
222#		CFLAGS='-O3 -prebind -I/sw/include -mcpu=7400 -mmultiple -faltivec'	\
223
224unixware:
225	$(MAKE) $(MAKEFLAGS) CC="cc"			\
226		PLATFORMFLAG='-DPLATFORM_UNIXWARE'	\
227		all
228
229ultrix:
230	$(MAKE) $(MAKEFLAGS) CC=mwcc			\
231		PLATFORMFLAG='-DPLATFORM_ULTRIX'	\
232		all
233
234# Uncomment this if default Irix won't work. (This might not work either)
235#irix:
236#	$(MAKE) $(MAKEFLAGS) CC=cc			\
237#		LDFLAGS='$(LDFLAGS) -lnet'		\
238#		OBJECTS='$(OBJECTS) stats-ult.o'	\
239#		SOURCES='$(SOURCES) stats-ult.c'	\
240#		CFLAGS=$(CFLAGS) -fullwarn		\
241#		PLATFORMFLAG='-DPLATFORM_ULTRIX'	\
242#		all-solaris
243
244irix:
245	$(MAKE) $(MAKEFLAGS) CC="cc"			\
246		PLATFORMFLAG='-DPLATFORM_SOLARIS'	\
247		all-irix
248
249solaris:
250	$(MAKE) $(MAKEFLAGS) CC="cc"			\
251		LDFLAGS='$(LDFLAGS) -lsocket -lnsl'	\
252		PLATFORMFLAG='-DPLATFORM_SOLARIS'	\
253		all-solaris
254
255linux:
256	$(MAKE) $(MAKEFLAGS) CC="cc"		\
257		PLATFORMFLAG='-DPLATFORM_LINUX'	\
258		all
259
260aix:
261	$(MAKE) $(MAKEFLAGS) CC=cc		\
262		PLATFORMFLAG='-DPLATFORM_AIX'	\
263		all
264
265beos:
266	$(MAKE) $(MAKEFLAGS) CC="cc"		\
267		PLATFORMFLAG='-DPLATFORM_BEOS'	\
268		all
269
270winnt:
271	$(MAKE) $(MAKEFLAGS) CC=bcc32					    \
272		CONFIGPATH="\"C:\\Program Files\\Upclient\\$(CONFIGFILE)\"" \
273		OBJECTS='$(OBJECTS) compat/wsyslog.o'			    \
274		SOURCES='$(SOURCES) compat/wsyslog.c'			    \
275		PLATFORMFLAG='-DPLATFORM_WINNT'				    \
276		all-win
277
278#########################################################################
279version:
280	@echo "Making ${PROGRAMNAME} $(UPCLIENT_VERSION)..."
281
282all: upclient upclient.man upclient.conf
283all-solaris: upclient upclient.man upclient.conf.solaris
284all-irix: all-solaris
285all-win: upclient upclient.conf
286
287$(OBJECTS): $(OBJECTSDIR)
288
289.c.o:
290	if [ ! -f $(OBJECTSDIR)/$@ ]; then			\
291	    $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LOCALEFLAGS)	\
292	    $(PLATFORMFLAG) $(PATHFLAGS) $(DEBUGFLAGS)		\
293	    $(WARNINGFLAGS) -c $< -o $(OBJECTSDIR)/$@;		\
294	 fi
295
296$(PRODUCTSDIR) $(OBJECTSDIR):
297	mkdir -p $@
298
299upclient: version $(OBJECTS) $(PRODUCTSDIR)
300	if [ ! -f $(PRODUCTSDIR)/$@ ]; then				\
301	    cd $(OBJECTSDIR) ; $(CC) $(OPTIMIZATION_CFLAGS) $(CFLAGS)	\
302	    $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LOCALELIBS)	\
303	    $(LOCALEFLAGS) $(PLATFORMFLAG) $(PATHFLAGS) $(DEBUGFLAGS)	\
304	    $(WARNINGFLAGS) $(OBJECTS) -o ../${PRODUCTSDIR}/${binname};	\
305	    echo "Done". ;						\
306	else								\
307	   echo "$@ is up to date." ;					\
308	fi
309
310upclient.man: $(PRODUCTSDIR)
311	@if [ -f $(PRODUCTSDIR)/$(MANFILE) ]; then			\
312	   echo $(MANFILE) is up to date. ;				\
313	 else								\
314	   echo Inserting paths into man file ;				\
315	   sed -e s@__NAME__@$(PROGRAMNAME)@g				\
316	       -e s@__UPCLIENT_VERSION__@$(UPCLIENT_VERSION)@g		\
317	       -e s@__BINNAME__@${binname}@g				\
318	       -e s@__SBINDIR__@${sbindir}@g				\
319	       -e s@__PIDFILE__@$(PIDPATH)@g				\
320	       -e s@__CONFIGFILE__@$(CONFIGPATH)@g			\
321	       -e s@__UPTIMES_SERVER__@${uptimes_server}@g		\
322	       -e s@__DATADIR__@${datadir}@g				\
323	       ./man/$(binname).man > $(PRODUCTSDIR)/$(MANFILE) ;	\
324	 fi
325
326upclient.conf: $(PRODUCTSDIR)
327	@if [ -f $(PRODUCTSDIR)/$@ ]; then			\
328	   echo $@ is up to date. ;				\
329	 else							\
330	   echo Making config file ;				\
331	   sed -e 's|@PIDFILE@|${PIDPATH}|g'			\
332	       -e 's|@UPTIMES_SERVER@|${uptimes_server}|g'	\
333	       ./conf/$(CONFIGFILE) > $(PRODUCTSDIR)/$@ ;	\
334	 fi
335
336upclient.conf.solaris: $(PRODUCTSDIR)
337	@if [ -f $(PRODUCTSDIR)/$(CONFIGFILE) ]; then			\
338	   echo $(CONFIGFILE) is up to date. ;				\
339	 else								\
340	   echo Making into config file ;				\
341	   sed -e 's|@PIDFILE@|${PIDPATH}|g'				\
342	       -e 's|@UPTIMES_SERVER@|${uptimes_server}|g'		\
343	       -e 's|SendIdle      = 1|SendIdle      = 0|g'		\
344	       -e 's|SendUsage     = 1|SendUsage     = 0|g'		\
345	       ./conf/$(CONFIGFILE) > $(PRODUCTSDIR)/$(CONFIGFILE) ;	\
346	 fi
347
348#########################################################################
349# Goals
350
351.phony: all all-solaris all-win install install-solaris solaris-install uninstall remove clean osxclean distclean cvsclean tarball cvsclean dist install-irix irix-install $(PRODUCTSDIR) $(OBJECTSDIR) $(LANGUAGES)
352
353install:
354	@echo Installing files
355	mkdir -p ${destdir}${sbindir}
356	mkdir -p ${destdir}${mandir}/man8
357	mkdir -p ${destdir}$(DOCDIR)
358	mkdir -p ${destdir}${sysconfdir}
359	mkdir -p ${destdir}${localstatedir}/run
360	if [ -f ${destdir}$(CONFIGPATH) ]; then \
361	   mv ${destdir}$(CONFIGPATH) ${destdir}$(CONFIGPATH).old; \
362	fi
363	$(INSTALL_PROGRAM) $(PRODUCTSDIR)/${binname} ${destdir}${sbindir}
364	$(INSTALL_DATA) $(PRODUCTSDIR)/$(MANFILE) ${destdir}${mandir}/man8
365	$(INSTALL_CONFIG) $(PRODUCTSDIR)/$(CONFIGFILE) ${destdir}$(CONFIGPATH)
366	cd .. && ln -f doc/Uptimes\ Protocol\ 5
367	cd .. && $(INSTALL_DATA) $(DOCS) ${destdir}$(DOCDIR)
368
369$(LANGUAGES):
370	    mkdir -p ${destdir}$(localedir)/$@/LC_MESSAGES
371	    $(INSTALL_DATA) ./locale/$@.mo ${destdir}$(localedir)/$@/LC_MESSAGES/${binname}.mo
372	    chmod 644 ${destdir}$(localedir)/$@/LC_MESSAGES/${binname}.mo
373
374install-locales: $(LANGUAGES)
375
376install-locales-solaris:
377	$(MAKE) $(LANGUAGES) INSTALL_DATA=cp
378
379install-locales-irix: install-locales-solaris
380install-solaris-locales: install-locales-solaris
381install-irix-locales: install-locales-solaris
382
383install-solaris:
384#	solaris install is reversed, or is it vice-versa?
385	mkdir -p ${destdir}${sbindir}
386	mkdir -p ${destdir}${mandir}/man8
387	mkdir -p ${destdir}$(DOCDIR)
388	mkdir -p ${destdir}${sysconfdir}
389	mkdir -p ${destdir}${localstatedir}/run
390	if [ -f ${destdir}$(CONFIGPATH) ]; then \
391	   mv ${destdir}$(CONFIGPATH) ${destdir}$(CONFIGPATH).old; \
392	fi
393	cd $(PRODUCTSDIR) && install -f ${destdir}${sbindir} -m 750 ${binname}
394	cd $(PRODUCTSDIR) && install -f ${destdir}${mandir}/man8 -m 644 $(MANFILE)
395#	note: use sysconfdir instead of CONFIGPATH
396	cd $(PRODUCTSDIR) && install -f ${destdir}${sysconfdir} -m 600 $(CONFIGFILE)
397#	no $(foreach) available in Solaris unless using gnumake
398	install -f ${destdir}$(DOCDIR) -m 644 ../AUTHORS
399	install -f ${destdir}$(DOCDIR) -m 644 ../INSTALL
400	install -f ${destdir}$(DOCDIR) -m 644 ../README
401	install -f ${destdir}$(DOCDIR) -m 644 ../TODO
402	install -f ${destdir}$(DOCDIR) -m 644 ../COPYING
403	install -f ${destdir}$(DOCDIR) -m 644 ../HISTORY
404	install -f ${destdir}$(DOCDIR) -m 644 ../HISTORY-BETA
405	install -f ${destdir}$(DOCDIR) -m 644  ../FAQ
406#	Solaris installer's built-in cp routines can't handle spaces in
407#	filenames
408	cp ../doc/Uptimes\ Protocol\ 5 ${destdir}$(DOCDIR)
409	chmod 644 ${destdir}$(DOCDIR)/Uptimes\ Protocol\ 5
410
411solaris-install: install-solaris
412irix-install: install-solaris
413install-irix: install-solaris
414
415uninstall:
416	rm -f ${destdir}${sbindir}/${binname} ${destdir}${mandir}/man8/$(MANFILE)
417	-@rmdir ${destdir}${mandir}/man8
418	-cd ${destdir}$(DOCDIR) && rm -f $(DOCS)
419	-@rmdir -p ${destdir}$(DOCDIR)
420
421remove: uninstall
422
423cleano:
424	rm -f core
425	-cd $(OBJECTSDIR) && rm -f $(OBJECTS) && rm -f core
426	-@rmdir -p $(OBJECTSDIR)
427
428clean: cleano
429	rm -f $(PRODUCTSDIR)/${binname} $(PRODUCTSDIR)/$(MANFILE) $(PRODUCTSDIR)/$(CONFIGFILE)
430	-@rmdir -p $(PRODUCTSDIR)
431
432mostlyclean: cleano
433	rm -f core $(OBJECTSDIR)/core $(PRODUCTSDIR)/core $(PRODUCTSDIR)/${binname}
434
435osxclean:
436	@rm -fR "Mac OS X Project Builder/build"
437	@find ../ -name .DS_Store -print -exec rm {} \;
438
439distclean: clean / osxclean
440
441#########################################################################
442# You probably don't want anything below this line, it might destroy your
443# package and you will have to download it again
444cvsclean:
445	-find ../ -name CVS -print -exec rm -R {} \;
446	-find ../ -name ".#*" -print -exec rm -R {} \;
447	-find ../ -name .cvsignore -print -exec rm {} \;
448
449dist: distclean / cvsclean
450	-rm -f "Mac OS X Project Builder/upclient.pbproj/*.pbxuser"
451	tar -cf ../../upclient-$(UPCLIENT_VERSION).tar ../../upclient-$(UPCLIENT_VERSION)
452	gzip -9 ../../upclient-$(UPCLIENT_VERSION).tar
453
454indentsplint:
455	$(MAKE) -j1 indent indentclean TODO-flawfinder TODO-splint
456
457indent:
458	@if [ -f .indent.pro ]; then						\
459	   echo "Reindenting source code" ;					\
460	   indent *.c *.h ;							\
461	 else									\
462	   echo "Sorry, this project's '.indent.pro' file is missing." ;	\
463	 fi
464
465indentclean:
466	rm -f *.c~
467	rm -f *.h~
468
469TODO-flawfinder:
470	@echo "\$$Id\$$" > ../$@
471	@echo "" >> ../$@
472	@echo "make flawfinder" >> ../$@
473	@echo "     using options: -c --inputs" >> ../$@
474	@echo "" >> ../$@
475	flawfinder -c --inputs $(SOURCES) >> ../$@
476
477
478TODO-splint:
479	@echo "\$$Id\$$" > ../$@
480	@echo "" >> ../$@
481	@echo "make splint" >> ../$@
482	@echo "     using options: +charint +ignoresigns +charindex +posixlib -skipposixheaders -exportlocal +boolint +charintliteral -exitarg -formatconst" >> ../$@
483	@echo "" >> ../$@
484	-splint +charint +ignoresigns +charindex +posixlib -skipposixheaders -exportlocal +boolint +charintliteral -exitarg -formatconst $(SOURCES) >> ../$@
485
486flawfinder: TODO-flawfinder
487splint: TODO-splint
488
489diff:
490	cd ..;cvs diff > ../../diff
491