#! /usr/bin/env bash # file : build/dist # license : GNU GPL v2 + exceptions; see accompanying LICENSE file # Create test distribution and generate makefiles. # # -src $(src_base) # -out # -xsd # -cxx # -hxx # -ixx # -gen # -cmd # -opt # -lib # # -win generate MS nmakefile # # bld_root # trap 'exit 1' ERR function error () { echo "$*" 1>&2 } function gen () { echo -e "$*" >>$makefile } type=gnu while [ $# -gt 0 ]; do case $1 in -src) src=$2 shift 2 ;; -out) out=$2 shift 2 ;; -xsd) xsd=$2 shift 2 ;; -cxx) cxx=$2 shift 2 ;; -hxx) hxx=$2 shift 2 ;; -ixx) ixx=$2 shift 2 ;; -gen) gen=$2 shift 2 ;; -cmd) cmd=$2 shift 2 ;; -opt) opt=$2 shift 2 ;; -win) type=win shift ;; -lib) lib=$2 shift 2 ;; *) error "unknown option: $1" exit 1 ;; esac done if [ "$src" = "" ]; then error "-src option is not specified" exit 1 fi if [ "$out" = "" ]; then error "-out option is not specified" exit 1 fi # Calculate the root path. # root=`echo $src | sed -e 's%.*/tests/\(.*\)%tests/\1%' -` out=$out/$root root=`echo $root | sed -e 's%[^/]*%..%g' -` # Sanitize any absolute paths in opt. # opt=`echo $opt | sed -e "s%$src/\([^ ]*\)%\1%g" -` # Gather object files. # if [ "$gen" != "" ]; then gen_cxx=`echo $gen | sed -e 's%[^ ]*\.[h|i]xx *%%g' -` gen_hxx=`echo $gen | sed -e 's%[^ ]*\.[c|i]xx *%%g' -` gen_ixx=`echo $gen_cxx | sed -e 's%.cxx%.ixx%g' -` fi obj=`echo $cxx $gen_cxx | sed -e 's%\.cxx%.o%g' -` if [ "$obj" = "" ]; then error "no source files specified" exit 1 fi # Find the test driver name. # if [ "$cxx" != "" ]; then driver=`echo $cxx | sed -e "s/ /\n/g" | sed -e "s/driver\.cxx/driver/" -e t -e d -` driver=`echo $driver` # Get rid of newlines. fi if [ "$driver" = "" -a "$gen_cxx" != "" ]; then # See if the driver is auto-generated. # driver=`echo $gen_cxx | sed -e "s/ /\n/g" | sed -e "s/\([^ ]*\)driver\.cxx/\1driver/" -e t -e d -` driver=`echo $driver` # Get rid of newlines. fi if [ "$driver" = "" ]; then error "no driver file found" exit 1 fi # Figure out the stem and pattern for the schema and gen files. If # we have more than one schema file, base the stem and the pattern # on the first file. # for i in $xsd; do stem=`echo $i | sed -e 's%\.xsd%%' -` pat=`echo $gen | sed -e "s/ /\n/g" | sed -e "s/$stem/%/" -e t -e d -` pat=`echo $pat` # Get rid of newlines. done # Sense what kind of tests we need to run. # xml=`find $src -name 'test-*.xml' | sed -e 's%.*/\([^/]*\)%\1%' -` std=`find $src -name 'test-*.std' | sed -e 's%.*/\([^/]*\)%\1%' -` # Install files. # install=$bld_root/install/install $install -d -m 755 $out for i in $cxx $hxx $ixx; do $install -p -m 644 $src/$i $out/$i done for i in $xsd; do $install -p -m 644 $src/$i $out/$i # See if we have a map file for this schema. # m=`echo $i | sed -e 's%\.xsd%.map%' -` if [ -f "$src/$m" ]; then $install -p -m 644 $src/$m $out/$m fi done for i in $xml; do $install -p -m 644 $src/$i $out/$i done for i in $std; do $install -p -m 644 $src/$i $out/$i done ## ## Generate the makefile. ## makefile=$out/makefile rm -f $makefile gen "root := $root" gen gen 'include $(root)/build/cxx/rules.make' gen gen 'EXTRA_CPPFLAGS := -I$(root)/libxsde' gen if [ "$lib" != "" ]; then s=`echo $lib | sed -e 's/\([^ ]*\)/-l\1/g' -` gen "override LIBS += $s" gen fi gen 'EXTRA_XSDFLAGS += --char-encoding $(XSDE_ENCODING)' gen gen 'ifeq ($(XSDE_STL),n)' gen 'EXTRA_XSDFLAGS += --no-stl' gen 'endif' gen gen 'ifeq ($(XSDE_IOSTREAM),n)' gen 'EXTRA_XSDFLAGS += --no-iostream' gen 'endif' gen gen 'ifeq ($(XSDE_EXCEPTIONS),n)' gen 'EXTRA_XSDFLAGS += --no-exceptions' gen 'endif' gen gen 'ifeq ($(XSDE_LONGLONG),n)' gen 'EXTRA_XSDFLAGS += --no-long-long' gen 'endif' gen if [ "$cmd" = "cxx-hybrid" ]; then gen 'ifeq ($(XSDE_PARSER_VALIDATION),n)' gen 'EXTRA_XSDFLAGS += --suppress-parser-val' gen 'endif' gen gen 'ifeq ($(XSDE_SERIALIZER_VALIDATION),n)' gen 'EXTRA_XSDFLAGS += --suppress-serializer-val' gen 'endif' elif [ "$cmd" = "cxx-parser" ]; then gen 'ifeq ($(XSDE_PARSER_VALIDATION),n)' gen 'EXTRA_XSDFLAGS += --suppress-validation' gen 'endif' elif [ "$cmd" = "cxx-serializer" ]; then gen 'ifeq ($(XSDE_SERIALIZER_VALIDATION),n)' gen 'EXTRA_XSDFLAGS += --suppress-validation' gen 'endif' elif [ "$cmd" != "" ]; then error "unknown compiler command" exit 1 fi gen gen 'ifeq ($(XSDE_REUSE_STYLE),mixin)' gen 'EXTRA_XSDFLAGS += --reuse-style-mixin' gen 'endif' gen gen 'ifeq ($(XSDE_POLYMORPHIC),y)' gen 'EXTRA_XSDFLAGS += --runtime-polymorphic' gen 'endif' gen gen 'ifeq ($(XSDE_CUSTOM_ALLOCATOR),y)' gen 'EXTRA_XSDFLAGS += --custom-allocator' gen 'endif' gen gen "$driver: $obj" '$(root)/libxsde/xsde/libxsde.a' gen for i in $cxx; do o=`echo $i | sed -e 's%\.cxx%.o%' -` gen "$o: $i $gen_hxx" done for i in $gen_cxx; do o=`echo $i | sed -e 's%\.cxx%.o%' -` gen "$o: $i" done gen if [ "$xsd" != "" ]; then gen ".PRECIOUS: $pat" gen "$pat: %.xsd" gen '\t$(root)/bin/xsde' $cmd '$(XSDFLAGS) $(EXTRA_XSDFLAGS)' $opt '$<' gen fi gen '.PHONY: gen' gen "gen: $gen" gen gen '.PHONY: test' gen "test: $driver" if [ "$xml" = "" ]; then if [ "$std" = "" ]; then # Simple return value test. # gen "\t./$driver" else # Test with result comparison. # gen "\t./$driver | diff -u $std -" fi else for i in $xml; do if [ "$std" = "" ]; then # Return value test with argument. # gen "\t./$driver $i" else # Test with argument and result comparison. # s=`echo $i | sed -e 's%\.xml%.std%' -` gen "\t./$driver $i | diff -u $s -" fi done fi gen gen '.PHONY: clean cleanobj' gen 'cleanobj:' gen "\trm -f $driver $obj" gen gen 'clean: cleanobj' if [ "$gen" != "" ]; then gen "\trm -f $gen_cxx $gen_ixx $gen_hxx" fi gen if [ "$type" != "win" ]; then exit 0 fi ## ## Generate nmakefile ## makefile=$out/nmakefile rm -f $makefile # Adjust paths and file names. # root=`echo $root | sed -e 's%/%\\\\%g' -` obj=`echo $cxx $gen_cxx | sed -e 's%\.cxx%.obj%g' -` driver=$driver.exe gen "root = $root" gen gen '!include $(root)\\build\\cxx\\rules.nmake' gen gen 'EXTRA_CPPFLAGS = /I$(root)\\libxsde' gen if [ "$lib" != "" ]; then s=`echo $lib | sed -e 's/\([^ ]*\)/\1.lib/g' -` gen 'LIBS = $(LIBS)' "$s" gen fi gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --char-encoding $(XSDE_ENCODING)' gen gen '!if "$(XSDE_STL)" == "n"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --no-stl' gen '!endif' gen gen '!if "$(XSDE_IOSTREAM)" == "n"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --no-iostream' gen '!endif' gen gen '!if "$(XSDE_EXCEPTIONS)" == "n"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --no-exceptions' gen '!endif' gen gen '!if "$(XSDE_LONGLONG)" == "n"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --no-long-long' gen '!endif' gen if [ "$cmd" = "cxx-hybrid" ]; then gen '!if "$(XSDE_PARSER_VALIDATION)" == "n"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --suppress-parser-val' gen '!endif' gen gen '!if "$(XSDE_SERIALIZER_VALIDATION)" == "n"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --suppress-serializer-val' gen '!endif' elif [ "$cmd" = "cxx-parser" ]; then gen '!if "$(XSDE_PARSER_VALIDATION)" == "n"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --suppress-validation' gen '!endif' elif [ "$cmd" = "cxx-serializer" ]; then gen '!if "$(XSDE_SERIALIZER_VALIDATION)" == "n"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --suppress-validation' gen '!endif' elif [ "$cmd" != "" ]; then error "unknown compiler command" exit 1 fi gen gen '!if "$(XSDE_REUSE_STYLE)" == "mixin"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --reuse-style-mixin' gen '!endif' gen gen '!if "$(XSDE_POLYMORPHIC)" == "y"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --runtime-polymorphic' gen '!endif' gen gen '!if "$(XSDE_CUSTOM_ALLOCATOR)" == "y"' gen 'EXTRA_XSDFLAGS = $(EXTRA_XSDFLAGS) --custom-allocator' gen '!endif' gen gen "$driver: $obj" '$(root)\\libxsde\\xsde\\xsde.lib' gen for i in $cxx; do o=`echo $i | sed -e 's%\.cxx%.obj%' -` gen "$o: $i $gen_hxx" done for i in $gen_cxx; do o=`echo $i | sed -e 's%\.cxx%.obj%' -` gen "$o: $i" done gen for i in $xsd; do stem=`echo $i | sed -e 's%\.xsd%%' -` pat=`echo $gen | sed -e "s/ /\n/g" | sed -e "s/\($stem.*\)/\1/" -e t -e d -` pat=`echo $pat` # Get rid of newlines. gen "$pat: $i" gen '\t$(root)\\bin\\xsde.exe' $cmd '$(XSDFLAGS) $(EXTRA_XSDFLAGS)' $opt $i gen done gen "gen: $gen" gen gen "test: $driver" if [ "$xml" = "" ]; then if [ "$std" = "" ]; then # Simple return value test. # gen "\t."'\\'"$driver" else # Test with result comparison. # gen "\t."'\\'"$driver >tmp" gen "\tfc $std tmp" gen "\tdel tmp" fi else for i in $xml; do if [ "$std" = "" ]; then # Return value test with argument. # gen "\t."'\\'"$driver $i" else # Test with argument and result comparison. # s=`echo $i | sed -e 's%\.xml%.std%' -` gen "\t."'\\'"$driver $i >tmp" gen "\tfc $s tmp" gen "\tdel tmp" fi done fi gen gen 'cleanobj:' gen "\t-del $driver $obj" gen gen 'clean: cleanobj' if [ "$gen" != "" ]; then gen "\t-del $gen_cxx $gen_ixx $gen_hxx" fi gen