-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (90 loc) · 3.37 KB
/
Makefile
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
121
122
123
#determine OS
#what extension the output gets
#how does the delete command word
ifeq ($(OS), Windows_NT)
CURR_OS = WIN
OUTEXTEN=.exe
DELCMD = del /q /s o
else
CURR_OS = LIN
OUTEXTEN=.out
DELCMD = rm -fv
endif
#user flags:
DFLAG=
ifeq ($(DFLAG),O3)
C_OPTIMIZING=-DNDEBUG -O3
CPP_OPTIMIZING=-DNDEBUG -O3
=
else
ifeq ($(DFLAG),prof)
C_OPTIMIZING=-pg
CPP_OPTIMIZING=-pg
else
C_OPTIMIZING=-g
CPP_OPTIMIZING=-g
endif
endif
#
CC = gcc
CPP = g++
SHELL = /bin/bash
C_COMPILER_FLAGS=$(WARNING_LEVEL) -fpic $(C_OPTIMIZING) -I./include/
CPP_COMPILER_FLAGS=$(WARNING_LEVEL) -Weffc++ -fpic $(CPP_OPTIMIZING) -I./include/
WARNING_LEVEL=-pedantic-errors -Wall -Wextra
C_ANSI=-ansi
CPP_ANSI=-std=c++2a
C_LINKER_FLAGS= -lm -pthread
C_LINKER_LRT= -lrt
PROJECTS = knights_tour product_without reverse_sentence five_stars calculator roman_numerals
TARGETS1 = $(addprefix output/,$(addsuffix $(OUTEXTEN),$(PROJECTS)))
all: $(TARGETS1)
########################################################
obj/%_test.o: test/%_test.cpp include/%.h
$(CPP) $(CPP_ANSI) $(CPP_COMPILER_FLAGS) -c $(<) -o $(@)
output/%$(OUTEXTEN): obj/%.o obj/%_test.o
$(CPP) $(CPP_ANSI) $(CPP_COMPILER_FLAGS) $(^) -o $(@)
obj/%.o: lib/%.cpp include/%.h
$(CPP) $(CPP_ANSI) $(CPP_COMPILER_FLAGS) -c $(<) -o $(@)
obj/%_test.o: test/%_test.c include/%.h
$(CPP) $(CPP_ANSI) $(CPP_COMPILER_FLAGS) -c $(<) -o $(@)
#################-EXAMPLES-####################
#output/%.out: examples/%.cpp
# $(CPP) $(CPP_ANSI) $(CPP_COMPILER_FLAGS) $(<) -o $(@)
########################################################
#runfiles/%.out: obj/%.o obj/%_test.o
# $(CC) $(C_ANSI) $(C_COMPILER_FLAGS) $(^) -o $(@) $(C_LINKER_FLAGS)
#obj/%.o: lib/%.c include/%.h
# $(CC) $(C_ANSI) $(C_COMPILER_FLAGS) -c $(<) -o $(@)
#obj/%_test.o: test/%_test.c include/%.h
# $(CC) $(C_ANSI) $(C_COMPILER_FLAGS) -c $(<) -o $(@)
########################################################
output/knights_tour$(OUTEXTEN): obj/knights_tour.o
$(CPP) $(C_ANSI) $(C_COMPILER_FLAGS) $(^) -o $(@) $(C_LINKER_FLAGS)
obj/knights_tour.o: knights_tour.cpp
$(CPP) $(C_ANSI) $(C_COMPILER_FLAGS) $(^) -c -o $(@)
output/product_without$(OUTEXTEN): obj/product_without.o
$(CPP) $(C_ANSI) $(C_COMPILER_FLAGS) $(^) -o $(@) $(C_LINKER_FLAGS)
obj/product_without.o: product_without.c
$(CC) $(C_ANSI) $(C_COMPILER_FLAGS) $(^) -c -o $(@)
output/reverse_sentence$(OUTEXTEN): obj/reverse_sentence.o
$(CC) $(C_ANSI) $(C_COMPILER_FLAGS) $(^) -o $(@) $(C_LINKER_FLAGS)
obj/reverse_sentence.o: reverse_sentence.c
$(CC) $(C_ANSI) $(C_COMPILER_FLAGS) $(^) -c -o $(@)
output/five_stars$(OUTEXTEN): obj/five_stars.o
$(CPP) $(C_ANSI) $(C_COMPILER_FLAGS) $(^) -o $(@) $(C_LINKER_FLAGS)
obj/five_stars.o: five_stars.cpp
$(CPP) $(C_ANSI) $(C_COMPILER_FLAGS) $(^) -c -o $(@)
########################################################
.PHONY: clean
clean:
$(DELCMD) output\*.out output\*.exe obj\*.o
.PRECIOUS: obj/%.o obj/%_test.o obj2/%.o obj2/%_test.o
.DEFAULT_GOAL:=all
#must be tab delimited, otherwise e get a missing seperator error#
#variables arne't qouatuion marks
#will print out the command, so don't pipe this.
#use ralative paths to c so it will work both regardless of computer (home or lab)
#sometimes we need -lm to inlude the math library
#for windows:
#mingw32-make.exe instead of make