1#
2# Linux router libbcmcrypto Makefile
3#
4# Copyright (C) 2012, Broadcom Corporation
5# All Rights Reserved.
6# 
7# This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8# the contents of this file may not be disclosed to third parties, copied
9# or duplicated in any form, in whole or in part, without the prior
10# written permission of Broadcom Corporation.
11#
12# $Id: Makefile 341899 2012-06-29 04:06:38Z $
13#
14
15include $(TOP)/.config
16
17CFLAGS	+= -Wsign-compare -I. -I$(SRCBASE)/common/include -I../httpd -I$(SRCBASE)/include ${WLAN_StdIncPathA} -Wall -fPIC
18#CFLAGS	+= -g -DDEBUG
19CFLAGS	+= -s
20LDFLAGS += -L.
21
22
23vpath %.c $(SRCBASE)/bcmcrypto
24ifeq ($(RTCONFIG_BCMARM),y)
25vpath %.o $(SRCBASE)/router/libbcmcrypto/prebuilt.arm
26else ifeq ($(RTCONFIG_RALINK),y)
27vpath %.o $(SRCBASE)/router/libbcmcrypto/prebuilt.mipsel
28else ifeq ($(RTCONFIG_QCA),y)
29vpath %.o $(SRCBASE)/router/libbcmcrypto/prebuilt.qca
30else
31vpath %.o $(SRCBASE)/router/libbcmcrypto/prebuilt.mipsel
32endif
33
34OBJS := aes.o aeskeywrap.o rijndael-alg-fst.o dh.o bn.o sha1.o passhash.o prf.o md5.o hmac.o rc4.o random.o
35# For customer backwords compatibility, for now we keep CONFIG_WSCCMD here and can be removed when
36# all customers migrate to new SDK (no CONFIG_WSCCMD in configration files).
37#ifneq ($(RTCONFIG_WPS)$(CONFIG_WPS)$(CONFIG_WSCCMD)$(CONFIG_MFP),)
38OBJS += sha256.o hmac_sha256.o
39#endif
40
41# Find all ELF binaries (including extra libraries)
42BINARIES := $(shell find $(TARGETDIR) -path $(TARGETDIR)/lib -prune -o -type f -print | file -f - | grep ELF | cut -d':' -f1)
43MAP := .map
44UNR := .unresolved
45SYM := .symbols
46
47all: libbcmcrypto.so
48
49install: all
50	install -d $(INSTALLDIR)/usr/lib
51	install -m 755 libbcmcrypto.so $(INSTALLDIR)/usr/lib
52	$(STRIP) $(INSTALLDIR)/usr/lib/libbcmcrypto.so
53
54clean:
55	rm -f *.o *.so *.a $(MAP) $(UNR) $(SYM)
56
57libbcmcrypto.so: $(OBJS)
58	$(LD) -shared -o $@ $^
59
60# rule for removing unneeded symbols in the shared library
61optimize: libbcmcrypto.so
62	$(NM) -o --defined-only --no-sort libbcmcrypto.so | cut -d' ' -f3 > $(MAP)
63ifeq ($(MKSYM),)
64	$(NM) --dynamic -u --no-sort $(BINARIES) | sort -u > $(UNR)
65	rm -rf $(SYM)
66	for symbol in `cat $(UNR)` ; do \
67	if grep -q "^$${symbol}$$" $(MAP) ; then echo "-u $${symbol}" >> $(SYM) ;  \
68	fi ; done
69else
70	$(NM) --dynamic -u --no-sort $(BINARIES) | sort -u | $(MKSYM) $(MAP) > $(SYM)
71endif
72	# if no symbols are needed then delete the shared lib
73	if ls $(SYM) ; then \
74	$(AR) cr libbcmcrypto.a $(OBJS) ; \
75	xargs -t $(LD) -shared -o libbcmcrypto.so libbcmcrypto.a < $(SYM) ; \
76	install libbcmcrypto.so $(TARGETDIR)/usr/lib ; \
77	$(STRIP) $(TARGETDIR)/usr/lib/libbcmcrypto.so ; \
78	else \
79	rm $(TARGETDIR)/usr/lib/libbcmcrypto.so ; fi
80