1*cdf0e10cSrcweir#!/bin/bash 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir# This script is needed in the process of generating exported 4*cdf0e10cSrcweir# symbols list out of map files on MinGW 5*cdf0e10cSrcweir# The magic generating the regular expression from the temporary 6*cdf0e10cSrcweir# mapfile containing only star and question mark symbols 7*cdf0e10cSrcweir# 8*cdf0e10cSrcweir# The script has to be called as follows: 9*cdf0e10cSrcweir# nm -gx <file>.o | addsym-mingw.sh <file-with-wildcard-symbols> <temporary-file-where-to-write-the-search-expression-to> 10*cdf0e10cSrcweir# See tg_shl.mk for an example of how to use the script 11*cdf0e10cSrcweir# 12*cdf0e10cSrcweir# Replace every * with .* and every ? with . to get awk expression 13*cdf0e10cSrcweir# Remove whitespaces and comments in expression 14*cdf0e10cSrcweir# Put ^ at the beginning of every expression 15*cdf0e10cSrcweir# Put $ at the beginning of every expression 16*cdf0e10cSrcweir# Connect them all on one line, separated by | 17*cdf0e10cSrcweir# Remove | at the end of this regular expression because the last end 18*cdf0e10cSrcweir# of line was also replaced by | 19*cdf0e10cSrcweir 20*cdf0e10cSrcweirif [ -s $1 ] 21*cdf0e10cSrcweirthen 22*cdf0e10cSrcweircat $1 | sed 's#*#.*#g 23*cdf0e10cSrcweirs#?#.#g 24*cdf0e10cSrcweirs#;.*##g 25*cdf0e10cSrcweirs# ##g 26*cdf0e10cSrcweirs# ##g 27*cdf0e10cSrcweirs#^#^# 28*cdf0e10cSrcweirs#$#$#' | tr '\n' '|' | sed "s#|\$##" >$2 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir# Please note that the awk expression expects to get the output of 'nm -gP'! 31*cdf0e10cSrcweirawk -v SYMBOLSREGEXP="`cat $2`" ' 32*cdf0e10cSrcweirmatch (substr ($1,2) ,SYMBOLSREGEXP) > 0 { print substr ($1,2) ";" }' 33*cdf0e10cSrcweirfi 34*cdf0e10cSrcweir 35