root / prex-0.9.0 / mk / common.mk @ c63c9752
History | View | Annotate | Download (3.11 KB)
1 |
# common.mk - common make rules to build Prex |
---|---|
2 |
|
3 |
# |
4 |
# This file includes the common rules to make Prex source tree. |
5 |
# The files are installed in /mk, and are, by convention, |
6 |
# named with the suffix ".mk". |
7 |
# |
8 |
# Supported environment variables: |
9 |
# |
10 |
# SRCDIR ... Root directory of source tree |
11 |
# NDEBUG ... Force disable debug switch (default: 0) |
12 |
# LIBGCC_PATH ... Path for libgcc.a (optional) |
13 |
# |
14 |
# Variables in local Makefile: |
15 |
# |
16 |
# TARGET ... Target file name |
17 |
# SUBDIR,SUBDIR-y ... List of subdirectories |
18 |
# SRCS,SRCS-y ... Source files |
19 |
# OBJS,OBJS-y ... Object files |
20 |
# LIBS ... Libraries |
21 |
# INCSDIR ... Include path |
22 |
# LIBSDIR ... Library path |
23 |
# DEFS ... Definition to pass to the compiler |
24 |
# MAP ... Name of map file |
25 |
# DISASM ... Name of disassemble file |
26 |
# SYMBOL ... Name of symbol file |
27 |
# |
28 |
|
29 |
ifndef _COMMON_MK_ |
30 |
_COMMON_MK_:= 1 |
31 |
|
32 |
ifdef _GNUC_ |
33 |
include $(SRCDIR)/mk/gcc.mk |
34 |
endif |
35 |
|
36 |
ifdef _PCC_ |
37 |
include $(SRCDIR)/mk/pcc.mk |
38 |
endif |
39 |
|
40 |
ifdef _SUNPRO_C_ |
41 |
include $(SRCDIR)/mk/suncc.mk |
42 |
endif |
43 |
|
44 |
ifdef DISASM |
45 |
ASMGEN= $(OBJDUMP) $@ --disassemble-all > $(DISASM) |
46 |
endif |
47 |
|
48 |
ifdef SYMBOL |
49 |
SYMGEN= cp $@ $(SYMBOL) |
50 |
endif |
51 |
|
52 |
SUBDIR+= $(SUBDIR-y) |
53 |
OBJS+= $(OBJS-y) |
54 |
SRCS+= $(SRCS-y) |
55 |
ifeq ($(OBJS),) |
56 |
OBJS+= $(addsuffix .o,$(basename $(SRCS))) |
57 |
endif |
58 |
|
59 |
.SUFFIXES: |
60 |
.SUFFIXES: .bin .a .o .S .c .cc .cpp .cxx .h |
61 |
|
62 |
ifeq ($(_SILENT_),1) |
63 |
echo-file= @echo ' $(1) $(subst $(SRCDIR)/,,$(abspath $(2)))' |
64 |
|
65 |
echo-files= @(for d in $(2) _ ; do \ |
66 |
if [ "$$d" != "_" ]; then \ |
67 |
echo " $(1) $(subst $(SRCDIR)/,,$(abspath $$d))" ; fi; \ |
68 |
done); |
69 |
endif |
70 |
|
71 |
# |
72 |
# Inference rules |
73 |
# |
74 |
%.o: %.c |
75 |
$(call echo-file,CC ,$<) |
76 |
$(CC) $(CFLAGS) $(CPPFLAGS) $(OUTPUT_OPTION) $< |
77 |
|
78 |
%.o: %.S |
79 |
$(call echo-file,AS ,$<) |
80 |
$(CPP) $(ACPPFLAGS) $(CPPFLAGS) $< $*.tmp |
81 |
$(AS) $(ASFLAGS) $(OUTPUT_OPTION) $*.tmp |
82 |
$(RM) $*.tmp |
83 |
|
84 |
|
85 |
# |
86 |
# Target |
87 |
# |
88 |
all: config $(SUBDIR) $(TARGET) |
89 |
|
90 |
|
91 |
# |
92 |
# Check configuration file |
93 |
# |
94 |
.PHONY: config |
95 |
config: |
96 |
ifndef ARCH |
97 |
@echo 'Error: You must run `configure` before make.' |
98 |
exit 1 |
99 |
endif |
100 |
|
101 |
# |
102 |
# Rules to process sub-directory |
103 |
# |
104 |
ifdef SUBDIR |
105 |
.PHONY: $(SUBDIR) |
106 |
$(SUBDIR): dummy |
107 |
@$(MAKE) -C $@ |
108 |
endif |
109 |
|
110 |
-include Makefile.dep |
111 |
|
112 |
# |
113 |
# Depend |
114 |
# |
115 |
.PHONY: depend dep |
116 |
depend dep: |
117 |
ifdef SUBDIR |
118 |
@(for d in $(SUBDIR) _ ; do \ |
119 |
if [ "$$d" != "_" ]; then $(MAKE) -C $$d depend; fi; \ |
120 |
done); |
121 |
endif |
122 |
$(RM) Makefile.dep |
123 |
@(for d in $(SRCS) _ ; do \ |
124 |
if [ "$$d" != "_" ]; then \ |
125 |
$(CPP) -M $(CPPFLAGS) $$d >> Makefile.dep; fi; \ |
126 |
done); |
127 |
|
128 |
# |
129 |
# Lint |
130 |
# |
131 |
.PHONY: lint |
132 |
lint: |
133 |
ifdef SUBDIR |
134 |
@(for d in $(SUBDIR) _ ; do \ |
135 |
if [ "$$d" != "_" ]; then $(MAKE) -C $$d lint; fi; \ |
136 |
done); |
137 |
endif |
138 |
@(for d in $(filter %.c, $(SRCS)) _ ; do \ |
139 |
if [ "$$d" != "_" ]; then \ |
140 |
echo ; \ |
141 |
echo "Checking $$d" ; \ |
142 |
$(LINT) $(CPPFLAGS) $(LINTFLAGS) $$d; fi; \ |
143 |
done); |
144 |
|
145 |
# |
146 |
# Clean up |
147 |
# |
148 |
CLEANS= Makefile.dep $(TARGET) $(OBJS) $(DISASM) $(MAP) $(SYMBOL) $(CLEANFILES) |
149 |
|
150 |
.PHONY: clean |
151 |
clean: |
152 |
ifdef SUBDIR |
153 |
@(for d in $(SUBDIR) _ ; do \ |
154 |
if [ "$$d" != "_" ]; then $(MAKE) -C $$d clean; fi; \ |
155 |
done); |
156 |
endif |
157 |
$(call echo-files,CLEAN ,$(CLEANS)) |
158 |
$(RM) $(CLEANS) |
159 |
|
160 |
.PHONY: dummy |
161 |
|
162 |
# |
163 |
# Build OS image |
164 |
# |
165 |
.PHINY: image |
166 |
image: config $(TARGET) |
167 |
|
168 |
endif # !_COMMON_MK_ |