blob: cc582ce015663e984931b7c069681bc55f168541 [file] [log] [blame]
Dominik Riebelingb24e5622011-12-14 21:59:37 +00001# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7
8# libtools.make
9#
10# Common Makefile for tools used by Rockbox Utility.
11# Provides rules for building as library, universal library (OS X) and
12# standalone binary.
13#
14# LIBSOURCES is a list of files to build the lib
15# SOURCES is a list of files to build for the main binary
16# EXTRADEPS is a list of make targets dependencies
17#
18ifndef V
19SILENT = @
20endif
21
22# Get directory this Makefile is in for relative paths.
23TOP := $(dir $(lastword $(MAKEFILE_LIST)))
24
25# overwrite for releases
Dominik Riebeling8c6c6a62012-01-02 16:59:22 +000026APPVERSION ?= $(shell $(TOP)/../tools/version.sh ../)
Dominik Riebelingb24e5622011-12-14 21:59:37 +000027CFLAGS += -DVERSION=\"$(APPVERSION)\"
Dominik Riebeling8c6c6a62012-01-02 16:59:22 +000028TARGET_DIR ?= $(shell pwd)/
Dominik Riebelingb24e5622011-12-14 21:59:37 +000029
Rafaël Carrédb3afb02012-02-05 14:03:10 -050030# use POSIX/C99 printf on windows
31CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
32
Dominik Riebelingb24e5622011-12-14 21:59:37 +000033BINARY = $(OUTPUT)
34# when building a Windows binary add the correct file suffix
35ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
36BINARY = $(OUTPUT).exe
37CFLAGS+=-mno-cygwin
38else
39ifeq ($(findstring MINGW,$(shell uname)),MINGW)
40BINARY = $(OUTPUT).exe
41else
42ifeq ($(findstring mingw,$(CROSS)$(CC)),mingw)
43BINARY = $(OUTPUT).exe
44endif
45endif
46endif
47
Dominik Riebelingc6dcec42012-01-05 22:26:08 +000048NATIVECC ?= gcc
Dominik Riebeling8c6c6a62012-01-02 16:59:22 +000049CC ?= gcc
Dominik Riebelingc6dcec42012-01-05 22:26:08 +000050# OS X specifics. Needs to consider cross compiling for Windows.
Dominik Riebelingb056e022011-12-16 18:35:01 +000051ifeq ($(findstring Darwin,$(shell uname)),Darwin)
Dominik Riebeling1f0e6532012-01-02 17:45:16 +000052ifneq ($(findstring mingw,$(CROSS)$(CC)),mingw)
Dominik Riebelingc6dcec42012-01-05 22:26:08 +000053# when building libs for OS X build for both i386 and ppc at the same time.
54# This creates fat objects, and ar can only create the archive but not operate
55# on it. As a result the ar call must NOT use the u (update) flag.
56CFLAGS += -arch ppc -arch i386
Dominik Riebelingb056e022011-12-16 18:35:01 +000057# building against SDK 10.4 is not compatible with gcc-4.2 (default on newer Xcode)
58# might need adjustment for older Xcode.
Dominik Riebeling8c6c6a62012-01-02 16:59:22 +000059CC ?= gcc-4.0
Dominik Riebelingb056e022011-12-16 18:35:01 +000060CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
Dominik Riebeling8c6c6a62012-01-02 16:59:22 +000061NATIVECC ?= gcc-4.0
Dominik Riebelingb056e022011-12-16 18:35:01 +000062endif
Dominik Riebeling1f0e6532012-01-02 17:45:16 +000063endif
Dominik Riebelingb056e022011-12-16 18:35:01 +000064WINDRES = windres
65
Dominik Riebeling8c6c6a62012-01-02 16:59:22 +000066BUILD_DIR ?= $(TARGET_DIR)build
Dominik Riebelingb24e5622011-12-14 21:59:37 +000067OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/
68
69ifdef RBARCH
70CFLAGS += -arch $(RBARCH)
71endif
72
73all: $(BINARY)
74
75OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(SOURCES))))
76LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(LIBSOURCES))))
77
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +000078# additional link dependencies for the standalone executable
79# extra dependencies: libucl
80LIBUCL = libucl$(RBARCH).a
81$(LIBUCL): $(OBJDIR)$(LIBUCL)
Dominik Riebelingb24e5622011-12-14 21:59:37 +000082
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +000083$(OBJDIR)$(LIBUCL):
84 $(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) $@
Dominik Riebelingb24e5622011-12-14 21:59:37 +000085
86# building the standalone executable
87$(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
88 @echo LD $@
89# $(SILENT)mkdir -p $(dir $@)
90# EXTRADEPS need to be built into OBJDIR.
Dominik Riebeling6c612312011-12-16 20:25:56 +000091 $(SILENT)$(CROSS)$(CC) $(CFLAGS) $(LDOPTS) -o $(BINARY) \
Dominik Riebeling17a0c832011-12-15 18:44:57 +000092 $(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \
93 $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
Dominik Riebelingb24e5622011-12-14 21:59:37 +000094
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +000095# common rules
96$(OBJDIR)%.o: %.c
97 @echo CC $<
98 $(SILENT)mkdir -p $(dir $@)
99 $(SILENT)$(CROSS)$(CC) $(CFLAGS) -c -o $@ $<
100
101# lib rules
102lib$(OUTPUT)$(RBARCH).a: $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
103lib$(OUTPUT)$(RBARCH): $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
104
Dominik Riebeling17a0c832011-12-15 18:44:57 +0000105$(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) \
106 $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
Dominik Riebeling84205022011-12-16 21:10:29 +0000107# rules to build a DLL. Only works for W32 as target (i.e. MinGW toolchain)
108dll: $(OUTPUT).dll
109$(OUTPUT).dll: $(TARGET_DIR)$(OUTPUT).dll
110$(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
111 @echo DLL $(notdir $@)
112 $(SILENT)mkdir -p $(dir $@)
113 $(SILENT)$(CROSS)$(CC) $(CFLAGS) -shared -o $@ $^ \
114 -Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def
115
Dominik Riebelingc6dcec42012-01-05 22:26:08 +0000116# create lib file from objects
Dominik Riebeling84205022011-12-16 21:10:29 +0000117$(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +0000118 @echo AR $(notdir $@)
119 $(SILENT)mkdir -p $(dir $@)
Dominik Riebelingc6dcec42012-01-05 22:26:08 +0000120 $(SILENT)$(AR) rcs $@ $^
Dominik Riebelingb24e5622011-12-14 21:59:37 +0000121
122clean:
123 rm -f $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg
124 rm -rf $(OUTPUT)-* i386 ppc $(OBJDIR)
125
126# OS X specifics
Dominik Riebelingded02d82012-01-06 09:24:38 +0000127$(OUTPUT).dmg: $(OUTPUT)
Dominik Riebelingb24e5622011-12-14 21:59:37 +0000128 @echo DMG $@
129 $(SILENT)mkdir -p $(OUTPUT)-dmg
Dominik Riebelingded02d82012-01-06 09:24:38 +0000130 $(SILENT)cp -p $(OUTPUT) $(OUTPUT)-dmg
Dominik Riebelingb24e5622011-12-14 21:59:37 +0000131 $(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@