Don't add LIBSOURCES to SOURCES.

Split source files for library and stand-alone binary and use library as
dependency when building the stand-alone binary. This avoids dependencies
getting added multiple times.

Remove outdated RBARCH handling, we always create fat binaries on OS X these
days.

Change-Id: Ia15a731296edcbe90869a1bf66dda2c3d6c7e317
This commit is contained in:
Dominik Riebeling 2016-12-16 19:39:07 +01:00
parent efe3775145
commit 6f4beaa52c
8 changed files with 17 additions and 24 deletions

View File

@ -11,7 +11,7 @@ CFLAGS += -g -Wall
OUTPUT = chinachippatcher
LIBSOURCES = chinachip.c
SOURCES = $(LIBSOURCES) main.c
SOURCES = main.c
include ../libtools.make

View File

@ -32,7 +32,7 @@ LDOPTS_OSX = -framework CoreFoundation -framework IOKit
LIBSOURCES = ipodpatcher.c fat32format.c arc4.c \
ipodio-posix.c ipodio-win32-scsi.c ipodio-win32.c
SOURCES = main.c $(BOOTSRC) $(LIBSOURCES)
SOURCES = main.c $(BOOTSRC)
ipodpatcher: SOURCES+= ipodio-posix.c
OUTPUT = ipodpatcher

View File

@ -37,8 +37,6 @@ TARGET_DIR ?= $(abspath .)/
NATIVECC ?= gcc
CC ?= gcc
CPPDEFINES := $(shell echo foo | $(CROSS)$(CC) -dM -E -)
# use POSIX/C99 printf on windows
CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
BINARY = $(OUTPUT)
# when building a Windows binary add the correct file suffix
@ -50,6 +48,8 @@ else
ifeq ($(findstring MINGW,$(CPPDEFINES)),MINGW)
BINARY = $(OUTPUT).exe
COMPILETARGET = mingw
# use POSIX/C99 printf on windows
CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
else
ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE)
COMPILETARGET = darwin
@ -79,16 +79,9 @@ CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
NATIVECC = gcc-4.0
endif
endif
WINDRES = windres
BUILD_DIR ?= $(TARGET_DIR)build$(COMPILETARGET)
ifdef RBARCH
ARCHFLAGS += -arch $(RBARCH)
OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/
else
OBJDIR = $(abspath $(BUILD_DIR))/
endif
all: $(BINARY)
@ -103,20 +96,20 @@ DEPS = $(addprefix $(OBJDIR),$(subst .c,.d,$(notdir $(SOURCES) $(LIBSOURCES))))
# additional link dependencies for the standalone executable
# extra dependencies: libucl
LIBUCL = libucl$(RBARCH).a
LIBUCL = libucl.a
$(LIBUCL): $(OBJDIR)$(LIBUCL)
$(OBJDIR)$(LIBUCL):
$(SILENT)$(MAKE) -C $(TOP)/../tools/ucl/src TARGET_DIR=$(OBJDIR) $@
# building the standalone executable
$(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
$(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) $(TARGET_DIR)lib$(OUTPUT).a
@echo LD $@
$(SILENT)$(call mkdir,$(dir $@))
# EXTRADEPS need to be built into OBJDIR.
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -o $(BINARY) \
$(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \
$(addprefix $(OBJDIR),$(EXTRALIBOBJS)) $(LDOPTS)
$(addprefix $(OBJDIR),$(EXTRALIBOBJS)) lib$(OUTPUT).a $(addprefix $(OBJDIR),$(EXTRADEPS)) $(LDOPTS)
# common rules
$(OBJDIR)%.o:
@ -125,10 +118,10 @@ $(OBJDIR)%.o:
$(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -c -o $@ $<
# lib rules
lib$(OUTPUT)$(RBARCH).a: $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
lib$(OUTPUT)$(RBARCH): $(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a
lib$(OUTPUT).a: $(TARGET_DIR)lib$(OUTPUT).a
lib$(OUTPUT): $(TARGET_DIR)lib$(OUTPUT).a
$(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) \
$(TARGET_DIR)lib$(OUTPUT).a: $(LIBOBJS) \
$(addprefix $(OBJDIR),$(EXTRALIBOBJS))
# rules to build a DLL. Only works for W32 as target (i.e. MinGW toolchain)
dll: $(OUTPUT).dll
@ -140,7 +133,7 @@ $(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
-Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def
# create lib file from objects
$(TARGET_DIR)lib$(OUTPUT)$(RBARCH).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
$(TARGET_DIR)lib$(OUTPUT).a: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
@echo AR $(notdir $@)
$(SILENT)$(call mkdir,$(dir $@))
$(SILENT)$(call rm,$@)

View File

@ -9,11 +9,11 @@
CFLAGS += -I../../tools/ucl/include -Wall
OUTPUT = mkamsboot
LIBUCL = libucl$(RBARCH).a
LIBUCL = libucl.a
# inputs
LIBSOURCES := dualboot.c md5.c mkamsboot.c
SOURCES := $(LIBSOURCES) main.c
SOURCES := main.c
# additional link dependencies for the standalone executable
EXTRADEPS := $(LIBUCL)

View File

@ -13,7 +13,7 @@ OUTPUT = mkmpioboot
# inputs
LIBSOURCES = mkmpioboot.c
SOURCES = $(LIBSOURCES) main.c
SOURCES = main.c
EXTRADEPS = $(LIBUCL)
include ../libtools.make

View File

@ -16,7 +16,7 @@ OUTPUT = mktccboot
# inputs
LIBSOURCES := mktccboot.c $(TOOLSDIR)telechips.c
SOURCES := $(LIBSOURCES) main.c
SOURCES := main.c
EXTRADEPS :=
include ../libtools.make

View File

@ -19,7 +19,7 @@ LIBSOURCES := dualboot.c mkzenboot.c md5.c utils.c \
$(addprefix $(TOOLS_DIR),$(TOOLS_SOURCES))
# inputs for binary only
SOURCES := $(LIBSOURCES) main.c
SOURCES := main.c
# dependencies for binary
EXTRADEPS :=

View File

@ -12,7 +12,7 @@ OUTPUT = sansapatcher
# inputs
LIBSOURCES := sansapatcher.c sansaio-posix.c sansaio-win32.c
SOURCES := $(LIBSOURCES) main.c
SOURCES := main.c
# additional link dependencies for the standalone executable
EXTRADEPS :=