blob: 2f69a5416c53ee511e01fa6b7b11ad11cc028c6a [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)\"
30TARGET_DIR ?= $(shell pwd)/
31
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
47ifndef BUILD_DIR
48BUILD_DIR = $(TARGET_DIR)build
49endif
50OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/
51
52ifdef RBARCH
53CFLAGS += -arch $(RBARCH)
54endif
55
56all: $(BINARY)
57
58OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(SOURCES))))
59LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(LIBSOURCES))))
60
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +000061# additional link dependencies for the standalone executable
62# extra dependencies: libucl
63LIBUCL = libucl$(RBARCH).a
64$(LIBUCL): $(OBJDIR)$(LIBUCL)
Dominik Riebelingb24e5622011-12-14 21:59:37 +000065
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +000066$(OBJDIR)$(LIBUCL):
67 $(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) $@
Dominik Riebelingb24e5622011-12-14 21:59:37 +000068
69# building the standalone executable
70$(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
71 @echo LD $@
72# $(SILENT)mkdir -p $(dir $@)
73# EXTRADEPS need to be built into OBJDIR.
Dominik Riebeling17a0c832011-12-15 18:44:57 +000074 $(SILENT)$(CROSS)$(CC) $(CFLAGS) -o $(BINARY) \
75 $(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \
76 $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
Dominik Riebelingb24e5622011-12-14 21:59:37 +000077
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +000078# common rules
79$(OBJDIR)%.o: %.c
80 @echo CC $<
81 $(SILENT)mkdir -p $(dir $@)
82 $(SILENT)$(CROSS)$(CC) $(CFLAGS) -c -o $@ $<
83
84# lib rules
85lib$(OUTPUT)$(RBARCH).a: $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
86lib$(OUTPUT)$(RBARCH): $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
87
Dominik Riebeling17a0c832011-12-15 18:44:57 +000088$(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) \
89 $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
Dominik Riebeling6b8f0b02011-12-14 22:00:06 +000090 @echo AR $(notdir $@)
91 $(SILENT)mkdir -p $(dir $@)
92 $(SILENT)$(AR) rucs $@ $^
93
Dominik Riebelingb24e5622011-12-14 21:59:37 +000094# some trickery to build ppc and i386 from a single call
95ifeq ($(RBARCH),)
96$(TARGET_DIR)lib$(OUTPUT)i386.a:
97 make RBARCH=i386 TARGET_DIR=$(TARGET_DIR) lib$(OUTPUT)i386.a
98
99$(TARGET_DIR)lib$(OUTPUT)ppc.a:
100 make RBARCH=ppc TARGET_DIR=$(TARGET_DIR) lib$(OUTPUT)ppc.a
101endif
102
Dominik Riebeling17a0c832011-12-15 18:44:57 +0000103lib$(OUTPUT)-universal: $(TARGET_DIR)lib$(OUTPUT)i386.a \
104 $(TARGET_DIR)lib$(OUTPUT)ppc.a
Dominik Riebelingb24e5622011-12-14 21:59:37 +0000105 @echo lipo $(TARGET_DIR)libmkamsboot.a
106 $(SILENT) rm -f $(TARGET_DIR)libmkamsboot.a
Dominik Riebeling17a0c832011-12-15 18:44:57 +0000107 $(SILENT)lipo -create $(TARGET_DIR)lib$(OUTPUT)i386.a \
108 $(TARGET_DIR)lib$(OUTPUT)ppc.a \
109 -output $(TARGET_DIR)lib$(OUTPUT).a
Dominik Riebelingb24e5622011-12-14 21:59:37 +0000110
111clean:
112 rm -f $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg
113 rm -rf $(OUTPUT)-* i386 ppc $(OBJDIR)
114
115# OS X specifics
116$(OUTPUT)-i386:
117 $(MAKE) RBARCH=i386
118 mv $(OUTPUT) $@
119
120$(OUTPUT)-ppc:
121 $(MAKE) RBARCH=ppc
122 mv $(OUTPUT) $@
123
124$(OUTPUT)-mac: $(OUTPUT)-i386 $(OUTPUT)-ppc
125 @echo LIPO $@
126 $(SILENT)lipo -create $(OUTPUT)-ppc $(OUTPUT)-i386 -output $@
127
128$(OUTPUT).dmg: $(OUTPUT)-mac
129 @echo DMG $@
130 $(SILENT)mkdir -p $(OUTPUT)-dmg
131 $(SILENT)cp -p $(OUTPUT)-mac $(OUTPUT)-dmg
132 $(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@