Makefile无法检测文件夹内的文件

时间:2019-01-22 12:25:56

标签: makefile aix

尝试在AIX环境中编译此makefile时遇到严重问题。

文件夹结构如下(使用此处答案之一提供的命令:Linux command to print directory structure in the form of a tree find . | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"):

 |-src
 | |-main.c
 |-obj
 |-bin
 |-Makefile
 |-main.c

我正在尝试使用以下makefile编译此结构:

.SUFFIXES:

.DEFAULT:

CC       = xlc_r
CFLAGSD  = -g
CFLAGS   = -Wall
CDEF     =
LOADOPTS =
BIN_DIR  = bin/
OBJ_DIR  = obj/
SRC_DIR  = src/
LIB_DIR  = lib/
INC_DIR  = include/

INC_BASE   = -I./$(INC_DIR)
INC_SOURCE = -I./$(SRC_DIR)
INC_ALL    = $(INC_BASE) $(INC_SOURCE)

# Libraries packed in macros
LIB_BASE = -L./$(LIB_DIR)
LIB_MATH = -lm
LIB_ALL  = -lrt $(LIB_BASE)

# Libraries needed by the different programs and their respective names
LIB_PROGRAM_01 = $(LIB_ALL)
PROGRAM_NAME_01 = main

.PHONY: all

all: $(PROGRAM_NAME_01) \
     execute \

$(OBJ_DIR)%.o: $(SRC_DIR)%.c
    # --- Compiling $< ---
    # $(CC) $(CFLAGSD) $(INC_ALL) -c $(SRC_DIR)$< -o $(OBJ_DIR)$@

create_directories:
    if [ ! -d ./$(BIN_DIR) ]; then mkdir -p ./$(BIN_DIR);fi
    if [ ! -d ./$(OBJ_DIR) ]; then mkdir -p ./$(OBJ_DIR);fi

execute: $(PROGRAM_NAME_01)
    # --- Execute $< ---
    # ./$(BIN_DIR)$<

$(PROGRAM_NAME_01): $(OBJ_DIR)main.o
    # --- Linking $< ---
    # $(CC) $(CDEF) $^ -o $(BIN_DIR)$@ $(INC_ALL) $(LIB_PROGRAM_01)

cleanobj:
    # --- Clean all objects ---
    # rm -f $(OBJ_DIR)*.o

clean:
    # --- Clean all objects and the bin dir too ---
    # rm -f $(OBJ_DIR)*.o $(BIN_DIR)*

allc: all \
     cleanobj

Debug: all

Release: all

default: all

我得到的错误是下一个:

make: 1254-002 Cannot find a rule to create target obj/main.o from dependencies.

但是,如果我尝试使用Cygwin或Debian进行编译,那么它将起作用。

我试图调用make -r -d来查看所有内部信息和调试符号,但是它从不引用远程src/main.c文件附近的内容。

使用-d,makefile显示以下内容:

#
#   Files that are only sources:
#       src/%.c [src/%.c]
#       obj/main.o [obj/main.o]
#*** Internal (default) Variables:
#*** Global Variables:

aix中make的版本为:1.1.1.3,使用命令grep bos /usr/ccs/lib/aix.mk

1 个答案:

答案 0 :(得分:1)

您的makefile是GNU Make的makefile,但是您的AIX make程序不是GNU Make 和will not understand many GNU Make makefiles。 Cygwin或Debian 中的make程序是 GNU Make。 Install and use GNU Make