1include ../common.mk
2
3PACKAGE_D ?= gkrellmd
4
5SINSTALLDIR ?= $(INSTALLROOT)/bin
6
7CFGDIR ?= $(INSTALLROOT)/etc
8CFGDIRMODE ?= 755
9CFGMODE ?= 644
10
11SMANDIR ?= $(INSTALLROOT)/share/man/man1
12
13EXTRAOBJS =
14
15ifeq ($(without-libsensors),yes)
16	CONFIGURE_ARGS += --without-libsensors
17endif
18ifeq ($(without-libsensors),1)
19	CONFIGURE_ARGS += --without-libsensors
20endif
21
22DUMMY_VAR := $(shell ./configure $(CONFIGURE_ARGS))
23
24HAVE_LIBSENSORS = $(shell grep -c HAVE_LIBSENSORS configure.h)
25ifeq ($(HAVE_LIBSENSORS),1)
26    SENSORS_LIBS ?= -lsensors
27endif
28
29GKRELLMD_INCLUDES = gkrellmd.h $(SHARED_PATH)/log.h
30
31PKG_INCLUDE := $(shell $(PKG_CONFIG) --cflags glib-2.0 gmodule-2.0 gthread-2.0)
32PKG_LIB := $(shell $(PKG_CONFIG) --libs glib-2.0 gmodule-2.0 gthread-2.0)
33
34FLAGS = $(PKG_INCLUDE)
35
36FLAGS += $(GTOP_INCLUDE) $(PTHREAD_INC) -I.. -I$(SHARED_PATH) -DGKRELLM_SERVER
37
38LIBS = $(PKG_LIB)
39LIBS += $(GTOP_LIBS_D) $(SYS_LIBS) $(SENSORS_LIBS)
40
41ifeq ($(debug),1)
42    FLAGS += -g
43endif
44ifeq ($(debug),yes)
45    FLAGS += -g
46endif
47
48ifeq ($(profile),1)
49    FLAGS += -g -pg
50endif
51ifeq ($(profile),yes)
52    FLAGS += -g -pg
53endif
54
55ifeq ($(enable_nls),1)
56    FLAGS += -DENABLE_NLS -DLOCALEDIR=\"$(LOCALEDIR)\"
57endif
58ifeq ($(enable_nls),yes)
59    FLAGS += -DENABLE_NLS -DLOCALEDIR=\"$(LOCALEDIR)\"
60endif
61
62ifneq ($(PACKAGE_D),gkrellmd)
63    FLAGS += -DPACKAGE_D=\"$(PACKAGE_D)\"
64endif
65
66ifeq ($(HAVE_GETADDRINFO),1)
67    FLAGS += -DHAVE_GETADDRINFO
68endif
69
70OS_RELEASE=$(shell uname -r)
71
72OBJS = main.o monitor.o mail.o plugins.o utils.o sysdeps-unix.o log.o
73
74all:	gkrellmd$(BINEXT)
75
76gkrellmd$(BINEXT): check_env gkrellmd.pc $(OBJS) $(EXTRAOBJS)
77	$(CC) $(OBJS) $(EXTRAOBJS) -o $@ \
78		$(LDFLAGS) $(LIBS) $(LINK_FLAGS)
79
80static: check_env gkrellmd.pc $(OBJS) $(EXTRAOBJS)
81	$(CC) $(OBJS) $(EXTRAOBJS) -o gkrellmd.static -static \
82		$(LDFLAGS) $(LIBS) $(LINK_FLAGS)
83
84gkrellmd.pc: Makefile
85	echo "prefix=$(INSTALLROOT)" > gkrellmd.pc
86	echo "Name: GKrellMd" >> gkrellmd.pc
87	echo "Description: Extensible GLIB system monitoring application server" >> gkrellmd.pc
88	echo "Version: $(VERSION)" >> gkrellmd.pc
89	echo "Requires: glib-2.0" >> gkrellmd.pc
90	echo "Cflags: -I$(INCLUDEDIR)" >> gkrellmd.pc
91
92freebsd2:
93	$(MAKE) EXTRAOBJS= SYS_LIBS="-lkvm " gkrellmd
94
95freebsd3 freebsd4:
96	$(MAKE) EXTRAOBJS= SYS_LIBS="-lkvm -ldevstat " gkrellmd
97
98freebsd5 freebsd6 freebsd7 freebsd8 freebsd:
99	$(MAKE) EXTRAOBJS= SYS_LIBS="-ldevstat " gkrellmd
100
101# Darwin target for systems that still have libkvm
102darwin:
103	$(MAKE) STRIP= HAVE_GETADDRINFO=1 \
104		EXTRAOBJS= \
105		SYS_LIBS="-framework CoreFoundation -framework IOKit -lkvm" \
106		LINK_FLAGS="-Wl,-bind_at_load" \
107		gkrellmd
108
109# Darwin 9.x and newer (OS X > 10.4) do not have libkvm, build without it
110darwin9:
111	$(MAKE) STRIP= HAVE_GETADDRINFO=1 \
112		EXTRAOBJS= \
113		SYS_LIBS="-framework CoreFoundation -framework IOKit" \
114		LINK_FLAGS="-Wl,-bind_at_load" \
115		gkrellmd
116
117# Same as darwin9
118macosx: darwin9
119
120netbsd1:
121	$(MAKE) EXTRAOBJS= SYS_LIBS="-lkvm" gkrellmd
122
123netbsd2:
124	$(MAKE) EXTRAOBJS= SYS_LIBS="-lkvm -pthread" gkrellmd
125
126openbsd:
127	$(MAKE) SYS_LIBS="-lkvm -pthread" gkrellmd
128
129solaris:
130ifeq ($(OS_RELEASE),5.8)
131	$(MAKE) CFLAGS="-Wno-implicit-int" \
132		SYS_LIBS="-lkstat -lkvm -ldevinfo -lsocket -lnsl -lintl" \
133		LINK_FLAGS="" gkrellmd
134else
135	$(MAKE) CFLAGS="-Wno-implicit-int" \
136		SYS_LIBS="-lkstat -lkvm -ldevinfo -lsocket -lnsl" \
137		LINK_FLAGS="" gkrellmd
138endif
139
140windows: libgkrellmd.a
141	$(MAKE) \
142		BINEXT=".exe" \
143		CFLAGS="${CFLAGS} -D_WIN32_WINNT=0x0501 -DWINVER=0x0501 -DWIN32_LEAN_AND_MEAN" \
144		LINK_FLAGS="-mconsole -Wl,--dynamicbase -Wl,--nxcompat" \
145		EXTRAOBJS="${EXTRAOBJS} win32-resource.o win32-plugin.o" \
146		SYS_LIBS="-lws2_32 -lwtsapi32 -lpdh -lnetapi32 -liphlpapi -lintl" \
147		all
148
149install: install_bin install_inc install_man install_gkrellmd.pc
150
151install_bin:
152	$(INSTALL) -d -m $(INSTALLDIRMODE) $(DESTDIR)$(SINSTALLDIR)
153	$(INSTALL) -c $(STRIP) -m $(BINMODE) $(PACKAGE_D)$(BINEXT) $(DESTDIR)$(SINSTALLDIR)/$(PACKAGE_D)$(BINEXT)
154
155install_inc:
156	$(INSTALL) -d -m $(INCLUDEDIRMODE) $(DESTDIR)$(INCLUDEDIR)/gkrellm2
157	$(INSTALL) -c -m $(INCLUDEMODE) $(GKRELLMD_INCLUDES) $(DESTDIR)$(INCLUDEDIR)/gkrellm2
158
159install_man:
160	$(INSTALL) -d -m $(MANDIRMODE) $(DESTDIR)$(SMANDIR)
161	$(INSTALL) -c -m $(MANMODE) ../gkrellmd.1 $(DESTDIR)$(SMANDIR)/$(PACKAGE_D).8
162
163install_cfg:
164	$(INSTALL) -d -m $(CFGDIRMODE) $(DESTDIR)$(CFGDIR)
165	$(INSTALL) -c -m $(CFGMODE) gkrellmd.conf $(DESTDIR)$(CFGDIR)/gkrellmd.conf
166
167install_gkrellmd.pc:
168	$(INSTALL) -d $(DESTDIR)$(PKGCONFIGDIR)
169	$(INSTALL) -c -m $(INCLUDEMODE) gkrellmd.pc $(DESTDIR)$(PKGCONFIGDIR)
170
171uninstall:
172	rm -f $(SINSTALLDIR)/$(PACKAGE_D)
173	rm -f $(SMANDIR)/$(PACKAGE_D).1
174	rm -f $(PKGCONFIGDIR)/gkrellmd.pc
175
176install_darwin install_darwin9 install_macosx:
177	$(MAKE) install STRIP=
178
179install_freebsd:
180	$(MAKE) install
181	chgrp kmem $(SINSTALLDIR)/$(PACKAGE_D)
182	chmod g+s $(SINSTALLDIR)/$(PACKAGE_D)
183
184install_netbsd:
185	$(MAKE) SMANDIR="$(INSTALLROOT)/man/man1" install
186
187install_openbsd:
188	$(MAKE) install
189	chgrp kmem $(SINSTALLDIR)/$(PACKAGE_D)
190	chmod g+sx $(SINSTALLDIR)/$(PACKAGE_D)
191
192install_solaris:
193	$(MAKE) install INSTALL=/usr/ucb/install
194	chgrp sys $(SINSTALLDIR)/$(PACKAGE_D)
195	chmod g+s $(SINSTALLDIR)/$(PACKAGE_D)
196
197install_windows: install_inc install_cfg
198	$(MAKE) BINEXT=".exe" install_bin
199	$(INSTALL) -d -m $(LIBDIRMODE) $(LIBDIR)
200	$(INSTALL) -c -m $(BINMODE) libgkrellmd.a $(LIBDIR)
201
202clean:
203	$(RM) *.o *~ *.bak configure.h configure.log gkrellmd gkrellmd.exe \
204		libgkrellmd.a core
205	$(RM) gkrellmd.pc
206
207SYSDEPS = ../src/sysdeps/bsd-common.c ../src/sysdeps/bsd-net-open.c \
208	../src/sysdeps/darwin.c \
209	../src/sysdeps/freebsd.c ../src/sysdeps/gtop.c \
210	../src/sysdeps/linux.c ../src/sysdeps/netbsd.c ../src/sysdeps/dragonfly.c \
211	../src/sysdeps/openbsd.c ../src/sysdeps/sensors-common.c \
212	../src/sysdeps/solaris.c ../src/sysdeps/win32.c
213
214GKRELLMD_H = gkrellmd.h gkrellmd-private.h
215
216main.o:		main.c $(GKRELLMD_H)
217monitor.o:	monitor.c $(GKRELLMD_H)
218mail.o:		mail.c $(GKRELLMD_H)
219plugins.o:	plugins.c $(GKRELLMD_H)
220utils.o:	utils.c $(GKRELLMD_H)
221sysdeps-unix.o: sysdeps-unix.c ../src/gkrellm-sysdeps.h $(SYSDEPS) $(GKRELLMD_H)
222log.o: $(SHARED_PATH)/log.c $(SHARED_PATH)/log.h $(GKRELLMD_H)
223win32-gui.o:	win32-gui.c
224win32-plugin.o:	win32-plugin.c win32-plugin.h $(GKRELLMD_H)
225win32-resource.o:	win32-resource.rc win32-resource.h
226	$(WINDRES) $< -o $@
227win32-libgkrellmd.o:	win32-libgkrellmd.c win32-plugin.h $(GKRELLMD_H)
228libgkrellmd.a:	win32-libgkrellmd.o
229	$(AR) -cr libgkrellmd.a win32-libgkrellmd.o
230
231# Checks if the build environment is ok
232check_env:
233	$(PKG_CONFIG) --atleast-version=2.32 glib-2.0
234