Skip to content

Commit 4f300cc

Browse files
committed
Fix the project directions
1 parent c5849e5 commit 4f300cc

File tree

4 files changed

+116
-3
lines changed

4 files changed

+116
-3
lines changed

myalg/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ FLAGS_COMPILE = -c -Wall -Wextra -Werror
88
SHELL = /bin/sh
99
DIR = $(PWD)
1010
DIR_OBJ = $(DIR)/obj/
11-
DIR_SRC = $(DIR)/
11+
DIR_SRC = $(DIR)/test/
1212
DIR_BIN = $(DIR)/bin/
1313
DIR_LIB = $(DIR)/lib/
14-
DIR_INC = $(DIR)/include/
14+
DIR_INC = $(DIR)/inc/
1515

1616
#target
1717
TARGET = test
@@ -36,7 +36,7 @@ LIB=-L$(DIR_LIB)$(LIBS)
3636
OBJ=$(patsubst %.cpp,${DIR_OBJ}%.o,$(notdir ${SRC}))
3737

3838
#----------------macro---------------#
39-
.PHONY:dir clean make
39+
.PHONY:dir clean make r
4040
#debug
4141
debug:$(OBJ)
4242
@echo "linking..."
@@ -103,3 +103,7 @@ make:
103103
fi
104104
@echo "done"
105105

106+
#r: re-make the project
107+
r:
108+
$(MAKE) -s clean
109+
$(MAKE) -s make
File renamed without changes.

myalg/test/Makefile

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#----------------options----------------#
2+
#environment
3+
CC = g++
4+
FLAGS_DEBUG = -g
5+
FLAGS_COMPILE = -c -Wall -Wextra -Werror
6+
7+
#directory
8+
SHELL = /bin/sh
9+
DIR = $(PWD)
10+
DIR_OBJ = $(DIR)/obj/
11+
DIR_SRC = $(DIR)/test/
12+
DIR_BIN = $(DIR)/bin/
13+
DIR_LIB = $(DIR)/lib/
14+
DIR_INC = $(DIR)/inc/
15+
16+
#target
17+
TARGET = test
18+
19+
#vpath
20+
#vpath %.cpp $(DIR_SRC)
21+
#vpath %.o $(DIR_OBJ)
22+
23+
#src
24+
SRC=$(wildcard ${DIR_SRC}*.cpp)
25+
26+
#include
27+
INC=-I$(DIR_INC)
28+
29+
#lib
30+
#LIBS depends on your needs
31+
#for instance: LIBS=-lsky which means there is a libsky.a file in DIR_LIB direction
32+
LIBS=
33+
LIB=-L$(DIR_LIB)$(LIBS)
34+
35+
#obj
36+
OBJ=$(patsubst %.cpp,${DIR_OBJ}%.o,$(notdir ${SRC}))
37+
38+
#----------------macro---------------#
39+
.PHONY:dir clean make r
40+
#debug
41+
debug:$(OBJ)
42+
@echo "linking..."
43+
@cd $(DIR_OBJ);$(CC) *.o -o $(DIR_BIN)$(TARGET)
44+
@echo "linking end..."
45+
@echo "execute the $(TARGET) in $(DIR_BIN)$(TARGET)"
46+
47+
$(DIR_OBJ)%.o:$(DIR_SRC)%.cpp
48+
@echo "compiling..."
49+
@echo "SRC:$<"
50+
$(CC) $(FLAGS_DEBUG) $(FLAGS_COMPILE) $< -o $@ $(INC)
51+
@echo "compiling end..."
52+
53+
#clean
54+
clean:
55+
@rm -rf $(DIR_OBJ)
56+
@rm -rf $(DIR_BIN)
57+
58+
#objects & executable direction
59+
dir:
60+
@mkdir -p $(DIR_OBJ)
61+
@mkdir -p $(DIR_BIN)
62+
63+
#help
64+
help:
65+
@echo "......------------Makefile------------......"
66+
@echo "Include four commands: #1.de; #2.clean; #3.dir; #4.help"
67+
@echo "#1.de:"
68+
@echo " debug the source file into a executable file that is included in the $(DIR_BIN)!"
69+
@echo "#2.clean:"
70+
@echo " delete the debug files and directions"
71+
@echo "#3.dir:"
72+
@echo " mkdir a new directions for objects and executable file:"
73+
@echo " $(DIR_BIN) for executable file"
74+
@echo " $(DIR_OBJ) for object file"
75+
@echo "#4.help:"
76+
@echo " help for using this makefile to debug a project which includes source files include files"
77+
@echo "......------------End------------......"
78+
79+
#make all the commands and get the executable file
80+
make:
81+
@echo "start debugging..."
82+
@$(MAKE) -s dir
83+
@$(MAKE) -s debug
84+
@echo "finish..."
85+
@echo "******************************"
86+
@echo "* ____ ____ _ ________*"
87+
@echo "* / __ \/ __ \/ | / / ____/*"
88+
@echo "* / / / / / / / |/ / __/ *"
89+
@echo "* / /_/ / /_/ / /| / /___ *"
90+
@echo "*/_____/\____/_/ |_/_____/ *"
91+
@echo "******************************"
92+
@echo "You want the executable file run itself?"
93+
@echo "'Y' for yes,'N' for no"
94+
@read -s -n1 key;\
95+
Y="Y";\
96+
y="y";\
97+
if [ $$key == $$Y ] || [ $$key == $$y ]; then\
98+
cd $(DIR_BIN);\
99+
$(DIR_BIN)$(TARGET);\
100+
exit 0;\
101+
else\
102+
echo "Not Execute the File!";\
103+
fi
104+
@echo "done"
105+
106+
#r: re-make the project
107+
r:
108+
$(MAKE) -s clean
109+
$(MAKE) -s make
File renamed without changes.

0 commit comments

Comments
 (0)