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)
|
2020-10-21 17:12:08 +00:00
|
|
|
SHELL = cmd.exe
|
2013-05-11 15:22:44 +00:00
|
|
|
mkdir = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
|
2014-01-05 16:08:50 +00:00
|
|
|
rm = if exist $(subst /,\,$(1)) del /q /s $(subst /,\,$(1))
|
2013-05-11 15:22:44 +00:00
|
|
|
else
|
|
|
|
mkdir = mkdir -p $(1)
|
2014-01-05 15:53:17 +00:00
|
|
|
rm = rm -rf $(1)
|
2013-05-11 15:22:44 +00:00
|
|
|
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)/..)
|
2016-12-16 20:50:36 +00:00
|
|
|
GCCFLAGS += -DVERSION=\"$(APPVERSION)\"
|
2013-04-05 17:49:04 +00:00
|
|
|
TARGET_DIR ?= $(abspath .)/
|
2011-12-14 21:59:37 +00:00
|
|
|
|
2016-12-16 18:29:52 +00:00
|
|
|
CC := gcc
|
|
|
|
CXX := g++
|
2016-12-16 20:50:36 +00:00
|
|
|
# use either CC or CXX to link: this makes sure the compiler knows about its
|
|
|
|
# internal dependencies. Use CXX if we have at least one c++ file, since we
|
|
|
|
# then need to link the c++ standard library (which CXX does for us).
|
|
|
|
ifeq ($(strip $(filter %.cpp,$(SOURCES) $(LIBSOURCES))),)
|
|
|
|
LD := $(CC)
|
|
|
|
else
|
|
|
|
LD := $(CXX)
|
|
|
|
endif
|
2013-05-10 15:45:37 +00:00
|
|
|
CPPDEFINES := $(shell echo foo | $(CROSS)$(CC) -dM -E -)
|
2012-02-05 19:03:10 +00:00
|
|
|
|
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
|
2016-12-16 20:50:36 +00:00
|
|
|
GCCFLAGS += -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
|
2016-12-16 18:39:07 +00:00
|
|
|
# use POSIX/C99 printf on windows
|
2016-12-16 20:50:36 +00:00
|
|
|
GCCFLAGS += -D__USE_MINGW_ANSI_STDIO=1
|
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)
|
2014-03-20 21:22:17 +00:00
|
|
|
# When building for 10.4+ we need to use gcc. Otherwise clang is used, so use
|
|
|
|
# that to determine if we need to set arch and isysroot.
|
|
|
|
ifeq ($(findstring __clang__,$(CPPDEFINES)),__clang__)
|
2016-12-16 20:50:36 +00:00
|
|
|
GCCFLAGS += -mmacosx-version-min=10.5
|
2020-10-18 16:53:48 +00:00
|
|
|
ifneq ($(ISYSROOT),)
|
|
|
|
GCCFLAGS += -isysroot $(ISYSROOT)
|
|
|
|
endif
|
2014-03-20 21:22:17 +00:00
|
|
|
else
|
|
|
|
# when building libs for OS X 10.4+ build for both i386 and ppc at the same time.
|
2012-01-05 22:26:08 +00:00
|
|
|
# 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
|
2016-12-16 20:50:36 +00:00
|
|
|
GCCFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
|
2011-12-16 18:35:01 +00:00
|
|
|
endif
|
2014-03-20 21:22:17 +00:00
|
|
|
endif
|
2011-12-16 18:35:01 +00:00
|
|
|
|
2013-04-05 17:49:04 +00:00
|
|
|
BUILD_DIR ?= $(TARGET_DIR)build$(COMPILETARGET)
|
2013-05-11 18:15:53 +00:00
|
|
|
OBJDIR = $(abspath $(BUILD_DIR))/
|
2011-12-14 21:59:37 +00:00
|
|
|
|
|
|
|
all: $(BINARY)
|
|
|
|
|
2016-12-16 18:29:52 +00:00
|
|
|
OBJS := $(addsuffix .o,$(addprefix $(OBJDIR),$(notdir $(SOURCES))))
|
|
|
|
LIBOBJS := $(addsuffix .o,$(addprefix $(OBJDIR),$(notdir $(LIBSOURCES))))
|
2011-12-14 21:59:37 +00:00
|
|
|
|
2013-05-11 18:15:53 +00:00
|
|
|
# create dependency files. Make sure to use the same prefix as with OBJS!
|
2016-12-16 18:29:52 +00:00
|
|
|
$(foreach src,$(SOURCES) $(LIBSOURCES),$(eval $(addprefix $(OBJDIR),$(notdir $(src).o)): $(src)))
|
|
|
|
$(foreach src,$(SOURCES) $(LIBSOURCES),$(eval $(addprefix $(OBJDIR),$(notdir $(src).d)): $(src)))
|
|
|
|
DEPS = $(addprefix $(OBJDIR),$(addsuffix .d,$(notdir $(SOURCES) $(LIBSOURCES))))
|
2013-05-11 18:15:53 +00:00
|
|
|
-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
|
2016-12-16 18:39:07 +00:00
|
|
|
LIBUCL = libucl.a
|
2011-12-14 22:00:06 +00:00
|
|
|
$(LIBUCL): $(OBJDIR)$(LIBUCL)
|
|
|
|
|
|
|
|
$(OBJDIR)$(LIBUCL):
|
2016-12-16 18:29:52 +00:00
|
|
|
$(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) CC=$(CC) $@
|
2011-12-14 22:00:06 +00:00
|
|
|
|
2020-04-08 18:39:30 +00:00
|
|
|
LIBBZIP2 = libbzip2.a
|
|
|
|
$(LIBBZIP2): $(OBJDIR)$(LIBBZIP2)
|
|
|
|
$(OBJDIR)$(LIBBZIP2):
|
|
|
|
$(SILENT)$(MAKE) -C $(TOP)/bzip2 TARGET_DIR=$(OBJDIR) CC=$(CC) $@
|
|
|
|
|
2011-12-14 22:00:06 +00:00
|
|
|
# building the standalone executable
|
2016-12-16 18:39:07 +00:00
|
|
|
$(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) $(TARGET_DIR)lib$(OUTPUT).a
|
2016-12-16 18:29:52 +00:00
|
|
|
$(info 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.
|
2016-12-16 20:50:36 +00:00
|
|
|
$(SILENT)$(CROSS)$(LD) $(ARCHFLAGS) $(LDFLAGS) -o $(BINARY) \
|
2011-12-15 18:44:57 +00:00
|
|
|
$(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \
|
2016-12-16 18:39:07 +00:00
|
|
|
$(addprefix $(OBJDIR),$(EXTRALIBOBJS)) lib$(OUTPUT).a $(addprefix $(OBJDIR),$(EXTRADEPS)) $(LDOPTS)
|
2011-12-14 22:00:06 +00:00
|
|
|
|
|
|
|
# common rules
|
2016-12-16 18:29:52 +00:00
|
|
|
$(OBJDIR)%.c.o:
|
|
|
|
$(info CC $<)
|
2013-05-11 15:22:44 +00:00
|
|
|
$(SILENT)$(call mkdir,$(dir $@))
|
2016-12-16 20:50:36 +00:00
|
|
|
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(GCCFLAGS) $(CFLAGS) -MMD -c -o $@ $<
|
2016-12-16 18:29:52 +00:00
|
|
|
|
|
|
|
$(OBJDIR)%.cpp.o:
|
|
|
|
$(info CXX $<)
|
|
|
|
$(SILENT)$(call mkdir,$(dir $@))
|
2016-12-16 20:50:36 +00:00
|
|
|
$(SILENT)$(CROSS)$(CXX) $(ARCHFLAGS) $(GCCFLAGS) $(CXXFLAGS) -MMD -c -o $@ $<
|
2011-12-14 21:59:37 +00:00
|
|
|
|
2011-12-14 22:00:06 +00:00
|
|
|
# lib rules
|
2016-12-16 18:39:07 +00:00
|
|
|
lib$(OUTPUT).a: $(TARGET_DIR)lib$(OUTPUT).a
|
|
|
|
lib$(OUTPUT): $(TARGET_DIR)lib$(OUTPUT).a
|
2011-12-14 21:59:37 +00:00
|
|
|
|
2016-12-16 18:39:07 +00:00
|
|
|
$(TARGET_DIR)lib$(OUTPUT).a: $(LIBOBJS) \
|
2011-12-15 18:44:57 +00:00
|
|
|
$(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))
|
2016-12-16 18:29:52 +00:00
|
|
|
$(info DLL $(notdir $@))
|
2013-05-11 15:22:44 +00:00
|
|
|
$(SILENT)$(call mkdir,$(dir $@))
|
2016-12-16 20:50:36 +00:00
|
|
|
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(GCCFLAGS) -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
|
2016-12-16 18:39:07 +00:00
|
|
|
$(TARGET_DIR)lib$(OUTPUT).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
|
2016-12-16 18:29:52 +00:00
|
|
|
$(info AR $(notdir $@))
|
2013-05-11 15:22:44 +00:00
|
|
|
$(SILENT)$(call mkdir,$(dir $@))
|
2014-01-05 15:53:17 +00:00
|
|
|
$(SILENT)$(call rm,$@)
|
2016-12-16 18:29:52 +00:00
|
|
|
$(SILENT)$(CROSS)$(AR) rcs $@ $^
|
2011-12-14 21:59:37 +00:00
|
|
|
|
|
|
|
clean:
|
2014-01-05 15:53:17 +00:00
|
|
|
$(call rm, $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg)
|
|
|
|
$(call rm, $(OUTPUT)-* i386 ppc $(OBJDIR))
|
2011-12-14 21:59:37 +00:00
|
|
|
|
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)
|
2016-12-16 18:29:52 +00:00
|
|
|
$(info DMG $@)
|
2020-06-29 19:08:57 +00:00
|
|
|
$(SILENT)$(call mkdir,"$(OUTPUT)-$(APPVERSION)")
|
|
|
|
$(SILENT)cp -p $(OUTPUT) "$(OUTPUT)-$(APPVERSION)"
|
|
|
|
$(SILENT)hdiutil create -srcfolder "$(OUTPUT)-$(APPVERSION)" $@
|