Skip to content

Commit 439602d

Browse files
authored
Merge pull request #10 from jgaffiot/improved_makefile
Improved Makfile, passing unknown rule to the Cmake generated Makefile
2 parents bf90e91 + d9b2cb7 commit 439602d

File tree

2 files changed

+82
-37
lines changed

2 files changed

+82
-37
lines changed

Makefile

Lines changed: 81 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,121 @@
1-
RELEASE_DIR := ./build/release/
2-
DEBUG_DIR := ./build/debug/
1+
ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
2+
RELEASE_DIR := $(ROOT_DIR)/build/release/
3+
DEBUG_DIR := $(ROOT_DIR)/build/debug/
4+
INSTALL_DIR := $(ROOT_DIR)/install
35

4-
TOOLS_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
5-
CMAKE := cmake $(TOOLS_DIR)/source
6+
CMAKE := cmake $(ROOT_DIR)/source
67
FLAG := -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
78

9+
# Enable the debug of the build or the Makefile itself
10+
# Use: "make DEBUG_BUILD=1"
811
ifdef DEBUG_BUILD
912
CMAKE += --trace --debug-output
1013
MAKE += --trace -d
14+
VERBOSE := 1
1115
else
1216
MAKE += --no-print-directory
1317
endif
1418

15-
all: install_release
19+
# By default, suppress display of executed commands.
20+
# Use: "make VERBOSE=1"
21+
$(VERBOSE).SILENT:
1622

23+
.PHONY: all
24+
all: install
25+
26+
.PHONY: debug
1727
debug: install_debug
1828

1929

20-
.PHONY: build_release
21-
build_release:
22-
@echo "Creating directory $(RELEASE_DIR) and running cmake in Release mode"
23-
@mkdir -p $(RELEASE_DIR);
24-
@( cd $(RELEASE_DIR)$ ; $(CMAKE) -DCMAKE_BUILD_TYPE=Release $(FLAG) ) || exit $$?;
30+
.PHONY: generate
31+
generate:
32+
echo "Creating directory $(RELEASE_DIR) and running cmake in Release mode"
33+
mkdir -p $(RELEASE_DIR);
34+
( cd $(RELEASE_DIR)$ ; $(CMAKE) -DCMAKE_BUILD_TYPE=Release $(FLAG) ) || exit $$?;
2535

26-
compile_release: | build_release
27-
@echo "Compiling in Release mode..."
28-
@( cd $(RELEASE_DIR)$ ; $(MAKE) all ) || exit $$?;
36+
$(RELEASE_DIR)/Makefile: generate
2937

30-
install_release: build_release compile_release
31-
@echo "Installing Release..."
32-
@( cd $(RELEASE_DIR)$ ; $(MAKE) install ) || exit $$?;
38+
.PHONY: build
39+
build: $(RELEASE_DIR)/Makefile
40+
echo "Compiling in Release mode..."
41+
( $(MAKE) -C $(RELEASE_DIR) all ) || exit $$?;
3342

43+
.PHONY: install
44+
install: build
45+
echo "Installing Release..."
46+
( $(MAKE) -C $(RELEASE_DIR) install ) || exit $$?;
3447

35-
.PHONY: build_debug
36-
build_debug:
37-
@echo "Creating directory $(DEBUG_DIR) and running cmake in Debug mode"
38-
@mkdir -p $(DEBUG_DIR);
39-
@( cd $(DEBUG_DIR)$ ; $(CMAKE) -DCMAKE_BUILD_TYPE=Debug $(FLAG)) || exit $$?;
48+
.PHONY: generate_debug
49+
generate_debug:
50+
echo "Creating directory $(DEBUG_DIR) and running cmake in Debug mode"
51+
mkdir -p $(DEBUG_DIR);
52+
( cd $(DEBUG_DIR)$ ; $(CMAKE) -DCMAKE_BUILD_TYPE=Debug $(FLAG)) || exit $$?;
4053

41-
compile_debug: | build_debug
42-
@echo "Compiling in Debug mode..."
43-
@( cd $(DEBUG_DIR)$ ; $(MAKE) all ) || exit $$?;
54+
$(DEBUG_DIR)/Makefile: generate_debug
55+
56+
.PHONY: build_debug
57+
build_debug: $(DEBUG_DIR)/Makefile
58+
echo "Compiling in Debug mode..."
59+
( $(MAKE) -C $(DEBUG_DIR) all ) || exit $$?;
4460

45-
install_debug: build_debug compile_debug
46-
@echo "Installing Debug..."
47-
@( cd $(DEBUG_DIR)$ ; $(MAKE) install ) || exit $$?;
61+
.PHONY: install_debug
62+
install_debug: build_debug
63+
echo "Installing Debug..."
64+
( $(MAKE) -C $(DEBUG_DIR) install ) || exit $$?;
4865

4966

5067
.PHONY: clean
51-
clean: clean_lib_bin
52-
@if [ -d $(RELEASE_DIR) ]; \
68+
clean: clean_install
69+
if [ -d $(RELEASE_DIR) ]; \
5370
then \
5471
echo "Cleaning compiled files"; \
55-
( cd $(RELEASE_DIR)$ ; $(MAKE) clean ); \
72+
( $(MAKE) -C $(RELEASE_DIR) clean ); \
5673
echo "Deleting the Release build directory $(RELEASE_DIR)"; \
5774
rm -rf $(RELEASE_DIR); \
5875
else \
5976
echo "The Release build directory does not exist"; \
6077
fi;
6178

6279
.PHONY: clean_debug
63-
clean_debug: clean_lib_bin
64-
@if [ -d $(DEBUG_DIR) ]; \
80+
clean_debug: clean_install
81+
if [ -d $(DEBUG_DIR) ]; \
6582
then \
6683
echo "Cleaning compiled files"; \
67-
( cd $(DEBUG_DIR)$ ; $(MAKE) clean ); \
84+
( $(MAKE) -C $(DEBUG_DIR) clean ); \
6885
echo "Deleting the Debug build directory $(DEBUG_DIR)"; \
6986
rm -rf $(DEBUG_DIR); \
7087
else \
7188
echo "The Debug build directory does not exist"; \
7289
fi;
7390

74-
.PHONY: clean_lib_bin
75-
clean_lib_bin:
76-
@echo "Cleaning binaries and libraries"
77-
@rm -rf ./install/*
91+
.PHONY: clean_install
92+
clean_install:
93+
echo "Cleaning installed binaries and libraries"
94+
rm -rf $(INSTALL_DIR)/
95+
96+
.PHONY : help
97+
help:
98+
echo "The following are some of the valid targets for this Makefile:"
99+
echo ".. all (the default if no target is provided)"
100+
echo ".. debug"
101+
echo ".. generate"
102+
echo ".. build"
103+
echo ".. install"
104+
echo ".. generate_debug"
105+
echo ".. build_debug"
106+
echo ".. install_debug"
107+
echo ".. clean"
108+
echo ".. clean_debug"
109+
echo ".. clean_install"
110+
if [ -d $(RELEASE_DIR) ]; \
111+
then \
112+
echo; echo "Targets of the CMake generated Makefile"; \
113+
( $(MAKE) -C $(RELEASE_DIR) help ) || exit $$?; \
114+
fi;
115+
116+
# Black magic: redirect all unknown rule to the CMake generated Makefile
117+
Makefile:;
118+
.PHONY: %
119+
%: $(RELEASE_DIR)/Makefile
120+
echo "Passing target '$'to generated Makefile in $(RELEASE_DIR)"
121+
( $(MAKE) -C $(RELEASE_DIR) $ ) || exit $$?;

test/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Unitary tests of Tools."""

0 commit comments

Comments
 (0)