| 1 |
# Copyright 1999-2007 Gentoo Foundation |
| 2 |
# Distributed under the terms of the GNU General Public License v2 |
| 3 |
|
| 4 |
CC ?= gcc |
| 5 |
|
| 6 |
CFLAGS ?= -Wall -O2 -pipe |
| 7 |
|
| 8 |
# Loads of nice flags to ensure our code is good |
| 9 |
CFLAGS += -pedantic -std=c99 \ |
| 10 |
-Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \ |
| 11 |
-Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \ |
| 12 |
-Wbad-function-cast -Wnested-externs -Wcomment -Winline \ |
| 13 |
-Wchar-subscripts -Wcast-align -Wno-format-nonliteral \ |
| 14 |
$(call check_gcc, -Wdeclaration-after-statement) \ |
| 15 |
$(call check_gcc, -Wsequence-point) \ |
| 16 |
$(call check_gcc, -Wextra) |
| 17 |
|
| 18 |
# For debugging. -Werror is pointless due to ISO C issues with dlsym |
| 19 |
#CFLAGS += -ggdb |
| 20 |
|
| 21 |
DESTDIR = |
| 22 |
LIB = lib |
| 23 |
|
| 24 |
LIBEINFOSOVER = 0 |
| 25 |
LIBEINFOSO = libeinfo.so.$(LIBRCSOVER) |
| 26 |
LIBEINFOOBJS= libeinfo.o |
| 27 |
|
| 28 |
LIBRCSOVER = 0 |
| 29 |
LIBRCSO = librc.so.$(LIBRCSOVER) |
| 30 |
LIBRCOBJS= librc.o librc-depend.o librc-daemon.o librc-misc.o librc-strlist.o |
| 31 |
|
| 32 |
LIB_TARGETS = $(LIBEINFOSO) $(LIBRCSO) |
| 33 |
BIN_TARGETS = rc-status |
| 34 |
SBIN_TARGETS = env-update rc rc-update runscript start-stop-daemon |
| 35 |
PRIV_BIN_TARGETS = fstabinfo mountinfo rc-depend |
| 36 |
SYS_WHITELIST = env_whitelist |
| 37 |
|
| 38 |
TARGET = $(LIB_TARGETS) $(BIN_TARGETS) $(SBIN_TARGETS) $(PRIV_BIN_TARGETS) |
| 39 |
|
| 40 |
RCLINKS = einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \ |
| 41 |
eindent eoutdent eflush color_terminal \ |
| 42 |
veinfo vewarn vebegin veend vewend veindent veoutdent \ |
| 43 |
service_starting service_inactive service_started \ |
| 44 |
service_stopping service_stopped \ |
| 45 |
service_inactive service_wasinactive \ |
| 46 |
service_coldplugged \ |
| 47 |
mark_service_starting mark_service_inactive mark_service_started \ |
| 48 |
mark_service_stopping mark_service_stopped \ |
| 49 |
mark_service_inactive mark_service_wasinactive \ |
| 50 |
mark_service_coldplugged \ |
| 51 |
get_options save_options \ |
| 52 |
is_runlevel_start is_runlevel_stop service_started_daemon |
| 53 |
|
| 54 |
# Quick hack to make my life easier on BSD and Linux |
| 55 |
ifeq ($(OS),) |
| 56 |
OS=$(shell uname -s) |
| 57 |
ifneq ($(OS),Linux) |
| 58 |
OS=BSD |
| 59 |
endif |
| 60 |
endif |
| 61 |
|
| 62 |
ifeq ($(OS),Linux) |
| 63 |
LDLIBS_RC = -ldl |
| 64 |
LDLIBS_RS = -ldl |
| 65 |
# Shouldn't need this, but it's the easiest workaround for silly |
| 66 |
# Linux headers that don't work with -std=c99 |
| 67 |
override CFLAGS += -D_GNU_SOURCE |
| 68 |
endif |
| 69 |
ifeq ($(OS),BSD) |
| 70 |
override LDLIBS += -lkvm |
| 71 |
endif |
| 72 |
|
| 73 |
HAVE_PAM = |
| 74 |
ifdef HAVE_PAM |
| 75 |
CFLAGS_SSD = -DHAVE_PAM |
| 76 |
LDLIBS_SSD = -lpam |
| 77 |
endif |
| 78 |
|
| 79 |
# We also define _BSD_SOURCE so both Linux and the BSDs get a few |
| 80 |
# handy functions which makes our lives a lot easier |
| 81 |
override CFLAGS += -DLIB=\"$(LIB)\" |
| 82 |
|
| 83 |
# IMPORTANT!!! |
| 84 |
# Remove this when releasing as it's a security risk |
| 85 |
# However, this does save us using libtool when we're testing |
| 86 |
# NOTE: The toplevel Makefile for baselayout will automatically |
| 87 |
# disable then when doing `make dist` |
| 88 |
override LDFLAGS += -Wl,-rpath . |
| 89 |
|
| 90 |
all: $(TARGET) |
| 91 |
|
| 92 |
$(LIBEINFOOBJS): CFLAGS += -fPIC |
| 93 |
$(LIBEINFOSO): LDLIBS = |
| 94 |
$(LIBEINFOSO): $(LIBEINFOOBJS) |
| 95 |
$(CC) -fPIC -shared -Wl,-soname,$(LIBEINFOSO) -o $(LIBEINFOSO) $(LIBEINFOOBJS) |
| 96 |
ln -sf $(LIBEINFOSO) libeinfo.so |
| 97 |
|
| 98 |
$(LIBRCOBJS): CFLAGS += -fPIC |
| 99 |
$(LIBRCSO): $(LIBRCOBJS) |
| 100 |
$(CC) -fPIC -shared -Wl,-soname,$(LIBRCSO) -o $(LIBRCSO) $(LIBRCOBJS) |
| 101 |
ln -sf $(LIBRCSO) librc.so |
| 102 |
|
| 103 |
env-update: $(LIBEINFOSO) $(LIBRCSO) env-update.o |
| 104 |
|
| 105 |
fstabinfo: $(LIBEINFOSO) fstabinfo.o |
| 106 |
|
| 107 |
mountinfo: $(LIBEINFOSO) $(LIBRCSO) mountinfo.o |
| 108 |
|
| 109 |
rc-depend: $(LIBEINFOSO) $(LIBRCSO) rc-depend.o |
| 110 |
|
| 111 |
rc-status: $(LIBEINFOSO) $(LIBRCSO) rc-status.o |
| 112 |
|
| 113 |
rc-update: $(LIBEINFOSO) $(LIBRCSO) rc-update.o |
| 114 |
|
| 115 |
rc: LDLIBS += $(LDLIBS_RC) |
| 116 |
rc: $(LIBEINFOSO) $(LIBRCSO) rc-plugin.o rc.o |
| 117 |
|
| 118 |
runscript: LDLIBS += $(LDLIBS_RS) |
| 119 |
runscript: $(LIBEINFOSO) $(LIBRCSO) rc-plugin.o runscript.o |
| 120 |
|
| 121 |
start-stop-daemon: CFLAGS += $(CFLAGS_SSD) |
| 122 |
start-stop-daemon: LDLIBS += $(LDLIBS_SSD) |
| 123 |
start-stop-daemon: $(LIBEINFOSO) $(LIBRCSO) start-stop-daemon.o |
| 124 |
|
| 125 |
links: rc |
| 126 |
for x in $(RCLINKS) $(RCPRIVLINKS); do ln -sf rc $$x; done |
| 127 |
|
| 128 |
install: $(TARGET) |
| 129 |
install -m 0755 -d $(DESTDIR)/$(LIB) |
| 130 |
install -m 0755 $(LIB_TARGETS) $(DESTDIR)/$(LIB) |
| 131 |
ln -sf $(LIBEINFOSO) $(DESTDIR)/$(LIB)/libeinfo.so |
| 132 |
ln -sf $(LIBRCSO) $(DESTDIR)/$(LIB)/librc.so |
| 133 |
install -m 0755 -d $(DESTDIR)/usr/include |
| 134 |
install -m 0644 einfo.h rc.h $(DESTDIR)/usr/include |
| 135 |
install -m 0755 -d $(DESTDIR)/bin |
| 136 |
install -m 0755 $(BIN_TARGETS) $(DESTDIR)/bin |
| 137 |
install -m 0755 -d $(DESTDIR)/sbin |
| 138 |
install -m 0755 $(SBIN_TARGETS) $(DESTDIR)/sbin |
| 139 |
ln -s rc-update $(DESTDIR)/sbin/update-rc |
| 140 |
install -m 0755 -d $(DESTDIR)/$(LIB)/rcscripts/conf.d |
| 141 |
install -m 0644 $(SYS_WHITELIST) $(DESTDIR)/$(LIB)/rcscripts/conf.d |
| 142 |
install -m 0755 -d $(DESTDIR)/$(LIB)/rcscripts/bin |
| 143 |
install -m 0755 $(PRIV_BIN_TARGETS) $(DESTDIR)/$(LIB)/rcscripts/bin |
| 144 |
for x in $(RCLINKS); do ln -sf $(DESTDIR)/sbin/rc $(DESTDIR)/$(LIB)/rcscripts/bin/$$x; done |
| 145 |
if test "$(HAVE_PAM)" != "" ; then \ |
| 146 |
install -m 0755 -d $(DESTDIR)/etc/pam.d ; \ |
| 147 |
install -m 0644 start-stop-daemon.pam $(DESTDIR)/etc/pam.d/start-stop-daemon ; \ |
| 148 |
fi |
| 149 |
|
| 150 |
clean: |
| 151 |
rm -f $(TARGET) $(RCLINKS) $(RCPRIVLINKS) |
| 152 |
rm -f *.o *~ *.core *.so |