Simplify build rules, based on patch from Mike Frysinger and Gentoo.
[sysvinit.git] / src / Makefile
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
11 CFLAGS ?= -ansi -O2 -fomit-frame-pointer
12 CFLAGS += -W -Wall -D_GNU_SOURCE
13 STATIC =
14
15 # For some known distributions we do not build all programs, otherwise we do.
16 BIN =
17 SBIN = init halt shutdown runlevel killall5
18 USRBIN = last mesg
19
20 MAN1 = last.1 lastb.1 mesg.1
21 MAN5 = initscript.5 inittab.5
22 MAN8 = halt.8 init.8 killall5.8 pidof.8 poweroff.8 reboot.8 runlevel.8
23 MAN8 += shutdown.8 telinit.8
24
25 ifeq ($(DISTRO),)
26 BIN += mountpoint
27 SBIN += sulogin bootlogd
28 USRBIN += utmpdump wall
29 MAN1 += mountpoint.1 wall.1
30 MAN8 += sulogin.8 bootlogd.8
31 endif
32
33 ifeq ($(DISTRO),Debian)
34 BIN += mountpoint
35 SBIN += sulogin bootlogd
36 MAN1 += mountpoint.1
37 MAN8 += sulogin.8 bootlogd.8
38 endif
39
40 ifeq ($(DISTRO),Owl)
41 USRBIN += wall
42 MAN1 += wall.1
43 endif
44
45 BIN_OWNER = root
46 BIN_GROUP = root
47 BIN_COMBO = $(BIN_OWNER):$(BIN_GROUP)
48 STRIP = strip -s -R .comment
49 INSTALL_EXEC = install -o $(BIN_OWNER) -g $(BIN_GROUP) -m 755
50 INSTALL_DATA = install -o $(BIN_OWNER) -g $(BIN_GROUP) -m 644
51 INSTALL_DIR = install -m 755 -d
52 MANDIR = /usr/share/man
53
54 ifeq ($(WITH_SELINUX),yes)
55 SELINUX_DEF=-DWITH_SELINUX
56 INIT_SELIBS=-lsepol -lselinux
57 SULOGIN_SELIBS=-lselinux
58 else
59 SELINUX_DEF=
60 INIT_SELIBS=
61 SULOGIN_SELIBS=
62 endif
63
64
65
66 # Additional libs for GNU libc.
67 ifneq ($(wildcard /usr/lib/libcrypt.a),)
68 LCRYPT = -lcrypt
69 endif
70
71 all: $(BIN) $(SBIN) $(USRBIN)
72
73 #%: %.o
74 # $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
75 #%.o: %.c
76 # $(CC) $(CFLAGS) $(CPPFLAGS) -c $^ -o $@
77
78 init: LDLIBS += $(INIT_SELIBS) $(STATIC)
79 init: init.o init_utmp.o
80
81 halt: halt.o ifdown.o hddown.o utmp.o reboot.h
82
83 last: last.o oldutmp.h
84
85 mesg: mesg.o
86
87 mountpoint: mountpoint.o
88
89 utmpdump: utmpdump.o
90
91 runlevel: runlevel.o
92
93 sulogin: LDLIBS += $(LCRYPT) $(SULOGIN_SELIBS) $(STATIC)
94 sulogin: sulogin.o
95
96 wall: dowall.o wall.o
97
98 shutdown: dowall.o shutdown.o utmp.o reboot.h
99
100 bootlogd: LDLIBS += -lutil
101 bootlogd: bootlogd.o
102
103 sulogin.o: CPPFLAGS += $(SELINUX_DEF)
104 sulogin.o: sulogin.c
105
106 init.o: CPPFLAGS += $(SELINUX_DEF)
107 init.o: init.c init.h set.h reboot.h initreq.h
108
109 utmp.o: utmp.c init.h
110
111 init_utmp.o: CPPFLAGS += -DINIT_MAIN
112 init_utmp.o: utmp.c init.h
113 $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
114
115 cleanobjs:
116 rm -f *.o *.bak
117
118 clean: cleanobjs
119 @echo Type \"make clobber\" to really clean up.
120
121 clobber: cleanobjs
122 rm -f $(BIN) $(SBIN) $(USRBIN)
123
124 distclean: clobber
125
126 install:
127 $(INSTALL_DIR) $(ROOT)/bin/ $(ROOT)/sbin/
128 $(INSTALL_DIR) $(ROOT)/usr/bin/
129 for i in $(BIN); do \
130 $(STRIP) $$i ; \
131 $(INSTALL_EXEC) $$i $(ROOT)/bin/ ; \
132 done
133 for i in $(SBIN); do \
134 $(STRIP) $$i ; \
135 $(INSTALL_EXEC) $$i $(ROOT)/sbin/ ; \
136 done
137 for i in $(USRBIN); do \
138 $(STRIP) $$i ; \
139 $(INSTALL_EXEC) $$i $(ROOT)/usr/bin/ ; \
140 done
141 # $(INSTALL_EXEC) etc/initscript.sample $(ROOT)/etc/
142 ln -sf halt $(ROOT)/sbin/reboot
143 ln -sf halt $(ROOT)/sbin/poweroff
144 ln -sf init $(ROOT)/sbin/telinit
145 ln -sf /sbin/killall5 $(ROOT)/bin/pidof
146 if [ ! -f $(ROOT)/usr/bin/lastb ]; then \
147 ln -sf last $(ROOT)/usr/bin/lastb; \
148 fi
149 $(INSTALL_DIR) $(ROOT)/usr/include/
150 $(INSTALL_DATA) initreq.h $(ROOT)/usr/include/
151 $(INSTALL_DIR) $(ROOT)$(MANDIR)/man1/
152 $(INSTALL_DIR) $(ROOT)$(MANDIR)/man5/
153 $(INSTALL_DIR) $(ROOT)$(MANDIR)/man8/
154 for i in $(MAN1); do \
155 $(INSTALL_DATA) ../man/$$i $(ROOT)$(MANDIR)/man1/; \
156 done
157 for i in $(MAN5); do \
158 $(INSTALL_DATA) ../man/$$i $(ROOT)$(MANDIR)/man5/; \
159 done
160 for i in $(MAN8); do \
161 $(INSTALL_DATA) ../man/$$i $(ROOT)$(MANDIR)/man8/; \
162 done
163 ifeq ($(ROOT),)
164 #
165 # This part is skipped on Debian systems, the
166 # debian.preinst script takes care of it.
167 @if [ ! -p /dev/initctl ]; then \
168 echo "Creating /dev/initctl"; \
169 rm -f /dev/initctl; \
170 mknod -m 600 /dev/initctl p; fi
171 endif