1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# We should strive to keep this Makefile working with the default make
# shipped with the OS's we support. Mainly because I'm lazy and just want
# to type make instead of gmake, but also so that other distros can pick
# it up and not rely on GNU Make.
# NOTE:- FreeBSD and DragonFly have no way of optionally including files
# that works with GNU make and vice versa. NetBSD and OpenBSD makes do.
# You can get a patch from
# http://www.freebsd.org/cgi/query-pr.cgi?pr=standards/116081
# to fix this. We include this patch with Gentoo/FreeBSD :)
CC ?= gcc
CFLAGS += -O2 -pipe
LDFLAGS += -L.
# GNU Make way of detecting gcc flags we can use
check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
then echo "$(1)"; else echo "$(2)"; fi)
# pmake check for extra cflags
WEXTRA != for x in -Wdeclaration-after-statement -Wsequence-point -Wextra; do \
if $(CC) -Wdeclaration-after-statement -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
then echo -n "$$x "; fi \
done
# Loads of nice flags to ensure our code is good
CFLAGS += -pedantic -std=c99 \
-Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
-Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \
-Wbad-function-cast -Wnested-externs -Wcomment -Winline \
-Wchar-subscripts -Wcast-align -Wno-format-nonliteral \
$(call check_gcc, -Wdeclaration-after-statement) \
$(call check_gcc, -Wsequence-point) \
$(call check_gcc, -Wextra) $(WEXTRA)
# For debugging. -Werror is pointless due to ISO C issues with dlsym
#CFLAGS += -ggdb
DESTDIR =
LIB = lib
RC_LIB = /$(LIB)/rc
# Set PAM = pam for pam support
PAM =
LIBEINFOSOVER = 0
LIBEINFOSO = libeinfo.so.$(LIBRCSOVER)
LIBEINFOOBJS= libeinfo.o
LDLIBS_LIBEINFO = $(LDLIBS)
LIBRCSOVER = 0
LIBRCSO = librc.so.$(LIBRCSOVER)
LIBRCOBJS = librc.o librc-depend.o librc-daemon.o librc-misc.o librc-strlist.o
LDLIBS_LIBRC =
RCOBJS = checkown.o env-update.o fstabinfo.o mountinfo.o \
rc-depend.o rc-misc.o rc-plugin.o rc-status.o rc-update.o \
runscript.o start-stop-daemon.o rc.o
LDLIBS_RC = -leinfo -lrc -lutil
LIB_TARGETS = $(LIBEINFOSO) $(LIBRCSO)
SBIN_TARGETS = rc
SYS_WHITELIST = env_whitelist
TARGET = $(LIB_TARGETS) $(BIN_TARGETS) $(SBIN_TARGETS)
RC_BINLINKS = einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \
eindent eoutdent esyslog eval_ecolors \
veinfo vewarn vebegin veend vewend veindent veoutdent \
service_starting service_started \
service_stopping service_stopped \
service_inactive service_wasinactive \
service_coldplugged \
is_runlevel_start is_runlevel_stop service_started_daemon \
checkown fstabinfo mountinfo rc-depend \
get_options save_options
RC_SBINLINKS = mark_service_starting mark_service_started \
mark_service_stopping mark_service_stopped \
mark_service_inactive mark_service_wasinactive \
mark_service_coldplugged mark_service_failed \
rc-abort
BINLINKS = rc-status
SBINLINKS = env-update rc-update runscript start-stop-daemon
ALL_LINKS = $(BINLINKS) $(SBINLINKS) $(RC_BINLINKS) $(RC_SBINLINKS)
# We also define _BSD_SOURCE so both Linux and the BSDs get a few
# handy functions which makes our lives a lot easier
CPPFLAGS += -DLIB=\"$(LIB)\"
# IMPORTANT!!!
# Ensure that we don't ship with a .svn directory to avoid RPATH security
# issues. However, this does ease development a little
_SVN_LDFLAGS_SH = if test -d .svn; then echo "-Wl,-rpath ."; else echo ""; fi
_SVN_LDFLAGS != $(_SVN_LDFLAGS_SH)
LDFLAGS += $(_SVN_LDFLAGS)$(shell $(_SVN_LDFLAGS_SH))
# Load an optional OS Makefile
_OS_SH = u=`uname -s`; case "$${u}" in *BSD|DragonFly) echo "BSD";; *) echo "$${u}";; esac
_OS != $(_OS_SH)
OS ?= $(_OS)$(shell $(_OS_SH))
-include Makefile.$(OS)
-include Makefile.$(PAM)
all: .depend $(TARGET)
$(LIBEINFOOBJS):
$(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -c $<
$(LIBEINFOSO): einfo.map $(LIBEINFOOBJS)
$(CC) $(LDFLAGS) -fPIC -shared \
-Wl,-soname,$(LIBEINFOSO) \
-Wl,-version-script einfo.map \
-o $(LIBEINFOSO) $(LIBEINFOOBJS) $(LDLIBS) $(LDLIBS_LIBEINFO)
ln -sf $(LIBEINFOSO) libeinfo.so
$(LIBRCOBJS):
$(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -c $<
$(LIBRCSO): rc.map $(LIBRCOBJS)
$(CC) $(LDFLAGS) -fPIC -shared \
-Wl,-soname,$(LIBRCSO) \
-Wl,-version-script rc.map \
-o $(LIBRCSO) $(LIBRCOBJS) $(LDLIBS) $(LDLIBS_LIBRC)
ln -sf $(LIBRCSO) librc.so
$(RCOBJS):
$(CC) $(CPPFLAGS) $(CPPFLAGS_SSD) $(CFLAGS) -c $<
rc: $(LIBEINFOSO) $(LIBRCSO) $(RCOBJS)
$(CC) $(LDFLAGS) -o rc $(RCOBJS) $(LDLIBS) $(LDLIBS_RC)
$(ALL_LINKS): rc
ln -sf rc $@
links: $(ALL_LINKS)
install: $(TARGET)
install -m 0755 -d $(DESTDIR)/$(LIB)
install -m 0755 $(LIB_TARGETS) $(DESTDIR)/$(LIB)
ln -sf $(LIBEINFOSO) $(DESTDIR)/$(LIB)/libeinfo.so
ln -sf $(LIBRCSO) $(DESTDIR)/$(LIB)/librc.so
install -m 0755 -d $(DESTDIR)/usr/include
install -m 0644 einfo.h rc.h $(DESTDIR)/usr/include
install -m 0755 -d $(DESTDIR)/bin
install -m 0755 -d $(DESTDIR)/sbin
install -m 0755 $(SBIN_TARGETS) $(DESTDIR)/sbin
ln -sf rc-update $(DESTDIR)/sbin/update-rc
install -m 0755 -d $(DESTDIR)/$(RC_LIB)/conf.d
install -m 0644 $(SYS_WHITELIST) $(DESTDIR)/$(RC_LIB)/conf.d
install -m 0755 -d $(DESTDIR)/$(RC_LIB)/bin
install -m 0755 -d $(DESTDIR)/$(RC_LIB)/sbin
for x in $(BINLINKS); do ln -sf ../sbin/rc $(DESTDIR)/bin/$$x; done
for x in $(SBINLINKS); do ln -sf rc $(DESTDIR)/sbin/$$x; done
for x in $(RC_BINLINKS); do ln -sf ../../../sbin/rc $(DESTDIR)/$(RC_LIB)/bin/$$x; done
for x in $(RC_SBINLINKS); do ln -sf ../../../sbin/rc $(DESTDIR)/$(RC_LIB)/sbin/$$x; done
if test "$(PAM)" = "pam" ; then \
install -m 0755 -d $(DESTDIR)/etc/pam.d ; \
install -m 0644 start-stop-daemon.pam $(DESTDIR)/etc/pam.d/start-stop-daemon ; \
fi
clean-links:
rm -f $(ALL_LINKS)
clean: clean-links
rm -f $(TARGET)
rm -f *.o *~ *.core *.so .depend
check:
$(MAKE) -C test $@
-include .depend
_DEPS != ls *.c *.h
.depend: $(_DEPS)$(wildcard *.c *.h)
$(CC) $(CPPFLAGS) -MM *.c > .depend
.PHONY: all clean clean-links install links
|