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