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 |
| 26 | ifndef APPVERSION |
| 27 | APPVERSION=$(shell $(TOP)/../tools/version.sh ../) |
| 28 | endif |
| 29 | CFLAGS += -DVERSION=\"$(APPVERSION)\" |
Dominik Riebeling | 98becd2 | 2011-12-16 18:59:38 +0000 | [diff] [blame] | 30 | TARGET_DIR = $(shell pwd)/ |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 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 | |
Dominik Riebeling | b056e02 | 2011-12-16 18:35:01 +0000 | [diff] [blame] | 47 | NATIVECC = gcc |
| 48 | CC = gcc |
| 49 | ifeq ($(findstring Darwin,$(shell uname)),Darwin) |
| 50 | # building against SDK 10.4 is not compatible with gcc-4.2 (default on newer Xcode) |
| 51 | # might need adjustment for older Xcode. |
| 52 | CC = gcc-4.0 |
| 53 | CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 |
| 54 | NATIVECC = gcc-4.0 |
| 55 | endif |
| 56 | WINDRES = windres |
| 57 | |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 58 | ifndef BUILD_DIR |
| 59 | BUILD_DIR = $(TARGET_DIR)build |
| 60 | endif |
| 61 | OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/ |
| 62 | |
| 63 | ifdef RBARCH |
| 64 | CFLAGS += -arch $(RBARCH) |
| 65 | endif |
| 66 | |
| 67 | all: $(BINARY) |
| 68 | |
| 69 | OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(SOURCES)))) |
| 70 | LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(LIBSOURCES)))) |
| 71 | |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 72 | # additional link dependencies for the standalone executable |
| 73 | # extra dependencies: libucl |
| 74 | LIBUCL = libucl$(RBARCH).a |
| 75 | $(LIBUCL): $(OBJDIR)$(LIBUCL) |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 76 | |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 77 | $(OBJDIR)$(LIBUCL): |
| 78 | $(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) $@ |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 79 | |
| 80 | # building the standalone executable |
| 81 | $(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
| 82 | @echo LD $@ |
| 83 | # $(SILENT)mkdir -p $(dir $@) |
| 84 | # EXTRADEPS need to be built into OBJDIR. |
Dominik Riebeling | 6c61231 | 2011-12-16 20:25:56 +0000 | [diff] [blame] | 85 | $(SILENT)$(CROSS)$(CC) $(CFLAGS) $(LDOPTS) -o $(BINARY) \ |
Dominik Riebeling | 17a0c83 | 2011-12-15 18:44:57 +0000 | [diff] [blame] | 86 | $(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \ |
| 87 | $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 88 | |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 89 | # common rules |
| 90 | $(OBJDIR)%.o: %.c |
| 91 | @echo CC $< |
| 92 | $(SILENT)mkdir -p $(dir $@) |
| 93 | $(SILENT)$(CROSS)$(CC) $(CFLAGS) -c -o $@ $< |
| 94 | |
| 95 | # lib rules |
| 96 | lib$(OUTPUT)$(RBARCH).a: $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a |
| 97 | lib$(OUTPUT)$(RBARCH): $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a |
| 98 | |
Dominik Riebeling | 17a0c83 | 2011-12-15 18:44:57 +0000 | [diff] [blame] | 99 | $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) \ |
| 100 | $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
Dominik Riebeling | 8420502 | 2011-12-16 21:10:29 +0000 | [diff] [blame] | 101 | # rules to build a DLL. Only works for W32 as target (i.e. MinGW toolchain) |
| 102 | dll: $(OUTPUT).dll |
| 103 | $(OUTPUT).dll: $(TARGET_DIR)$(OUTPUT).dll |
| 104 | $(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
| 105 | @echo DLL $(notdir $@) |
| 106 | $(SILENT)mkdir -p $(dir $@) |
| 107 | $(SILENT)$(CROSS)$(CC) $(CFLAGS) -shared -o $@ $^ \ |
| 108 | -Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def |
| 109 | |
| 110 | $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 111 | @echo AR $(notdir $@) |
| 112 | $(SILENT)mkdir -p $(dir $@) |
| 113 | $(SILENT)$(AR) rucs $@ $^ |
| 114 | |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 115 | # some trickery to build ppc and i386 from a single call |
| 116 | ifeq ($(RBARCH),) |
| 117 | $(TARGET_DIR)lib$(OUTPUT)i386.a: |
| 118 | make RBARCH=i386 TARGET_DIR=$(TARGET_DIR) lib$(OUTPUT)i386.a |
| 119 | |
| 120 | $(TARGET_DIR)lib$(OUTPUT)ppc.a: |
| 121 | make RBARCH=ppc TARGET_DIR=$(TARGET_DIR) lib$(OUTPUT)ppc.a |
| 122 | endif |
| 123 | |
Dominik Riebeling | 17a0c83 | 2011-12-15 18:44:57 +0000 | [diff] [blame] | 124 | lib$(OUTPUT)-universal: $(TARGET_DIR)lib$(OUTPUT)i386.a \ |
| 125 | $(TARGET_DIR)lib$(OUTPUT)ppc.a |
Dominik Riebeling | 98becd2 | 2011-12-16 18:59:38 +0000 | [diff] [blame] | 126 | @echo LIPO $(notdir $(TARGET_DIR)lib$(OUTPUT).a) |
| 127 | $(SILENT) rm -f $(TARGET_DIR)lib$(OUTPUT).a |
Dominik Riebeling | 17a0c83 | 2011-12-15 18:44:57 +0000 | [diff] [blame] | 128 | $(SILENT)lipo -create $(TARGET_DIR)lib$(OUTPUT)i386.a \ |
| 129 | $(TARGET_DIR)lib$(OUTPUT)ppc.a \ |
| 130 | -output $(TARGET_DIR)lib$(OUTPUT).a |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 131 | |
| 132 | clean: |
| 133 | rm -f $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg |
| 134 | rm -rf $(OUTPUT)-* i386 ppc $(OBJDIR) |
| 135 | |
| 136 | # OS X specifics |
| 137 | $(OUTPUT)-i386: |
| 138 | $(MAKE) RBARCH=i386 |
| 139 | mv $(OUTPUT) $@ |
| 140 | |
| 141 | $(OUTPUT)-ppc: |
| 142 | $(MAKE) RBARCH=ppc |
| 143 | mv $(OUTPUT) $@ |
| 144 | |
| 145 | $(OUTPUT)-mac: $(OUTPUT)-i386 $(OUTPUT)-ppc |
| 146 | @echo LIPO $@ |
| 147 | $(SILENT)lipo -create $(OUTPUT)-ppc $(OUTPUT)-i386 -output $@ |
| 148 | |
| 149 | $(OUTPUT).dmg: $(OUTPUT)-mac |
| 150 | @echo DMG $@ |
| 151 | $(SILENT)mkdir -p $(OUTPUT)-dmg |
| 152 | $(SILENT)cp -p $(OUTPUT)-mac $(OUTPUT)-dmg |
| 153 | $(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@ |