Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 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 |
Dominik Riebeling | 8c6c6a6 | 2012-01-02 16:59:22 +0000 | [diff] [blame] | 26 | APPVERSION ?= $(shell $(TOP)/../tools/version.sh ../) |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 27 | CFLAGS += -DVERSION=\"$(APPVERSION)\" |
Dominik Riebeling | 8c6c6a6 | 2012-01-02 16:59:22 +0000 | [diff] [blame] | 28 | TARGET_DIR ?= $(shell pwd)/ |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 29 | |
Rafaël Carré | db3afb0 | 2012-02-05 14:03:10 -0500 | [diff] [blame] | 30 | # use POSIX/C99 printf on windows |
| 31 | CFLAGS += -D__USE_MINGW_ANSI_STDIO=1 |
| 32 | |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 33 | BINARY = $(OUTPUT) |
| 34 | # when building a Windows binary add the correct file suffix |
| 35 | ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) |
| 36 | BINARY = $(OUTPUT).exe |
| 37 | CFLAGS+=-mno-cygwin |
| 38 | else |
| 39 | ifeq ($(findstring MINGW,$(shell uname)),MINGW) |
| 40 | BINARY = $(OUTPUT).exe |
| 41 | else |
| 42 | ifeq ($(findstring mingw,$(CROSS)$(CC)),mingw) |
| 43 | BINARY = $(OUTPUT).exe |
| 44 | endif |
| 45 | endif |
| 46 | endif |
| 47 | |
Dominik Riebeling | c6dcec4 | 2012-01-05 22:26:08 +0000 | [diff] [blame] | 48 | NATIVECC ?= gcc |
Dominik Riebeling | 8c6c6a6 | 2012-01-02 16:59:22 +0000 | [diff] [blame] | 49 | CC ?= gcc |
Dominik Riebeling | c6dcec4 | 2012-01-05 22:26:08 +0000 | [diff] [blame] | 50 | # OS X specifics. Needs to consider cross compiling for Windows. |
Dominik Riebeling | b056e02 | 2011-12-16 18:35:01 +0000 | [diff] [blame] | 51 | ifeq ($(findstring Darwin,$(shell uname)),Darwin) |
Dominik Riebeling | 1f0e653 | 2012-01-02 17:45:16 +0000 | [diff] [blame] | 52 | ifneq ($(findstring mingw,$(CROSS)$(CC)),mingw) |
Dominik Riebeling | c6dcec4 | 2012-01-05 22:26:08 +0000 | [diff] [blame] | 53 | # when building libs for OS X build for both i386 and ppc at the same time. |
| 54 | # This creates fat objects, and ar can only create the archive but not operate |
| 55 | # on it. As a result the ar call must NOT use the u (update) flag. |
| 56 | CFLAGS += -arch ppc -arch i386 |
Dominik Riebeling | b056e02 | 2011-12-16 18:35:01 +0000 | [diff] [blame] | 57 | # building against SDK 10.4 is not compatible with gcc-4.2 (default on newer Xcode) |
| 58 | # might need adjustment for older Xcode. |
Dominik Riebeling | 8c6c6a6 | 2012-01-02 16:59:22 +0000 | [diff] [blame] | 59 | CC ?= gcc-4.0 |
Dominik Riebeling | b056e02 | 2011-12-16 18:35:01 +0000 | [diff] [blame] | 60 | CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 |
Dominik Riebeling | 8c6c6a6 | 2012-01-02 16:59:22 +0000 | [diff] [blame] | 61 | NATIVECC ?= gcc-4.0 |
Dominik Riebeling | b056e02 | 2011-12-16 18:35:01 +0000 | [diff] [blame] | 62 | endif |
Dominik Riebeling | 1f0e653 | 2012-01-02 17:45:16 +0000 | [diff] [blame] | 63 | endif |
Dominik Riebeling | b056e02 | 2011-12-16 18:35:01 +0000 | [diff] [blame] | 64 | WINDRES = windres |
| 65 | |
Dominik Riebeling | 8c6c6a6 | 2012-01-02 16:59:22 +0000 | [diff] [blame] | 66 | BUILD_DIR ?= $(TARGET_DIR)build |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 67 | OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/ |
| 68 | |
| 69 | ifdef RBARCH |
| 70 | CFLAGS += -arch $(RBARCH) |
| 71 | endif |
| 72 | |
| 73 | all: $(BINARY) |
| 74 | |
| 75 | OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(SOURCES)))) |
| 76 | LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(LIBSOURCES)))) |
| 77 | |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 78 | # additional link dependencies for the standalone executable |
| 79 | # extra dependencies: libucl |
| 80 | LIBUCL = libucl$(RBARCH).a |
| 81 | $(LIBUCL): $(OBJDIR)$(LIBUCL) |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 82 | |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 83 | $(OBJDIR)$(LIBUCL): |
| 84 | $(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) $@ |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 85 | |
| 86 | # building the standalone executable |
| 87 | $(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
| 88 | @echo LD $@ |
| 89 | # $(SILENT)mkdir -p $(dir $@) |
| 90 | # EXTRADEPS need to be built into OBJDIR. |
Dominik Riebeling | 6c61231 | 2011-12-16 20:25:56 +0000 | [diff] [blame] | 91 | $(SILENT)$(CROSS)$(CC) $(CFLAGS) $(LDOPTS) -o $(BINARY) \ |
Dominik Riebeling | 17a0c83 | 2011-12-15 18:44:57 +0000 | [diff] [blame] | 92 | $(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \ |
| 93 | $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 94 | |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 95 | # common rules |
| 96 | $(OBJDIR)%.o: %.c |
| 97 | @echo CC $< |
| 98 | $(SILENT)mkdir -p $(dir $@) |
| 99 | $(SILENT)$(CROSS)$(CC) $(CFLAGS) -c -o $@ $< |
| 100 | |
| 101 | # lib rules |
| 102 | lib$(OUTPUT)$(RBARCH).a: $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a |
| 103 | lib$(OUTPUT)$(RBARCH): $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a |
| 104 | |
Dominik Riebeling | 17a0c83 | 2011-12-15 18:44:57 +0000 | [diff] [blame] | 105 | $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) \ |
| 106 | $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
Dominik Riebeling | 8420502 | 2011-12-16 21:10:29 +0000 | [diff] [blame] | 107 | # rules to build a DLL. Only works for W32 as target (i.e. MinGW toolchain) |
| 108 | dll: $(OUTPUT).dll |
| 109 | $(OUTPUT).dll: $(TARGET_DIR)$(OUTPUT).dll |
| 110 | $(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
| 111 | @echo DLL $(notdir $@) |
| 112 | $(SILENT)mkdir -p $(dir $@) |
| 113 | $(SILENT)$(CROSS)$(CC) $(CFLAGS) -shared -o $@ $^ \ |
| 114 | -Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def |
| 115 | |
Dominik Riebeling | c6dcec4 | 2012-01-05 22:26:08 +0000 | [diff] [blame] | 116 | # create lib file from objects |
Dominik Riebeling | 8420502 | 2011-12-16 21:10:29 +0000 | [diff] [blame] | 117 | $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 118 | @echo AR $(notdir $@) |
| 119 | $(SILENT)mkdir -p $(dir $@) |
Dominik Riebeling | c6dcec4 | 2012-01-05 22:26:08 +0000 | [diff] [blame] | 120 | $(SILENT)$(AR) rcs $@ $^ |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 121 | |
| 122 | clean: |
| 123 | rm -f $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg |
| 124 | rm -rf $(OUTPUT)-* i386 ppc $(OBJDIR) |
| 125 | |
| 126 | # OS X specifics |
Dominik Riebeling | ded02d8 | 2012-01-06 09:24:38 +0000 | [diff] [blame] | 127 | $(OUTPUT).dmg: $(OUTPUT) |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 128 | @echo DMG $@ |
| 129 | $(SILENT)mkdir -p $(OUTPUT)-dmg |
Dominik Riebeling | ded02d8 | 2012-01-06 09:24:38 +0000 | [diff] [blame] | 130 | $(SILENT)cp -p $(OUTPUT) $(OUTPUT)-dmg |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 131 | $(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@ |