-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNU_makefile_template
56 lines (46 loc) · 2.09 KB
/
GNU_makefile_template
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
#g++ compiler: options
# -std=c++0x enables ISO C++ 11 standard
# -I.. pulls in the Version_test.h file for conditional compilation
# of code the uses features that might not yet be implemented
CC = g++
CCFLAGS = -std=c++0x -I..
# Some programs include headers defined in earlier chapters
# LOCFLAGS used to set tell the compiler where to find a
# header that is not in the same directory as the source file itself
# LOCFLAGS will be set in directory level makefiles as needed
LOCFLAGS =
###
####### To compile without using a makefile
# To compile an object file from a source file you could execute
# g++ -std=c++0x -c filename.cc # produces filename.obj
# To compile an executable file from an object file, you would execute
# g++ -std=c++0x filename.o # produces filename.exe
# To compile an executable file from a source file, you would execute
# g++ -std=c++0x filename.cc # produces filename.exe
#######
# each subdirectory contains a Makefile that lists the executable
# files that can be made in that directory. That list is assigned
# to the make macro named $OBJECTS
# This rule says that the make target named "all" depends on those
# files. Executing "make all" in a subdirectory will cause make
# to build each .exe file listed in that subdirectory's makefile
all: $(OBJECTS)
# rule that says how to make a .o object file from a .cc source file
# for a given source file in a given directory you could compile it
# into an object file by executing "make filename.o"
# $< and $@ are macros defined by make
# $< refers to the file being processed (i.e., compiled or linked)
# $@ refers to the generated file
%.o: %.cc
$(CC) $(CCFLAGS) $(LOCFLAGS) -c $< -o $@
# rule that says how to make a .exe executable file from a .o object file
%.exe: %.o
$(CC) $(CCFLAGS) $(LOCFLAGS) $< -o $@
# target to clean up the object files and any core files
# executing "make clean" in a subdirectory will remove all
# files named core or any file ending in .obj, or .stackdump
clean:
rm -rf *.o core *.stackdump
# target to remove executable files as well as object and core files
clobber: clean
rm -rf *.exe