Bump version numbers for 3.13
[maemo-rb.git] / rbutil / libtools.make
blob77142355c6e838b2eecb2e83ad477f9b2d63c513
1 # __________ __ ___.
2 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
3 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6 # \/ \/ \/ \/ \/
8 # libtools.make
10 # Common Makefile for tools used by Rockbox Utility.
11 # Provides rules for building as library, universal library (OS X) and
12 # standalone binary.
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
18 ifndef V
19 SILENT = @
20 endif
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
33 BINARY = $(OUTPUT)
34 # when building a Windows binary add the correct file suffix
35 ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
36 BINARY = $(OUTPUT).exe
37 CFLAGS+=-mno-cygwin
38 else
39 ifeq ($(findstring MINGW,$(shell uname)),MINGW)
40 BINARY = $(OUTPUT).exe
41 else
42 ifeq ($(findstring mingw,$(CROSS)$(CC)),mingw)
43 BINARY = $(OUTPUT).exe
44 endif
45 endif
46 endif
48 NATIVECC ?= gcc
49 CC ?= gcc
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.
59 CC ?= gcc-4.0
60 CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
61 NATIVECC ?= gcc-4.0
62 endif
63 endif
64 WINDRES = windres
66 BUILD_DIR ?= $(TARGET_DIR)build
67 OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/
69 ifdef RBARCH
70 CFLAGS += -arch $(RBARCH)
71 endif
73 all: $(BINARY)
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)
83 $(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))
88 @echo LD $@
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))
95 # common rules
96 $(OBJDIR)%.o: %.c
97 @echo CC $<
98 $(SILENT)mkdir -p $(dir $@)
99 $(SILENT)$(CROSS)$(CC) $(CFLAGS) -c -o $@ $<
101 # lib rules
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)
108 dll: $(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
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 $@ $^
122 clean:
123 rm -f $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg
124 rm -rf $(OUTPUT)-* i386 ppc $(OBJDIR)
126 # extra tools
127 BIN2C = $(TOP)/tools/bin2c
128 $(BIN2C):
129 $(MAKE) -C $(TOP)/tools
131 # OS X specifics
132 $(OUTPUT).dmg: $(OUTPUT)
133 @echo DMG $@
134 $(SILENT)mkdir -p $(OUTPUT)-dmg
135 $(SILENT)cp -p $(OUTPUT) $(OUTPUT)-dmg
136 $(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@