summaryrefslogtreecommitdiffstats
path: root/rules.mk
blob: 7d0fc31ffb85f8b399b979a7ec8b79f7a9274db1 (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
#
# General make rules
#
.DEFAULT:	all
.PHONY:		$(ALLTARGETS)

include $(TOP)config.mk

##################################################################
# Subdirectory handling
##################################################################
ifneq ($(SUBDIRS),)
$(ALLTARGETS)::
	@set -e; for d in $(SUBDIRS); do \
		echo "Making $@ in $$d"; \
		$(MAKE) $(MFLAGS) --no-print-directory \
			-C $$d TOP=../$(TOP) $@; \
	done
endif

##################################################################
# Building an RPC daemon
##################################################################
ifneq ($(PROGRAM),)
TARGET	= $(PROGRAM)

$(PROGRAM): $(OBJS) $(LIBDEPS)
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

install:: $(PROGRAM)
	-$(MKDIR) $(SBINDIR)
	$(INSTALLBIN) $(PROGRAM) $(SBINDIR)/$(PREFIX)$k$(PROGRAM)
endif

##################################################################
# Building a tool
##################################################################
ifneq ($(TOOL),)
TARGET	= $(TOOL)

$(TOOL): $(OBJS) $(LIBDEPS)
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
endif

##################################################################
# Building a library
##################################################################
ifneq ($(LIBNAME),)
TARGET	= $(LIBNAME)

$(LIBNAME): $(OBJS)
	$(AR) cr $@ $^
	$(RANLIB) $@
endif

##################################################################
# Generic target rules
##################################################################
ifneq ($(TARGET),)
all:: $(TARGET)
	@echo "Building $(TARGET) done."

install:: $(TARGET)

distclean::
	rm -f $(TARGET)
endif

##################################################################
# Cleaning rules
##################################################################
clean distclean::
	rm -f *.o *~ \#* a.out core

distclean::
	rm -f LOG X Y Z x y z .depend

##################################################################
# Manpage installation
# Isn't GNU make a wonderful thing?
##################################################################
ifneq ($(MAN1)$(MAN5)$(MAN8)$(MAN9),)
MANINIT	= ext=$(MAN$sEXT); dir=$(MAN$sDIR); pgs="$(MAN$s)";
MANLOOP = $(MANINIT) for man in $$pgs; do mn=`echo $$man | sed 's/[0-9]$$//'`; eval $$cmd; done
MDCMD	= $(MKDIR) \$$dir
MICMD	= $(RM) \$$dir/\$$mn.\$$ext; \
	  echo $(INSTALLMAN) \$$man.man \$$dir/\$$mn.\$$ext; \
	  $(INSTALLMAN) \$$man.man \$$dir/\$$mn.\$$ext
LNCMD	= $(RM) \$$dir/$(PREFIX)\$$mn.\$$ext; \
	  echo $(LN_S) \$$mn.\$$ext \$$dir/$(PREFIX)\$$mn.\$$ext; \
	  $(LN_S) \$$mn.\$$ext \$$dir/$(PREFIX)\$$mn.\$$ext
PSCMD	= echo \"$(MAN2PS) \$$man.man > $(TOP)postscript/\$$man.ps\"; \
	  $(MAN2PS) \$$man.man > $(TOP)postscript/\$$man.ps

installman::
	@$(foreach s, 1 5 7 8 9, cmd="$(MDCMD)" $(MANLOOP);)
	@$(foreach s, 1 5 7 8 9, cmd="$(MICMD)" $(MANLOOP);)
ifneq ($(PREFIX),)
	@$(foreach s, 1 5 7 8 9, cmd="$(LNCMD)" $(MANLOOP);)
endif

postscript::
	@$(foreach s, 1 5 8 9, cmd="$(PSCMD)" $(MANLOOP);)
else
postscript installman::
	@: No manpages...
endif

##################################################################
# Indenting
##################################################################
ifneq ($(SRCS),)
indent:
	$(INDENT) $(SRCS)
endif

##################################################################
# Handling of dependencies
##################################################################
ifneq ($(OBJS),)
predep::
depend dep:: predep
	$(CC) $(CFLAGS) -M $(OBJS:.o=.c) > .depend
else
depend dep::
endif

ifeq (.depend,$(wildcard .depend))
include .depend
endif