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)\" |
| 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 | |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 61 | # additional link dependencies for the standalone executable |
| 62 | # extra dependencies: libucl |
| 63 | LIBUCL = libucl$(RBARCH).a |
| 64 | $(LIBUCL): $(OBJDIR)$(LIBUCL) |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 65 | |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 66 | $(OBJDIR)$(LIBUCL): |
| 67 | $(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) $@ |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 68 | |
| 69 | # building the standalone executable |
| 70 | $(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
| 71 | @echo LD $@ |
| 72 | # $(SILENT)mkdir -p $(dir $@) |
| 73 | # EXTRADEPS need to be built into OBJDIR. |
Dominik Riebeling | 17a0c83 | 2011-12-15 18:44:57 +0000 | [diff] [blame] | 74 | $(SILENT)$(CROSS)$(CC) $(CFLAGS) -o $(BINARY) \ |
| 75 | $(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \ |
| 76 | $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 77 | |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 78 | # common rules |
| 79 | $(OBJDIR)%.o: %.c |
| 80 | @echo CC $< |
| 81 | $(SILENT)mkdir -p $(dir $@) |
| 82 | $(SILENT)$(CROSS)$(CC) $(CFLAGS) -c -o $@ $< |
| 83 | |
| 84 | # lib rules |
| 85 | lib$(OUTPUT)$(RBARCH).a: $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a |
| 86 | lib$(OUTPUT)$(RBARCH): $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a |
| 87 | |
Dominik Riebeling | 17a0c83 | 2011-12-15 18:44:57 +0000 | [diff] [blame] | 88 | $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) \ |
| 89 | $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) |
Dominik Riebeling | 6b8f0b0 | 2011-12-14 22:00:06 +0000 | [diff] [blame] | 90 | @echo AR $(notdir $@) |
| 91 | $(SILENT)mkdir -p $(dir $@) |
| 92 | $(SILENT)$(AR) rucs $@ $^ |
| 93 | |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 94 | # some trickery to build ppc and i386 from a single call |
| 95 | ifeq ($(RBARCH),) |
| 96 | $(TARGET_DIR)lib$(OUTPUT)i386.a: |
| 97 | make RBARCH=i386 TARGET_DIR=$(TARGET_DIR) lib$(OUTPUT)i386.a |
| 98 | |
| 99 | $(TARGET_DIR)lib$(OUTPUT)ppc.a: |
| 100 | make RBARCH=ppc TARGET_DIR=$(TARGET_DIR) lib$(OUTPUT)ppc.a |
| 101 | endif |
| 102 | |
Dominik Riebeling | 17a0c83 | 2011-12-15 18:44:57 +0000 | [diff] [blame] | 103 | lib$(OUTPUT)-universal: $(TARGET_DIR)lib$(OUTPUT)i386.a \ |
| 104 | $(TARGET_DIR)lib$(OUTPUT)ppc.a |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 105 | @echo lipo $(TARGET_DIR)libmkamsboot.a |
| 106 | $(SILENT) rm -f $(TARGET_DIR)libmkamsboot.a |
Dominik Riebeling | 17a0c83 | 2011-12-15 18:44:57 +0000 | [diff] [blame] | 107 | $(SILENT)lipo -create $(TARGET_DIR)lib$(OUTPUT)i386.a \ |
| 108 | $(TARGET_DIR)lib$(OUTPUT)ppc.a \ |
| 109 | -output $(TARGET_DIR)lib$(OUTPUT).a |
Dominik Riebeling | b24e562 | 2011-12-14 21:59:37 +0000 | [diff] [blame] | 110 | |
| 111 | clean: |
| 112 | rm -f $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg |
| 113 | rm -rf $(OUTPUT)-* i386 ppc $(OBJDIR) |
| 114 | |
| 115 | # OS X specifics |
| 116 | $(OUTPUT)-i386: |
| 117 | $(MAKE) RBARCH=i386 |
| 118 | mv $(OUTPUT) $@ |
| 119 | |
| 120 | $(OUTPUT)-ppc: |
| 121 | $(MAKE) RBARCH=ppc |
| 122 | mv $(OUTPUT) $@ |
| 123 | |
| 124 | $(OUTPUT)-mac: $(OUTPUT)-i386 $(OUTPUT)-ppc |
| 125 | @echo LIPO $@ |
| 126 | $(SILENT)lipo -create $(OUTPUT)-ppc $(OUTPUT)-i386 -output $@ |
| 127 | |
| 128 | $(OUTPUT).dmg: $(OUTPUT)-mac |
| 129 | @echo DMG $@ |
| 130 | $(SILENT)mkdir -p $(OUTPUT)-dmg |
| 131 | $(SILENT)cp -p $(OUTPUT)-mac $(OUTPUT)-dmg |
| 132 | $(SILENT)hdiutil create -srcfolder $(OUTPUT)-dmg $@ |