summaryrefslogtreecommitdiff
path: root/rbutil/libtools.make
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/libtools.make')
-rw-r--r--rbutil/libtools.make117
1 files changed, 117 insertions, 0 deletions
diff --git a/rbutil/libtools.make b/rbutil/libtools.make
new file mode 100644
index 0000000000..1e5a297f79
--- /dev/null
+++ b/rbutil/libtools.make
@@ -0,0 +1,117 @@
1# __________ __ ___.
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
61$(OBJDIR)%.o: %.c
62 @echo CC $<
63 $(SILENT)mkdir -p $(dir $@)
64 $(SILENT)$(CROSS)$(CC) $(CFLAGS) -c -o $@ $<
65
66lib$(OUTPUT)$(RBARCH).a: $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
67lib$(OUTPUT)$(RBARCH): $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
68
69$(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
70 @echo AR $(notdir $@)
71 $(SILENT)mkdir -p $(dir $@)
72 $(SILENT)$(AR) rucs $@ $^
73
74
75# building the standalone executable
76$(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
77 @echo LD $@
78# $(SILENT)mkdir -p $(dir $@)
79# EXTRADEPS need to be built into OBJDIR.
80 $(SILENT)$(CROSS)$(CC) $(CFLAGS) -o $(BINARY) $(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
81
82# some trickery to build ppc and i386 from a single call
83ifeq ($(RBARCH),)
84$(TARGET_DIR)lib$(OUTPUT)i386.a:
85 make RBARCH=i386 TARGET_DIR=$(TARGET_DIR) lib$(OUTPUT)i386.a
86
87$(TARGET_DIR)lib$(OUTPUT)ppc.a:
88 make RBARCH=ppc TARGET_DIR=$(TARGET_DIR) lib$(OUTPUT)ppc.a
89endif
90
91lib$(OUTPUT)-universal: $(TARGET_DIR)lib$(OUTPUT)i386.a $(TARGET_DIR)lib$(OUTPUT)ppc.a
92 @echo lipo $(TARGET_DIR)libmkamsboot.a
93 $(SILENT) rm -f $(TARGET_DIR)libmkamsboot.a
94 $(SILENT)lipo -create $(TARGET_DIR)lib$(OUTPUT)i386.a $(TARGET_DIR)lib$(OUTPUT)ppc.a -output $(TARGET_DIR)lib$(OUTPUT).a
95
96clean:
97 rm -f $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg
98 rm -rf $(OUTPUT)-* i386 ppc $(OBJDIR)
99
100# OS X specifics
101$(OUTPUT)-i386:
102 $(MAKE) RBARCH=i386
103 mv $(OUTPUT) $@
104
105$(OUTPUT)-ppc:
106 $(MAKE) RBARCH=ppc
107 mv $(OUTPUT) $@
108
109$(OUTPUT)-mac: $(OUTPUT)-i386 $(OUTPUT)-ppc
110 @echo LIPO $@
111 $(SILENT)lipo -create $(OUTPUT)-ppc $(OUTPUT)-i386 -output $@
112
113$(OUTPUT).dmg: $(OUTPUT)-mac
114 @echo DMG $@
115 $(SILENT)mkdir -p $(OUTPUT)-dmg
116 $(SILENT)cp -p $(OUTPUT)-mac $(OUTPUT)-dmg
117 $(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@