我想了解如何为小项目编写自己的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 '+='
任何人都可以复习并帮助我吗?
答案 0 :(得分:1)
对于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变量命名方案,我相信错误将会消失。