我想了解如何为小项目编写自己的 makefile,所以我有几个问题
我的项目包括 src
包含 main.c
的目录, file1.c
, file2.c
, header1.h
,最后 header2.h
这些文件使用了我创建的非标准库中的一些库和非标准头文件,库目录位于 usr/lib/pr__lib
头目录位于usr/include/lib
所以我应该创建两个 makefile.am
一个将位于 src
目录,另一个将在项目的根目录中 makefile.am
的 src
目录如下:
program_NAME := PRDSL
bin_PROGRAMS = PRDSL_AutoProject
program_INCLUDE_DIRS := /usr/bin/PR__bin
program_LIBRARY_DIRS := /usr/lib/PR__lib
CFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir))
program_LIBRARIES := \
libprdependency \
libprdynarray_pic \
libprhistogram_pic \
libprlistofarrays \
libprlistofarrays_pic \
libprmalloc \
libvreo_wrapper_library
AM_LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir))
AM_LDFLAGS += $(foreach library,$(program_LIBRARIES),-l$(library))
PRDSL_AutoProject_SOURCES = \
main.c \
file1.c \
file2.c
depend :
makedepend --$(CFLAGS) --$(PRDSL_AutoProject_SOURCES)
all: $(program_NAME)
第二 makefile.am
在根目录下如下图:
SUBDIRS = src
PRDSL_AutoProjectdocdir = ${prefix}/doc/PRDSL_AutoProject
PRDSL_AutoProjectdoc_DATA = \
README\
COPYING\
AUTHORS\
ChangeLog\
INSTALL\
NEWS
INTLTOOL_FILES = intltool-extract.in \
intltool-merge.in \
intltool-update.in
EXTRA_DIST = $(PRDSL_AutoProjectdoc_DATA) \
$(INTLTOOL_FILES)
DISTCLEANFILES = intltool-extract \
intltool-merge \
intltool-update \
po/.intltool-merge-cache
# Remove doc directory on uninstall
uninstall-local:
-rm -r $(PRDSL_AutoProjectdocdir)
但我在运行时收到以下错误和警告 automake
命令:
src/Makefile.am:20: error: 'program_LIBRARIES' is used but 'programdir' is undefined
src/Makefile.am:18: warning: 'CFLAGS' is a user variable, you should not override it;
src/Makefile.am:18: use 'AM_CFLAGS' instead
src/Makefile.am:43: error: AM_LDFLAGS must be set with '=' before using '+='
有人可以查看并帮助我吗?
最佳答案
对于 src/Makefile.am:43: error: AM_LDFLAGS must be set with '=' before using '+='
见my answer到你的previous question .
是的,下面几行告诉你使用 AM_CFLAGS
而不是 CFLAGS
因为,如错误所示,CFLAGS
是用户指定的值,您应该保留它。
src/Makefile.am:18: warning: 'CFLAGS' is a user variable, you should not override it;
src/Makefile.am:18: use 'AM_CFLAGS' instead
我相信,虽然我还不确定,但你得到 src/Makefile.am:20: error: 'program_LIBRARIES' is used but 'programdir' is undefined
的原因是因为您正在使用变量 program_LIBRARIES
autotools 认为这是一个他们应该使用的变量,但您没有以这种方式使用,而是在为 AM_LDFLAGS
设置值的循环中使用.因此,假设我是正确的,如果您将其重命名为不遵循 autotool 变量命名方案,我相信错误将会消失。
关于c - 初学者编写makefile;检查我的 Makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27657900/