1#!/usr/bin/env python 2 3# This Source Code Form is subject to the terms of the Mozilla Public 4# License, v. 2.0. If a copy of the MPL was not distributed with this 5# file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7# This script processes NSS .def files according to the rules defined in 8# a comment at the top of each one. The files are used to define the 9# exports from NSS shared libraries, with -DEFFILE on Windows, a linker 10# script on Linux, or with -exported_symbols_list on OS X. 11# 12# The NSS build system processes them using a series of sed replacements, 13# but the Mozilla build system is already running a Python script to generate 14# the file so it's simpler to just do the replacement in Python. 15# 16# One difference between the NSS build system and Mozilla's is that 17# Mozilla's supports building on Linux for Windows using MinGW. MinGW 18# expects all lines containing ;+ removed and all ;- tokens removed. 19 20import buildconfig 21 22 23def main(output, input): 24 is_darwin = buildconfig.substs['OS_ARCH'] == 'Darwin' 25 is_mingw = "WINNT" == buildconfig.substs['OS_ARCH'] and buildconfig.substs['GCC_USE_GNU_LD'] 26 27 with open(input, 'rb') as f: 28 for line in f: 29 line = line.rstrip() 30 # On everything except MinGW, remove all lines containing ';-' 31 if not is_mingw and ';-' in line: 32 continue 33 # On OS X, remove all lines containing ';+' 34 if is_darwin and ';+' in line: 35 continue 36 # Remove the string ' DATA '. 37 line = line.replace(' DATA ', '') 38 # Remove the string ';+' 39 if not is_mingw: 40 line = line.replace(';+', '') 41 # Remove the string ';;' 42 line = line.replace(';;', '') 43 # If a ';' is present, remove everything after it, 44 # and on OS X, remove it as well. 45 i = line.find(';') 46 if i != -1: 47 if is_darwin or is_mingw: 48 line = line[:i] 49 else: 50 line = line[:i+1] 51 # On OS X, symbols get an underscore in front. 52 if line and is_darwin: 53 output.write('_') 54 output.write(line) 55 output.write('\n') 56