help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

complex makefile help


From: Chris Inacio
Subject: complex makefile help
Date: Tue, 23 Mar 2004 15:07:46 -0500
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

Hello all,

I think I am getting too tricky in my makefile, but here is my problem none the less. Firstly, I would like to state that I am converting an older makefile (for dmake) into something even yet more complicated. I would never choosen to build some parts of the makefile the way they are constructed if I had complete freedom. But the problem at hand is that I want to build 3 different targets from the same sort of source files; the changes are limited to a small set of files the output of which changes using compiler set (-D) defines. The vast majority of the files are the same from one output to the other. I've mostly solved it, EXCEPT for one irritating problem. In my CVarBuildTarget and CXXVarBuildTarget functions, the "$<" gets evaluated to "" and thus the output fails. After examining the macro, someone will tell me to replace "$<" with "$(1)", but that won't work, because I use vpath's to find my source files, and vpath doesn't expand a file name in a command like that :( At least not for me. If it makes a difference, I'm using mingw gnu make 3.8. Here's the "snippet" of the makefile that is failing:


###
#
#Target specific Sources and Objects
#
###
TARGET_SYS = VOIP GATEWAY SUMMIT

TARGET_SRC_C = \
             osemain.c \
             lifinit.c  \
             lifboard.c \
dspdrv.c TARGET_SRC_CXX = \
             SignalProcessingClient.cpp    \
             GatewayConfiguration.cpp      \
             GatewayConfigurationShell.cpp \
             VoiceManager.cpp              \
LifDspTest.cpp TARGET_SRC = $(TARGET_SRC_C) $(TARGET_SRC_CXX)

###
# create an object file definition for each variant
###
LIF_VOIP_OBJS = $(foreach file,$(TARGET_SRC),$(basename $(file))_VOIP.o)
LIF_GATEWAY_OBJS = $(foreach file,$(TARGET_SRC),$(basename $(file))_GATEWAY.o)
LIF_SUMMIT_OBJS = $(foreach file,$(TARGET_SRC),$(basename $(file))_SUMMIT.o)

#
# fileBaseName
#
define fileBaseName
$(notdir $(basename $(1)))
endef

#
#  CVarTargetBuild
#
# Arguments:
# 1 - source file name
# 2 - target name
#
define CVarTargetBuild
$(call fileBaseName,$(1))_$(2).o : $(1)
   $(CC) -DLIF_$(2) $(LIFKRN_CFLAGS) -c $<
   -$(MV) $(call fileBaseName,$(1)).* $(LIFKRN_OBJDIR)
endef

#
# CVarDependBuild
#
# 1 - source file name
# 2 - target name
#
define CVarDependBuild
$(call fileBaseName,$(1))_$(2).d : $(1)
$(CC) -Make -DLIF_$(2) $(LIFKRN_CFLAGS) $< > $(call fileBaseName,$(1))_$(2).tmp sed "s,\($*\)\.o[ :]*,\1.o $@ : ,g" < $(call fileBaseName,$(1))_$(2).tmp > $(call fileBaseName,$(1))_$(2).d
   -$(RM) $(subst /,\,$(call fileBaseName,$(1)))_$(2).tmp
endef

#
#  CXXVarTargetBuild
#
# Arguments:
# 1 - source file name
# 2 - target name
#
define CXXVarTargetBuild
$(call fileBaseName,$(1))_$(2).o : $(1)
   $(CXX) -DLIF_$(2) $(LIFKRN_CXXFLAGS) -c $<
   -$(MV) $(call fileBaseName,$(1)).* $(LIFKRN_OBJDIR)
endef


#
# CXXVarDependBuild
#
# 1 - source file name
# 2 - target name
#
define CXXVarDependBuild
$(call fileBaseName,$(1))_$(2).d : $(1)
$(CXX) -Make -DLIF_$(2) $(LIFKRN_CXXFLAGS) $< > $(call fileBaseName,$(1))_$(2).tmp sed "s,\($*\)\.o[ :]*,\1.o $@ : ,g" < $(call fileBaseName,$(1))_$(2).tmp > $(call fileBaseName,$(1))_$(2).d
   -$(RM) $(subst /,\,$(call fileBaseName,$(1)))_$(2).tmp
endef


#
#
# 1 - target name
# 2 - list of files
# 3 - name of function to call (CXXVarTagetBuild or CVarTargetBuild)
#
define FileExpander
$(foreach tfile,$(2),$(eval $(call $(3),$(tfile),$(1))))
endef

#
# generate object file build commands
#
$(foreach tget,$(TARGET_SYS),$(call FileExpander,$(tget),$(TARGET_SRC_C),CVarTargetBuild)) $(foreach tget,$(TARGET_SYS),$(call FileExpander,$(tget),$(TARGET_SRC_C),CXXVarTargetBuild))

#
# generate depends file build commands
#
$(foreach tget,$(TARGET_SYS),$(call FileExpander,$(tget),$(TARGET_SRC_C),CVarDependBuild)) $(foreach tget,$(TARGET_SYS),$(call FileExpander,$(tget),$(TARGET_SRC_C),CXXVarDependBuild))


###
# include dependency information for each target variant
###
-include $(foreach tget,$(TARGET_SYS),$(foreach tfile,$(TARGET_SRC),$(call fileBaseName,$(tfile))_$(tget).d))




For those who would like me to simplify the dependency steps, I am not using gnu cc. (Which should be obvious from the -Make switch.) I could call the depend files .P instead of .d, but that's relatively insignificant.

Any help would be GREATLY appreciated. I've really struggled to build this rube goldberg system :) for obvious reasons. And if you think this part is ugly, you should see how I wrapped the building of a gnu make file called from a dmake file!!

thanks,
Chris Inacio
address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]