Home | History | Annotate | Line # | Download | only in dspgen
do_subst.awk revision 1.1
      1 # $NetBSD: do_subst.awk,v 1.1 2001/02/09 18:34:10 uch Exp $
      2 #
      3 # Copyright (c) 1999, 2000 Christopher G. Demetriou.  All rights reserved.
      4 #
      5 # Redistribution and use in source and binary forms, with or without
      6 # modification, are permitted provided that the following conditions
      7 # are met:
      8 # 1. Redistributions of source code must retain the above copyright
      9 #    notice, this list of conditions and the following disclaimer.
     10 # 2. Redistributions in binary form must reproduce the above copyright
     11 #    notice, this list of conditions and the following disclaimer in the
     12 #    documentation and/or other materials provided with the distribution.
     13 # 3. All advertising materials mentioning features or use of this software
     14 #    must display the following acknowledgement:
     15 #      This product includes software developed by Christopher G. Demetriou
     16 #      for the NetBSD Project.
     17 # 4. The name of the author may not be used to endorse or promote products
     18 #    derived from this software without specific prior written permission
     19 #
     20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30 
     31 function setup_md_files (arch, srclist) {
     32 	srclist=""
     33 	asm_tmpl="dspgen/asm_build." arch
     34 	prop_tmpl="dspgen/property." arch
     35 	env="SRCFILE_LIST_" arch
     36 
     37 	sz = split(ENVIRON[env], a, "[ \t\n]+");
     38 	for (i = 1; i <= sz; i++) {
     39 		if (a[i] == "") {
     40 			continue
     41 		}
     42 		if (srclist != "") {
     43 			srclist=srclist "\n"
     44 		}
     45 		srclist=srclist "# Begin Source File\n"
     46 		srclist=srclist "\n"
     47 		srclist=srclist "SOURCE=.\\" a[i] "\n"
     48 		base = index (a[i], ".asm")
     49 		if (base != 0) {
     50 		  basename = substr (a[i], 0, base - 1)
     51 		  while (getline < asm_tmpl > 0) {
     52 		    gsub ("%%% ASM_BASENAME %%%", basename)
     53 		    srclist=srclist $0 "\n"
     54 		  }
     55 		  close (asm_tmpl)
     56 		} else {
     57 		  while (getline < prop_tmpl > 0)
     58 		    srclist=srclist $0 "\n"
     59 		    close (prop_tmpl)
     60 		}
     61 		srclist=srclist "# End Source File"
     62 	}
     63 	return srclist
     64 }
     65 
     66 BEGIN {
     67 	NAME=ENVIRON["NAME"]
     68 
     69 	SRCFILES=""
     70 	sz = split(ENVIRON["SRCFILE_LIST"], a, "[ \t\n]+");
     71 	for (i = 1; i <= sz; i++) {
     72 		if (a[i] == "") {
     73 			continue
     74 		}
     75 		if (SRCFILES != "") {
     76 			SRCFILES=SRCFILES "\n"
     77 		}
     78 		SRCFILES=SRCFILES "# Begin Source File\n"
     79 		SRCFILES=SRCFILES "\n"
     80 		SRCFILES=SRCFILES "SOURCE=.\\" a[i] "\n"
     81 		SRCFILES=SRCFILES "# End Source File"
     82 	}
     83 
     84 	SRCFILES_ARM = setup_md_files("ARM", SRCFILES_ARM)
     85 	SRCFILES_SH3 = setup_md_files("SH3", SRCFILES_SH3)
     86 	SRCFILES_MIPS = setup_md_files("MIPS", SRCFILES_MIPS)
     87 
     88 	CPPDEFS=""
     89 	sz = split(ENVIRON["STD_CPPDEF_LIST"], a, "[ \t\n]+");
     90 	for (i = 1; i <= sz; i++) {
     91 		if (a[i] == "") {
     92 			continue
     93 		}
     94 		if (CPPDEFS != "") {
     95 			CPPDEFS=CPPDEFS " "
     96 		}
     97 		CPPDEFS=CPPDEFS "/D \"" a[i] "\""
     98 	}
     99 	sz = split(ENVIRON["CPPDEF_LIST"], a, "[ \t\n]+");
    100 	for (i = 1; i <= sz; i++) {
    101 		if (a[i] == "") {
    102 			continue
    103 		}
    104 		if (CPPDEFS != "") {
    105 			CPPDEFS=CPPDEFS " "
    106 		}
    107 		CPPDEFS=CPPDEFS "/D \"" a[i] "\""
    108 	}
    109 
    110 	INCDIRS=""
    111 	sz = split(ENVIRON["STD_INCDIR_LIST"], a, "[ \t\n]+");
    112 	for (i = 1; i <= sz; i++) {
    113 		if (a[i] == "") {
    114 			continue
    115 		}
    116 		if (INCDIRS != "") {
    117 			INCDIRS=INCDIRS " "
    118 		}
    119 		INCDIRS=INCDIRS "/I \"" a[i] "\""
    120 	}
    121 	sz = split(ENVIRON["INCDIR_LIST"], a, "[ \t\n]+");
    122 	for (i = 1; i <= sz; i++) {
    123 		if (a[i] == "") {
    124 			continue
    125 		}
    126 		if (INCDIRS != "") {
    127 			INCDIRS=INCDIRS " "
    128 		}
    129 		INCDIRS=INCDIRS "/I \"" a[i] "\""
    130 	}
    131 	sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
    132 	for (i = 1; i <= sz; i++) {
    133 		if (a[i] == "") {
    134 			continue
    135 		}
    136 		if (INCDIRS != "") {
    137 			INCDIRS=INCDIRS " "
    138 		}
    139 		INCDIRS=INCDIRS "/I \"..\\" a[i] "\""
    140         }
    141 
    142 	LIBRARIES=""
    143 	sz = split(ENVIRON["STD_LIBRARY_LIST"], a, "[ \t\n]+");
    144 	for (i = 1; i <= sz; i++) {
    145 		if (a[i] == "") {
    146 			continue
    147 		}
    148 		if (LIBRARIES != "") {
    149 			LIBRARIES=LIBRARIES " "
    150 		}
    151 		LIBRARIES=LIBRARIES a[i] ".lib"
    152 	}
    153 	sz = split(ENVIRON["LIBRARY_LIST"], a, "[ \t\n]+");
    154 	for (i = 1; i <= sz; i++) {
    155 		if (a[i] == "") {
    156 			continue
    157 		}
    158 		if (LIBRARIES != "") {
    159 			LIBRARIES=LIBRARIES " "
    160 		}
    161 		LIBRARIES=LIBRARIES a[i] ".lib"
    162         }
    163 	sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
    164 	for (i = 1; i <= sz; i++) {
    165 		if (a[i] == "") {
    166 			continue
    167 		}
    168 		if (LIBRARIES != "") {
    169 			LIBRARIES=LIBRARIES " "
    170 		}
    171 		LIBRARIES=LIBRARIES a[i] ".lib"
    172 	}
    173 
    174 	sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
    175 	DEBUG_LIBPATH=""
    176 	RELEASE_LIBPATH=""
    177 	for (i = 1; i <= sz; i++) {
    178 		if (a[i] == "") {
    179 			continue
    180 		}
    181 		if (i > 1) {
    182 			DEBUG_LIBPATH=DEBUG_LIBPATH " "
    183 			RELEASE_LIBPATH=RELEASE_LIBPATH " "
    184 		}
    185 		DEBUG_LIBPATH=DEBUG_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSDbg\""
    186 		RELEASE_LIBPATH=RELEASE_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSRel\""
    187 	}
    188 }
    189 {
    190 	gsub("%%% SRCFILES %%%", SRCFILES)
    191 	gsub("%%% SRCFILES_ARM %%%", SRCFILES_ARM)
    192 	gsub("%%% SRCFILES_SH3 %%%", SRCFILES_SH3)
    193 	gsub("%%% SRCFILES_SH4 %%%", SRCFILES_SH4)
    194 	gsub("%%% SRCFILES_MIPS %%%", SRCFILES_MIPS)
    195 	gsub("%%% CPPDEFS %%%", CPPDEFS)
    196 	gsub("%%% INCDIRS %%%", INCDIRS)
    197 	gsub("%%% LIBRARIES %%%", LIBRARIES)
    198 	gsub("%%% DEBUG_LIBPATH %%%", DEBUG_LIBPATH)
    199 	gsub("%%% RELEASE_LIBPATH %%%", RELEASE_LIBPATH)
    200 	gsub("%%% NAME %%%", NAME)
    201 	print $0
    202 }
    203