source: Make/Makerules @ 13

Revision 13, 3.6 KB checked in by art, 13 years ago (diff)
Line 
1#-----------------------------------------------
2# Makefile rules for building or installing
3#-----------------------------------------------
4all: default
5default: __info build
6build: __preparebuild depend $(TARGET)
7       
8__info:
9        @echo 'Used flags for compilation are: '
10        @echo 'CFLAGS = $(CFLAGS)'
11        @echo 'LDFLAGS = $(LDFLAGS)'
12       
13$(TARGET): $(OBJECTS)
14        @ echo -n 'Create $@ ...'
15        @ $(CC) $(CFLAGS) $(addprefix $(BUILDPATH)/,$(OBJECTS) ) -o $@ $(LDFLAGS)
16        @ echo 'OK'
17
18       
19$(OBJECTS): %.o: %.cpp
20        @ echo -n 'Compile $< ...'
21        @ $(CC) $(CFLAGS) -c $< -o $(BUILDPATH)/$@ && echo ' OK'
22       
23       
24$(DEPENDS): %.d: %.cpp
25        @ echo -n 'Create dependency list for $@ ...'
26        @ $(SHELL) -ec '$(CC) $(DEPARG) $(CFLAGS) $< > $(BUILDPATH)/$@'
27        @ echo ' OK'
28        @ echo "AUTOMAGICALY GENERATED FILE" > $(BUILDPATH)/.deps.exists
29       
30depend: $(DEPENDS)
31        @ $(SHELL) -c 'if [ -f $(BUILDPATH)/.deps.exists ] ; then \
32                echo -n "Combine dependencies list into make.dep ..."; \
33                cat $(BUILDPATH)/*.d | sed -e s/\\.cpp\\.o/.o/g > make.dep; \
34                echo " OK"; \
35        fi; '
36       
37#-----------------------------------------------
38# Prepare the building directory for writing
39#-----------------------------------------------
40__preparebuild:
41        @ if [ ! -d $(BUILDPATH) ]; then \
42                $(MKDIR) $(BUILDPATH); \
43        fi;
44
45#-----------------------------------------------
46# Install rules for parts of the package
47#-----------------------------------------------
48install: build __installdirs __installinc __installlib
49
50__installdirs:
51        @ $(SHELL) -c ' \
52                dirs="$(INSTALL_DIRS) $(INSTALL_DST_INC) $(INSTALL_DST_LIB)"; \
53                for d in $$dirs; do \
54                        if [ ! -d $$d ]; then \
55                                echo -n "Creating directory $$d ..."; \
56                                $(INSTALL_DIR) $$d; \
57                                echo " OK"; \
58                        fi; \
59                done; '
60       
61__installlib:
62        @ $(MAKE) INSTALL_SRC="$(INSTALL_SRC_LIB)" INSTALL_DST="$(INSTALL_DST_LIB)" INSTALL_CMD?="$(INSTALL_LIB)" __install
63
64__installinc:
65        @ $(MAKE) INSTALL_SRC="$(INSTALL_SRC_INC)" INSTALL_DST="$(INSTALL_DST_INC)" INSTALL_CMD?="$(INSTALL_INC)" __install
66
67__install:
68        @ $(SHELL) -c ' \
69                src="$(INSTALL_SRC)"; \
70                for f in $$src; \
71                do \
72                        if [ -f $$f ]; \
73                        then \
74                                $(INSTALL_CMD) $$f $(INSTALL_DST); \
75                                echo "Installing $$f in $(INSTALL_DST)"; \
76                        fi; \
77                done; '
78
79#-----------------------------------------------
80# Uninstall rules for removing the package
81#-----------------------------------------------
82uninstall: __uninstalllib __uninstallinc __uninstalldirs
83
84__uninstalllib:
85        @ $(MAKE) INSTALL_SRC="$(INSTALL_SRC_LIB)" INSTALL_DST="$(INSTALL_DST_LIB)" __uninstall
86
87__uninstallinc:
88        @ $(MAKE) INSTALL_SRC="$(INSTALL_SRC_INC)" INSTALL_DST="$(INSTALL_DST_INC)" __uninstall
89
90# Check for UNINSTALL_DIR entries and remove them
91__uninstalldirs:
92        @ $(SHELL) -c ' \
93                dirs="$(UNINSTALL_DIR)"; \
94                for d in $$dirs; do \
95                        if [ -d $$d ]; then \
96                                echo -n "Removing directory $$d ..."; \
97                                rm -rf $$d; \
98                                echo " OK"; \
99                        fi; \
100                done; '
101       
102__uninstall:
103        @ $(SHELL) -c ' \
104                src="$(INSTALL_SRC)"; \
105                for f in $$src; \
106                do \
107                        if [ -f $$f ]; \
108                        then \
109                                echo "Remove $$f from $(INSTALL_DST)"; \
110                                rm -f $(INSTALL_DST)/$$f; \
111                        fi; \
112                done; \
113                empty="ls $(INSTALL_DST)"; \
114                if [ -z "$$empty" ]; then \
115                        echo "$(INSTALL_DST) is empty, so remove it"; \
116                        rm -rf $(INSTALL_DST); \
117                fi; '
118
119#-----------------------------------------------
120# Make test suite
121#-----------------------------------------------
122check: test
123test:
124        (cd $(TOPDIR)/Test && make all)
125               
126#-----------------------------------------------
127# Clean all files
128#-----------------------------------------------
129.PHONY : clean
130clean:
131        @ echo -n "Clean building directory ..."
132        @ rm -rf $(BUILDPATH)
133        @ rm -rf *~
134        @ rm -rf *.d
135        @ rm -rf make.dep       
136        @ echo "OK"
137
Note: See TracBrowser for help on using the repository browser.