summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2011-12-14 21:59:37 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2011-12-14 21:59:37 +0000
commitb24e562061213cae3a40625e3423572fb58a2d83 (patch)
tree12eaa443f88d03795b1e021c360d86c57e6efd31
parent8e6030c8223bfb3102048b2daccbf6a6f4e97ba2 (diff)
downloadrockbox-b24e562061213cae3a40625e3423572fb58a2d83.tar.gz
rockbox-b24e562061213cae3a40625e3423572fb58a2d83.zip
Initial common Makefile for Rockbox Utility tools / libs.
Introduce a new Makefile holding the common functionality for building tools used by Rockbox Utility (*patcher / mk*boot). This converts mktccboot to use the common Makefile. Also introduces BUILD_DIR variable to control the path used for placing intermediate objects into. This should avoid filename clashes between different tools. Filenames are (still) assumed to be unique withing a single tool. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31257 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--rbutil/libtools.make117
-rw-r--r--rbutil/mktccboot/Makefile92
2 files changed, 127 insertions, 82 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 $@
diff --git a/rbutil/mktccboot/Makefile b/rbutil/mktccboot/Makefile
index b01f25dc3d..3bca0ba05e 100644
--- a/rbutil/mktccboot/Makefile
+++ b/rbutil/mktccboot/Makefile
@@ -8,98 +8,26 @@
8# 8#
9 9
10# We use the Telechips code available in the Rockbox tools/ directory 10# We use the Telechips code available in the Rockbox tools/ directory
11TOOLSDIR=../../tools 11TOOLSDIR = ../../tools/
12CFLAGS := -O -g -W -Wall -Wshadow -pedantic -I$(TOOLSDIR) 12CFLAGS := -O -g -W -Wall -Wshadow -pedantic -I$(TOOLSDIR)
13 13
14ifndef V 14OUTPUT = mktccboot
15SILENT = @
16endif
17 15
18ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
19OUTPUT=mktccboot.exe
20CFLAGS+=-mno-cygwin
21else
22ifeq ($(findstring MINGW,$(shell uname)),MINGW)
23OUTPUT=mktccboot.exe
24else
25ifeq ($(findstring mingw,$(CC)),mingw)
26OUTPUT=mktccboot.exe
27else
28OUTPUT=mktccboot
29endif
30endif
31endif
32
33ifdef RBARCH
34CFLAGS += -arch $(RBARCH)
35endif
36
37TARGET_DIR ?= $(shell pwd)/
38OBJDIR = $(TARGET_DIR)build$(RBARCH)
39
40all: $(OUTPUT)
41 16
42# inputs 17# inputs
43LIBSOURCES := mktccboot.c $(TOOLSDIR)/telechips.o 18LIBSOURCES := mktccboot.c $(TOOLSDIR)telechips.c
44SOURCES := $(LIBSOURCES) main.c 19SOURCES := $(LIBSOURCES) main.c
45OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR)/,$(notdir $(SOURCES))))
46LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR)/,$(notdir $(LIBSOURCES))))
47EXTRADEPS := 20EXTRADEPS :=
48 21
49# rule for sources from tools dir 22include ../libtools.make
50$(OBJDIR)/%.o: $(TOOLSDIR)/%.c
51 @echo CC $<
52 $(SILENT)mkdir -p $(dir $@)
53 $(SILENT)$(CC) $(CFLAGS) -c -o $@ $<
54 23
55$(OBJDIR)/%.o: %.c 24# rule for sources from tools dir
25# Rules go _after_ including mkboot.make to have OBJDIR set up correctly.
26# Paths are assumed to end with a /
27telechips.o: $(OBJDIR)telechips.o
28$(OBJDIR)%.o: $(TOOLSDIR)%.c
56 @echo CC $< 29 @echo CC $<
57 $(SILENT)mkdir -p $(dir $@) 30 $(SILENT)mkdir -p $(dir $@)
58 $(SILENT)$(CC) $(CFLAGS) -c -o $@ $< 31 $(SILENT)$(CROSS)$(CC) $(CFLAGS) -c -o $@ $<
59
60libmktccboot$(RBARCH).a: $(TARGET_DIR)libmktccboot$(RBARCH).a
61
62$(TARGET_DIR)libmktccboot$(RBARCH).a: $(LIBOBJS)
63 @echo AR $(notdir $@)
64 $(SILENT)$(AR) rucs $@ $^
65
66# building the standalone executable
67$(OUTPUT): $(OBJS) $(EXTRADEPS)
68 @echo LD $@
69 $(SILENT)$(CC) $(CFLAGS) -o$(OUTPUT) $(OBJS) $(EXTRADEPS)
70
71# some trickery to build ppc and i386 from a single call
72ifeq ($(RBARCH),)
73$(TARGET_DIR)libmktccbooti386.a:
74 make RBARCH=i386 TARGET_DIR=$(TARGET_DIR) libmktccbooti386.a
75
76$(TARGET_DIR)libmktccbootppc.a:
77 make RBARCH=ppc TARGET_DIR=$(TARGET_DIR) libmktccbootppc.a
78endif
79
80libmktccboot-universal: $(TARGET_DIR)libmktccbooti386.a $(TARGET_DIR)libmktccbootppc.a
81 @echo lipo $(TARGET_DIR)libmktccboot.a
82 $(SILENT) rm -f $(TARGET_DIR)libmktccboot.a
83 $(SILENT)lipo -create $(TARGET_DIR)libmktccbootppc.a $(TARGET_DIR)libmktccbooti386.a -output $(TARGET_DIR)libmktccboot.a
84
85clean:
86 rm -f $(OUTPUT) $(TARGET_DIR)libmktccboot*.a mktccboot.dmg
87 rm -rf $(OBJDIR)
88
89mktccboot-i386:
90 $(MAKE) RBARCH=i386
91 mv mktccboot mktccboot-i386
92
93mktccboot-ppc:
94 make RBARCH=ppc
95 mv mktccboot mktccboot-ppc
96
97mktccboot-mac: mktccboot-i386 mktccboot-ppc
98 $(SILENT)lipo -create mktccboot-ppc mktccboot-i386 -output mktccboot-mac
99
100mktccboot.dmg: mktccboot-mac
101 mkdir -p mktccboot-dmg
102 cp -p mktccboot-mac mktccboot-dmg
103 hdiutil create -srcfolder mktccboot-dmg mktccboot.dmg
104 32
105 33