1# 2# C library Makefile 3# 4# Copyright (C) 2014, Broadcom Corporation. All Rights Reserved. 5# 6# Permission to use, copy, modify, and/or distribute this software for any 7# purpose with or without fee is hereby granted, provided that the above 8# copyright notice and this permission notice appear in all copies. 9# 10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 13# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 15# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 16# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17# 18# $Id: Makefile 341899 2012-06-29 04:06:38Z $ 19# 20 21include $(TOP)/.config 22include $(SRCBASE)/makefiles/WLAN_Common.mk 23 24#ifdef __CONFIG_NORTON__ 25ifeq ($(CONFIG_NORTON),y) 26# 27# Symantec gateway binaries are downloaded via LiveUpdate mechanism. There 28# is no way to know ahead of time which symbols are needed so libc 29# optimization (CONFIG_LIBOPT) must be disabled to guarantee that Symantec 30# applications will run today and the future. 31# 32ifeq ($(call wlan_version_ge,$(BCM_KVERSIONSTRING),2.6.36),TRUE) 33CONFIG_LIBOPT=n 34endif 35endif 36#endif /* __CONFIG_NORTON__ */ 37 38# Extra libraries 39lib-$(CONFIG_LIBCRYPT) += libcrypt 40lib-$(CONFIG_LIBDL) += libdl 41lib-$(CONFIG_LIBM) += libm 42lib-$(CONFIG_LIBNSL) += libnsl 43lib-$(CONFIG_LIBPTHREAD) += libpthread 44lib-$(CONFIG_LIBRESOLV) += libresolv 45lib-$(CONFIG_LIBUTIL) += libutil 46 47ifeq ($(ARCH), arm) 48 49ifeq ($(CONFIG_NFC),y) 50lib-y += librt 51endif 52 53lib-y += libgcc_s 54else ifneq ($(CONFIG_LIBOPT),y) 55lib-y += libgcc_s 56endif 57 58ifeq ($(CONFIG_UCLIBC),y) 59 60# uClibc names 61LINKER := ld-uClibc.so.0 62LIBC := libc.so.0 63MAP := uClibc.map 64 65else 66 67# GNU libc names 68LINKER := $(foreach lib,ld.so.* ld-linux.so.*,$(notdir $(wildcard $(LIBDIR)/$(lib)))) 69LIBC := libc.so.6 70MAP := libc.map 71 72endif 73 74# Nothing to do until installation 75all: 76 77ifeq ($(CONFIG_LIBOPT),y) 78 79# Find all ELF binaries (including extra libraries) 80BINARIES := $(shell find $(TARGETDIR) -path $(TARGETDIR)/lib -prune -o -type f -print | file -f - | grep ELF | cut -d':' -f1) 81BINARIES += $(wildcard $(foreach lib,$(LINKER) $(lib-y),$(LIBDIR)/$(lib) $(LIBDIR)/$(lib).so.?)) 82 83ifneq ($(wildcard $(LIBDIR)/optinfo),) 84# Try the toolchain directory first for precursors 85OPTINFO := $(LIBDIR)/optinfo 86else 87ifneq ($(wildcard $(LIBDIR)),) 88OPTINFO := $(LIBDIR) 89else 90# Fall back on platform directory 91OPTINFO := $(PLATFORM) 92endif 93endif 94ifeq ($(CONFIG_UCLIBC),y) 95 96# uClibc precursors 97ifeq ($(ARCH), arm) 98OBJS := $(wildcard $(foreach file,libgcc-need.a libc_so.a interp.o,$(OPTINFO)/$(file))) 99else 100OBJS := $(wildcard $(foreach file,libgcc-need.a libc.a interp.o,$(OPTINFO)/$(file))) 101endif 102 103ifneq (2_4,$(LINUX_VERSION)) 104ifeq ($(ARCH), arm) 105CUSTOM_UCLIBC := $(TOOLCHAIN)/lib/libc_so.a 106else 107CUSTOM_UCLIBC := $(TOOLCHAIN)/lib/libc.a 108endif 109else 110CUSTOM_UCLIBC := mipsel-uclibc/libc.a 111endif 112 113ifeq ($(CONFIG_IPV6),y) 114OBJS := $(wildcard $(foreach file,libgcc-need.a interp.o,$(OPTINFO)/$(file))) $(CUSTOM_UCLIBC) 115endif # CONFIG_IPV6 = y 116# Foxconn, added by Michael, for DLNA to use uClibc 117$(LIBC): 118 cp $(TOOLCHAIN)/lib/libuClibc-0.9.32.1.so libc.so.0 119# Foxconn, ended by Michael, for DLNA to use uClibc. 120 121# Foconn, marked by Michael, for DLNA to use uClibc. 122# uClibc link parameters 123#ENTRY := __uClibc_init 124#LDFLAGS := -s -shared --warn-common --warn-once -z combreloc -soname=$(LIBC) -init $(ENTRY) 125#LIBGCC := $(shell $(CC) -print-libgcc-file-name) 126 127#ifeq ($(CONFIG_IPV6),y) 128#$(MAP): $(CUSTOM_UCLIBC) 129#else 130ifeq ($(ARCH), arm) 131$(MAP): $(OPTINFO)/libc_so.a 132else 133#$(MAP): $(OPTINFO)/libc.a 134endif 135# $(NM) -o --defined-only --no-sort $< | cut -d' ' -f3 > $@ 136 137# Find all unresolved symbols that uClibc could resolve 138#.symbols: $(MAP) $(BINARIES) 139ifeq ($(MKSYM),) 140# rm -f $@ 141# for symbol in `$(NM) --dynamic -u --no-sort $(BINARIES) | sort -u` ; do \ 142# if grep -q "^$${symbol}$$" $(MAP) ; then \ 143# echo "-u $${symbol}" >> $@ ; \ 144# fi ; \ 145# done 146else 147 $(NM) --dynamic -u --no-sort $(BINARIES) | sort -u | $(MKSYM) $(MAP) > $@ 148endif 149 150# Re-link uClibc 151#$(LIBC): .symbols $(OBJS) 152# xargs -t $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBGCC) < .symbols 153# Foxconn, mark ended by Michael. 154 155else #<------------- don't care start: 156 157# GNU libc precursors 158OBJS := $(wildcard $(foreach file,soinit.os libc_pic.a sofini.os,$(OPTINFO)/$(file))) 159 160# GNU libc link parameters 161ENTRY := __libc_main 162CFLAGS := -shared -Wl,-O1 -Wl,-dynamic-linker=$(LINKER) -Wl,--version-script=$(MAP) -Wl,-soname=$(LIBC) -nostdlib -nostartfiles -e $(ENTRY) 163 164$(MAP): $(OPTINFO)/libc.map 165 cp $< $@ 166 167# Find all unresolved symbols that GNU libc could resolve 168.symbols: $(MAP) $(BINARIES) 169 rm -f $@ 170 for symbol in `$(NM) --dynamic -u --no-sort $(BINARIES) | sort -u` ; do \ 171 grep -q "$${symbol};" $(MAP) && echo "-u $${symbol}" >> $@ ; \ 172 done 173 174# Re-link GNU libc 175$(LIBC): .symbols $(OBJS) $(LIBDIR)/$(LINKER) 176 xargs $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBDIR)/$(LINKER) -lgcc < .symbols 177 178endif #<------------------- don't care end. 179 180# Install optimized C library 181install: $(LIBC) 182 183else 184 185# Install default C library 186install: $(LIBDIR)/$(LIBC) 187 188endif 189 190# Also install extra libraries 191install: $(wildcard $(foreach lib,$(LINKER) $(lib-y),$(LIBDIR)/$(lib) $(LIBDIR)/$(lib).so.?)) 192 install -d $(TARGETDIR)/lib 193 install $^ $(TARGETDIR)/lib/ 194 $(STRIP) $(TARGETDIR)/lib/*.so.* 195ifeq ($(shell grep "^SUBDIRS += openssl" $(SRCBASE)/../ap/gpl/Makefile),) 196 install $(TOOLCHAIN)/usr/lib/libcrypto.so.1.0.0 $(TARGETDIR)/lib/libcrypto.so 197 install $(TOOLCHAIN)/usr/lib/libssl.so.1.0.0 $(TARGETDIR)/lib/libssl.so 198endif 199 #install $(SRCBASE)/../ap/gpl/openssl-1.0.2d/libcrypto.so.1.0.0 $(TARGETDIR)/lib/libcrypto.so 200 #install $(SRCBASE)/../ap/gpl/openssl-1.0.2d/libssl.so.1.0.0 $(TARGETDIR)/lib/libssl.so 201 202 203ifneq ($(ARCH), arm) 204ifeq ($(CONFIG_LIBOPT),y) 205 (cd $(TARGETDIR)/lib/ && ln -sf libc.so.0 libgcc_s.so.1) 206endif 207endif 208 209clean: 210 rm -f $(LIBC) $(MAP) .symbols 211