2011-12-14 21:59:37 +00:00
|
|
|
# __________ __ ___.
|
|
|
|
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
# \/ \/ \/ \/ \/
|
|
|
|
|
|
|
|
# libtools.make
|
|
|
|
#
|
|
|
|
# Common Makefile for tools used by Rockbox Utility.
|
|
|
|
# Provides rules for building as library, universal library (OS X) and
|
|
|
|
# standalone binary.
|
|
|
|
#
|
|
|
|
# LIBSOURCES is a list of files to build the lib
|
|
|
|
# SOURCES is a list of files to build for the main binary
|
|
|
|
# EXTRADEPS is a list of make targets dependencies
|
|
|
|
#
|
|
|
|
ifndef V
|
|
|
|
SILENT = @
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Get directory this Makefile is in for relative paths.
|
|
|
|
TOP := $(dir $(lastword $(MAKEFILE_LIST)))
|
2013-05-11 15:22:44 +00:00
|
|
|
ifeq ($(OS),Windows_NT)
|
|
|
|
mkdir = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
|
|
|
|
else
|
|
|
|
mkdir = mkdir -p $(1)
|
|
|
|
endif
|
2011-12-14 21:59:37 +00:00
|
|
|
|
|
|
|
# overwrite for releases
|
2013-01-01 09:51:11 +00:00
|
|
|
APPVERSION ?= $(shell $(TOP)/../tools/version.sh $(TOP)/..)
|
2013-05-10 15:45:37 +00:00
|
|
|
CFLAGS += -DVERSION=\"$(APPVERSION)\"
|
2013-04-05 17:49:04 +00:00
|
|
|
TARGET_DIR ?= $(abspath .)/
|
2011-12-14 21:59:37 +00:00
|
|
|
|
2013-05-03 21:50:12 +00:00
|
|
|
NATIVECC ?= gcc
|
|
|
|
CC ?= gcc
|
2013-05-10 15:45:37 +00:00
|
|
|
CPPDEFINES := $(shell echo foo | $(CROSS)$(CC) -dM -E -)
|
2012-02-05 19:03:10 +00:00
|
|
|
# use POSIX/C99 printf on windows
|
|
|
|
CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
|
|
|
|
|
2011-12-14 21:59:37 +00:00
|
|
|
BINARY = $(OUTPUT)
|
|
|
|
# when building a Windows binary add the correct file suffix
|
2013-04-05 17:49:04 +00:00
|
|
|
ifeq ($(findstring CYGWIN,$(CPPDEFINES)),CYGWIN)
|
2011-12-14 21:59:37 +00:00
|
|
|
BINARY = $(OUTPUT).exe
|
|
|
|
CFLAGS+=-mno-cygwin
|
2013-04-05 17:49:04 +00:00
|
|
|
COMPILETARGET = cygwin
|
2011-12-14 21:59:37 +00:00
|
|
|
else
|
2013-04-05 17:49:04 +00:00
|
|
|
ifeq ($(findstring MINGW,$(CPPDEFINES)),MINGW)
|
2011-12-14 21:59:37 +00:00
|
|
|
BINARY = $(OUTPUT).exe
|
2013-04-05 17:49:04 +00:00
|
|
|
COMPILETARGET = mingw
|
2011-12-14 21:59:37 +00:00
|
|
|
else
|
2013-04-05 17:49:04 +00:00
|
|
|
ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE)
|
|
|
|
COMPILETARGET = darwin
|
2013-04-05 18:03:45 +00:00
|
|
|
LDOPTS += $(LDOPTS_OSX)
|
2013-04-05 17:49:04 +00:00
|
|
|
else
|
|
|
|
COMPILETARGET = posix
|
2011-12-14 21:59:37 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
2013-04-05 17:49:04 +00:00
|
|
|
$(info Compiler creates $(COMPILETARGET) binaries)
|
2011-12-14 21:59:37 +00:00
|
|
|
|
2012-01-05 22:26:08 +00:00
|
|
|
# OS X specifics. Needs to consider cross compiling for Windows.
|
2013-04-05 17:49:04 +00:00
|
|
|
ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE)
|
2012-01-05 22:26:08 +00:00
|
|
|
# when building libs for OS X build for both i386 and ppc at the same time.
|
|
|
|
# This creates fat objects, and ar can only create the archive but not operate
|
|
|
|
# on it. As a result the ar call must NOT use the u (update) flag.
|
2013-06-09 17:43:37 +00:00
|
|
|
ARCHFLAGS += -arch ppc -arch i386
|
2011-12-16 18:35:01 +00:00
|
|
|
# building against SDK 10.4 is not compatible with gcc-4.2 (default on newer Xcode)
|
|
|
|
# might need adjustment for older Xcode.
|
2013-04-05 18:03:45 +00:00
|
|
|
CC = gcc-4.0
|
2011-12-16 18:35:01 +00:00
|
|
|
CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
|
2013-04-05 18:03:45 +00:00
|
|
|
NATIVECC = gcc-4.0
|
2011-12-16 18:35:01 +00:00
|
|
|
endif
|
|
|
|
WINDRES = windres
|
|
|
|
|
2013-04-05 17:49:04 +00:00
|
|
|
BUILD_DIR ?= $(TARGET_DIR)build$(COMPILETARGET)
|
2011-12-14 21:59:37 +00:00
|
|
|
|
|
|
|
ifdef RBARCH
|
2013-06-09 17:43:37 +00:00
|
|
|
ARCHFLAGS += -arch $(RBARCH)
|
2013-05-11 18:15:53 +00:00
|
|
|
OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/
|
|
|
|
else
|
|
|
|
OBJDIR = $(abspath $(BUILD_DIR))/
|
2011-12-14 21:59:37 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
all: $(BINARY)
|
|
|
|
|
|
|
|
OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(SOURCES))))
|
|
|
|
LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(LIBSOURCES))))
|
|
|
|
|
2013-05-11 18:15:53 +00:00
|
|
|
# create dependency files. Make sure to use the same prefix as with OBJS!
|
2013-05-11 09:28:08 +00:00
|
|
|
$(foreach src,$(SOURCES) $(LIBSOURCES),$(eval $(addprefix $(OBJDIR),$(subst .c,.o,$(notdir $(src)))): $(src)))
|
2013-05-11 18:15:53 +00:00
|
|
|
$(foreach src,$(SOURCES) $(LIBSOURCES),$(eval $(addprefix $(OBJDIR),$(subst .c,.d,$(notdir $(src)))): $(src)))
|
|
|
|
DEPS = $(addprefix $(OBJDIR),$(subst .c,.d,$(notdir $(SOURCES) $(LIBSOURCES))))
|
|
|
|
-include $(DEPS)
|
2013-05-11 09:28:08 +00:00
|
|
|
|
2011-12-14 22:00:06 +00:00
|
|
|
# additional link dependencies for the standalone executable
|
|
|
|
# extra dependencies: libucl
|
|
|
|
LIBUCL = libucl$(RBARCH).a
|
|
|
|
$(LIBUCL): $(OBJDIR)$(LIBUCL)
|
|
|
|
|
|
|
|
$(OBJDIR)$(LIBUCL):
|
|
|
|
$(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) $@
|
|
|
|
|
|
|
|
# building the standalone executable
|
|
|
|
$(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
|
|
|
|
@echo LD $@
|
2013-05-11 15:22:44 +00:00
|
|
|
$(SILENT)$(call mkdir,$(dir $@))
|
2011-12-14 22:00:06 +00:00
|
|
|
# EXTRADEPS need to be built into OBJDIR.
|
2013-06-09 17:43:37 +00:00
|
|
|
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) $(LDOPTS) -o $(BINARY) \
|
2011-12-15 18:44:57 +00:00
|
|
|
$(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \
|
|
|
|
$(addprefix $(OBJDIR),$(EXTRALIBOBJS))
|
2011-12-14 22:00:06 +00:00
|
|
|
|
|
|
|
# common rules
|
2013-05-11 09:28:08 +00:00
|
|
|
$(OBJDIR)%.o:
|
2011-12-14 21:59:37 +00:00
|
|
|
@echo CC $<
|
2013-05-11 15:22:44 +00:00
|
|
|
$(SILENT)$(call mkdir,$(dir $@))
|
2013-06-09 17:43:37 +00:00
|
|
|
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -c -o $@ $<
|
2011-12-14 21:59:37 +00:00
|
|
|
|
2011-12-14 22:00:06 +00:00
|
|
|
# lib rules
|
2011-12-14 21:59:37 +00:00
|
|
|
lib$(OUTPUT)$(RBARCH).a: $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
|
|
|
|
lib$(OUTPUT)$(RBARCH): $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
|
|
|
|
|
2011-12-15 18:44:57 +00:00
|
|
|
$(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) \
|
|
|
|
$(addprefix $(OBJDIR),$(EXTRALIBOBJS))
|
2011-12-16 21:10:29 +00:00
|
|
|
# rules to build a DLL. Only works for W32 as target (i.e. MinGW toolchain)
|
|
|
|
dll: $(OUTPUT).dll
|
|
|
|
$(OUTPUT).dll: $(TARGET_DIR)$(OUTPUT).dll
|
|
|
|
$(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
|
|
|
|
@echo DLL $(notdir $@)
|
2013-05-11 15:22:44 +00:00
|
|
|
$(SILENT)$(call mkdir,$(dir $@))
|
2013-06-09 17:43:37 +00:00
|
|
|
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -shared -o $@ $^ \
|
2011-12-16 21:10:29 +00:00
|
|
|
-Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def
|
|
|
|
|
2012-01-05 22:26:08 +00:00
|
|
|
# create lib file from objects
|
2011-12-16 21:10:29 +00:00
|
|
|
$(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
|
2011-12-14 21:59:37 +00:00
|
|
|
@echo AR $(notdir $@)
|
2013-05-11 15:22:44 +00:00
|
|
|
$(SILENT)$(call mkdir,$(dir $@))
|
2012-01-05 22:26:08 +00:00
|
|
|
$(SILENT)$(AR) rcs $@ $^
|
2011-12-14 21:59:37 +00:00
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg
|
|
|
|
rm -rf $(OUTPUT)-* i386 ppc $(OBJDIR)
|
|
|
|
|
2013-05-11 18:15:53 +00:00
|
|
|
%.d:
|
|
|
|
$(SILENT)$(call mkdir,$(BUILD_DIR))
|
|
|
|
$(SILENT)$(CC) -MG -MM -MT $(subst .d,.o,$@) $(CFLAGS) -o $(BUILD_DIR)/$(notdir $@) $<
|
|
|
|
|
2012-04-28 10:05:50 +00:00
|
|
|
# extra tools
|
|
|
|
BIN2C = $(TOP)/tools/bin2c
|
|
|
|
$(BIN2C):
|
|
|
|
$(MAKE) -C $(TOP)/tools
|
|
|
|
|
2011-12-14 21:59:37 +00:00
|
|
|
# OS X specifics
|
2012-01-06 09:24:38 +00:00
|
|
|
$(OUTPUT).dmg: $(OUTPUT)
|
2011-12-14 21:59:37 +00:00
|
|
|
@echo DMG $@
|
2013-05-11 15:22:44 +00:00
|
|
|
$(SILENT)$(call mkdir,$(OUTPUT)-dmg))
|
2012-01-06 09:24:38 +00:00
|
|
|
$(SILENT)cp -p $(OUTPUT) $(OUTPUT)-dmg
|
2011-12-14 21:59:37 +00:00
|
|
|
$(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@
|