|
| 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 |
0 commit comments