2014-12-27 31 views
0

我想爲我的項目編寫依賴關係規則,因爲項目包含src目錄,並且src文件夾包含依賴於file1.c和file1.c的main.c取決於file2 .C 我有非標準庫目錄和非標準包括目錄 我用AM_CFLAGS = /路徑,包括目錄和AM_LDFLAGS =路徑lib目錄 我想使通用的依賴關係規則 我試着在makefile中爲使用AM_LDFLAGS的項目編寫依賴關係規則

depend: 
    makedepend $(AM_CFLAGS) $(SRC_DIR) 

但它抱怨它使用的庫,所以我想在ord中設置通用依賴規則當任何一個增加了新的文件呃不重寫規則或改變的東西在文件

這裏的src目錄中生成文件:

program_NAME := SRR 

    AM_CPPFLAGS = \ 
     -DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \ 
     -DPACKAGE_SRC_DIR=\""$(srcdir)"\" \ 
     -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" 


    bin_PROGRAMS = SRR_AutoProject 

    program_INCLUDE_DIRS := /usr/bin/SRR__bin 

    program_LIBRARY_DIRS := /usr/lib/SRR__lib 

    AM_CFLAGS = 

    AM_CFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir)) 

    program_lib2 := \ 
     SRR___wrapper_library__ml \ 
     srrynarray \ 
     prhash \ 
     prhash_pic \ 
     prhistogram \ 
     prlistofarrays \ 
     vreo_wrapper_library 
AM_LDFLAGS = 

AM_LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir)) 

AM_LDFLAGS += $(foreach library,$(program_lib2),-l$(library)) 

SRR_AutoProject_SOURCES = \ 
     main.c \ 
     file1.c \ 
     file2.c 

    depend: 
    makedepend $(AM_CFLAGS) $(SRR_AutoProject_SOURCES) 

根目錄下的Makefile文件,如下圖所示:

SUBDIRS = src 

    SRR_AutoProjectdocdir = ${prefix}/doc/PRDSL_AutoProject 
    SRR_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) 

回答

0
here is a makedepend rule, extracted from: 
<http://www.cs.swarthmore.edu/~newhall/unixhelp/howto_makefiles.html> 

INCLUDES := -I/home/newhall/include -I../include 
SRCS := $(wildcard:*.c) 

.PHONY: depend 

depend: $(SRCS) 
    makedepend $(INCLUDES) $^ 

# DO NOT DELETE THIS LINE -- make depend needs it 
+0

謝謝,但LDFLAGS呢? – Sara 2014-12-28 08:35:00