Support C++ in libtools.make and rewrite dependency handling.
- Change suffix of objects and depencency files to keep the original file suffix. This makes it easy to distinguish between C and C++ files when building and avoids implicit make rules trying to build in a way we don't want to. - Implicitly handle dependencies instead of having an explicit rule. Simplifies things a bit. - Support C++ files by adding an explicit rule for them. With keeping the original file suffixes this becomes quite simple. To use C++ files simply add them to SOURCES (or LIBSOURCES). Change-Id: I22c56a6e153e281cfa675e91ad4a70fd18e2c43c
This commit is contained in:
parent
6f4beaa52c
commit
78cb7f0cf0
1 changed files with 21 additions and 21 deletions
|
@ -34,8 +34,8 @@ APPVERSION ?= $(shell $(TOP)/../tools/version.sh $(TOP)/..)
|
||||||
CFLAGS += -DVERSION=\"$(APPVERSION)\"
|
CFLAGS += -DVERSION=\"$(APPVERSION)\"
|
||||||
TARGET_DIR ?= $(abspath .)/
|
TARGET_DIR ?= $(abspath .)/
|
||||||
|
|
||||||
NATIVECC ?= gcc
|
CC := gcc
|
||||||
CC ?= gcc
|
CXX := g++
|
||||||
CPPDEFINES := $(shell echo foo | $(CROSS)$(CC) -dM -E -)
|
CPPDEFINES := $(shell echo foo | $(CROSS)$(CC) -dM -E -)
|
||||||
|
|
||||||
BINARY = $(OUTPUT)
|
BINARY = $(OUTPUT)
|
||||||
|
@ -76,7 +76,6 @@ ARCHFLAGS += -arch ppc -arch i386
|
||||||
# might need adjustment for older Xcode.
|
# might need adjustment for older Xcode.
|
||||||
CC = gcc-4.0
|
CC = gcc-4.0
|
||||||
CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
|
CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
|
||||||
NATIVECC = gcc-4.0
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -85,13 +84,13 @@ OBJDIR = $(abspath $(BUILD_DIR))/
|
||||||
|
|
||||||
all: $(BINARY)
|
all: $(BINARY)
|
||||||
|
|
||||||
OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(SOURCES))))
|
OBJS := $(addsuffix .o,$(addprefix $(OBJDIR),$(notdir $(SOURCES))))
|
||||||
LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(LIBSOURCES))))
|
LIBOBJS := $(addsuffix .o,$(addprefix $(OBJDIR),$(notdir $(LIBSOURCES))))
|
||||||
|
|
||||||
# create dependency files. Make sure to use the same prefix as with OBJS!
|
# create dependency files. Make sure to use the same prefix as with OBJS!
|
||||||
$(foreach src,$(SOURCES) $(LIBSOURCES),$(eval $(addprefix $(OBJDIR),$(subst .c,.o,$(notdir $(src)))): $(src)))
|
$(foreach src,$(SOURCES) $(LIBSOURCES),$(eval $(addprefix $(OBJDIR),$(notdir $(src).o)): $(src)))
|
||||||
$(foreach src,$(SOURCES) $(LIBSOURCES),$(eval $(addprefix $(OBJDIR),$(subst .c,.d,$(notdir $(src)))): $(src)))
|
$(foreach src,$(SOURCES) $(LIBSOURCES),$(eval $(addprefix $(OBJDIR),$(notdir $(src).d)): $(src)))
|
||||||
DEPS = $(addprefix $(OBJDIR),$(subst .c,.d,$(notdir $(SOURCES) $(LIBSOURCES))))
|
DEPS = $(addprefix $(OBJDIR),$(addsuffix .d,$(notdir $(SOURCES) $(LIBSOURCES))))
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
||||||
# additional link dependencies for the standalone executable
|
# additional link dependencies for the standalone executable
|
||||||
|
@ -100,11 +99,11 @@ LIBUCL = libucl.a
|
||||||
$(LIBUCL): $(OBJDIR)$(LIBUCL)
|
$(LIBUCL): $(OBJDIR)$(LIBUCL)
|
||||||
|
|
||||||
$(OBJDIR)$(LIBUCL):
|
$(OBJDIR)$(LIBUCL):
|
||||||
$(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) $@
|
$(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) CC=$(CC) $@
|
||||||
|
|
||||||
# building the standalone executable
|
# building the standalone executable
|
||||||
$(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) $(TARGET_DIR)lib$(OUTPUT).a
|
$(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) $(TARGET_DIR)lib$(OUTPUT).a
|
||||||
@echo LD $@
|
$(info LD $@)
|
||||||
$(SILENT)$(call mkdir,$(dir $@))
|
$(SILENT)$(call mkdir,$(dir $@))
|
||||||
# EXTRADEPS need to be built into OBJDIR.
|
# EXTRADEPS need to be built into OBJDIR.
|
||||||
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -o $(BINARY) \
|
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -o $(BINARY) \
|
||||||
|
@ -112,10 +111,15 @@ $(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) $(TARGET_
|
||||||
$(addprefix $(OBJDIR),$(EXTRALIBOBJS)) lib$(OUTPUT).a $(addprefix $(OBJDIR),$(EXTRADEPS)) $(LDOPTS)
|
$(addprefix $(OBJDIR),$(EXTRALIBOBJS)) lib$(OUTPUT).a $(addprefix $(OBJDIR),$(EXTRADEPS)) $(LDOPTS)
|
||||||
|
|
||||||
# common rules
|
# common rules
|
||||||
$(OBJDIR)%.o:
|
$(OBJDIR)%.c.o:
|
||||||
@echo CC $<
|
$(info CC $<)
|
||||||
$(SILENT)$(call mkdir,$(dir $@))
|
$(SILENT)$(call mkdir,$(dir $@))
|
||||||
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -c -o $@ $<
|
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -MMD -c -o $@ $<
|
||||||
|
|
||||||
|
$(OBJDIR)%.cpp.o:
|
||||||
|
$(info CXX $<)
|
||||||
|
$(SILENT)$(call mkdir,$(dir $@))
|
||||||
|
$(SILENT)$(CROSS)$(CXX) $(ARCHFLAGS) $(CFLAGS) -MMD -c -o $@ $<
|
||||||
|
|
||||||
# lib rules
|
# lib rules
|
||||||
lib$(OUTPUT).a: $(TARGET_DIR)lib$(OUTPUT).a
|
lib$(OUTPUT).a: $(TARGET_DIR)lib$(OUTPUT).a
|
||||||
|
@ -127,26 +131,22 @@ $(TARGET_DIR)lib$(OUTPUT).a: $(LIBOBJS) \
|
||||||
dll: $(OUTPUT).dll
|
dll: $(OUTPUT).dll
|
||||||
$(OUTPUT).dll: $(TARGET_DIR)$(OUTPUT).dll
|
$(OUTPUT).dll: $(TARGET_DIR)$(OUTPUT).dll
|
||||||
$(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
|
$(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
|
||||||
@echo DLL $(notdir $@)
|
$(info DLL $(notdir $@))
|
||||||
$(SILENT)$(call mkdir,$(dir $@))
|
$(SILENT)$(call mkdir,$(dir $@))
|
||||||
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -shared -o $@ $^ \
|
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -shared -o $@ $^ \
|
||||||
-Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def
|
-Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def
|
||||||
|
|
||||||
# create lib file from objects
|
# create lib file from objects
|
||||||
$(TARGET_DIR)lib$(OUTPUT).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
|
$(TARGET_DIR)lib$(OUTPUT).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
|
||||||
@echo AR $(notdir $@)
|
$(info AR $(notdir $@))
|
||||||
$(SILENT)$(call mkdir,$(dir $@))
|
$(SILENT)$(call mkdir,$(dir $@))
|
||||||
$(SILENT)$(call rm,$@)
|
$(SILENT)$(call rm,$@)
|
||||||
$(SILENT)$(AR) rcs $@ $^
|
$(SILENT)$(CROSS)$(AR) rcs $@ $^
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(call rm, $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg)
|
$(call rm, $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg)
|
||||||
$(call rm, $(OUTPUT)-* i386 ppc $(OBJDIR))
|
$(call rm, $(OUTPUT)-* i386 ppc $(OBJDIR))
|
||||||
|
|
||||||
%.d:
|
|
||||||
$(SILENT)$(call mkdir,$(BUILD_DIR))
|
|
||||||
$(SILENT)$(CC) -MG -MM -MT $(subst .d,.o,$@) $(CFLAGS) -o $(BUILD_DIR)/$(notdir $@) $<
|
|
||||||
|
|
||||||
# extra tools
|
# extra tools
|
||||||
BIN2C = $(TOP)/tools/bin2c
|
BIN2C = $(TOP)/tools/bin2c
|
||||||
$(BIN2C):
|
$(BIN2C):
|
||||||
|
@ -154,7 +154,7 @@ $(BIN2C):
|
||||||
|
|
||||||
# OS X specifics
|
# OS X specifics
|
||||||
$(OUTPUT).dmg: $(OUTPUT)
|
$(OUTPUT).dmg: $(OUTPUT)
|
||||||
@echo DMG $@
|
$(info DMG $@)
|
||||||
$(SILENT)$(call mkdir,$(OUTPUT)-dmg))
|
$(SILENT)$(call mkdir,$(OUTPUT)-dmg))
|
||||||
$(SILENT)cp -p $(OUTPUT) $(OUTPUT)-dmg
|
$(SILENT)cp -p $(OUTPUT) $(OUTPUT)-dmg
|
||||||
$(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@
|
$(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@
|
||||||
|
|
Loading…
Reference in a new issue