-
Notifications
You must be signed in to change notification settings - Fork 6
/
makerules
120 lines (105 loc) · 4.09 KB
/
makerules
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
# makerules (rules to create object files) for M root directory
# $Id$
# flags to be set based upon the type of object
M_FLAGS_o := -c
ifndef USE_MAC
M_FLAGS_so := -shared
else
M_FLAGS_so := -dynamiclib -undefined suppress -flat_namespace -bind_at_load
endif
M_FLAGS_ii := -E
M_FLAGS_s := -S
##############################################################################
# Some explanations: the rules M_COMPILE_CPP/CC/CXX defined above are very
# flexible as they allow you to define flags just for some dir1/dir2/foo.c
# (define CFLAGS_dir1_dir2_foo_o) or for all the files in some directory
# (define CFLAGS_dir1_dir2). Of course, the same applies to CPP/CXXFLAGS as
# well.
##############################################################################
# cpp (C preprocessor) flags:
# - first line is for global flags, can't be overridden (M_FLAGS_xxx is set
# above)
# - second line is for per-directory flags (e.g. CPPFLAGS_Python)
# - final line is for the current ($@) file (e.g. CPPFLAGS_Python_MDialogs_o)
define M_COMPILE_CPP
$(M_FLAGS$(subst .,_,$(suffix $@))) $(CPPFLAGS) \
$(CPPFLAGS$(subst /,_,$(subst /$(notdir $*),,/$*))) \
$(CPPFLAGS_$(subst .,_,$(subst /,_,$@)))
endef
# C compiler flags
#
# VZ: I have no idea why do we need unfiltered version...
define M_COMPILE_CC_unfiltered
$(M_COMPILE_CPP) $(CFLAGS) \
$(CFLAGS$(subst /,_,$(subst /$(notdir $*),,/$*))) \
$(CFLAGS_$(subst .,_,$(subst /,_,$@)))
endef
define M_COMPILE_CC
$(filter-out $(FILTER_OUT$(subst /,_,$(subst /$(notdir $*),,/$*))) \
$(FILTER_OUT_$(subst .,_,$(subst /,_,$@))),$(M_COMPILE_CC_unfiltered)) \
$(FILTER_IN$(subst /,_,$(subst /$(notdir $*),,/$*))) \
$(FILTER_IN_$(subst .,_,$(subst /,_,$@)))
endef
# C++ compiler flags
define M_COMPILE_CXX_unfiltered
$(M_COMPILE_CPP) $(CXXFLAGS) \
$(CXXFLAGS$(subst /,_,$(subst /$(notdir $*),,/$*))) \
$(CXXFLAGS_$(subst .,_,$(subst /,_,$@)))
endef
define M_COMPILE_CXX
$(filter-out $(FILTER_OUT$(subst /,_,$(subst /$(notdir $*),,/$*))) \
$(FILTER_OUT_$(subst .,_,$(subst /,_,$@))),$(M_COMPILE_CXX_unfiltered)) \
$(FILTER_IN$(subst /,_,$(subst /$(notdir $*),,/$*))) \
$(FILTER_IN_$(subst .,_,$(subst /,_,$@)))
endef
# linker flags
define M_LD_FLAGS
$(LDFLAGS) $(LDFLAGS$(subst /,_,$(subst /$(notdir $*),,/$*))) \
$(LDFLAGS_$(subst .,_,$(subst /,_,$@)))
endef
vpath %.h .src
vpath %.c .src
%.o: %.c
$(CC) -o $@ $(strip $(M_COMPILE_CC)) $<
@f=$(notdir $*); test ! -f $$f.d || { sed "s,^$$f\.o:,$@:," $$f.d >$*.t && rm -f $$f.d && mv $*.t $*.d; }
%.s: %.c # to look at assembly code during debugging
$(CC) -o $@ $(strip $(M_COMPILE_CC)) $<
vpath %.cc .src
%.o: %.cc
$(CXX) -o $@ $(strip $(M_COMPILE_CXX)) $<
@f=$(notdir $*); test ! -f $$f.d || { sed "s,^$$f\.o:,$@:," $$f.d >$*.t && rm -f $$f.d && mv $*.t $*.d; }
vpath %.cpp .src
%.o: %.cpp
$(CXX) -o $@ $(strip $(M_COMPILE_CXX)) $<
@f=$(notdir $*); test ! -f $$f.d || { sed "s,^$$f\.o:,$@:," $$f.d >$*.t && rm -f $$f.d && mv $*.t $*.d; }
%.ii: %.cpp # to look at post-processed source during debugging
$(CXX) -o $@ $(strip $(M_COMPILE_CXX)) $<
%.s: %.cpp # to look at assembly code during debugging
$(CXX) -o $@ $(strip $(M_COMPILE_CXX)) $<
# as a side-effect of building a .so file, any corresponding .o is removed
%.so: %.cpp
$(CXX) -o $@ $(SHARED_CFLAGS) $(strip $(M_COMPILE_CXX) $< $(M_LD_FLAGS))
@f=$(notdir $*); test ! -f $$f.d || { sed "s,^$$f\.o:,$@:," $$f.d >$*.o && rm -f $$f.d && mv $*.o $*.d; }
ifdef YACC
vpath %.y .src
%.o: %.y
$(YACC) $(YFLAGS) $< && mv y.tab.c $*.c
$(CC) -o $@ $(M_COMPILE_CC) $*.c
@f=$(notdir $*); test ! -f $$f.d || { sed -e "s,^$$f\.o:,$@:," -e "s,$*.c,$<," $$f.d >$*.t && rm -f $$f.d && mv $*.t $*.d; }
@rm -f $*.c
else
# we have to rename the file to have .c extension, otherwise some compilers
# refuse to accept it
vpath %.c-yacc .src
%.y.c: %.c-yacc
@cp $< $@
%.o: %.y.c
$(CC) -o $@ $(M_COMPILE_CC) $<
@f=$(notdir $*); test ! -f $$f.d || { sed -e "s,^$$f\.o:,$@:," -e "s,$*.c,$<," $$f.d >$*.t && rm -f $$f.d && mv $*.t $*.d; }
endif
# this syntax is for exuberant ctags
tags:
ctags -i mCF --lang=c++ $(SRC) $(CXXSRC) include/*.h include/*/*.h
stdclean:
$(RM) -r *.o *.so *.a *.lo *.d .libs
.PHONY: all install stdclean tags msgcat