0

我对makefile很陌生。我正在阅读 GNU-make 手册,但我仍然不清楚如何为编译器和链接器设置参数,当它们被隐式规则执行时。这是 makefile 的一部分,请注意没有明确声明如何编译和链接所有内容:

.PHONY: $(TARGET) build_libs

all: build_libs $(TARGET)

$(TARGET):
    @echo "============> building target: $(TARGET)"
    @$(MAKE) -C $(SDK_PATH)/VP_SDK/Build $(TMP_SDK_FLAGS) $(SDK_FLAGS) $(MAKECMDGOALS) USE_LINUX=yes
    mv $(ARDRONE_TARGET_DIR)/ardrone_testing_tool $(TARGET)
    mv $(TARGET) $(ARDRONE_TARGET_DIR)/
    @echo "============> end building target: $(TARGET)"

$(MAKECMDGOALS): build_libs
    @echo "============> making cmd goals"
    @$(MAKE) -C $(SDK_PATH)/VP_SDK/Build $(TMP_SDK_FLAGS) $(SDK_FLAGS) $(MAKECMDGOALS) USE_LINUX=yes
    @echo "============> end making cmd goals"

build_libs:
    @echo "============> building libs"
    @$(MAKE) -C $(SDK_PATH)/Soft/Build $(TMP_SDK_FLAGS) $(SDK_FLAGS) $(MAKECMDGOALS) USE_LINUX=yes
    @echo "============> end building libs"

该 makefile 从源文件和库构建可执行文件。但我想将它们编译成一个共享库。因此,我(我想我)必须将-fPIC参数 添加到. 我试过and ,但没有用。有没有人建议如何获得共享库?如果您需要更多信息,请询问。提前致谢!cc-shared-sonameldCFLAGS=-fPICLDFLAGS=-shared -soname foo

更新: $(SDK_PATH)/Soft/Build 中的生成文件:

GEN_CUSTOM_HEADER:=../Common/generated_custom.h

include custom.makefile 
include config.makefile

GNUTOOLS_PATH=/usr/local/$(GNUTOOLS_VERSION)/bin

define ADD_RULE_TEMPLATE
  TO_BUILD+=build_$(1)
endef

# Add rule for each target
$(foreach target,$(TARGETS),$(eval $(call ADD_RULE_TEMPLATE,$(target))))

.PHONY: linux_sample svn_update $(TO_BUILD) build_libs $(MAKECMDGOALS)

all: $(GEN_CUSTOM_HEADER) build_libs $(TO_BUILD)

$(GEN_CUSTOM_HEADER): custom.makefile
    @echo "#ifndef _GENERATED_CUSTOM_CONFIGURATION_H_" > $@
    @echo "#define _GENERATED_CUSTOM_CONFIGURATION_H_" >> $@
    @echo >> $@
    @echo "#if  defined(BR2_PACKAGE_BCM4318_AP)" >> $@
    @echo "#  define AP" >> $@
    @echo "#else" >> $@
    @echo "#  define STA" >> $@
    @echo "#endif" >> $@
    @echo "#define CURRENT_NUM_VERSION_SOFT \"$(MAJOR_VERSION).$(MINOR_VERSION).$(MODIF_VERSION)\"" >> $@
    @echo "#define CURRENT_BUILD_DATE \"$(shell date +%F\ %H:%M)\"" >> $@
    @echo >> $@
ifeq ("$(VIDEO_YUV)","yes")
    @echo "#define USE_VIDEO_YUV" >> $@
endif
ifeq ("$(RECORD_VISION_DATA)","yes")
    @echo "#define RECORD_VISION_DATA" >> $@
endif
    @echo >> $@
    @echo "#define WIFI_NETWORK_NAME \"$(WIFI_NETWORK_NAME)\"" >> $@
    @echo "#define WIFI_BROADCAST \"$(WIFI_BROADCAST)\"" >> $@
    @echo "#define WIFI_ARDRONE_IP \"$(WIFI_ARDRONE_IP)\"" >> $@
    @echo >> $@
    @echo "#if defined(__linux__) || defined(USE_MINGW32)" >> $@
    @echo "# define WIFI_MOBILE_IP \"$(WIFI_MOBILE_IP)\"" >> $@
    @echo "# define WIRED_ITFNAME \"$(WIRED_ITFNAME)\"" >> $@
    @echo "#endif // ! __linux__" >> $@
    @echo >> $@
    @echo >> $@
    @echo "#endif // ! _GENERATED_CUSTOM_CONFIGURATION_H_" >> $@

ifneq "$(MAKECMDGOALS)" ""
  ifneq "$(MAKECMDGOALS)" "clean"
    ifneq "$(MAKECMDGOALS)" "update"
      $(MAKECMDGOALS):
      @echo -e "\nCannot make what you ask me to do :-("
    else
      $(MAKECMDGOALS): svn_update
    endif
  endif
endif

$(MAKECMDGOALS): build_libs $(TO_BUILD)

checkpackages:
ifeq ($(IPHONE_MODE),yes)
    sh $(shell pwd)/check_dependencies.sh iphone RELEASE_BUILD=$(RELEASE_BUILD) $(MAKECMDGOALS)
else
ifeq ($(USE_LINUX),yes)
    sh $(shell pwd)/check_dependencies.sh static RELEASE_BUILD=$(RELEASE_BUILD) $(MAKECMDGOALS)
else
ifeq ($(USE_ANDROID),yes)
    sh $(shell pwd)/check_dependencies.sh android_no_neon RELEASE_BUILD=$(RELEASE_BUILD) $(MAKECMDGOALS)
endif
endif
endif

define GENERIC_RULES_TEMPLATE
build_$(1): 
    @$(MAKE) -C $(1) $(MAKECMDGOALS)
endef

$(foreach target,$(TARGETS),$(eval $(call GENERIC_RULES_TEMPLATE,$(target))))

build_libs: checkpackages
    @$(MAKE) PC_TARGET=yes USE_ARDRONE_TOOL=yes TARGET=pc_ USE_MINGW32=no -C ../Lib/Build $(MAKECMDGOALS)
    @$(MAKE) PC_TARGET=yes USE_ARDRONE_TOOL=no TARGET=pc_ USE_MINGW32=no -C ../Lib/Build $(MAKECMDGOALS)

ifeq ("$(MINGW32_MODE)","yes")
ifeq ($(shell which i586-mingw32msvc-gcc 2> /dev/null),)
        $(warning You need MinGW32 to compile My Ardrone lib for Windows if you want. (under Debian: apt-get install mingw32))
else
#   @$(MAKE) PC_TARGET=yes TARGET=mingw32_ USE_MINGW32=yes TMP_SDK_FLAGS="USE_MINGW32=yes NO_COM=yes USE_BLUEZ=no" -C ../Lib/Build $(MAKECMDGOALS)
#   @$(MAKE) PC_TARGET=yes TARGET=emb_mingw32_ USE_MINGW32=yes CONTROL_DLL=yes TMP_SDK_FLAGS="USE_MINGW32=yes NO_COM=yes USE_BLUEZ=no" -C ../Lib/Build $(MAKECMDGOALS)
endif
endif
ifeq ($(WIIMOTE_SUPPORT),yes)
#   @$(MAKE) PC_TARGET=yes TARGET=pc_ TMP_SDK_FLAGS="USE_BLUEZ=yes" -C ../Lib/libcwiid $(MAKECMDGOALS)
endif

define svn_update_template
   cd ../.. ; \
    echo "Checking out tag $(1) of $(2) ..." ; \
    if [ $(1) != head ] ; then \
       svn co -r $(1) https://svn.ardrone.org/repo/ARDrone_API/$(2) ; \
    else \
        svn co https://svn.ardrone.org/repo/ARDrone_API/$(2) ; \
    fi ; \
    cd Soft/Build ; 
endef

svn_update:
    @-$(call svn_update_template,$(SDK_VERSION),ARDroneLib)

如果需要 custom.makefile 和 config.makefile,你可以在这里找到它们:http: //pastebin.com/H8PNKKhu

更新 2:我刚刚发现了这个,位于$(SDK_PATH)/VP_SDK/Build: http: //pastebin.com/3knnSkmy

4

3 回答 3

1

这不是焦点。这些似乎是生成的makefile,因此很难追踪,显然发生的事情比我们看到的要多(我不怪你没有发布所有内容),而且我看不到build_libs规则的走向,或链接器的任何使用,或任何可以构建静态库的东西。我们可以向您展示如何编写显式规则来构建共享库,但是如果没有源或对象的列表,我们将不知道将什么放入该库中。

这越来越绝望,但你可以尝试以下方法:

1) make -C $(SDK_PATH)/Soft/Build(为 $(SDK_PATH) 输入适当的值)并验证这是否会生成静态库。

2) make -n,捕获输出的洪流并将其放入pastebin。我们将尝试查看它使用了什么规则,这可能会导致我们需要什么。

于 2012-08-06T11:46:43.303 回答
1

由于您没有向我们展示 中的 makefile $(SDK_PATH)/Soft/Build,我将猜测一下。

在 GNU Make 手册中,有隐式规则使用的变量列表:

  • CFLAGS: 给 C 编译器的额外标志。
  • LDFLAGS: 当编译器应该调用链接器'ld'时提供给编译器的额外标志。

此外,隐式规则目录中提到了LDLIBS隐式链接规则中使用的命名库的变量。(当您链接单个源文件或其中一个目标文件是最终可执行文件的名称时,隐式链接规则很好,否则您需要编写显式链接规则。)

于 2012-08-05T21:18:16.600 回答
0

我做的。最后!!!

解决方案:$(SDK_PATH)/VP_SDK/Build有一个名为generic.makefile包含所有编译器和链接器调用的文件。我不得不在其中一些中添加-sharedand-fPIC参数。听起来很简单,但没有任何记录,所以我首先不得不寻找隐藏的编译器/链接器调用......

于 2012-08-09T18:43:15.680 回答