2 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
3 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 # Common Makefile for tools used by Rockbox Utility.
11 # Provides rules for building as library, universal library (OS X) and
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
22 # Get directory this Makefile is in for relative paths.
23 TOP
:= $(dir $(lastword
$(MAKEFILE_LIST
)))
25 # overwrite for releases
26 APPVERSION ?
= $(shell $(TOP
)/..
/tools
/version.sh
$(TOP
)/..
)
27 CFLAGS
+= -DVERSION
=\""$(APPVERSION)"\"
28 TARGET_DIR ?
= $(shell pwd
)/
30 # use POSIX/C99 printf on windows
31 CFLAGS
+= -D__USE_MINGW_ANSI_STDIO
=1
34 # when building a Windows binary add the correct file suffix
35 ifeq ($(findstring CYGWIN
,$(shell uname
)),CYGWIN
)
36 BINARY
= $(OUTPUT
).exe
39 ifeq ($(findstring MINGW
,$(shell uname
)),MINGW
)
40 BINARY
= $(OUTPUT
).exe
42 ifeq ($(findstring mingw
,$(CROSS
)$(CC
)),mingw
)
43 BINARY
= $(OUTPUT
).exe
50 # OS X specifics. Needs to consider cross compiling for Windows.
51 ifeq ($(findstring Darwin
,$(shell uname
)),Darwin
)
52 ifneq ($(findstring mingw
,$(CROSS
)$(CC
)),mingw
)
53 # 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.
56 CFLAGS
+= -arch ppc
-arch i386
57 # building against SDK 10.4 is not compatible with gcc-4.2 (default on newer Xcode)
58 # might need adjustment for older Xcode.
60 CFLAGS
+= -isysroot
/Developer
/SDKs
/MacOSX10.4u.sdk
-mmacosx-version-min
=10.4
66 BUILD_DIR ?
= $(TARGET_DIR
)build
67 OBJDIR
= $(abspath
$(BUILD_DIR
)/$(RBARCH
))/
70 CFLAGS
+= -arch
$(RBARCH
)
75 OBJS
:= $(patsubst %.c
,%.o
,$(addprefix $(OBJDIR
),$(notdir $(SOURCES
))))
76 LIBOBJS
:= $(patsubst %.c
,%.o
,$(addprefix $(OBJDIR
),$(notdir $(LIBSOURCES
))))
78 # additional link dependencies for the standalone executable
79 # extra dependencies: libucl
80 LIBUCL
= libucl
$(RBARCH
).a
81 $(LIBUCL
): $(OBJDIR
)$(LIBUCL
)
84 $(SILENT
)$(MAKE
) -C
$(TOP
)/..
/tools
/ucl
/src TARGET_DIR
=$(OBJDIR
) $@
86 # building the standalone executable
87 $(BINARY
): $(OBJS
) $(EXTRADEPS
) $(addprefix $(OBJDIR
),$(EXTRALIBOBJS
))
89 # $(SILENT)mkdir -p $(dir $@)
90 # EXTRADEPS need to be built into OBJDIR.
91 $(SILENT
)$(CROSS
)$(CC
) $(CFLAGS
) $(LDOPTS
) -o
$(BINARY
) \
92 $(OBJS
) $(addprefix $(OBJDIR
),$(EXTRADEPS
)) \
93 $(addprefix $(OBJDIR
),$(EXTRALIBOBJS
))
98 $(SILENT
)mkdir
-p
$(dir $@
)
99 $(SILENT
)$(CROSS
)$(CC
) $(CFLAGS
) -c
-o
$@
$<
102 lib
$(OUTPUT
)$(RBARCH
).a
: $(TARGET_DIR
)lib
$(OUTPUT
)$(RBARCH
).a
103 lib
$(OUTPUT
)$(RBARCH
): $(TARGET_DIR
)lib
$(OUTPUT
)$(RBARCH
).a
105 $(TARGET_DIR
)lib
$(OUTPUT
)$(RBARCH
).a
: $(LIBOBJS
) \
106 $(addprefix $(OBJDIR
),$(EXTRALIBOBJS
))
107 # rules to build a DLL. Only works for W32 as target (i.e. MinGW toolchain)
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
116 # create lib file from objects
117 $(TARGET_DIR
)lib
$(OUTPUT
)$(RBARCH
).a
: $(LIBOBJS
) $(addprefix $(OBJDIR
),$(EXTRALIBOBJS
))
118 @echo AR
$(notdir $@
)
119 $(SILENT
)mkdir
-p
$(dir $@
)
120 $(SILENT
)$(AR
) rcs
$@
$^
123 rm -f
$(OBJS
) $(OUTPUT
) $(TARGET_DIR
)lib
$(OUTPUT
)*.a
$(OUTPUT
).dmg
124 rm -rf
$(OUTPUT
)-* i386 ppc
$(OBJDIR
)
127 BIN2C
= $(TOP
)/tools
/bin2c
129 $(MAKE
) -C
$(TOP
)/tools
132 $(OUTPUT
).dmg
: $(OUTPUT
)
134 $(SILENT
)mkdir
-p
$(OUTPUT
)-dmg
135 $(SILENT
)cp
-p
$(OUTPUT
) $(OUTPUT
)-dmg
136 $(SILENT
)hdiutil create
-srcfolder
$(OUTPUT
)-dmg
$@