blob: 227d61b7d48f8a77205cda4d97f9d54651d5325e [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
26ifndef APPVERSION
27APPVERSION=$(shell $(TOP)/../tools/version.sh ../)
28endif
29CFLAGS += -DVERSION=\"$(APPVERSION)\"
Dominik Riebeling98becd22011-12-16 18:59:38 +000030TARGET_DIR = $(shell pwd)/
Dominik Riebelingb24e5622011-12-14 21:59:37 +000031
32BINARY = $(OUTPUT)
33# when building a Windows binary add the correct file suffix
34ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
35BINARY = $(OUTPUT).exe
36CFLAGS+=-mno-cygwin
37else
38ifeq ($(findstring MINGW,$(shell uname)),MINGW)
39BINARY = $(OUTPUT).exe
40else
41ifeq ($(findstring mingw,$(CROSS)$(CC)),mingw)
42BINARY = $(OUTPUT).exe
43endif
44endif
45endif
46
Dominik Riebelingb056e022011-12-16 18:35:01 +000047NATIVECC = gcc
48CC = gcc
49ifeq ($(findstring Darwin,$(shell uname)),Darwin)
50# building against SDK 10.4 is not compatible with gcc-4.2 (default on newer Xcode)
51# might need adjustment for older Xcode.
52CC = gcc-4.0
53CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
54NATIVECC = gcc-4.0
55endif
56WINDRES = windres
57
Dominik Riebelingb24e5622011-12-14 21:59:37 +000058ifndef BUILD_DIR
59BUILD_DIR = $(TARGET_DIR)build
60endif
61OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/
62
63ifdef RBARCH
64CFLAGS += -arch $(RBARCH)
65endif
66
67all: $(BINARY)
68
69OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(SOURCES))))
70LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(LIBSOURCES))))
71
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +000072# additional link dependencies for the standalone executable
73# extra dependencies: libucl
74LIBUCL = libucl$(RBARCH).a
75$(LIBUCL): $(OBJDIR)$(LIBUCL)
Dominik Riebelingb24e5622011-12-14 21:59:37 +000076
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +000077$(OBJDIR)$(LIBUCL):
78 $(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) $@
Dominik Riebelingb24e5622011-12-14 21:59:37 +000079
80# building the standalone executable
81$(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
82 @echo LD $@
83# $(SILENT)mkdir -p $(dir $@)
84# EXTRADEPS need to be built into OBJDIR.
Dominik Riebeling6c612312011-12-16 20:25:56 +000085 $(SILENT)$(CROSS)$(CC) $(CFLAGS) $(LDOPTS) -o $(BINARY) \
Dominik Riebeling17a0c832011-12-15 18:44:57 +000086 $(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \
87 $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
Dominik Riebelingb24e5622011-12-14 21:59:37 +000088
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +000089# common rules
90$(OBJDIR)%.o: %.c
91 @echo CC $<
92 $(SILENT)mkdir -p $(dir $@)
93 $(SILENT)$(CROSS)$(CC) $(CFLAGS) -c -o $@ $<
94
95# lib rules
96lib$(OUTPUT)$(RBARCH).a: $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
97lib$(OUTPUT)$(RBARCH): $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
98
Dominik Riebeling17a0c832011-12-15 18:44:57 +000099$(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) \
100 $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
Dominik Riebeling84205022011-12-16 21:10:29 +0000101# rules to build a DLL. Only works for W32 as target (i.e. MinGW toolchain)
102dll: $(OUTPUT).dll
103$(OUTPUT).dll: $(TARGET_DIR)$(OUTPUT).dll
104$(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
105 @echo DLL $(notdir $@)
106 $(SILENT)mkdir -p $(dir $@)
107 $(SILENT)$(CROSS)$(CC) $(CFLAGS) -shared -o $@ $^ \
108 -Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def
109
110$(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +0000111 @echo AR $(notdir $@)
112 $(SILENT)mkdir -p $(dir $@)
113 $(SILENT)$(AR) rucs $@ $^
114
Dominik Riebelingb24e5622011-12-14 21:59:37 +0000115# some trickery to build ppc and i386 from a single call
116ifeq ($(RBARCH),)
117$(TARGET_DIR)lib$(OUTPUT)i386.a:
118 make RBARCH=i386 TARGET_DIR=$(TARGET_DIR) lib$(OUTPUT)i386.a
119
120$(TARGET_DIR)lib$(OUTPUT)ppc.a:
121 make RBARCH=ppc TARGET_DIR=$(TARGET_DIR) lib$(OUTPUT)ppc.a
122endif
123
Dominik Riebeling17a0c832011-12-15 18:44:57 +0000124lib$(OUTPUT)-universal: $(TARGET_DIR)lib$(OUTPUT)i386.a \
125 $(TARGET_DIR)lib$(OUTPUT)ppc.a
Dominik Riebeling98becd22011-12-16 18:59:38 +0000126 @echo LIPO $(notdir $(TARGET_DIR)lib$(OUTPUT).a)
127 $(SILENT) rm -f $(TARGET_DIR)lib$(OUTPUT).a
Dominik Riebeling17a0c832011-12-15 18:44:57 +0000128 $(SILENT)lipo -create $(TARGET_DIR)lib$(OUTPUT)i386.a \
129 $(TARGET_DIR)lib$(OUTPUT)ppc.a \
130 -output $(TARGET_DIR)lib$(OUTPUT).a
Dominik Riebelingb24e5622011-12-14 21:59:37 +0000131
132clean:
133 rm -f $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg
134 rm -rf $(OUTPUT)-* i386 ppc $(OBJDIR)
135
136# OS X specifics
137$(OUTPUT)-i386:
138 $(MAKE) RBARCH=i386
139 mv $(OUTPUT) $@
140
141$(OUTPUT)-ppc:
142 $(MAKE) RBARCH=ppc
143 mv $(OUTPUT) $@
144
145$(OUTPUT)-mac: $(OUTPUT)-i386 $(OUTPUT)-ppc
146 @echo LIPO $@
147 $(SILENT)lipo -create $(OUTPUT)-ppc $(OUTPUT)-i386 -output $@
148
149$(OUTPUT).dmg: $(OUTPUT)-mac
150 @echo DMG $@
151 $(SILENT)mkdir -p $(OUTPUT)-dmg
152 $(SILENT)cp -p $(OUTPUT)-mac $(OUTPUT)-dmg
153 $(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@