Example Code: Fundamental Engineering#

Example Code for Makefile#

Example code for the section Makefile in Fundamental Engineering.

1
2
3
#pragma once
void hello();
// vim: set sw=4 ts=4 sts=4 et:
1
2
3
4
5
6
7
#include <iostream>
#include "hello.hpp"
void hello()
{
    std::cout << "hello with standalone compiling unit" << std::endl;
}
// vim: set sw=4 ts=4 sts=4 et:
1
2
3
#pragma once
void hello();
// vim: set sw=4 ts=4 sts=4 et:

Listing of Makefiles#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
CXX = g++

hello: hello.o hellomain.o
	$(CXX) hello.o hellomain.o -o hello

hello.o: hello.cpp hello.hpp
	$(CXX) -c hello.cpp -o hello.o

hellomain.o: hellomain.cpp hello.hpp
	$(CXX) -c hellomain.cpp -o hellomain.o

# vim: set noet nobomb fenc=utf8 ff=unix:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
CXX = g++

hello: hello.o hellomain.o
	$(CXX) $^ -o $@

hello.o: hello.cpp hello.hpp
	$(CXX) -c $< -o $@

hellomain.o: hellomain.cpp hello.hpp
	$(CXX) -c $< -o $@

# vim: set noet nobomb fenc=utf8 ff=unix:
1
2
3
4
5
6
7
8
9
CXX = g++

hello: hello.o hellomain.o
	$(CXX) $^ -o $@

%.o: %.cpp hello.hpp
	$(CXX) -c $< -o $@

# vim: set noet nobomb fenc=utf8 ff=unix:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
CXX = g++

# If the following two lines are commented out, the default target becomes hello.o.
.PHONY: default
default: hello

# Implicit rules will be skipped when searching for default.
#%.o: %.cpp hello.hpp
#	$(CXX) -c $< -o $@

hello.o: hello.cpp hello.hpp
	$(CXX) -c $< -o $@

hellomain.o: hellomain.cpp hello.hpp
	$(CXX) -c $< -o $@

hello: hello.o hellomain.o
	$(CXX) $^ -o $@

.PHONY: clean
clean:
	rm -rf hello *.o

# vim: set noet nobomb fenc=utf8 ff=unix: