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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
#
# Copyright (c) 2000, 2001, 2007 Dmitry Butskoy
# <buc@citadel.stu.neva.ru>
# License: GPL v2 or any later
#
# See COPYING for the status of this software.
#
#
# Common rule and variable definitions.
# This file should be included by main and by per-target Makefiles.
#
ifndef srcdir
$(error srcdir variable not defined)
endif
MAKE = make --no-print-directory -r
# Use env=yes on cmdline to inherit environment values
ifeq ($(env),yes)
define set
$(eval ifneq ($$(origin $(1)),environment)
$(1) = $(2)
else
override MAKE := $(1)="$($(strip $(1)))" $(MAKE)
endif)
endef
else
set = $(eval $(1) = $(2))
endif
$(call set, CROSS, )
$(call set, CC, $$(CROSS)gcc)
$(call set, AS, $$(CROSS)as)
$(call set, LD, $$(CROSS)ld)
$(call set, DEPEND, $$(CROSS)gcc -MM -MG)
$(call set, AR, $$(CROSS)ar)
$(call set, RANLIB, $$(CROSS)ranlib)
$(call set, INSTALL, cp)
$(call set, INDENT, true)
gcc = $(findstring gcc,$(CC))
$(call set, CFLAGS, $(if $(gcc), -O2 -Wall, -O))
$(call set, CPPFLAGS, )
$(call set, LDFLAGS, -s)
$(call set, LIBS, )
# install stuff
prefix = /usr/local
ifneq ($(wildcard /lib64/libc.* /usr/lib64/libc.*),)
lib := lib64
else
lib := lib
endif
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
sbindir = $(exec_prefix)/sbin
libdir = $(exec_prefix)/$(lib)
libexecdir = $(exec_prefix)/libexec/$(NAME)
sysconfdir = $(prefix)/etc
includedir = $(prefix)/include
datadir = $(prefix)/share
mandir = $(datadir)/man
infodir = $(datadir)/info
localstatedir = $(prefix)/var
sharedstatedir = $(prefix)/com
DESTDIR =
# layout stuff
SKIPDIRS = tmp%
INCLUDEDIRS = include%
LIBDIRS = lib%
MODDIRS = mod%
SKIPINSTALL = test%
include $(srcdir)/Make.defines
ifndef NAME
NAME = $(notdir $(srcdir))
endif
ifndef subdirs
ifeq ($(TARGET),.MAIN)
# for better performance...
subdirs := $(patsubst %/,%,$(wildcard */))
else
subdirs := $(patsubst $(srcdir)/%/,%,$(filter %/,$(wildcard $(srcdir)/*/)))
endif
subdirs := $(filter-out $(SKIPDIRS), $(subdirs))
endif
install install-%: subdirs := $(filter-out $(SKIPINSTALL), $(subdirs))
override MAKE += srcdir=$(srcdir) subdirs="$(subdirs)" shared=$(shared)
INCLUDEDIRS := $(filter $(INCLUDEDIRS), $(subdirs))
LIBDIRS := $(filter $(LIBDIRS), $(subdirs))
MODDIRS := $(filter $(MODDIRS), $(subdirs))
EXEDIRS := $(filter-out $(INCLUDEDIRS) $(LIBDIRS) $(MODDIRS), $(subdirs))
MODUSERS := $(filter $(MODUSERS), $(subdirs))
SBINUSERS := $(filter $(SBINUSERS), $(subdirs))
LIBDIRS := $(filter-out $(LIBLAST),$(LIBDIRS)) $(filter $(LIBDIRS),$(LIBLAST))
includes = $(foreach dir, $(INCLUDEDIRS) $(LIBDIRS), $(srcdir)/$(dir))
ifneq ($(gcc),)
CPATH = $(subst $(empty) ,:,$(includes))
export CPATH
else
override CPPFLAGS += $(patsubst %,-I%,$(includes))
endif
libraries = $(foreach dir, $(filter lib%,$(LIBDIRS)), $(srcdir)/$(dir))
vpath lib%.so $(libraries)
vpath lib%.a $(libraries)
_libs = $(strip $(foreach _lib,$(LIBDIRS),\
$(if $(filter lib%,$(_lib)),\
$(patsubst lib%,-l%,$(_lib)),\
$(wildcard $(srcdir)/$(_lib)/$(_lib).so \
$(srcdir)/$(_lib)/$(_lib).a))))
override LIBS := $(_libs) -lm $(LIBS)
ifeq ($(CC),gcc)
LIBRARY_PATH = $(subst $(empty) ,:,$(libraries))
export LIBRARY_PATH
else
override LIBS += $(patsubst %,-L%,$(libraries))
endif
LIBDEPS = $(filter-out -L%,$(LIBS))
#
# SUBDIRS STUFF
#
ifneq ($(TARGET),.MAIN)
obj := o
ifeq ($(shared),yes)
ifneq ($(PIC),no)
ifeq ($(filter $(TARGET),$(LIBDIRS) $(MODDIRS) .MODULE),$(TARGET))
obj := lo
endif
endif
endif
sources = $(wildcard *.c)
OBJS = $(sources:.c=.$(obj))
.PHONY: dummy all depend install clean force
dummy: all
clean:
rm -f *.o *.a *.lo *.so $(TARGET) core a.out
ifneq ($(sources),)
depend: $(sources)
$(DEPEND) $(CFLAGS) $(CPPFLAGS) $^ >.depend
else
depend:
@true
endif
%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $*.c
%.lo: %.c
$(CC) -fPIC $(CFLAGS) $(CPPFLAGS) -o $*.lo -c $*.c
%.o: %.s
$(AS) -o $*.o $*.s
%.o: %.S
$(CC) -traditional $(CPPFLAGS) -c $*.S
# include if it is present only...
ifeq (.depend, $(wildcard .depend))
include .depend
endif
endif
#
# ...end of SUBDIRS STUFF
#
|