11cb0ef41Sopenharmony_ci#!/bin/sh
21cb0ef41Sopenharmony_ci# Writes out all of the exported symbols to a file.
31cb0ef41Sopenharmony_ci# This is needed on AIX as symbols are not exported
41cb0ef41Sopenharmony_ci# by an executable by default and need to be listed
51cb0ef41Sopenharmony_ci# specifically for export so that they can be used
61cb0ef41Sopenharmony_ci# by native add-ons.
71cb0ef41Sopenharmony_ci#
81cb0ef41Sopenharmony_ci# The raw symbol data is obtained by using nm on
91cb0ef41Sopenharmony_ci# the .a files which make up the node executable.
101cb0ef41Sopenharmony_ci#
111cb0ef41Sopenharmony_ci# -Xany processes symbols for both 32-bit and
121cb0ef41Sopenharmony_ci# 64-bit (the default is for 32-bit only).
131cb0ef41Sopenharmony_ci#
141cb0ef41Sopenharmony_ci# -g selects only exported symbols.
151cb0ef41Sopenharmony_ci#
161cb0ef41Sopenharmony_ci# -C, -B and -p ensure that the output is in a
171cb0ef41Sopenharmony_ci# format that can be easily parsed and converted
181cb0ef41Sopenharmony_ci# into the required symbol.
191cb0ef41Sopenharmony_ci#
201cb0ef41Sopenharmony_ci# -C suppresses the demangling of C++ names.
211cb0ef41Sopenharmony_ci# -B writes the output in BSD format.
221cb0ef41Sopenharmony_ci# -p displays the info in a standard portable
231cb0ef41Sopenharmony_ci#    output format.
241cb0ef41Sopenharmony_ci#
251cb0ef41Sopenharmony_ci# Only include symbols if they are of the following
261cb0ef41Sopenharmony_ci# types and don't start with a dot.
271cb0ef41Sopenharmony_ci#
281cb0ef41Sopenharmony_ci# T - Global text symbol.
291cb0ef41Sopenharmony_ci# D - Global data symbol.
301cb0ef41Sopenharmony_ci# B - Global bss symbol.
311cb0ef41Sopenharmony_ci#
321cb0ef41Sopenharmony_ci# The final sort allows removal of any duplicates.
331cb0ef41Sopenharmony_ci#
341cb0ef41Sopenharmony_ci# Symbols for the gtest libraries are excluded as
351cb0ef41Sopenharmony_ci# they are not linked into the node executable.
361cb0ef41Sopenharmony_ci#
371cb0ef41Sopenharmony_ciecho "Searching $1 to write out expfile to $2"
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci# This special sequence must be at the start of the exp file.
401cb0ef41Sopenharmony_ciecho "#!." > "$2.tmp"
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci# Pull the symbols from the .a files.
431cb0ef41Sopenharmony_cifind "$1" -name "*.a" | grep -v gtest \
441cb0ef41Sopenharmony_ci  | xargs nm -Xany -BCpg \
451cb0ef41Sopenharmony_ci  | awk '{
461cb0ef41Sopenharmony_ci      if ((($2 == "T") || ($2 == "D") || ($2 == "B")) &&
471cb0ef41Sopenharmony_ci          (substr($3,1,1) != ".")) { print $3 }
481cb0ef41Sopenharmony_ci    }' \
491cb0ef41Sopenharmony_ci  | sort -u >> "$2.tmp"
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_cimv -f "$2.tmp" "$2"
52