Compilation problems is currently in the fun is only one directory. C file, compile is ok, but there are multiple. C, will only generate a compilation. O file, feeling is there is something wrong with the fun of makefile
The total Makefile
# define GCC
CC: GCC=
CFLAGS=- g - O - Wall - pthread
SUBDIRS:=the main SRC obj
INCDIR: -i=$(shell PWD)/SRC/fun/inc
PRJDIR:=$(shell PWD)
BIN_DIR:=bin
BIN:=my_app
OBJS_DIR: obj=
RM: RM=
Export CC OBJS_DIR BIN_DIR BIN INCDIR PRJDIR LIB
All: check_bin compile_src
Check_bin:
Echo $(PWD)
The mkdir -p $(BIN_DIR) $(LIB)
Compile_src:
@ the set - e; For I in $(SUBDIRS); Do $(MAKE) - C $$I; The done
PHONY: clean cleanall
Clean:
$(RM) - rf $(OBJS_DIR)/*. O $(OBJS_DIR)//*. * * o
Cleanall:
$(RM) - rf $(OBJS_DIR)/*. O $(OBJS_DIR)//*. * * o $(BIN_DIR)/$(BIN)
Under the SRC Makefile
SUBDIRS:=fun
All: compile_src
Compile_src:
@ the set - e; For I in $(SUBDIRS); Do $(MAKE) - C $$I; The done
Under the fun of Makefile
SRC=$(wildcard * */*. C)
OBJS:=$(addprefix $(PRJDIR)/$(OBJS_DIR)/fun/, $(patsubst %. C, % o, $(notdir $(SRC))))
$(OBJS) : $(SRC)
@ mkdir -p $(PRJDIR)/$(OBJS_DIR)/fun
$(CC) $(INCDIR) - c $& lt; -o $@
Feel $(OBJS) : $(SRC) this compilation is wrong, changed to
$(PRJDIR)/$(OBJS_DIR)/fun/%. O: SRC/%. C
Still is not correct, to ask how to write here
CodePudding user response:
Must add in the makefile under the fun of target depends onCompile_src: $(OBJS)
CodePudding user response:
%. O: c%.$(CC) $(INCDIR) - c $& lt; -o $(PRJDIR)/$(OBJS_DIR)/fun/$@
Fun Makefile, to try this, command before the CC thus add & lt; TAB>