Include -Wunreachable-code when building.
[sysvinit.git] / src / Makefile
... / ...
CommitLineData
1#
2# Makefile Makefile for the systemV init suite.
3# Targets: all compiles everything
4# install installs the binaries (not the scripts)
5# clean cleans up object files
6# clobber really cleans up
7#
8# Version: @(#)Makefile 2.85-13 23-Mar-2004 miquels@cistron.nl
9#
10
11CPPFLAGS =
12CFLAGS ?= -ansi -O2 -fomit-frame-pointer -fstack-protector
13override CFLAGS += -W -Wall -Wunreachable-code -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -D_XOPEN_SOURCE -D_GNU_SOURCE
14STATIC =
15MANDB := s@^\('\\\\\"\)[^\*-]*-\*- coding: [^[:blank:]]\+ -\*-@\1@
16
17#
18# Leave empty if the mountpoint(1) command from util-linux 2.20
19# and above should be used, otherwise set it to yes.
20#
21MNTPOINT=
22
23# For some known distributions we do not build all programs, otherwise we do.
24BIN =
25SBIN = init halt shutdown runlevel killall5 fstab-decode
26USRBIN = last mesg
27
28MAN1 = last.1 lastb.1 mesg.1
29MAN5 = initscript.5 inittab.5
30MAN8 = halt.8 init.8 killall5.8 pidof.8 poweroff.8 reboot.8 runlevel.8
31MAN8 += shutdown.8 telinit.8 fstab-decode.8
32
33ifeq ($(DISTRO),)
34SBIN += sulogin bootlogd
35USRBIN += utmpdump wall
36MAN1 += utmpdump.1 wall.1
37MAN8 += sulogin.8 bootlogd.8
38endif
39
40ifeq ($(DISTRO),Debian)
41CPPFLAGS+= -DACCTON_OFF
42SBIN += sulogin bootlogd
43MAN8 += sulogin.8 bootlogd.8
44MANDB :=
45endif
46
47ifeq ($(DISTRO),Owl)
48USRBIN += wall
49MAN1 += wall.1
50MANDB :=
51endif
52
53ifeq ($(DISTRO),SuSE)
54CPPFLAGS+= -DUSE_SYSFS -DSANE_TIO -DSIGINT_ONLYONCE -DUSE_ONELINE
55SBIN += sulogin
56USRBIN += utmpdump
57MAN1 += utmpdump.1
58MAN8 += sulogin.8
59MANDB :=
60endif
61
62ifeq ($(MNTPOINT),yes)
63BIN += mountpoint
64MAN1 += mountpoint.1
65endif
66
67ID = $(shell id -u)
68BIN_OWNER = root
69BIN_GROUP = root
70BIN_COMBO = $(BIN_OWNER):$(BIN_GROUP)
71ifeq ($(ID),0)
72 INSTALL_EXEC = install -o $(BIN_OWNER) -g $(BIN_GROUP) -m 755
73 INSTALL_DATA = install -o $(BIN_OWNER) -g $(BIN_GROUP) -m 644
74else
75 INSTALL_EXEC = install -m 755
76 INSTALL_DATA = install -m 644
77endif
78INSTALL_DIR = install -m 755 -d
79MANDIR = /usr/share/man
80
81ifeq ($(WITH_SELINUX),yes)
82 SELINUX_DEF = -DWITH_SELINUX
83 INITLIBS += -lsepol -lselinux
84 SULOGINLIBS = -lselinux
85else
86 SELINUX_DEF =
87 INITLIBS =
88 SULOGINLIBS =
89endif
90
91# Additional libs for GNU libc.
92ifneq ($(wildcard /usr/lib*/libcrypt.*),)
93 SULOGINLIBS += -lcrypt
94endif
95
96# Additional libs for GNU libc / multiarch on Debian based systems.
97ifneq ($(wildcard /usr/lib/*/libcrypt.*),)
98 SULOGINLIBS += -lcrypt
99endif
100
101all: $(BIN) $(SBIN) $(USRBIN)
102
103#%: %.o
104# $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
105#%.o: %.c
106# $(CC) $(CFLAGS) $(CPPFLAGS) -c $^ -o $@
107
108init: LDLIBS += $(INITLIBS) $(STATIC)
109init: init.o init_utmp.o
110
111halt: LDLIBS += $(STATIC)
112halt: halt.o ifdown.o hddown.o utmp.o
113
114last: LDLIBS += $(STATIC)
115last: last.o
116
117mesg: LDLIBS += $(STATIC)
118mesg: mesg.o
119
120mountpoint: LDLIBS += $(STATIC)
121mountpoint: mountpoint.o
122
123utmpdump: LDLIBS += $(STATIC)
124utmpdump: utmpdump.o
125
126runlevel: LDLIBS += $(STATIC)
127runlevel: runlevel.o
128
129sulogin: LDLIBS += $(SULOGINLIBS) $(STATIC)
130sulogin: sulogin.o consoles.o
131
132wall: LDLIBS += $(STATIC)
133wall: dowall.o wall.o
134
135shutdown: LDLIBS += $(STATIC)
136shutdown: dowall.o shutdown.o utmp.o
137
138bootlogd: LDLIBS += -lutil $(STATIC)
139bootlogd: bootlogd.o
140
141fstab-decode: LDLIBS += $(STATIC)
142fstab-decode: fstab-decode.o
143
144sulogin.o: CPPFLAGS += $(SELINUX_DEF)
145sulogin.o: sulogin.c
146
147init.o: CPPFLAGS += $(SELINUX_DEF)
148init.o: init.c init.h initreq.h paths.h reboot.h set.h
149
150utmp.o:
151
152init_utmp.o: CPPFLAGS += -DINIT_MAIN
153init_utmp.o: utmp.c init.h initreq.h paths.h
154 $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
155
156utmpdump.o: utmpdump.c oldutmp.h
157
158shutdown.o: shutdown.c paths.h reboot.h initreq.h init.h
159
160halt.o: halt.c reboot.h
161
162last.o: last.c oldutmp.h
163
164consoles.o: consoles.c consoles.h
165
166cleanobjs:
167 rm -f *.o *.bak
168
169clean: cleanobjs
170 @echo Type \"make clobber\" to really clean up.
171
172clobber: cleanobjs
173 rm -f $(BIN) $(SBIN) $(USRBIN)
174
175distclean: clobber
176
177install:
178 $(INSTALL_DIR) $(ROOT)/bin/ $(ROOT)/sbin/
179 $(INSTALL_DIR) $(ROOT)/usr/bin/
180 for i in $(BIN); do \
181 $(INSTALL_EXEC) $$i $(ROOT)/bin/ ; \
182 done
183 for i in $(SBIN); do \
184 $(INSTALL_EXEC) $$i $(ROOT)/sbin/ ; \
185 done
186 for i in $(USRBIN); do \
187 $(INSTALL_EXEC) $$i $(ROOT)/usr/bin/ ; \
188 done
189 # $(INSTALL_DIR) $(ROOT)/etc/
190 # $(INSTALL_EXEC) initscript.sample $(ROOT)/etc/
191 ln -sf halt $(ROOT)/sbin/reboot
192 ln -sf halt $(ROOT)/sbin/poweroff
193 ln -sf init $(ROOT)/sbin/telinit
194 ln -sf /sbin/killall5 $(ROOT)/bin/pidof
195 if [ ! -f $(ROOT)/usr/bin/lastb ]; then \
196 ln -sf last $(ROOT)/usr/bin/lastb; \
197 fi
198 $(INSTALL_DIR) $(ROOT)/usr/include/
199 $(INSTALL_DATA) initreq.h $(ROOT)/usr/include/
200 $(INSTALL_DIR) $(ROOT)$(MANDIR)/man1/
201 $(INSTALL_DIR) $(ROOT)$(MANDIR)/man5/
202 $(INSTALL_DIR) $(ROOT)$(MANDIR)/man8/
203 for man in $(MAN1); do \
204 $(INSTALL_DATA) ../man/$$man $(ROOT)$(MANDIR)/man1/; \
205 sed -i "1{ $(MANDB); }" $(ROOT)$(MANDIR)/man1/$$man ; \
206 done
207 for man in $(MAN5); do \
208 $(INSTALL_DATA) ../man/$$man $(ROOT)$(MANDIR)/man5/; \
209 sed -i "1{ $(MANDB); }" $(ROOT)$(MANDIR)/man5/$$man ; \
210 done
211 for man in $(MAN8); do \
212 $(INSTALL_DATA) ../man/$$man $(ROOT)$(MANDIR)/man8/; \
213 sed -i "1{ $(MANDB); }" $(ROOT)$(MANDIR)/man8/$$man ; \
214 done
215ifeq ($(ROOT),)
216 #
217 # This part is skipped on Debian systems, the
218 # debian.preinst script takes care of it.
219 @if [ ! -p /dev/initctl ]; then \
220 echo "Creating /dev/initctl"; \
221 rm -f /dev/initctl; \
222 mknod -m 600 /dev/initctl p; fi
223endif