aboutsummaryrefslogtreecommitdiff
path: root/src/Makefile
blob: ab100477d2120cbef203163d8466785eb2d02a8e (plain)
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
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

CC ?= gcc

CFLAGS ?= -Wall -O2 -pipe
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

# Early GCC versions don't support these flags, so you may need to comment
# this line out
CFLAGS += -Wsequence-point -Wextra -Wdeclaration-after-statement

# For debugging. -Werror is pointless due to ISO C issues with dlsym
#CFLAGS += -ggdb

DESTDIR =
LIB = lib

LIBEINFOSOVER = 0
LIBEINFOSO = libeinfo.so.$(LIBRCSOVER)
LIBEINFOOBJS= libeinfo.o

LIBRCSOVER = 0
LIBRCSO = librc.so.$(LIBRCSOVER)
LIBRCOBJS= librc.o librc-depend.o librc-daemon.o librc-misc.o librc-strlist.o

LIB_TARGETS = $(LIBEINFOSO) $(LIBRCSO)
BIN_TARGETS = rc-status
SBIN_TARGETS = rc rc-update runscript start-stop-daemon
PRIV_BIN_TARGETS = env-update fstabinfo mountinfo rc-depend
SYS_WHITELIST = env_whitelist

TARGET = $(LIB_TARGETS) $(BIN_TARGETS) $(SBIN_TARGETS) $(PRIV_BIN_TARGETS)

RCLINKS = einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \
	      eindent eoutdent eflush color_terminal \
	      veinfo vewarn vebegin veend vewend veindent veoutdent \
	      service_starting service_inactive service_started \
	      service_stopping service_stopped \
	      service_inactive service_wasinactive \
	      service_coldplugged \
	      mark_service_starting mark_service_inactive mark_service_started \
	      mark_service_stopping mark_service_stopped \
	      mark_service_inactive mark_service_wasinactive \
	      mark_service_coldplugged \
	      get_options save_options \
	      is_runlevel_start is_runlevel_stop service_started_daemon

# Quick hack to make my life easier on BSD and Linux
ifeq ($(OS),)
OS=$(shell uname -s)
ifneq ($(OS),Linux)
OS=BSD
endif
endif

ifeq ($(OS),Linux)
LDLIBS_RC = -ldl
LDLIBS_RS = -ldl
# Shouldn't need this, but it's the easiest workaround for silly
# Linux headers that don't work with -std=c99
override CFLAGS += -D_GNU_SOURCE
endif
ifeq ($(OS),BSD)
override LDLIBS += -lkvm
endif

HAVE_PAM = 
ifdef HAVE_PAM
CFLAGS_SSD = -DHAVE_PAM
LDLIBS_SSD = -lpam
endif

# We also define _BSD_SOURCE so both Linux and the BSDs get a few
# handy functions which makes our lives a lot easier
override CFLAGS += -DLIBDIR=\"$(LIB)\"

# IMPORTANT!!!
# Remove this when releasing as it's a security risk
# However, this does save us using libtool when we're testing
# NOTE: The toplevel Makefile for baselayout will automatically
# disable then when doing `make dist`
##override LDFLAGS += -Wl,-rpath .

all: $(TARGET)

$(LIBEINFOOBJS): CFLAGS += -fPIC
$(LIBEINFOSO): LDLIBS =
$(LIBEINFOSO): $(LIBEINFOOBJS) 
	$(CC) -fPIC -shared -Wl,-soname,$(LIBEINFOSO) -o $(LIBEINFOSO) $(LIBEINFOOBJS)
	ln -sf $(LIBEINFOSO) libeinfo.so

$(LIBRCOBJS): CFLAGS += -fPIC
$(LIBRCSO): $(LIBRCOBJS) 
	$(CC) -fPIC -shared -Wl,-soname,$(LIBRCSO) -o $(LIBRCSO) $(LIBRCOBJS)
	ln -sf $(LIBRCSO) librc.so

splash: CFLAGS += -fPIC
splash: splash.o
	$(CC) -fPIC -shared -Wl,-soname,splash.so -o splash.so splash.o

env-update: $(LIBEINFOSO) $(LIBRCSO) env-update.o

fstabinfo: $(LIBEINFOSO) fstabinfo.o

mountinfo: $(LIBEINFOSO) $(LIBRCSO) mountinfo.o

rc-depend: $(LIBEINFOSO) $(LIBRCSO) rc-depend.o

rc-status: $(LIBEINFOSO) $(LIBRCSO) rc-status.o

rc-update: $(LIBEINFOSO) $(LIBRCSO) rc-update.o

rc: LDLIBS += $(LDLIBS_RC)
rc: $(LIBEINFOSO) $(LIBRCSO) rc-plugin.o rc.o

runscript: LDLIBS += $(LDLIBS_RS)
runscript: $(LIBEINFOSO) $(LIBRCSO) rc-plugin.o runscript.o

start-stop-daemon: CFLAGS += $(CFLAGS_SSD)
start-stop-daemon: LDLIBS += $(LDLIBS_SSD)
start-stop-daemon: $(LIBEINFOSO) $(LIBRCSO) start-stop-daemon.o

links: rc
	for x in $(RCLINKS) $(RCPRIVLINKS); do ln -sf rc $$x; done

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 $(BIN_TARGETS) $(DESTDIR)/bin
	install -m 0755 -d $(DESTDIR)/sbin
	install -m 0755 $(SBIN_TARGETS) $(DESTDIR)/sbin
	install -m 0755 -d $(DESTDIR)/$(LIB)/rcscripts/conf.d
	install -m 0644 $(SYS_WHITELIST) $(DESTDIR)/$(LIB)/rcscripts/conf.d
	install -m 0755 -d $(DESTDIR)/$(LIB)/rcscripts/bin
	install -m 0755 $(PRIV_BIN_TARGETS) $(DESTDIR)/$(LIB)/rcscripts/bin
	for x in $(RCLINKS); do ln -sf $(DESTDIR)/sbin/rc $(DESTDIR)/$(LIB)/rcscripts/bin/$$x; done
	if test "$(HAVE_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:
	rm -f $(TARGET) $(RCLINKS) $(RCPRIVLINKS)
	rm -f *.o *~ *.core *.so