Share makefile rules and vars between client/server

Move all make variables and rules duplicated between gkrellm and
gkrellmd makefiles into a common file that can be included. This
avoids duplication and hopefully avoids the two makefiles getting out
of sync too much. This is also a preparation to ease overriding
toolchain binaries (compiler, linker, pkgconfig) as part of windows
cross compiling.

This change also puts the "ar" tool into a variable that can be
overridden if needed.

Please note that this change uses the GNU Make specific include
statement but AFAICS the makefiles already depend on GNU extensions in
other areas (":=" and "ifdef" are non-standard make syntax).
This commit is contained in:
Stefan Gehn 2014-08-23 17:56:46 +02:00
parent 434d79d413
commit b0b6b5d559
3 changed files with 43 additions and 60 deletions

35
common.mk Normal file
View File

@ -0,0 +1,35 @@
# makefile variables and rules shared by both gkrellm and gkrellmd
CC ?= gcc
AR ?= ar
PKG_CONFIG ?= pkg-config
WINDRES ?= windres
PREFIX ?= /usr/local
INSTALLROOT ?= $(DESTDIR)$(PREFIX)
BINMODE ?= 755
BINEXT ?=
INSTALLDIRMODE ?= 755
INCLUDEDIR ?= $(INSTALLROOT)/include
INCLUDEMODE ?= 644
INCLUDEDIRMODE ?= 755
LIBDIR ?= $(INSTALLROOT)/lib
LIBDIRMODE ?= 755
MANMODE ?= 644
MANDIRMODE ?= 755
INSTALL ?= install
STRIP ?= -s
LINK_FLAGS ?= -Wl,-E
SHARED_PATH = ../shared
# Make GNU Make search for sources somewhere else as well
VPATH = $(SHARED_PATH)
%.o: %.c
$(CC) -c -Wall $(FLAGS) $(CFLAGS) $(CPPFLAGS) $< -o $@

View File

@ -1,35 +1,16 @@
PACKAGE_D ?= gkrellmd
PKG_CONFIG ?= pkg-config
BINMODE ?= 755
BINEXT ?=
include ../common.mk
PREFIX ?= /usr/local
INSTALLROOT ?= $(DESTDIR)$(PREFIX)
PACKAGE_D ?= gkrellmd
SINSTALLDIR ?= $(INSTALLROOT)/bin
INSTALLDIRMODE ?= 755
INCLUDEDIR ?= $(INSTALLROOT)/include
INCLUDEMODE ?= 644
INCLUDEDIRMODE ?= 755
LIBDIR ?= $(INSTALLROOT)/lib
LIBDIRMODE ?= 755
CFGDIR ?= $(INSTALLROOT)/etc
CFGDIRMODE ?= 755
CFGMODE ?= 644
SMANDIR ?= $(INSTALLROOT)/share/man/man1
MANMODE ?= 644
MANDIRMODE ?= 755
INSTALL ?= install
LINK_FLAGS ?= -Wl,-E
EXTRAOBJS =
SHARED_PATH = ../shared
# Make GNU Make search for sources somewhere else as well
VPATH = $(SHARED_PATH)
EXTRAOBJS =
ifeq ($(without-libsensors),yes)
CONFIGURE_ARGS += --without-libsensors
@ -45,11 +26,6 @@ ifeq ($(HAVE_LIBSENSORS),1)
SENSORS_LIBS ?= -lsensors
endif
CC ?= gcc
WINDRES ?= windres
STRIP ?= -s
GKRELLMD_INCLUDES = gkrellmd.h $(SHARED_PATH)/log.h
PKG_INCLUDE = `$(PKG_CONFIG) --cflags glib-2.0 gmodule-2.0 gthread-2.0`
@ -234,11 +210,8 @@ win32-resource.o: win32-resource.rc win32-resource.h
$(WINDRES) $< -o $@
win32-libgkrellmd.o: win32-libgkrellmd.c win32-plugin.h $(GKRELLMD_H)
libgkrellmd.a: win32-libgkrellmd.o
ar -cr libgkrellmd.a win32-libgkrellmd.o
$(AR) -cr libgkrellmd.a win32-libgkrellmd.o
# Checks if the build environment is ok
check_env:
$(PKG_CONFIG) --atleast-version=2.32 glib-2.0
%.o: %.c
$(CC) -c -Wall $(FLAGS) $(CFLAGS) $(CPPFLAGS) $< -o $@

View File

@ -1,31 +1,13 @@
PACKAGE ?= gkrellm
PKG_CONFIG ?= pkg-config
BINMODE ?= 755
BINEXT ?=
include ../common.mk
PREFIX ?= /usr/local
INSTALLROOT ?= $(DESTDIR)$(PREFIX)
PACKAGE ?= gkrellm
INSTALLDIR ?= $(INSTALLROOT)/bin
INSTALLDIRMODE ?= 755
INCLUDEDIR ?= $(INSTALLROOT)/include
INCLUDEMODE ?= 644
INCLUDEDIRMODE ?= 755
LIBDIR ?= $(INSTALLROOT)/lib
LIBDIRMODE ?= 755
MANDIR ?= $(INSTALLROOT)/share/man/man1
MANMODE ?= 644
MANDIRMODE ?= 755
INSTALL ?= install
LINK_FLAGS ?= -Wl,-E
X11_LIBS ?= -L/usr/X11R6/lib -lX11 -lSM -lICE
MATH_LIB ?= -lm
SHARED_PATH = ../shared
# Make GNU Make search for sources somewhere else as well
VPATH = $(SHARED_PATH)
ifeq ($(without-gnutls),1)
CONFIGURE_ARGS += --without-gnutls
endif
@ -60,10 +42,6 @@ ifneq ($(HAVE_SSL),1)
EXTRAOBJS ?= md5c.o
endif
CC ?= gcc
WINDRES ?= windres
STRIP ?= -s
GKRELLM_INCLUDES = gkrellm.h gkrellm-public-proto.h $(SHARED_PATH)/log.h
PKG_INCLUDE = `$(PKG_CONFIG) --cflags gtk+-2.0 gmodule-2.0 gthread-2.0`
@ -348,12 +326,9 @@ win32-resource.o: win32-resource.rc win32-resource.h
$(WINDRES) $< -o $@
libgkrellm.a: win32-libgkrellm.o
ar -cr libgkrellm.a win32-libgkrellm.o
$(AR) -cr libgkrellm.a win32-libgkrellm.o
# Checks if the build environment is ok
check_env:
$(PKG_CONFIG) --atleast-version=2.32 glib-2.0
$(PKG_CONFIG) --atleast-version=2.4 gtk+-2.0
%.o: %.c
$(CC) -c -Wall $(FLAGS) $(CFLAGS) $(CPPFLAGS) $< -o $@