diff options
Diffstat (limited to 'rbutil/libtools.make')
-rw-r--r-- | rbutil/libtools.make | 117 |
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 | # | ||
18 | ifndef V | ||
19 | SILENT = @ | ||
20 | endif | ||
21 | |||
22 | # Get directory this Makefile is in for relative paths. | ||
23 | TOP := $(dir $(lastword $(MAKEFILE_LIST))) | ||
24 | |||
25 | # overwrite for releases | ||
26 | ifndef APPVERSION | ||
27 | APPVERSION=$(shell $(TOP)/../tools/version.sh ../) | ||
28 | endif | ||
29 | CFLAGS += -DVERSION=\"$(APPVERSION)\" | ||
30 | TARGET_DIR ?= $(shell pwd)/ | ||
31 | |||
32 | BINARY = $(OUTPUT) | ||
33 | # when building a Windows binary add the correct file suffix | ||
34 | ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) | ||
35 | BINARY = $(OUTPUT).exe | ||
36 | CFLAGS+=-mno-cygwin | ||
37 | else | ||
38 | ifeq ($(findstring MINGW,$(shell uname)),MINGW) | ||
39 | BINARY = $(OUTPUT).exe | ||
40 | else | ||
41 | ifeq ($(findstring mingw,$(CROSS)$(CC)),mingw) | ||
42 | BINARY = $(OUTPUT).exe | ||
43 | endif | ||
44 | endif | ||
45 | endif | ||
46 | |||
47 | ifndef BUILD_DIR | ||
48 | BUILD_DIR = $(TARGET_DIR)build | ||
49 | endif | ||
50 | OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/ | ||
51 | |||
52 | ifdef RBARCH | ||
53 | CFLAGS += -arch $(RBARCH) | ||
54 | endif | ||
55 | |||
56 | all: $(BINARY) | ||
57 | |||
58 | OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(SOURCES)))) | ||
59 | LIBOBJS := $(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 | |||
66 | lib$(OUTPUT)$(RBARCH).a: $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a | ||
67 | lib$(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 | ||
83 | ifeq ($(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 | ||
89 | endif | ||
90 | |||
91 | lib$(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 | |||
96 | clean: | ||
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 $@ | ||