Choose appropriate build configuration automatically.
[oweals/dinit.git] / src / Makefile
1 include ../mconfig
2
3 ifeq ($(BUILD_SHUTDOWN),yes)
4   SHUTDOWN=shutdown
5 endif
6
7 dinit_objects = dinit.o load-service.o service.o proc-service.o baseproc-service.o control.o dinit-log.o \
8                 dinit-main.o run-child-proc.o
9
10 objects = $(dinit_objects) dinitctl.o shutdown.o
11
12 all: dinit dinitctl $(SHUTDOWN)
13
14 # Look for a suitable build config file and use it.
15 ../mconfig:
16         @UNAME=`uname`;\
17         if [ -f "../configs/mconfig.$$UNAME" ]; then \
18             echo "Found configuration for OS: $$UNAME"; \
19             ln -sf "configs/mconfig.$$UNAME" ../mconfig; \
20         else \
21             echo "No config available. Please create suitable mconfig file."; \
22         fi
23
24 includes/mconfig.h: mconfig-gen
25         ./mconfig-gen SBINDIR=$(SBINDIR) SYSCONTROLSOCKET=$(SYSCONTROLSOCKET) > includes/mconfig.h
26
27 mconfig-gen: mconfig-gen.cc ../mconfig
28         $(CXX) $(CXXOPTS) -o mconfig-gen mconfig-gen.cc $(LDFLAGS)
29
30 $(dinit_objects): includes/mconfig.h
31
32 dinit: $(dinit_objects)
33         $(CXX) -o dinit $(dinit_objects) $(LDFLAGS)
34
35 dinitctl: dinitctl.o
36         $(CXX) -o dinitctl dinitctl.o $(LDFLAGS)
37         
38 shutdown: shutdown.o
39         $(CXX) -o shutdown shutdown.o $(LDFLAGS)
40
41 $(objects): %.o: %.cc
42         $(CXX) $(CXXOPTS) -MMD -MP -Iincludes -Idasynq -c $< -o $@
43
44 check:
45         $(MAKE) -C tests check
46
47 run-cppcheck:
48         cppcheck --std=c++11 -Iincludes -Idasynq --force --enable=all *.cc 2>../cppcheck-report.txt
49
50 install: all
51         install -d $(DESTDIR)$(SBINDIR)
52         install -s dinit dinitctl $(SHUTDOWN) $(DESTDIR)$(SBINDIR)
53 ifeq ($(BUILD_SHUTDOWN),yes)
54         ln $(DESTDIR)$(SBINDIR)/shutdown $(DESTDIR)$(SBINDIR)/halt
55         ln $(DESTDIR)$(SBINDIR)/shutdown $(DESTDIR)$(SBINDIR)/reboot
56 endif
57
58 clean:
59         rm -f *.o *.d
60         rm -f dinit dinitctl shutdown mconfig-gen
61         rm -f includes/mconfig.h
62         $(MAKE) -C tests clean
63
64 -include $(objects:.o=.d)