diff options
author | John Koleszar <jkoleszar@google.com> | 2010-05-18 11:58:33 -0400 |
---|---|---|
committer | John Koleszar <jkoleszar@google.com> | 2010-05-18 11:58:33 -0400 |
commit | 0ea50ce9cb4b65eee6afa1d041fe8beb5abda667 (patch) | |
tree | 1f3b9019f28bc56fd3156f96e5a9653a983ee61b /build/make | |
download | libvpx-0ea50ce9cb4b65eee6afa1d041fe8beb5abda667.tar.gz |
Initial WebM releasev0.9.0
Diffstat (limited to 'build/make')
-rwxr-xr-x | build/make/Makefile | 341 | ||||
-rwxr-xr-x | build/make/ads2gas.pl | 149 | ||||
-rwxr-xr-x | build/make/ads2gas_apple.pl | 194 | ||||
-rwxr-xr-x | build/make/armlink_adapter.sh | 51 | ||||
-rwxr-xr-x | build/make/configure.sh | 907 | ||||
-rwxr-xr-x | build/make/gen_asm_deps.sh | 63 | ||||
-rwxr-xr-x | build/make/gen_msvs_def.sh | 82 | ||||
-rwxr-xr-x | build/make/gen_msvs_proj.sh | 717 | ||||
-rwxr-xr-x | build/make/gen_msvs_sln.sh | 272 | ||||
-rw-r--r-- | build/make/obj_int_extract.c | 755 | ||||
-rwxr-xr-x | build/make/version.sh | 75 |
11 files changed, 3606 insertions, 0 deletions
diff --git a/build/make/Makefile b/build/make/Makefile new file mode 100755 index 000000000..412629ee7 --- /dev/null +++ b/build/make/Makefile @@ -0,0 +1,341 @@ +## +## Copyright (c) 2010 The VP8 project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license and patent +## grant that can be found in the LICENSE file in the root of the source +## tree. All contributing project authors may be found in the AUTHORS +## file in the root of the source tree. +## + + +include config.mk +quiet?=true +ifeq ($(target),) +# If a target wasn't specified, invoke for all enabled targets. +.DEFAULT: + @for t in $(ALL_TARGETS); do \ + $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\ + done +all: .DEFAULT +clean:: .DEFAULT + + +# Note: md5sum is not installed on OS X, but openssl is. Openssl may not be +# installed on cygwin, so we need to autodetect here. +md5sum := $(firstword $(wildcard \ + $(foreach e,md5sum openssl,\ + $(foreach p,$(subst :, ,$(PATH)),$(p)/$(e)*))\ + )) +md5sum := $(if $(filter %openssl,$(md5sum)),$(md5sum) dgst -md5,$(md5sum)) + +TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN))) +install: + @for t in $(ALL_TARGETS); do \ + $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\ + done + # Run configure for the user with the current toolchain. + @if [ -d "$(DIST_DIR)/src" ]; then \ + mkdir -p "$(DIST_DIR)/build"; \ + cd "$(DIST_DIR)/build"; \ + if [ $(TGT_CC) = "rvct" ] ; then \ + echo "../src/configure --target=$(TOOLCHAIN) --libc=$(ALT_LIBC)"; \ + ../src/configure --target=$(TOOLCHAIN) --libc=$(ALT_LIBC); \ + else \ + echo "../src/configure --target=$(TOOLCHAIN)"; \ + ../src/configure --target=$(TOOLCHAIN); \ + fi; \ + $(if $(filter vs%,$(TGT_CC)),make NO_LAUNCH_DEVENV=1;) \ + fi + @if [ -d "$(DIST_DIR)" ]; then \ + echo " [MD5SUM] $(DIST_DIR)"; \ + cd $(DIST_DIR) && \ + $(md5sum) `find . -name md5sums.txt -prune -o -type f -print` \ + | sed -e 's/MD5(\(.*\))= \([0-9a-f]\{32\}\)/\2 \1/' \ + > md5sums.txt;\ + fi + + +svnstat: ALL_TARGETS:=$(firstword $(ALL_TARGETS)) +endif + +ifneq ($(target),) +# Normally, we want to build the filename from the target and the toolchain. +# This disambiguates from the $(target).mk file that exists in the source tree. +# However, the toolchain is part of the target in universal builds, so we +# don't want to include TOOLCHAIN in that case. FAT_ARCHS is used to test +# if we're in the universal case. +include $(target)$(if $(FAT_ARCHS),,-$(TOOLCHAIN)).mk +endif +BUILD_ROOT?=. +VPATH=$(SRC_PATH_BARE) +CFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH) +ASFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH) +DIST_DIR?=dist +HOSTCC?=gcc +TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN))) +TGT_OS:=$(word 2, $(subst -, ,$(TOOLCHAIN))) +TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN))) +quiet:=$(if $(verbose),,yes) +qexec=$(if $(quiet),@) + +# Cancel built-in implicit rules +%: %.o +%.asm: +%.a: + +# +# Common rules" +# +.PHONY: all-$(target) +all-$(target): + +.PHONY: clean +clean:: + rm -f $(OBJS-yes) $(OBJS-yes:.o=.d) $(OBJS-yes:.asm.s.o=.asm.s) + rm -f $(CLEAN-OBJS) + +.PHONY: install +install: +.PHONY: install-helper +install-helper: + +$(BUILD_PFX)%.c.d: %.c + $(if $(quiet),@echo " [DEP] $@") + $(qexec)mkdir -p $(dir $@) + $(qexec)$(CC) $(CFLAGS) -M $< | $(fmt_deps) > $@ + +$(BUILD_PFX)%.c.o: %.c + $(if $(quiet),@echo " [CC] $@") + $(qexec)$(CC) $(CFLAGS) -c -o $@ $< + +$(BUILD_PFX)%.asm.d: %.asm + $(if $(quiet),@echo " [DEP] $@") + $(qexec)mkdir -p $(dir $@) + $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \ + --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@ + +$(BUILD_PFX)%.asm.o: %.asm + $(if $(quiet),@echo " [AS] $@") + $(qexec)$(AS) $(ASFLAGS) -o $@ $< + +$(BUILD_PFX)%.s.d: %.s + $(if $(quiet),@echo " [DEP] $@") + $(qexec)mkdir -p $(dir $@) + $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \ + --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@ + +$(BUILD_PFX)%.s.o: %.s + $(if $(quiet),@echo " [AS] $@") + $(qexec)$(AS) $(ASFLAGS) -o $@ $< + +.PRECIOUS: %.asm.s +$(BUILD_PFX)%.asm.s: %.asm + $(if $(quiet),@echo " [ASM CONVERSION] $@") + $(qexec)mkdir -p $(dir $@) + $(qexec)$(ASM_CONVERSION) <$< >$@ + +# If we're in debug mode, pretend we don't have GNU strip, to fall back to +# the copy implementation +HAVE_GNU_STRIP := $(if $(CONFIG_DEBUG),,$(HAVE_GNU_STRIP)) +ifeq ($(HAVE_GNU_STRIP),yes) +# Older binutils strip global sybols not needed for relocation processing +# when given --strip-unneeded. Use nm and awk to identify globals and +# keep them. +%.a: %_g.a + $(if $(quiet),@echo " [STRIP] $@ < $<") + $(qexec)$(STRIP) --strip-unneeded \ + `$(NM) $< | grep ' [A-TV-Z] ' | awk '{print "-K"$$3'}`\ + -o $@ $< +else +%.a: %_g.a + $(if $(quiet),@echo " [CP] $@ < $<") + $(qexec)cp $< $@ +endif + +# +# Rule to extract assembly constants from C sources +# +obj_int_extract: build/make/obj_int_extract.c + $(if $(quiet),echo " [HOSTCC] $@") + $(qexec)$(HOSTCC) -I. -o $@ $< +CLEAN-OBJS += obj_int_extract + +# +# Utility functions +# +pairmap=$(if $(strip $(2)),\ + $(call $(1),$(word 1,$(2)),$(word 2,$(2)))\ + $(call pairmap,$(1),$(wordlist 3,$(words $(2)),$(2)))\ +) + +enabled=$(filter-out $($(1)-no),$($(1)-yes)) +cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2))) + +find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2))))) +find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) ) +obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o +objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) )) + +install_map_templates=$(eval $(call install_map_template,$(1),$(2))) + +not=$(subst yes,no,$(1)) + +ifeq ($(CONFIG_MSVS),yes) +lib_file_name=$(1).lib +else +lib_file_name=lib$(1).a +endif +# +# Rule Templates +# +define linker_template +$(1): $(filter-out -%,$(2)) +$(1): + $(if $(quiet),@echo " [LD] $$@") + $(qexec)$$(LD) $$(strip $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs)) +endef +# make-3.80 has a bug with expanding large input strings to the eval function, +# which was triggered in some cases by the following component of +# linker_template: +# $(1): $$(call find_file, $(patsubst -l%,lib%.a,$(filter -l%,$(2))),\ +# $$(patsubst -L%,%,$$(filter -L%,$$(LDFLAGS) $(2)))) +# This may be useful to revisit in the future (it tries to locate libraries +# in a search path and add them as prerequisites + +define install_map_template +$(DIST_DIR)/$(1): $(2) + $(if $(quiet),@echo " [INSTALL] $$@") + $(qexec)mkdir -p $$(dir $$@) + $(qexec)cp -p $$< $$@ +endef + +define archive_template +# Not using a pattern rule here because we don't want to generate empty +# archives when they are listed as a dependency in files not responsible +# for creating them. +$(1): + $(if $(quiet),@echo " [AR] $$@") + $(qexec)$$(AR) $$(ARFLAGS) $$@ $$? +endef + +define lipo_lib_template +$(1): $(addsuffix /$(1),$(FAT_ARCHS)) + $(if $(quiet),@echo " [LIPO] $$@") + $(qexec)libtool -static -o $$@ $$? +endef + +define lipo_bin_template +$(1): $(addsuffix /$(1),$(FAT_ARCHS)) + $(if $(quiet),@echo " [LIPO] $$@") + $(qexec)lipo -output $$@ -create $$? +endef + + +# +# Get current configuration +# +ifneq ($(target),) +include $(SRC_PATH_BARE)/$(target:-$(TOOLCHAIN)=).mk +endif +ifeq ($(filter clean,$(MAKECMDGOALS)),) + # Older versions of make don't like -include directives with no arguments + ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),) + -include $(filter %.d,$(OBJS-yes:.o=.d)) + endif +endif + +# +# Configuration dependant rules +# +$(call pairmap,install_map_templates,$(INSTALL_MAPS)) + +DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,DOCS) +.docs: $(DOCS) + @touch $@ + +INSTALL-DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,INSTALL-DOCS) +.install-docs: .docs $(addprefix $(DIST_DIR)/,$(INSTALL-DOCS)) + @touch $@ + +clean:: + rm -f .docs .install-docs $(DOCS) + +BINS=$(call enabled,BINS) +.bins: $(BINS) + @touch $@ + +INSTALL-BINS=$(call cond_enabled,CONFIG_INSTALL_BINS,INSTALL-BINS) +.install-bins: .bins $(addprefix $(DIST_DIR)/,$(INSTALL-BINS)) + @touch $@ + +clean:: + rm -f .bins .install-bins $(BINS) + +LIBS=$(call enabled,LIBS) +.libs: $(LIBS) + @touch $@ +$(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib)))) + +INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS) +.install-libs: .libs $(addprefix $(DIST_DIR)/,$(INSTALL-LIBS)) + @touch $@ + +clean:: + rm -f .libs .install-libs $(LIBS) + +ifeq ($(CONFIG_EXTERNAL_BUILD),yes) +PROJECTS=$(call enabled,PROJECTS) +.projects: $(PROJECTS) + @touch $@ + +INSTALL-PROJECTS=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,INSTALL-PROJECTS) +.install-projects: .projects $(addprefix $(DIST_DIR)/,$(INSTALL-PROJECTS)) + @touch $@ + +clean:: + rm -f .projects .install-projects $(PROJECTS) +endif + +# If there are any source files to be installed, then include the build +# system too. +ifneq ($(call enabled,INSTALL-SRCS),) + INSTALL-SRCS-yes += configure + INSTALL-SRCS-yes += build/make/configure.sh + INSTALL-SRCS-yes += build/make/gen_asm_deps.sh + INSTALL-SRCS-yes += build/make/Makefile + INSTALL-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_def.sh + INSTALL-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_proj.sh + INSTALL-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_sln.sh + INSTALL-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh + # + # This isn't really ARCH_ARM dependent, it's dependant on whether we're + # using assembly code or not (CONFIG_OPTIMIZATIONS maybe). Just use + # this for now. + INSTALL-SRCS-$(ARCH_ARM) += build/make/obj_int_extract.c + INSTALL-SRCS-$(ARCH_ARM) += build/make/ads2gas.pl + INSTALL-SRCS-yes += $(target:-$(TOOLCHAIN)=).mk +endif +INSTALL-SRCS := $(call cond_enabled,CONFIG_INSTALL_SRCS,INSTALL-SRCS) +.install-srcs: $(addprefix $(DIST_DIR)/src/,$(INSTALL-SRCS)) + @touch $@ + +clean:: + rm -f .install-srcs + +ifeq ($(CONFIG_EXTERNAL_BUILD),yes) + BUILD_TARGETS += .projects + INSTALL_TARGETS += .install-projects +endif +BUILD_TARGETS += .docs .libs .bins +INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins +all-$(target): $(BUILD_TARGETS) +install: $(INSTALL_TARGETS) + +# +# Development helper targets +# +ifneq ($(SRC_PATH_BARE),) +.PHONY: svnstat +svnstat: + svn stat $(SRC_PATH_BARE) +endif diff --git a/build/make/ads2gas.pl b/build/make/ads2gas.pl new file mode 100755 index 000000000..6fcba8462 --- /dev/null +++ b/build/make/ads2gas.pl @@ -0,0 +1,149 @@ +#!/usr/bin/perl +## +## Copyright (c) 2010 The VP8 project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license and patent +## grant that can be found in the LICENSE file in the root of the source +## tree. All contributing project authors may be found in the AUTHORS +## file in the root of the source tree. +## + + +# ads2gas.pl +# Author: Eric Fung (efung (at) acm.org) +# +# Convert ARM Developer Suite 1.0.1 syntax assembly source to GNU as format +# +# Usage: cat inputfile | perl ads2gas.pl > outputfile +# +print "@ This file was created from a .asm file\n"; +print "@ using the ads2gas.pl script.\n"; +print "\t.equ DO1STROUNDING, 0\n"; + +while (<STDIN>) +{ + # Comment character + s/;/@/g; + + # Hexadecimal constants prefaced by 0x + s/#&/#0x/g; + + # Convert :OR: to | + s/:OR:/ | /g; + + # Convert :AND: to & + s/:AND:/ & /g; + + # Convert :NOT: to ~ + s/:NOT:/ ~ /g; + + # Convert :SHL: to << + s/:SHL:/ << /g; + + # Convert :SHR: to >> + s/:SHR:/ >> /g; + + # Convert ELSE to .else + s/ELSE/.else/g; + + # Convert ENDIF to .endif + s/ENDIF/.endif/g; + + # Convert ELSEIF to .elseif + s/ELSEIF/.elseif/g; + + # Convert LTORG to .ltorg + s/LTORG/.ltorg/g; + + # Convert IF :DEF:to .if + # gcc doesn't have the ability to do a conditional + # if defined variable that is set by IF :DEF: on + # armasm, so convert it to a normal .if and then + # make sure to define a value elesewhere + if (s/\bIF :DEF:\b/.if /g) + { + s/=/==/g; + } + + # Convert IF to .if + if (s/\bIF\b/.if/g) + { + s/=+/==/g; + } + + # Convert INCLUDE to .INCLUDE "file" + s/INCLUDE(\s*)(.*)$/.include $1\"$2\"/; + + # Code directive (ARM vs Thumb) + s/CODE([0-9][0-9])/.code $1/; + + # No AREA required + s/^\s*AREA.*$/.text/; + + # DCD to .word + # This one is for incoming symbols + s/DCD\s+\|(\w*)\|/.long $1/; + + # DCW to .short + s/DCW\s+\|(\w*)\|/.short $1/; + s/DCW(.*)/.short $1/; + + # Constants defined in scope + s/DCD(.*)/.long $1/; + s/DCB(.*)/.byte $1/; + + # RN to .req + if (s/RN\s+([Rr]\d+|lr)/.req $1/) + { + print; + next; + } + + # Make function visible to linker, and make additional symbol with + # prepended underscore + s/EXPORT\s+\|([\$\w]*)\|/.global $1 \n\t.type $1, function/; + s/IMPORT\s+\|([\$\w]*)\|/.global $1/; + + # No vertical bars required; make additional symbol with prepended + # underscore + s/^\|(\$?\w+)\|/_$1\n\t$1:/g; + + # Labels need trailing colon +# s/^(\w+)/$1:/ if !/EQU/; + # put the colon at the end of the line in the macro + s/^([a-zA-Z_0-9\$]+)/$1:/ if !/EQU/; + + # Strip ALIGN + s/\sALIGN/@ ALIGN/g; + + # Strip ARM + s/\sARM/@ ARM/g; + + # Strip REQUIRE8 + #s/\sREQUIRE8/@ REQUIRE8/g; + s/\sREQUIRE8/@ /g; #EQU cause problem + + # Strip PRESERVE8 + s/\sPRESERVE8/@ PRESERVE8/g; + + # Strip PROC and ENDPROC + s/\sPROC/@/g; + s/\sENDP/@/g; + + # EQU directive + s/(.*)EQU(.*)/.equ $1, $2/; + + # Begin macro definition + if (/MACRO/) { + $_ = <STDIN>; + s/^/.macro/; + s/\$//g; # remove formal param reference + s/;/@/g; # change comment characters + } + + # For macros, use \ to reference formal params + s/\$/\\/g; # End macro definition + s/MEND/.endm/; # No need to tell it where to stop assembling + next if /^\s*END\s*$/; + print; +} diff --git a/build/make/ads2gas_apple.pl b/build/make/ads2gas_apple.pl new file mode 100755 index 000000000..569c3e762 --- /dev/null +++ b/build/make/ads2gas_apple.pl @@ -0,0 +1,194 @@ +#!/usr/bin/env perl +## +## Copyright (c) 2010 The VP8 project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license and patent +## grant that can be found in the LICENSE file in the root of the source +## tree. All contributing project authors may be found in the AUTHORS +## file in the root of the source tree. +## + + +# ads2gas.pl +# Author: Eric Fung (efung (at) acm.org) +# +# Convert ARM Developer Suite 1.0.1 syntax assembly source to GNU as format +# +# Usage: cat inputfile | perl ads2gas.pl > outputfile +# +print "@ This file was created from a .asm file\n"; +print "@ using the ads2gas_apple.pl script.\n\n"; +print "\t.set WIDE_REFERENCE, 0\n"; +print "\t.set ARCHITECTURE, 5\n"; +print "\t.set DO1STROUNDING, 0\n"; + +my %register_aliases; +my %macro_aliases; + +my @mapping_list = ("\$0", "\$1", "\$2", "\$3", "\$4", "\$5", "\$6", "\$7", "\$8", "\$9"); + +my @incoming_array; + +# Perl trim function to remove whitespace from the start and end of the string +sub trim($) +{ + my $string = shift; + $string =~ s/^\s+//; + $string =~ s/\s+$//; + return $string; +} + +while (<STDIN>) +{ + # Comment character + s/;/@/g; + + # Hexadecimal constants prefaced by 0x + s/#&/#0x/g; + + # Convert :OR: to | + s/:OR:/ | /g; + + # Convert :AND: to & + s/:AND:/ & /g; + + # Convert :NOT: to ~ + s/:NOT:/ ~ /g; + + # Convert :SHL: to << + s/:SHL:/ << /g; + + # Convert :SHR: to >> + s/:SHR:/ >> /g; + + # Convert ELSE to .else + s/ELSE/.else/g; + + # Convert ENDIF to .endif + s/ENDIF/.endif/g; + + # Convert ELSEIF to .elseif + s/ELSEIF/.elseif/g; + + # Convert LTORG to .ltorg + s/LTORG/.ltorg/g; + + # Convert IF :DEF:to .if + # gcc doesn't have the ability to do a conditional + # if defined variable that is set by IF :DEF: on + # armasm, so convert it to a normal .if and then + # make sure to define a value elesewhere + if (s/\bIF :DEF:\b/.if /g) + { + s/=/==/g; + } + + # Convert IF to .if + if (s/\bIF\b/.if/g) + { + s/=/==/g; + } + + # Convert INCLUDE to .INCLUDE "file" + s/INCLUDE(\s*)(.*)$/.include $1\"$2\"/; + + # Code directive (ARM vs Thumb) + s/CODE([0-9][0-9])/.code $1/; + + # No AREA required + s/^\s*AREA.*$/.text/; + + # DCD to .word + # This one is for incoming symbols + s/DCD\s+\|(\w*)\|/.long $1/; + + # DCW to .short + s/DCW\s+\|(\w*)\|/.short $1/; + s/DCW(.*)/.short $1/; + + # Constants defined in scope + s/DCD(.*)/.long $1/; + s/DCB(.*)/.byte $1/; + + # Build a hash of all the register - alias pairs. + if (s/(.*)RN(.*)/$1 .req $2/g) + { + $register_aliases{trim($1)} = trim($2); + next; + } + + while (($key, $value) = each(%register_aliases)) + { + s/\b$key\b/$value/g; + } + + # Make function visible to linker, and make additional symbol with + # prepended underscore + s/EXPORT\s+\|([\$\w]*)\|/.globl _$1\n\t.globl $1/; + s/IMPORT\s+\|([\$\w]*)\|/.globl $1/; + + # No vertical bars required; make additional symbol with prepended + # underscore + s/^\|(\$?\w+)\|/_$1\n\t$1:/g; + + # Labels need trailing colon +# s/^(\w+)/$1:/ if !/EQU/; + # put the colon at the end of the line in the macro + s/^([a-zA-Z_0-9\$]+)/$1:/ if !/EQU/; + + # Strip ALIGN + s/\sALIGN/@ ALIGN/g; + + # Strip ARM + s/\sARM/@ ARM/g; + + # Strip REQUIRE8 + #s/\sREQUIRE8/@ REQUIRE8/g; + s/\sREQUIRE8/@ /g; + + # Strip PRESERVE8 + s/\sPRESERVE8/@ PRESERVE8/g; + + # Strip PROC and ENDPROC + s/PROC/@/g; + s/ENDP/@/g; + + # EQU directive + s/(.*)EQU(.*)/.set $1, $2/; + + # Begin macro definition + if (/MACRO/) + { + # Process next line down, which will be the macro definition + $_ = <STDIN>; + + $trimmed = trim($_); + + # remove commas that are separating list + $trimmed =~ s/,//g; + + # string to array + @incoming_array = split(/ /, $trimmed); + + print ".macro @incoming_array[0]\n"; + + # remove the first element, as that is the name of the macro + shift (@incoming_array); + + @macro_aliases{@incoming_array} = @mapping_list; + + next; + } + + while (($key, $value) = each(%macro_aliases)) + { + $key =~ s/\$/\\\$/; + s/$key\b/$value/g; + } + + # For macros, use \ to reference formal params +# s/\$/\\/g; # End macro definition + s/MEND/.endm/; # No need to tell it where to stop assembling + next if /^\s*END\s*$/; + print; +} diff --git a/build/make/armlink_adapter.sh b/build/make/armlink_adapter.sh new file mode 100755 index 000000000..dcaa82ca6 --- /dev/null +++ b/build/make/armlink_adapter.sh @@ -0,0 +1,51 @@ +#!/bin/bash +## +## Copyright (c) 2010 The VP8 project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license and patent +## grant that can be found in the LICENSE file in the root of the source +## tree. All contributing project authors may be found in the AUTHORS +## file in the root of the source tree. +## + + +verbose=0 +set -- $* +for i; do + if [ "$i" == "-o" ]; then + on_of=1 + elif [ "$i" == "-v" ]; then + verbose=1 + elif [ "$on_of" == "1" ]; then + outfile=$i + on_of=0 + elif [ -f "$i" ]; then + infiles="$infiles $i" + elif [ "${i:0:2}" == "-l" ]; then + libs="$libs ${i#-l}" + elif [ "${i:0:2}" == "-L" ]; then + libpaths="${libpaths} ${i#-L}" + else + args="${args} ${i}" + fi + shift +done + +# Absolutize library file names +for f in $libs; do + found=0 + for d in $libpaths; do + [ -f "$d/$f" ] && infiles="$infiles $d/$f" && found=1 && break + [ -f "$d/lib${f}.so" ] && infiles="$infiles $d/lib${f}.so" && found=1 && break + [ -f "$d/lib${f}.a" ] && infiles="$infiles $d/lib${f}.a" && found=1 && break + done + [ $found -eq 0 ] && infiles="$infiles $f" +done +for d in $libpaths; do + [ -n "$libsearchpath" ] && libsearchpath="${libsearchpath}," + libsearchpath="${libsearchpath}$d" +done + +cmd="armlink $args --userlibpath=$libsearchpath --output=$outfile $infiles" +[ $verbose -eq 1 ] && echo $cmd +$cmd diff --git a/build/make/configure.sh b/build/make/configure.sh new file mode 100755 index 000000000..ed3a34f78 --- /dev/null +++ b/build/make/configure.sh @@ -0,0 +1,907 @@ +#!/bin/bash +## +## Copyright (c) 2010 The VP8 project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license and patent +## grant that can be found in the LICENSE file in the root of the source +## tree. All contributing project authors may be found in the AUTHORS +## file in the root of the source tree. +## + + + +# +# Logging / Output Functions +# +die_unknown(){ + echo "Unknown option \"$1\"." + echo "See $0 --help for available options." + clean_temp_files + exit 1 +} + + +die() { + echo "$@" + echo + echo "Configuration failed. This could reflect a misconfiguration of your" + echo "toolchains, improper options selected, or another problem. If you" + echo "don't see any useful error messages above, the next step is to look" + echo "at the configure error log file ($logfile) to determine what" + echo "configure was trying to do when it died." + clean_temp_files + exit 1 +} + + +log(){ + echo "$@" >>$logfile +} + + +log_file(){ + log BEGIN $1 + pr -n -t $1 >>$logfile + log END $1 +} + + +log_echo() { + echo "$@" + log "$@" +} + + +fwrite () { + outfile=$1 + shift + echo "$@" >> ${outfile} +} + + +show_help_pre(){ + for opt in ${CMDLINE_SELECT}; do + opt2=`echo $opt | sed -e 's;_;-;g'` + if enabled $opt; then + eval "toggle_${opt}=\"--disable-${opt2}\"" + else + eval "toggle_${opt}=\"--enable-${opt2} \"" + fi + done + + cat <<EOF +Usage: configure [options] +Options: + +Build options: + --help print this message + --log=yes|no|FILE file configure log is written to [config.err] + --target=TARGET target platform tuple [generic-gnu] + --cpu=CPU optimize for a specific cpu rather than a family + ${toggle_extra_warnings} emit harmless warnings (always non-fatal) + ${toggle_werror} treat warnings as errors, if possible + (not available with all compilers) + ${toggle_optimizations} turn on/off compiler optimization flags + ${toggle_pic} turn on/off Position Independant Code + ${toggle_ccache} turn on/off compiler cache + ${toggle_debug} enable/disable debug mode + ${toggle_gprof} enable/disable gprof profiling instrumentation + ${toggle_gcov} enable/disable gcov coverage instrumentation + +Install options: + ${toggle_install_docs} control whether docs are installed + ${toggle_install_bins} control whether binaries are installed + ${toggle_install_libs} control whether libraries are installed + ${toggle_install_srcs} control whether sources are installed + + +EOF +} + + +show_help_post(){ + cat <<EOF + + +NOTES: + Object files are built at the place where configure is launched. + + All boolean options can be negated. The default value is the opposite + of that shown above. If the option --disable-foo is listed, then + the default value for foo is enabled. + +Supported targets: +EOF + show_targets ${all_platforms} + echo + exit 1 +} + + +show_targets() { + while [ -n "$*" ]; do + if [ "${1%%-*}" == "${2%%-*}" ]; then + if [ "${2%%-*}" == "${3%%-*}" ]; then + printf " %-24s %-24s %-24s\n" "$1" "$2" "$3" + shift; shift; shift + else + printf " %-24s %-24s\n" "$1" "$2" + shift; shift + fi + else + printf " %-24s\n" "$1" + shift + fi + done +} + + +show_help() { + show_help_pre + show_help_post +} + +# +# List Processing Functions +# +set_all(){ + value=$1 + shift + for var in $*; do + eval $var=$value + done +} + + +is_in(){ + value=$1 + shift + for var in $*; do + [ $var = $value ] && return 0 + done + return 1 +} + + +add_cflags() { + CFLAGS="${CFLAGS} $@" +} + + +add_ldflags() { + LDFLAGS="${LDFLAGS} $@" +} + + +add_asflags() { + ASFLAGS="${ASFLAGS} $@" +} + + +add_extralibs() { + extralibs="${extralibs} $@" +} + +# +# Boolean Manipulation Functions +# +enable(){ + set_all yes $* +} + +disable(){ + set_all no $* +} + +enabled(){ + eval test "x\$$1" = "xyes" +} + +disabled(){ + eval test "x\$$1" = "xno" +} + + +soft_enable() { + for var in $*; do + if ! disabled $var; then + log_echo " enabling $var" + enable $var + fi + done +} + +soft_disable() { + for var in $*; do + if ! enabled $var; then + log_echo " disabling $var" + disable $var + fi + done +} + + +# +# Text Processing Functions +# +toupper(){ + echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ +} + + +tolower(){ + echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz +} + + +# +# Temporary File Functions +# +source_path=${0%/*} +enable source_path_used +if test -z "$source_path" -o "$source_path" = "." ; then + source_path="`pwd`" + disable source_path_used +fi + +if test ! -z "$TMPDIR" ; then + TMPDIRx="${TMPDIR}" +elif test ! -z "$TEMPDIR" ; then + TMPDIRx="${TEMPDIR}" +else + TMPDIRx="/tmp" +fi +TMP_H="${TMPDIRx}/vpx-conf-$$-${RANDOM}.h" +TMP_C="${TMPDIRx}/vpx-conf-$$-${RANDOM}.c" +TMP_O="${TMPDIRx}/vpx-conf-$$-${RANDOM}.o" +TMP_X="${TMPDIRx}/vpx-conf-$$-${RANDOM}.x" + +clean_temp_files() { + rm -f ${TMP_C} ${TMP_H} ${TMP_O} ${TMP_X} +} + +# +# Toolchain Check Functions +# +check_cmd() { + log "$@" + "$@" >>${logfile} 2>&1 +} + +check_cc() { + log check_cc "$@" + cat >${TMP_C} + log_file ${TMP_C} + check_cmd ${CC} ${CFLAGS} "$@" -c -o ${TMP_O} ${TMP_C} +} + +check_cpp() { + log check_cpp "$@" + cat > ${TMP_C} + log_file ${TMP_C} + check_cmd ${CC} ${CFLAGS} "$@" -E -o ${TMP_O} ${TMP_C} +} + +check_ld() { + log check_ld "$@" + check_cc $@ \ + && check_cmd ${LD} ${LDFLAGS} "$@" -o ${TMP_X} ${TMP_O} ${extralibs} +} + +check_header(){ + log check_header "$@" + header=$1 + shift + var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'` + disable $var + check_cpp "$@" <<EOF && enable $var +#include "$header" +int x; +EOF +} + + +check_cflags() { + log check_cflags "$@" + check_cc "$@" <<EOF +int x; +EOF +} + +check_add_cflags() { + check_cflags "$@" && add_cflags "$@" +} + +check_add_asflags() { + log add_asflags "$@" + add_asflags "$@" +} + +check_add_ldflags() { + log add_ldflags "$@" + add_ldflags "$@" +} + +write_common_config_banner() { + echo '# This file automatically generated by configure. Do not edit!' > config.mk + echo "TOOLCHAIN := ${toolchain}" >> config.mk + + case ${toolchain} in + *-linux-rvct) + echo "ALT_LIBC := ${alt_libc}" >> config.mk + ;; + esac +} + +write_common_config_targets() { + for t in ${all_targets}; do + if enabled ${t}; then + if enabled universal || enabled child; then + fwrite config.mk "ALL_TARGETS += ${t}-${toolchain}" + else + fwrite config.mk "ALL_TARGETS += ${t}" + fi + fi + true; + done +true +} + +write_common_target_config_mk() { + [ -n "$2" ] && local have_config_h="-DHAVE_CONFIG_H=\"${2##*/}\"" + local CC=${CC} + enabled ccache && CC="ccache ${CC}" + + cat > $1 << EOF +# This file automatically generated by configure. Do not edit! +SRC_PATH="$source_path" +SRC_PATH_BARE=$source_path +BUILD_PFX=${BUILD_PFX} +TOOLCHAIN=${toolchain} +ASM_CONVERSION=${asm_conversion_cmd:-${source_path}/build/make/ads2gas.pl} + +CC=${CC} +AR=${AR} +LD=${LD} +AS=${AS} +STRIP=${STRIP} +NM=${NM} + +CFLAGS = ${CFLAGS} ${have_config_h} +ARFLAGS = -rus\$(if \$(quiet),c,v) +LDFLAGS = ${LDFLAGS} +ASFLAGS = ${ASFLAGS} +extralibs = ${extralibs} +AS_SFX = ${AS_SFX:-.asm} +EOF + + if enabled rvct; then cat >> $1 << EOF +fmt_deps = sed -e 's;^__image.axf;\$(dir \$@)\$(notdir \$<).o \$@;' #hide +EOF + else cat >> $1 << EOF +fmt_deps = sed -e 's;^\(.*\)\.o;\$(dir \$@)\1\$(suffix \$<).o \$@;' #hide +EOF + fi + + print_config_mk ARCH "${1}" ${ARCH_LIST} + print_config_mk HAVE "${1}" ${HAVE_LIST} + print_config_mk CONFIG "${1}" ${CONFIG_LIST} + print_config_mk HAVE "${1}" gnu_strip + + enabled msvs && echo "CONFIG_VS_VERSION=${vs_version}" >> "${1}" + +} + + +write_common_target_config_h() { + cat > ${TMP_H} << EOF +/* This file automatically generated by configure. Do not edit! */ +#define INLINE ${INLINE} +#define FORCEINLINE ${FORCEINLINE:-${INLINE}} +#define RESTRICT ${RESTRICT} +EOF + print_config_h ARCH "${TMP_H}" ${ARCH_LIST} + print_config_h HAVE "${TMP_H}" ${HAVE_LIST} + print_config_h CONFIG "${TMP_H}" ${CONFIG_LIST} + mkdir -p `dirname "$1"` + cmp "$1" ${TMP_H} >/dev/null 2>&1 || mv ${TMP_H} "$1" +} + +process_common_cmdline() { + for opt in "$@"; do + optval="${opt#*=}" + case "$opt" in + --child) enable child + ;; + --log*) + logging="$optval" + if ! disabled logging ; then + enabled logging || logfile="$logging" + else + logfile=/dev/null + fi + ;; + --target=*) toolchain="${toolchain:-${optval}}" + ;; + --force-target=*) toolchain="${toolchain:-${optval}}"; enable force_toolchain + ;; + --cpu) + ;; + --cpu=*) tune_cpu="$optval" + ;; + --enable-?*|--disable-?*) + eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'` + echo "${CMDLINE_SELECT} ${ARCH_EXT_LIST}" | grep "^ *$option\$" >/dev/null || die_unknown $opt + $action $option + ;; + --force-enable-?*|--force-disable-?*) + eval `echo "$opt" | sed 's/--force-/action=/;s/-/ option=/;s/-/_/g'` + $action $option + ;; + --libc=*) + [ -d "${optval}" ] || die "Not a directory: ${optval}" + disable builtin_libc + alt_libc="${optval}" + ;; + --libc) + die "Option ${opt} requires argument" + ;; + --help|-h) show_help + ;; + *) die_unknown $opt + ;; + esac + done +} + +process_cmdline() { + for opt do + optval="${opt#*=}" + case "$opt" in + *) process_common_cmdline $opt + ;; + esac + done +} + +post_process_cmdline() { + true; +} + +setup_gnu_toolchain() { + CC=${CC:-${CROSS}gcc} + AR=${AR:-${CROSS}ar} + LD=${LD:-${CROSS}${link_with_cc:-ld}} + AS=${AS:-${CROSS}as} + STRIP=${STRIP:-${CROSS}strip} + NM=${NM:-${CROSS}nm} + AS_SFX=.s +} + +process_common_toolchain() { + toolchain=${toolchain:-generic-gnu} + + is_in ${toolchain} ${all_platforms} || enabled force_toolchain \ + || die "Unrecognized toolchain '${toolchain}'" + + enabled child || log_echo "Configuring for target '${toolchain}'" + + # + # Set up toolchain variables + # + tgt_isa=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $1}') + tgt_os=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $2}') + tgt_cc=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $3}') + + # Mark the specific ISA requested as enabled + soft_enable ${tgt_isa} + enable ${tgt_os} + enable ${tgt_cc} + + # Enable the architecture family + case ${tgt_isa} in + arm*|iwmmxt*) enable arm;; + mips*) enable mips;; + esac + + # Handle darwin variants + case ${toolchain} in + *-darwin8-gcc) + add_cflags "-isysroot /Developer/SDKs/MacOSX10.4u.sdk" + add_cflags "-mmacosx-version-min=10.4" + add_ldflags "-isysroot /Developer/SDKs/MacOSX10.4u.sdk" + add_ldflags "-mmacosx-version-min=10.4" + ;; + *-darwin9-gcc) + add_cflags "-isysroot /Developer/SDKs/MacOSX10.5.sdk" + add_cflags "-mmacosx-version-min=10.5" + add_ldflags "-isysroot /Developer/SDKs/MacOSX10.5.sdk" + add_ldflags "-mmacosx-version-min=10.5" + ;; + esac + + # Process ARM architecture variants + case ${toolchain} in + arm*|iwmmxt*) + # on arm, isa versions are supersets + enabled armv7a && soft_enable armv7 ### DEBUG + enabled armv7 && soft_enable armv6 + enabled armv6 && soft_enable armv5te + enabled armv6 && soft_enable fast_unaligned + enabled iwmmxt2 && soft_enable iwmmxt + enabled iwmmxt && soft_enable armv5te + + asm_conversion_cmd="cat" + + case ${tgt_cc} in + gcc) + if enabled iwmmxt || enabled iwmmxt2 + then + CROSS=${CROSS:-arm-iwmmxt-linux-gnueabi-} + elif enabled symbian; then + CROSS=${CROSS:-arm-none-symbianelf-} + else + CROSS=${CROSS:-arm-none-linux-gnueabi-} + fi + link_with_cc=gcc + setup_gnu_toolchain + arch_int=${tgt_isa##armv} + arch_int=${arch_int%%te} + check_add_asflags --defsym ARCHITECTURE=${arch_int} + tune_cflags="-mtune=" + if enabled iwmmxt || enabled iwmmxt2 + then + check_add_asflags -mcpu=${tgt_isa} + elif enabled armv7 + then + check_add_cflags -march=armv7-a -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp #-ftree-vectorize + check_add_asflags -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp #-march=armv7-a + else + check_add_cflags -march=${tgt_isa} + check_add_asflags -march=${tgt_isa} + fi + + asm_conversion_cmd="${source_path}/build/make/ads2gas.pl" + ;; + rvct) + CC=armcc + AR=armar + AS=armasm + LD=${source_path}/build/make/armlink_adapter.sh + STRIP=arm-none-linux-gnueabi-strip + NM=arm-none-linux-gnueabi-nm + tune_cflags="--cpu=" + tune_asflags="--cpu=" + if [ -z "${tune_cpu}" ]; then + if enabled armv7 + then + check_add_cflags --cpu=Cortex-A8 --fpu=softvfp+vfpv3 + check_add_asflags --cpu=Cortex-A8 --fpu=none + else + check_add_cflags --cpu=${tgt_isa##armv} + check_add_asflags --cpu=${tgt_isa##armv} + fi + fi + arch_int=${tgt_isa##armv} + arch_int=${arch_int%%te} + check_add_asflags --pd "\"ARCHITECTURE SETA ${arch_int}\"" + ;; + esac + + case ${tgt_os} in + darwin*) + SDK_PATH=/Developer/Platforms/iPhoneOS.platform/Developer + TOOLCHAIN_PATH=${SDK_PATH}/usr/bin + CC=${TOOLCHAIN_PATH}/gcc + AR=${TOOLCHAIN_PATH}/ar + LD=${TOOLCHAIN_PATH}/arm-apple-darwin9-gcc-4.2.1 + AS=${TOOLCHAIN_PATH}/as + STRIP=${TOOLCHAIN_PATH}/strip + NM=${TOOLCHAIN_PATH}/nm + AS_SFX=.s + + # ASFLAGS is written here instead of using check_add_asflags + # because we need to overwrite all of ASFLAGS and purge the + # options that were put in above + ASFLAGS="-version -arch ${tgt_isa} -g" + + add_cflags -arch ${tgt_isa} + add_ldflags -arch_only ${tgt_isa} + + add_cflags "-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk" + + # This should be overridable + alt_libc=${SDK_PATH}/SDKs/iPhoneOS3.1.sdk + + # Add the paths for the alternate libc +# for d in usr/include usr/include/gcc/darwin/4.0/; do + for d in usr/include usr/include/gcc/darwin/4.0/ usr/lib/gcc/arm-apple-darwin9/4.0.1/include/; do + try_dir="${alt_libc}/${d}" + [ -d "${try_dir}" ] && add_cflags -I"${try_dir}" + done + + for d in lib usr/lib; do + try_dir="${alt_libc}/${d}" + [ -d "${try_dir}" ] && add_ldflags -L"${try_dir}" + done + + asm_conversion_cmd="${source_path}/build/make/ads2gas_apple.pl" + ;; + + linux*) + enable linux + if enabled rvct; then + # Compiling with RVCT requires an alternate libc (glibc) when + # targetting linux. + disabled builtin_libc \ + || die "Must supply --libc when targetting *-linux-rvct" + + # Set up compiler + add_cflags --gnu + add_cflags --enum_is_int + add_cflags --library_interface=aeabi_glibc + add_cflags --no_hide_all + add_cflags --wchar32 + add_cflags --dwarf2 + add_cflags --gnu + + # Set up linker + add_ldflags --sysv --no_startup --no_ref_cpp_init + add_ldflags --entry=_start + add_ldflags --keep '"*(.init)"' --keep '"*(.fini)"' + add_ldflags --keep '"*(.init_array)"' --keep '"*(.fini_array)"' + add_ldflags --dynamiclinker=/lib/ld-linux.so.3 + add_extralibs libc.so.6 -lc_nonshared crt1.o crti.o crtn.o + + # Add the paths for the alternate libc + for d in usr/include; do + try_dir="${alt_libc}/${d}" + [ -d "${try_dir}" ] && add_cflags -J"${try_dir}" + done + add_cflags -J"${RVCT31INC}" + for d in lib usr/lib; do + try_dir="${alt_libc}/${d}" + [ -d "${try_dir}" ] && add_ldflags -L"${try_dir}" + done + + + # glibc has some struct members named __align, which is a + # storage modifier in RVCT. If we need to use this modifier, + # we'll have to #undef it in our code. Note that this must + # happen AFTER all libc inclues. + add_cflags -D__align=x_align_x + fi + ;; + + symbian*) + enable symbian + # Add the paths for the alternate libc + for d in include/libc; do + try_dir="${alt_libc}/${d}" + [ -d "${try_dir}" ] && add_cflags -I"${try_dir}" + done + for d in release/armv5/urel; do + try_dir="${alt_libc}/${d}" + [ -d "${try_dir}" ] && add_ldflags -L"${try_dir}" + done + add_cflags -DIMPORT_C= + + esac + ;; + mips*) + CROSS=${CROSS:-mipsel-linux-uclibc-} + link_with_cc=gcc + setup_gnu_toolchain + tune_cflags="-mtune=" + check_add_cflags -march=${tgt_isa} + check_add_asflags -march=${tgt_isa} + check_add_asflags -KPIC + ;; + ppc*) + enable ppc + bits=${tgt_isa##ppc} + link_with_cc=gcc + setup_gnu_toolchain + add_asflags -force_cpusubtype_ALL -I"\$(dir \$<)darwin" + add_cflags -maltivec -faltivec + soft_enable altivec + + case "$tgt_os" in + linux*) + add_asflags -maltivec -mregnames -I"\$(dir \$<)linux" + ;; + darwin*) + darwin_arch="-arch ppc" + enabled ppc64 && darwin_arch="${darwin_arch}64" + add_cflags ${darwin_arch} -m${bits} -fasm-blocks + add_asflags ${darwin_arch} -force_cpusubtype_ALL -I"\$(dir \$<)darwin" + add_ldflags ${darwin_arch} -m${bits} + ;; + esac + ;; + x86*) + bits=32 + enabled x86_64 && bits=64 + soft_enable runtime_cpu_detect + soft_enable mmx + soft_enable sse + soft_enable sse2 + soft_enable sse3 + soft_enable ssse3 + + case ${tgt_os} in + solaris*) + CC=${CC:-${CROSS}gcc} + LD=${LD:-${CROSS}gcc} + CROSS=${CROSS:-g} + ;; + esac + + case ${tgt_cc} in + icc*) + CC=${CC:-icc} + LD=${LD:-icc} + setup_gnu_toolchain + add_cflags -use-msasm -use-asm + add_ldflags -i-static + ;; + gcc*) + add_cflags -m${bits} + add_ldflags -m${bits} + link_with_cc=gcc + setup_gnu_toolchain + ;; + esac + + AS=yasm + AS_SFX=.asm + case ${tgt_os} in + win*) + add_asflags -f win${bits} + enabled debug && add_asflags -g dwarf2 + ;; + linux*|solaris*) + add_asflags -f elf${bits} + enabled debug && add_asflags -g dwarf2 + ;; + darwin*) + add_asflags -f macho${bits} + enabled x86 && darwin_arch="-arch i386" || darwin_arch="-arch x86_64" + add_cflags ${darwin_arch} + add_ldflags ${darwin_arch} + # -mdynamic-no-pic is still a bit of voodoo -- it was required at + # one time, but does not seem to be now, and it breaks some of the + # code that still relies on inline assembly. + # enabled icc && ! enabled pic && add_cflags -fno-pic -mdynamic-no-pic + enabled icc && ! enabled pic && add_cflags -fno-pic + ;; + *) log "Warning: Unknown os $tgt_os while setting up yasm flags" + ;; + esac + ;; + universal*|*-gcc|generic-gnu) + link_with_cc=gcc + setup_gnu_toolchain + ;; + esac + + # Try to enable CPU specific tuning + if [ -n "${tune_cpu}" ]; then + if [ -n "${tune_cflags}" ]; then + check_add_cflags ${tune_cflags}${tune_cpu} || \ + die "Requested CPU '${tune_cpu}' not supported by compiler" + fi + if [ -n "${tune_asflags}" ]; then + check_add_asflags ${tune_asflags}${tune_cpu} || \ + die "Requested CPU '${tune_cpu}' not supported by assembler" + fi + if [ -z "${tune_cflags}${tune_asflags}" ]; then + log_echo "Warning: CPU tuning not supported by this toolchain" + fi + fi + + enabled debug && check_add_cflags -g && check_add_ldflags -g + enabled gprof && check_add_cflags -pg && check_add_ldflags -pg + enabled gcov && + check_add_cflags -fprofile-arcs -ftest-coverage && + check_add_ldflags -fprofile-arcs -ftest-coverage + enabled optimizations && check_add_cflags -O3 + if enabled rvct; then + enabled optimizations && check_add_cflags -Otime + fi + + # Position Independant Code (PIC) support, for building relocatable + # shared objects + enabled gcc && enabled pic && check_add_cflags -fPIC + + # Check for strip utility variant + ${STRIP} -V 2>/dev/null | grep GNU >/dev/null && enable gnu_strip + + # Try to determine target endianness + check_cc <<EOF + unsigned int e = 'O'<<24 | '2'<<16 | 'B'<<8 | 'E'; +EOF + [ -f "${TMP_O}" ] && od -A n -t x1 "${TMP_O}" | tr -d '\n' | + grep '4f *32 *42 *45' >/dev/null 2>&1 && enable big_endian + + # Almost every platform uses pthreads. + if enabled multithread; then + case ${toolchain} in + *-win*);; + *) check_header pthread.h && add_extralibs -lpthread + esac + fi + + # glibc needs these + if enabled linux; then + add_cflags -D_LARGEFILE_SOURCE + add_cflags -D_FILE_OFFSET_BITS=64 + fi +} + +process_toolchain() { + process_common_toolchain +} + +print_config_mk() { + prefix=$1 + makefile=$2 + shift 2 + for cfg; do + upname="`toupper $cfg`" + if enabled $cfg; then + echo "${prefix}_${upname}=yes" >> $makefile + fi + done +} + +print_config_h() { + prefix=$1 + header=$2 + shift 2 + for cfg; do + upname="`toupper $cfg`" + if enabled $cfg; then + echo "#define ${prefix}_${upname} 1" >> $header + else + echo "#define ${prefix}_${upname} 0" >> $header + fi + done +} + +process_targets() { + true; +} + +process_detect() { + true; +} + +enable logging +logfile="config.err" +self=$0 +process() { + cmdline_args="$@" + process_cmdline "$@" + if enabled child; then + echo "# ${self} $@" >> ${logfile} + else + echo "# ${self} $@" > ${logfile} + fi + post_process_cmdline + process_toolchain + process_detect + process_targets + + OOT_INSTALLS="${OOT_INSTALLS}" + if enabled source_path_used; then + # Prepare the PWD for building. + for f in ${OOT_INSTALLS}; do + install -D ${source_path}/$f $f + done + fi + cp ${source_path}/build/make/Makefile . + + clean_temp_files + true +} diff --git a/build/make/gen_asm_deps.sh b/build/make/gen_asm_deps.sh new file mode 100755 index 000000000..c1118e1a8 --- /dev/null +++ b/build/make/gen_asm_deps.sh @@ -0,0 +1,63 @@ +#!/bin/bash +## +## Copyright (c) 2010 The VP8 project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license and patent +## grant that can be found in the LICENSE file in the root of the source +## tree. All contributing project authors may be found in the AUTHORS +## file in the root of the source tree. +## + + +self=$0 +show_help() { + echo "usage: $self [options] <srcfile>" + echo + echo "Generate Makefile dependency information from assembly code source" + echo + exit 1 +} +die_unknown(){ + echo "Unknown option \"$1\"." + echo "See $0 --help for available options." + exit 1 +} +for opt do + optval="${opt#*=}" + case "$opt" in + --build-pfx=*) pfx="${optval}" + ;; + --depfile=*) out="${optval}" + ;; + -I*) raw_inc_paths="${raw_inc_paths} ${opt}" + inc_path="${inc_path} ${opt#-I}" + ;; + -h|--help) show_help + ;; + *) [ -f "$opt" ] && srcfile="$opt" + ;; + esac +done + +[ -n "$srcfile" ] || show_help +sfx=${sfx:-asm} +includes=$(egrep -i "include +\"?+[a-z0-9_/]+\.${sfx}" $srcfile | + perl -p -e "s;.*?([a-z0-9_/]+.${sfx}).*;\1;") +#" restore editor state +for inc in ${includes}; do + found_inc_path= + for idir in ${inc_path}; do + [ -f "${idir}/${inc}" ] && found_inc_path="${idir}" && break + done + if [ -f `dirname $srcfile`/$inc ]; then + # Handle include files in the same directory as the source + $self --build-pfx=$pfx --depfile=$out ${raw_inc_paths} `dirname $srcfile`/$inc + elif [ -n "${found_inc_path}" ]; then + # Handle include files on the include path + $self --build-pfx=$pfx --depfile=$out ${raw_inc_paths} "${found_inc_path}/$inc" + else + # Handle generated includes in the build root (which may not exist yet) + echo ${out} ${out%d}o: "${pfx}${inc}" + fi +done +echo ${out} ${out%d}o: $srcfile diff --git a/build/make/gen_msvs_def.sh b/build/make/gen_msvs_def.sh new file mode 100755 index 000000000..68b240624 --- /dev/null +++ b/build/make/gen_msvs_def.sh @@ -0,0 +1,82 @@ +#!/bin/bash +## +## Copyright (c) 2010 The VP8 project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license and patent +## grant that can be found in the LICENSE file in the root of the source +## tree. All contributing project authors may be found in the AUTHORS +## file in the root of the source tree. +## + + +self=$0 +self_basename=${self##*/} +EOL=$'\n' + +show_help() { + cat <<EOF +Usage: ${self_basename} [options] file1 [file2 ...] + +This script generates a MSVC module definition file containing a list of symbols +to export from a DLL. Source files are technically bash scripts (and thus may +use #comment syntax) but in general, take the form of a list of symbols: + + <kind> symbol1 [symbol2, symbol3, ...] + +where <kind> is either 'text' or 'data' + + +Options: + --help Print this message + --out=filename Write output to a file [stdout] + --name=project_name Name of the library (required) +EOF + exit 1 +} + +die() { + echo "${self_basename}: $@" + exit 1 +} + +die_unknown(){ + echo "Unknown option \"$1\"." + echo "See ${self_basename} --help for available options." + exit 1 +} + +text() { + for sym in "$@"; do + echo " $sym" >> ${outfile} + done +} + +data() { + for sym in "$@"; do + printf " %-40s DATA\n" "$sym" >> ${outfile} + done +} + +# Process command line +for opt in "$@"; do + optval="${opt#*=}" + case "$opt" in + --help|-h) show_help + ;; + --out=*) outfile="$optval" + ;; + --name=*) name="${optval}" + ;; + -*) die_unknown $opt + ;; + *) file_list[${#file_list[@]}]="$opt" + esac +done +outfile=${outfile:-/dev/stdout} +[ -n "$name" ] || die "Library name (--name) must be specified!" + +echo "LIBRARY ${name}" > ${outfile} +echo "EXPORTS" >> ${outfile} +for f in "${file_list[@]}"; do + . $f +done diff --git a/build/make/gen_msvs_proj.sh b/build/make/gen_msvs_proj.sh new file mode 100755 index 000000000..eb482a4cb --- /dev/null +++ b/build/make/gen_msvs_proj.sh @@ -0,0 +1,717 @@ +#!/bin/bash +## +## Copyright (c) 2010 The VP8 project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license and patent +## grant that can be found in the LICENSE file in the root of the source +## tree. All contributing project authors may be found in the AUTHORS +## file in the root of the source tree. +## + + +self=$0 +self_basename=${self##*/} +EOL=$'\n' + +show_help() { + cat <<EOF +Usage: ${self_basename} --name=projname [options] file1 [file2 ...] + +This script generates a Visual Studio project file from a list of source +code files. + +Options: + --help Print this message + --exe Generate a project for building an Application + --lib Generate a project for creating a static library + --static-crt Use the static C runtime (/MT) + --target=isa-os-cc Target specifier (required) + --out=filename Write output to a file [stdout] + --name=project_name Name of the project (required) + --proj-guid=GUID GUID to use for the project + --module-def=filename File containing export definitions (for DLLs) + --ver=version Version (7,8) of visual studio to generate for + -Ipath/to/include Additional include directories + -DFLAG[=value] Preprocessor macros to define + -Lpath/to/lib Additional library search paths + -llibname Library to link against +EOF + exit 1 +} + +die() { + echo "${self_basename}: $@" >&2 + exit 1 +} + +die_unknown(){ + echo "Unknown option \"$1\"." >&2 + echo "See ${self_basename} --help for available options." >&2 + exit 1 +} + +generate_uuid() { + local hex="0123456789ABCDEF" + local i + local uuid="" + local j + #93995380-89BD-4b04-88EB-625FBE52EBFB + for ((i=0; i<32; i++)); do + (( j = $RANDOM % 16 )) + uuid="${uuid}${hex:$j:1}" + done + echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}" +} + +indent1=" " +indent="" +indent_push() { + indent="${indent}${indent1}" +} +indent_pop() { + indent="${indent%${indent1}}" +} + +tag_attributes() { + for opt in "$@"; do + optval="${opt#*=}" + [ -n "${optval}" ] || + die "Missing attribute value in '$opt' while generating $tag tag" + echo "${indent}${opt%%=*}=\"${optval}\"" + done +} + +open_tag() { + local tag=$1 + shift + if [ $# -ne 0 ]; then + echo "${indent}<${tag}" + indent_push + tag_attributes "$@" + echo "${indent}>" + else + echo "${indent}<${tag}>" + indent_push + fi +} + +close_tag() { + local tag=$1 + indent_pop + echo "${indent}</${tag}>" +} + +tag() { + local tag=$1 + shift + if [ $# -ne 0 ]; then + echo "${indent}<${tag}" + indent_push + tag_attributes "$@" + indent_pop + echo "${indent}/>" + else + echo "${indent}<${tag}/>" + fi +} + +generate_filter() { + local var=$1 + local name=$2 + local pats=$3 + local file_list_sz + local i + local f + local saveIFS="$IFS" + local pack + echo "generating filter '$name' from ${#file_list[@]} files" >&2 + IFS=* + + open_tag Filter \ + Name=$name \ + Filter=$pats \ + UniqueIdentifier=`generate_uuid` + + file_list_sz=${#file_list[@]} + for i in ${!file_list[@]}; do + f=${file_list[i]} + for pat in ${pats//;/$IFS}; do + if [ "${f##*.}" == "$pat" ]; then + unset file_list[i] + + open_tag File RelativePath="./$f" + if [ "$pat" == "asm" ] && $asm_use_custom_step; then + for plat in "${platforms[@]}"; do + for cfg in Debug Release; do + open_tag FileConfiguration \ + Name="${cfg}|${plat}" + tag Tool \ + Name="VCCustomBuildTool" \ + Description="Assembling \$(InputFileName)" \ + CommandLine="$(eval echo \$asm_${cfg}_cmdline)"\ + Outputs="\$(InputName).obj" + close_tag FileConfiguration + done + done + fi + + if [ "${f##*.}" == "cpp" ]; then + for plat in "${platforms[@]}"; do + for cfg in Debug Release; do + open_tag FileConfiguration \ + Name="${cfg}|${plat}" + tag Tool \ + Name="VCCLCompilerTool" \ + CompileAs="2" + close_tag FileConfiguration + done + done + fi + close_tag File + + break + fi + done + done + + close_tag Filter + IFS="$saveIFS" +} + +# Process command line +unset target +for opt in "$@"; do + optval="${opt#*=}" + case "$opt" in + --help|-h) show_help + ;; + --target=*) target="${optval}" + ;; + --out=*) outfile="$optval" + ;; + --name=*) name="${optval}" + ;; + --proj-guid=*) guid="${optval}" + ;; + --module-def=*) + link_opts="${link_opts} ModuleDefinitionFile=${optval}" + ;; + --exe) proj_kind="exe" + ;; + --lib) proj_kind="lib" + ;; + --static-crt) use_static_runtime=true + ;; + --ver=*) vs_ver="$optval" + case $optval in + [78]) + ;; + *) die Unrecognized Visual Studio Version in $opt + ;; + esac + ;; + -I*) opt="${opt%/}" + incs="${incs}${incs:+;}"${opt##-I}"" + yasmincs="${yasmincs} ${opt}" + ;; + -D*) defines="${defines}${defines:+;}${opt##-D}" + ;; + -L*) # fudge . to $(OutDir) + if [ "${opt##-L}" == "." ]; then + libdirs="${libdirs}${libdirs:+;}"\$(OutDir)"" + else + # Also try directories for this platform/configuration + libdirs="${libdirs}${libdirs:+;}"${opt##-L}"" + libdirs="${libdirs}${libdirs:+;}"${opt##-L}/\$(PlatformName)/\$(ConfigurationName)"" + libdirs="${libdirs}${libdirs:+;}"${opt##-L}/\$(PlatformName)"" + fi + ;; + -l*) libs="${libs}${libs:+ }${opt##-l}.lib" + ;; + -*) die_unknown $opt + ;; + *) file_list[${#file_list[@]}]="$opt" + case "$opt" in + *.asm) uses_asm=true;; + esac + esac +done +outfile=${outfile:-/dev/stdout} +guid=${guid:-`generate_uuid`} +asm_use_custom_step=false +uses_asm=${uses_asm:-false} +case "${vs_ver:-8}" in + 7) vs_ver_id="7.10" + asm_use_custom_step=$uses_asm + ;; + 8) vs_ver_id="8.00" + ;; +esac + +[ -n "$name" ] || die "Project name (--name) must be specified!" +[ -n "$target" ] || die "Target (--target) must be specified!" + +if ${use_static_runtime:-false}; then + release_runtime=0 + debug_runtime=1 + lib_sfx=mt +else + release_runtime=2 + debug_runtime=3 + lib_sfx=md +fi + +# Calculate debug lib names: If a lib ends in ${lib_sfx}.lib, then rename +# it to ${lib_sfx}d.lib. This precludes linking to release libs from a +# debug exe, so this may need to be refactored later. +for lib in ${libs}; do + if [ "$lib" != "${lib%${lib_sfx}.lib}" ]; then + lib=${lib%.lib}d.lib + fi + debug_libs="${debug_libs}${debug_libs:+ }${lib}" +done + + +# List Keyword for this target +case "$target" in + x86*) + keyword="ManagedCProj" + ;; + arm*|iwmmx*) + keyword="Win32Proj" + ;; + *) die "Unsupported target $target!" +esac + +# List of all platforms supported for this target +case "$target" in + x86_64*) + platforms[0]="x64" + ;; + x86*) + platforms[0]="Win32" + # these are only used by vs7 + asm_Debug_cmdline="yasm -Xvc -g cv8 -f \$(PlatformName) ${yasmincs} \$(InputPath)" + asm_Release_cmdline="yasm -Xvc -f \$(PlatformName) ${yasmincs} \$(InputPath)" + ;; + arm*|iwmmx*) + case "${name}" in + obj_int_extract) platforms[0]="Win32" + ;; + *) platforms[0]="Pocket PC 2003 (ARMV4)" + ;; + esac + ;; + *) die "Unsupported target $target!" +esac + +# List Command-line Arguments for this target +case "$target" in + arm*|iwmmx*) + if [ "$name" == "example" ];then + ARGU="--codec vp6 --flipuv --progress _bnd.vp6" + fi + if [ "$name" == "xma" ];then + ARGU="--codec vp6 -h 240 -w 320 -v" + fi + ;; +esac + +generate_vcproj() { + case "$proj_kind" in + exe) vs_ConfigurationType=1 + ;; + *) vs_ConfigurationType=4 + ;; + esac + + echo "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>" + open_tag VisualStudioProject \ + ProjectType="Visual C++" \ + Version="${vs_ver_id}" \ + Name="${name}" \ + ProjectGUID="{${guid}}" \ + RootNamespace="${name}" \ + Keyword="${keyword}" + + open_tag Platforms + for plat in "${platforms[@]}"; do + tag Platform Name="$plat" + done + close_tag Platforms + + open_tag ToolFiles + case "$target" in + x86*) $uses_asm && tag DefaultToolFile FileName="yasm.rules" + ;; + arm*|iwmmx*) + if [ "$name" == "vpx_decoder" ];then + case "$target" in + armv5*) + tag DefaultToolFile FileName="armasmv5.rules" + ;; + armv6*) + tag DefaultToolFile FileName="armasmv6.rules" + ;; + iwmmxt*) + tag DefaultToolFile FileName="armasmxscale.rules" + ;; + esac + fi + ;; + esac + close_tag ToolFiles + + open_tag Configurations + for plat in "${platforms[@]}"; do + plat_no_ws=`echo $plat | sed 's/[^A-Za-z0-9_]/_/g'` + open_tag Configuration \ + Name="Debug|$plat" \ + OutputDirectory="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \ + IntermediateDirectory="$plat_no_ws/\$(ConfigurationName)/${name}" \ + ConfigurationType="$vs_ConfigurationType" \ + CharacterSet="1" + + if [ "$target" == "armv6-wince-vs8" ] || [ "$target" == "armv5te-wince-vs8" ] || [ "$target" == "iwmmxt-wince-vs8" ] || [ "$target" == "iwmmxt2-wince-vs8" ];then + case "$name" in + vpx_decoder) tag Tool \ + Name="VCPreBuildEventTool" \ + CommandLine="call obj_int_extract.bat \$(ConfigurationName)" + tag Tool \ + Name="VCMIDLTool" \ + TargetEnvironment="1" + tag Tool \ + Name="VCCLCompilerTool" \ + ExecutionBucket="7" \ + Optimization="0" \ + AdditionalIncludeDirectories="$incs" \ + PreprocessorDefinitions="_DEBUG;_WIN32_WCE=\$(CEVER);UNDER_CE;\$(PLATFORMDEFINES);WINCE;DEBUG;_LIB;\$(ARCHFAM);\$(_ARCHFAM_);_UNICODE;UNICODE;HAVE_CONFIG_H" \ + MinimalRebuild="true" \ + RuntimeLibrary="1" \ + BufferSecurityCheck="false" \ + UsePrecompiledHeader="0" \ + WarningLevel="3" \ + DebugInformationFormat="1" \ + CompileAs="1" + tag Tool \ + Name="VCResourceCompilerTool" \ + PreprocessorDefinitions="_DEBUG;_WIN32_WCE=\$(CEVER);UNDER_CE;\$(PLATFORMDEFINES)" \ + Culture="1033" \ + AdditionalIncludeDirectories="\$(IntDir)" \ + ;; + example|xma) tag Tool \ + Name="VCCLCompilerTool" \ + ExecutionBucket="7" \ + Optimization="0" \ + AdditionalIncludeDirectories="$incs" \ + PreprocessorDefinitions="_DEBUG;_WIN32_WCE=\$(CEVER);UNDER_CE;\$(PLATFORMDEFINES);WINCE;DEBUG;_CONSOLE;\$(ARCHFAM);\$(_ARCHFAM_);_UNICODE;UNICODE;HAVE_CONFIG_H" \ + MinimalRebuild="true" \ + RuntimeLibrary="1" \ + BufferSecurityCheck="false" \ + UsePrecompiledHeader="0" \ + WarningLevel="3" \ + DebugInformationFormat="1" \ + CompileAs="1" + tag Tool \ + Name="VCResourceCompilerTool" \ + PreprocessorDefinitions="_DEBUG;_WIN32_WCE=\$(CEVER);UNDER_CE;\$(PLATFORMDEFINES)" \ + Culture="1033" \ + AdditionalIncludeDirectories="\$(IntDir)" \ + ;; + obj_int_extract) tag Tool \ + Name="VCCLCompilerTool" \ + Optimization="0" \ + AdditionalIncludeDirectories="$incs" \ + PreprocessorDefinitions="WIN32;DEBUG;_CONSOLE" \ + RuntimeLibrary="1" \ + WarningLevel="3" \ + DebugInformationFormat="1" \ + ;; + esac + fi + + case "$target" in + x86*) tag Tool \ + Name="VCCLCompilerTool" \ + Optimization="0" \ + AdditionalIncludeDirectories="$incs" \ + PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;$defines" \ + RuntimeLibrary="$debug_runtime" \ + UsePrecompiledHeader="0" \ + WarningLevel="3" \ + DebugInformationFormat="1" \ + Detect64BitPortabilityProblems="true" \ + + $uses_asm && tag Tool Name="YASM" IncludePaths="$incs" Debug="1" + ;; + esac + + case "$proj_kind" in + exe) + case "$target" in + x86*) tag Tool \ + Name="VCLinkerTool" \ + AdditionalDependencies="$debug_libs \$(NoInherit)" \ + AdditionalLibraryDirectories="$libdirs" \ + GenerateDebugInformation="true" \ + ProgramDatabaseFile="\$(OutDir)/${name}.pdb" \ + + ;; + arm*|iwmmx*) + case "$name" in + obj_int_extract) tag Tool \ + Name="VCLinkerTool" \ + OutputFile="${name}.exe" \ + GenerateDebugInformation="true" + ;; + *) tag Tool \ + Name="VCLinkerTool" \ + AdditionalDependencies="$debug_libs" \ + OutputFile="\$(OutDir)/${name}.exe" \ + LinkIncremental="2" \ + AdditionalLibraryDirectories="${libdirs};"..\lib/$plat_no_ws"" \ + DelayLoadDLLs="\$(NOINHERIT)" \ + GenerateDebugInformation="true" \ + ProgramDatabaseFile="\$(OutDir)/${name}.pdb" \ + SubSystem="9" \ + StackReserveSize="65536" \ + StackCommitSize="4096" \ + EntryPointSymbol="mainWCRTStartup" \ + TargetMachine="3" + ;; + esac + ;; + esac + ;; + lib) + case "$target" in + arm*|iwmmx*) tag Tool \ + Name="VCLibrarianTool" \ + AdditionalOptions=" /subsystem:windowsce,4.20 /machine:ARM" \ + OutputFile="\$(OutDir)/${name}.lib" \ + ;; + *) tag Tool \ + Name="VCLibrarianTool" \ + OutputFile="\$(OutDir)/${name}${lib_sfx}d.lib" \ + ;; + esac + ;; + dll) tag Tool \ + Name="VCLinkerTool" \ + AdditionalDependencies="\$(NoInherit)" \ + LinkIncremental="2" \ + GenerateDebugInformation="true" \ + AssemblyDebug="1" \ + TargetMachine="1" \ + $link_opts + esac + + if [ "$target" == "armv6-wince-vs8" ] || [ "$target" == "armv5te-wince-vs8" ] || [ "$target" == "iwmmxt-wince-vs8" ] || [ "$target" == "iwmmxt2-wince-vs8" ];then + case "$name" in + vpx_decoder) tag DeploymentTool \ + ForceDirty="-1" \ + RegisterOutput="0" + ;; + example|xma) tag DeploymentTool \ + ForceDirty="-1" \ + RegisterOutput="0" + tag DebuggerTool \ + Arguments="${ARGU}" + ;; + esac + fi + close_tag Configuration + + open_tag Configuration \ + Name="Release|$plat" \ + OutputDirectory="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \ + IntermediateDirectory="$plat_no_ws/\$(ConfigurationName)/${name}" \ + ConfigurationType="$vs_ConfigurationType" \ + CharacterSet="1" \ + WholeProgramOptimization="0" + + if [ "$target" == "armv6-wince-vs8" ] || [ "$target" == "armv5te-wince-vs8" ] || [ "$target" == "iwmmxt-wince-vs8" ] || [ "$target" == "iwmmxt2-wince-vs8" ];then + case "$name" in + vpx_decoder) tag Tool \ + Name="VCPreBuildEventTool" \ + CommandLine="call obj_int_extract.bat \$(ConfigurationName)" + tag Tool \ + Name="VCMIDLTool" \ + TargetEnvironment="1" + tag Tool \ + Name="VCCLCompilerTool" \ + ExecutionBucket="7" \ + Optimization="2" \ + FavorSizeOrSpeed="1" \ + AdditionalIncludeDirectories="$incs" \ + PreprocessorDefinitions="NDEBUG;_WIN32_WCE=\$(CEVER);UNDER_CE;\$(PLATFORMDEFINES);WINCE;_LIB;\$(ARCHFAM);\$(_ARCHFAM_);_UNICODE;UNICODE;HAVE_CONFIG_H" \ + RuntimeLibrary="0" \ + BufferSecurityCheck="false" \ + UsePrecompiledHeader="0" \ + WarningLevel="3" \ + DebugInformationFormat="0" \ + CompileAs="1" + tag Tool \ + Name="VCResourceCompilerTool" \ + PreprocessorDefinitions="NDEBUG;_WIN32_WCE=\$(CEVER);UNDER_CE;\$(PLATFORMDEFINES)" \ + Culture="1033" \ + AdditionalIncludeDirectories="\$(IntDir)" \ + ;; + example|xma) tag Tool \ + Name="VCCLCompilerTool" \ + ExecutionBucket="7" \ + Optimization="2" \ + FavorSizeOrSpeed="1" \ + AdditionalIncludeDirectories="$incs" \ + PreprocessorDefinitions="NDEBUG;_WIN32_WCE=\$(CEVER);UNDER_CE;\$(PLATFORMDEFINES);WINCE;_CONSOLE;\$(ARCHFAM);\$(_ARCHFAM_);_UNICODE;UNICODE;HAVE_CONFIG_H" \ + RuntimeLibrary="0" \ + BufferSecurityCheck="false" \ + UsePrecompiledHeader="0" \ + WarningLevel="3" \ + DebugInformationFormat="0" \ + CompileAs="1" + tag Tool \ + Name="VCResourceCompilerTool" \ + PreprocessorDefinitions="NDEBUG;_WIN32_WCE=\$(CEVER);UNDER_CE;\$(PLATFORMDEFINES)" \ + Culture="1033" \ + AdditionalIncludeDirectories="\$(IntDir)" \ + ;; + obj_int_extract) tag Tool \ + Name="VCCLCompilerTool" \ + AdditionalIncludeDirectories="$incs" \ + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" \ + RuntimeLibrary="0" \ + UsePrecompiledHeader="0" \ + WarningLevel="3" \ + Detect64BitPortabilityProblems="true" \ + DebugInformationFormat="0" \ + ;; + esac + fi + + case "$target" in + x86*) tag Tool \ + Name="VCCLCompilerTool" \ + AdditionalIncludeDirectories="$incs" \ + PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;$defines" \ + RuntimeLibrary="$release_runtime" \ + UsePrecompiledHeader="0" \ + WarningLevel="3" \ + DebugInformationFormat="0" \ + Detect64BitPortabilityProblems="true" + + $uses_asm && tag Tool Name="YASM" IncludePaths="$incs" + ;; + esac + + case "$proj_kind" in + exe) + case "$target" in + x86*) tag Tool \ + Name="VCLinkerTool" \ + AdditionalDependencies="$libs \$(NoInherit)" \ + AdditionalLibraryDirectories="$libdirs" \ + ;; + arm*|iwmmx*) + case "$name" in + obj_int_extract) tag Tool \ + Name="VCLinkerTool" \ + OutputFile="${name}.exe" \ + LinkIncremental="1" \ + GenerateDebugInformation="false" \ + SubSystem="0" \ + OptimizeReferences="0" \ + EnableCOMDATFolding="0" \ + TargetMachine="0" + ;; + *) tag Tool \ + Name="VCLinkerTool" \ + AdditionalDependencies="$libs" \ + OutputFile="\$(OutDir)/${name}.exe" \ + LinkIncremental="1" \ + AdditionalLibraryDirectories="${libdirs};"..\lib/$plat_no_ws"" \ + DelayLoadDLLs="\$(NOINHERIT)" \ + GenerateDebugInformation="true" \ + ProgramDatabaseFile="\$(OutDir)/${name}.pdb" \ + SubSystem="9" \ + StackReserveSize="65536" \ + StackCommitSize="4096" \ + OptimizeReferences="2" \ + EnableCOMDATFolding="2" \ + EntryPointSymbol="mainWCRTStartup" \ + TargetMachine="3" + ;; + esac + ;; + esac + ;; + lib) + case "$target" in + arm*|iwmmx*) tag Tool \ + Name="VCLibrarianTool" \ + AdditionalOptions=" /subsystem:windowsce,4.20 /machine:ARM" \ + OutputFile="\$(OutDir)/${name}.lib" \ + ;; + *) tag Tool \ + Name="VCLibrarianTool" \ + OutputFile="\$(OutDir)/${name}${lib_sfx}.lib" \ + ;; + esac + ;; + dll) # note differences to debug version: LinkIncremental, AssemblyDebug + tag Tool \ + Name="VCLinkerTool" \ + AdditionalDependencies="\$(NoInherit)" \ + LinkIncremental="1" \ + GenerateDebugInformation="true" \ + TargetMachine="1" \ + $link_opts + esac + + if [ "$target" == "armv6-wince-vs8" ] || [ "$target" == "armv5te-wince-vs8" ] || [ "$target" == "iwmmxt-wince-vs8" ] || [ "$target" == "iwmmxt2-wince-vs8" ];then + case "$name" in + vpx_decoder) tag DeploymentTool \ + ForceDirty="-1" \ + RegisterOutput="0" + ;; + example|xma) tag DeploymentTool \ + ForceDirty="-1" \ + RegisterOutput="0" + tag DebuggerTool \ + Arguments="${ARGU}" + ;; + esac + fi + + close_tag Configuration + done + close_tag Configurations + + open_tag Files + generate_filter srcs "Source Files" "cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + generate_filter hdrs "Header Files" "h;hpp;hxx;hm;inl;inc;xsd" + generate_filter resrcs "Resource Files" "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" + generate_filter resrcs "Build Files" "mk" + close_tag Files + + tag Globals + close_tag VisualStudioProject + + # This must be done from within the {} subshell + echo "Ignored files list (${#file_list[@]} items) is:" >&2 + for f in "${file_list[@]}"; do + echo " $f" >&2 + done +} + +generate_vcproj | + sed -e '/"/s;\([^ "]\)/;\1\\;g' > ${outfile} + +exit +<!-- +TODO: Add any files not captured by filters. + <File + RelativePath=".\ReadMe.txt" + > + </File> +--> diff --git a/build/make/gen_msvs_sln.sh b/build/make/gen_msvs_sln.sh new file mode 100755 index 000000000..b670ec598 --- /dev/null +++ b/build/make/gen_msvs_sln.sh @@ -0,0 +1,272 @@ +#!/bin/bash +## +## Copyright (c) 2010 The VP8 project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license and patent +## grant that can be found in the LICENSE file in the root of the source +## tree. All contributing project authors may be found in the AUTHORS +## file in the root of the source tree. +## + + +self=$0 +self_basename=${self##*/} +EOL=$'\n' +EOLDOS=$'\r' + +show_help() { + cat <<EOF +Usage: ${self_basename} [options] file1 [file2 ...] + +This script generates a Visual Studio 2005 solution file from a list of project +files. + +Options: + --help Print this message + --out=outfile Redirect output to a file + --ver=version Version (7,8) of visual studio to generate for + --target=isa-os-cc Target specifier +EOF + exit 1 +} + +die() { + echo "${self_basename}: $@" >&2 + [ -f "${outfile}" ] && rm -f ${outfile}{,.mk} + exit 1 +} + +die_unknown(){ + echo "Unknown option \"$1\"." >&2 + echo "See ${self_basename} --help for available options." >&2 + [ -f "${outfile}" ] && rm -f ${outfile}{,.mk} + exit 1 +} + +indent1=$'\t' +indent="" +indent_push() { + indent="${indent}${indent1}" +} +indent_pop() { + indent="${indent%${indent1}}" +} + +parse_project() { + local file=$1 + local name=`grep Name "$file" | awk 'BEGIN {FS="\""}{if (NR==1) print $2}'` + local guid=`grep ProjectGUID "$file" | awk 'BEGIN {FS="\""}{if (NR==1) print $2}'` + + # save the project GUID to a varaible, normalizing to the basename of the + # vcproj file without the extension + local var + var=${file##*/} + var=${var%%.vcproj} + eval "${var}_file=\"$1\"" + eval "${var}_name=$name" + eval "${var}_guid=$guid" + + # assume that all projects have the same list of possible configurations, + # so overwriting old config_lists is not a problem + config_list=`grep -A1 '<Configuration' $file | + grep Name | cut -d\" -f2` + proj_list="${proj_list} ${var}" +} + +process_project() { + eval "local file=\${$1_file}" + eval "local name=\${$1_name}" + eval "local guid=\${$1_guid}" + + # save the project GUID to a varaible, normalizing to the basename of the + # vcproj file without the extension + local var + var=${file##*/} + var=${var%%.vcproj} + eval "${var}_guid=$guid" + + echo "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$name\", \"$file\", \"$guid\"" + indent_push + + eval "local deps=\"\${${var}_deps}\"" + if [ -n "$deps" ]; then + echo "${indent}ProjectSection(ProjectDependencies) = postProject" + indent_push + + for dep in $deps; do + eval "local dep_guid=\${${dep}_guid}" + [ -z "${dep_guid}" ] && die "Unknown GUID for $dep (dependency of $var)" + echo "${indent}$dep_guid = $dep_guid" + done + + indent_pop + echo "${indent}EndProjectSection" + + fi + + indent_pop + echo "EndProject" +} + +process_global() { + echo "Global" + indent_push + + # + # Solution Configuration Platforms + # + echo "${indent}GlobalSection(SolutionConfigurationPlatforms) = preSolution" + indent_push + IFS_bak=${IFS} + IFS=$'\r'$'\n' + for config in ${config_list}; do + echo "${indent}$config = $config" + done + IFS=${IFS_bak} + indent_pop + echo "${indent}EndGlobalSection" + + # + # Project Configuration Platforms + # + echo "${indent}GlobalSection(ProjectConfigurationPlatforms) = postSolution" + indent_push + for proj in ${proj_list}; do + eval "local proj_guid=\${${proj}_guid}" + IFS=$'\r'$'\n' + for config in ${config_list}; do + echo "${indent}${proj_guid}.${config}.ActiveCfg = ${config}" + echo "${indent}${proj_guid}.${config}.Build.0 = ${config}" + + if [ "$target" == "armv6-wince-vs8" ] || [ "$target" == "armv5te-wince-vs8" ] || [ "$target" == "iwmmxt-wince-vs8" ] || [ "$target" == "iwmmxt2-wince-vs8" ];then + echo "${indent}${proj_guid}.${config}.Deploy.0 = ${config}" + fi + done + IFS=${IFS_bak} + done + indent_pop + echo "${indent}EndGlobalSection" + + # + # Solution Properties + # + echo "${indent}GlobalSection(SolutionProperties) = preSolution" + indent_push + echo "${indent}HideSolutionNode = FALSE" + indent_pop + echo "${indent}EndGlobalSection" + + indent_pop + echo "EndGlobal" +} + +process_makefile() { + IFS_bak=${IFS} + IFS=$'\r'$'\n' + local TAB=$'\t' + cat <<EOF +found_devenv := \$(shell which devenv.com >/dev/null 2>&1 && echo yes) +.nodevenv.once: +${TAB}@echo " * devenv.com not found in path." +${TAB}@echo " * " +${TAB}@echo " * You will have to build all configurations manually using the" +${TAB}@echo " * Visual Studio IDE. To allow make to build them automatically," +${TAB}@echo " * add the Common7/IDE directory of your Visual Studio" +${TAB}@echo " * installation to your path, eg:" +${TAB}@echo " * C:\Program Files\Microsoft Visual Studio 8\Common7\IDE" +${TAB}@echo " * " +${TAB}@touch \$@ +CLEAN-OBJS += \$(if \$(found_devenv),,.nodevenv.once) + +EOF + + for sln_config in ${config_list}; do + local config=${sln_config%%|*} + local platform=${sln_config##*|} + local nows_sln_config=`echo $sln_config | sed -e 's/[^a-zA-Z0-9]/_/g'` + cat <<EOF +BUILD_TARGETS += \$(if \$(NO_LAUNCH_DEVENV),,$nows_sln_config) +clean:: +${TAB}rm -rf "$platform"/"$config" +.PHONY: $nows_sln_config +ifneq (\$(found_devenv),) + ifeq (\$(CONFIG_VS_VERSION),7) +$nows_sln_config: $outfile +${TAB}devenv.com $outfile /build "$config" + + else +$nows_sln_config: $outfile +${TAB}devenv.com $outfile /build "$sln_config" + + endif +else +$nows_sln_config: $outfile .nodevenv.once +${TAB}@echo " * Skipping build of $sln_config (devenv.com not in path)." +${TAB}@echo " * " +endif + +EOF + done + IFS=${IFS_bak} +} + +# Process command line +outfile=/dev/stdout +for opt in "$@"; do + optval="${opt#*=}" + case "$opt" in + --help|-h) show_help + ;; + --out=*) outfile="${optval}"; mkoutfile="${optval}".mk + ;; + --dep=*) eval "${optval%%:*}_deps=\"\${${optval%%:*}_deps} ${optval##*:}\"" + ;; + --ver=*) vs_ver="$optval" + case $optval in + [78]) + ;; + *) die Unrecognized Visual Studio Version in $opt + ;; + esac + ;; + --ver=*) vs_ver="$optval" + case $optval in + 7) sln_vers="8.00" + sln_vers_str="Visual Studio .NET 2003" + ;; + 8) + ;; + *) die "Unrecognized Visual Studio Version '$optval' in $opt" + ;; + esac + ;; + --target=*) target="${optval}" + ;; + -*) die_unknown $opt + ;; + *) file_list[${#file_list[@]}]="$opt" + esac +done +outfile=${outfile:-/dev/stdout} +mkoutfile=${mkoutfile:-/dev/stdout} +case "${vs_ver:-8}" in + 7) sln_vers="8.00" + sln_vers_str="Visual Studio .NET 2003" + ;; + 8) sln_vers="9.00" + sln_vers_str="Visual Studio 2005" + ;; +esac + +for f in "${file_list[@]}"; do + parse_project $f +done +cat >${outfile} <<EOF +Microsoft Visual Studio Solution File, Format Version $sln_vers${EOLDOS} +# $sln_vers_str${EOLDOS} +EOF +for proj in ${proj_list}; do + process_project $proj >>${outfile} +done +process_global >>${outfile} +process_makefile >${mkoutfile} diff --git a/build/make/obj_int_extract.c b/build/make/obj_int_extract.c new file mode 100644 index 000000000..cef14e7f7 --- /dev/null +++ b/build/make/obj_int_extract.c @@ -0,0 +1,755 @@ +/* + * Copyright (c) 2010 The VP8 project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license and patent + * grant that can be found in the LICENSE file in the root of the source + * tree. All contributing project authors may be found in the AUTHORS + * file in the root of the source tree. + */ + + +#include <stdio.h> +#include <stdlib.h> + +#include "vpx_config.h" + +#if defined(_MSC_VER) +#include <io.h> +#include <share.h> +#include "vpx_ports/vpx_integer.h" +#else +#include <stdint.h> +#include <unistd.h> +#endif + +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdarg.h> + +typedef enum +{ + OUTPUT_FMT_PLAIN, + OUTPUT_FMT_RVDS, + OUTPUT_FMT_GAS, +} output_fmt_t; + +int log_msg(const char *fmt, ...) +{ + int res; + va_list ap; + va_start(ap, fmt); + res = vfprintf(stderr, fmt, ap); + va_end(ap); + return res; +} + +#if defined(__GNUC__) && __GNUC__ + +#if defined(__MACH__) + +#include <mach-o/loader.h> +#include <mach-o/nlist.h> + +int parse_macho(uint8_t *base_buf, size_t sz) +{ + int i, j; + struct mach_header header; + uint8_t *buf = base_buf; + int base_data_section = 0; + + memcpy(&header, buf, sizeof(struct mach_header)); + buf += sizeof(struct mach_header); + + if (header.magic != MH_MAGIC) + { + log_msg("Bad magic number for object file. 0x%x expected, 0x%x found.\n", + header.magic, MH_MAGIC); + goto bail; + } + + if (header.cputype != CPU_TYPE_ARM) + { + log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_ARM.\n"); + goto bail; + } + + if (header.filetype != MH_OBJECT) + { + log_msg("Bad filetype for object file. Currently only tested for MH_OBJECT.\n"); + goto bail; + } + + for (i = 0; i < header.ncmds; i++) + { + struct load_command lc; + struct symtab_command sc; + struct segment_command seg_c; + + memcpy(&lc, buf, sizeof(struct load_command)); + + if (lc.cmd == LC_SEGMENT) + { + uint8_t *seg_buf = buf; + struct section s; + + memcpy(&seg_c, buf, sizeof(struct segment_command)); + + seg_buf += sizeof(struct segment_command); + + for (j = 0; j < seg_c.nsects; j++) + { + memcpy(&s, seg_buf + (j * sizeof(struct section)), sizeof(struct section)); + + // Need to get this offset which is the start of the symbol table + // before matching the strings up with symbols. + base_data_section = s.offset; + } + } + else if (lc.cmd == LC_SYMTAB) + { + uint8_t *sym_buf = base_buf; + uint8_t *str_buf = base_buf; + + if (base_data_section != 0) + { + memcpy(&sc, buf, sizeof(struct symtab_command)); + + if (sc.cmdsize != sizeof(struct symtab_command)) + log_msg("Can't find symbol table!\n"); + + sym_buf += sc.symoff; + str_buf += sc.stroff; + + for (j = 0; j < sc.nsyms; j++) + { + struct nlist nl; + int val; + + memcpy(&nl, sym_buf + (j * sizeof(struct nlist)), sizeof(struct nlist)); + + val = *((int *)(base_buf + base_data_section + nl.n_value)); + + // Location of string is cacluated each time from the + // start of the string buffer. On darwin the symbols + // are prefixed by "_". On other platforms it is not + // so it needs to be removed. That is the reason for + // the +1. + printf("%-40s EQU %5d\n", str_buf + nl.n_un.n_strx + 1, val); + } + } + } + + buf += lc.cmdsize; + } + + return 0; +bail: + return 1; + +} + +int main(int argc, char **argv) +{ + int fd; + char *f; + struct stat stat_buf; + uint8_t *file_buf; + int res; + + if (argc < 2 || argc > 3) + { + fprintf(stderr, "Usage: %s [output format] <obj file>\n\n", argv[0]); + fprintf(stderr, " <obj file>\tMachO format object file to parse\n"); + fprintf(stderr, "Output Formats:\n"); + fprintf(stderr, " gas - compatible with GNU assembler\n"); + fprintf(stderr, " rvds - compatible with armasm\n"); + goto bail; + } + + f = argv[2]; + + if (!((!strcmp(argv[1], "rvds")) || (!strcmp(argv[1], "gas")))) + f = argv[1]; + + fd = open(f, O_RDONLY); + + if (fd < 0) + { + perror("Unable to open file"); + goto bail; + } + + if (fstat(fd, &stat_buf)) + { + perror("stat"); + goto bail; + } + + file_buf = malloc(stat_buf.st_size); + + if (!file_buf) + { + perror("malloc"); + goto bail; + } + + if (read(fd, file_buf, stat_buf.st_size) != stat_buf.st_size) + { + perror("read"); + goto bail; + } + + if (close(fd)) + { + perror("close"); + goto bail; + } + + res = parse_macho(file_buf, stat_buf.st_size); + free(file_buf); + + if (!res) + return EXIT_SUCCESS; + +bail: + return EXIT_FAILURE; +} + +#else +#include "elf.h" + +#define COPY_STRUCT(dst, buf, ofst, sz) do {\ + if(ofst + sizeof((*(dst))) > sz) goto bail;\ + memcpy(dst, buf+ofst, sizeof((*(dst))));\ + } while(0) + +#define ENDIAN_ASSIGN(val, memb) do {\ + if(!elf->le_data) {log_msg("Big Endian data not supported yet!\n");goto bail;}\ + (val) = (memb);\ + } while(0) + +#define ENDIAN_ASSIGN_IN_PLACE(memb) do {\ + ENDIAN_ASSIGN(memb, memb);\ + } while(0) + +typedef struct +{ + uint8_t *buf; /* Buffer containing ELF data */ + size_t sz; /* Buffer size */ + int le_data; /* Data is little-endian */ + Elf32_Ehdr hdr; +} elf_obj_t; + +int parse_elf32_header(elf_obj_t *elf) +{ + int res; + /* Verify ELF32 header */ + COPY_STRUCT(&elf->hdr, elf->buf, 0, elf->sz); + res = elf->hdr.e_ident[EI_MAG0] == ELFMAG0; + res &= elf->hdr.e_ident[EI_MAG1] == ELFMAG1; + res &= elf->hdr.e_ident[EI_MAG2] == ELFMAG2; + res &= elf->hdr.e_ident[EI_MAG3] == ELFMAG3; + res &= elf->hdr.e_ident[EI_CLASS] == ELFCLASS32; + res &= elf->hdr.e_ident[EI_DATA] == ELFDATA2LSB + || elf->hdr.e_ident[EI_DATA] == ELFDATA2MSB; + + if (!res) goto bail; + + elf->le_data = elf->hdr.e_ident[EI_DATA] == ELFDATA2LSB; + + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_type); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_machine); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_version); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_entry); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_phoff); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_shoff); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_flags); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_ehsize); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_phentsize); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_phnum); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_shentsize); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_shnum); + ENDIAN_ASSIGN_IN_PLACE(elf->hdr.e_shstrndx); + return 0; +bail: + return 1; +} + +int parse_elf32_section(elf_obj_t *elf, int idx, Elf32_Shdr *hdr) +{ + if (idx >= elf->hdr.e_shnum) + goto bail; + + COPY_STRUCT(hdr, elf->buf, elf->hdr.e_shoff + idx * elf->hdr.e_shentsize, + elf->sz); + ENDIAN_ASSIGN_IN_PLACE(hdr->sh_name); + ENDIAN_ASSIGN_IN_PLACE(hdr->sh_type); + ENDIAN_ASSIGN_IN_PLACE(hdr->sh_flags); + ENDIAN_ASSIGN_IN_PLACE(hdr->sh_addr); + ENDIAN_ASSIGN_IN_PLACE(hdr->sh_offset); + ENDIAN_ASSIGN_IN_PLACE(hdr->sh_size); + ENDIAN_ASSIGN_IN_PLACE(hdr->sh_link); + ENDIAN_ASSIGN_IN_PLACE(hdr->sh_info); + ENDIAN_ASSIGN_IN_PLACE(hdr->sh_addralign); + ENDIAN_ASSIGN_IN_PLACE(hdr->sh_entsize); + return 0; +bail: + return 1; +} + +char *parse_elf32_string_table(elf_obj_t *elf, int s_idx, int idx) +{ + Elf32_Shdr shdr; + + if (parse_elf32_section(elf, s_idx, &shdr)) + { + log_msg("Failed to parse ELF string table: section %d, index %d\n", + s_idx, idx); + return ""; + } + + return (char *)(elf->buf + shdr.sh_offset + idx); +} + +int parse_elf32_symbol(elf_obj_t *elf, unsigned int ofst, Elf32_Sym *sym) +{ + COPY_STRUCT(sym, elf->buf, ofst, elf->sz); + ENDIAN_ASSIGN_IN_PLACE(sym->st_name); + ENDIAN_ASSIGN_IN_PLACE(sym->st_value); + ENDIAN_ASSIGN_IN_PLACE(sym->st_size); + ENDIAN_ASSIGN_IN_PLACE(sym->st_info); + ENDIAN_ASSIGN_IN_PLACE(sym->st_other); + ENDIAN_ASSIGN_IN_PLACE(sym->st_shndx); + return 0; +bail: + return 1; +} + +int parse_elf32(uint8_t *buf, size_t sz, output_fmt_t mode) +{ + elf_obj_t elf; + Elf32_Shdr shdr; + unsigned int ofst; + int i; + Elf32_Off strtab_off; /* save String Table offset for later use */ + + memset(&elf, 0, sizeof(elf)); + elf.buf = buf; + elf.sz = sz; + + /* Parse Header */ + if (parse_elf32_header(&elf)) + { + log_msg("Parse error: File does not appear to be valid ELF32\n"); + return 1; + } + + for (i = 0; i < elf.hdr.e_shnum; i++) + { + parse_elf32_section(&elf, i, &shdr); + + if (shdr.sh_type == SHT_STRTAB) + { + char strtsb_name[128]; + + strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name)); + + if (!(strcmp(strtsb_name, ".shstrtab"))) + { + log_msg("found section: %s\n", strtsb_name); + strtab_off = shdr.sh_offset; + break; + } + } + } + + /* Parse all Symbol Tables */ + for (i = 0; i < elf.hdr.e_shnum; i++) + { + + parse_elf32_section(&elf, i, &shdr); + + if (shdr.sh_type == SHT_SYMTAB) + { + for (ofst = shdr.sh_offset; + ofst < shdr.sh_offset + shdr.sh_size; + ofst += shdr.sh_entsize) + { + Elf32_Sym sym; + + parse_elf32_symbol(&elf, ofst, &sym); + + /* For all OBJECTS (data objects), extract the value from the + * proper data segment. + */ + if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name) + log_msg("found data object %s\n", + parse_elf32_string_table(&elf, + shdr.sh_link, + sym.st_name)); + + if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT + && sym.st_size == 4) + { + Elf32_Shdr dhdr; + int32_t val; + char section_name[128]; + + parse_elf32_section(&elf, sym.st_shndx, &dhdr); + + /* For explanition - refer to _MSC_VER version of code */ + strcpy(section_name, (char *)(elf.buf + strtab_off + dhdr.sh_name)); + log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); + + if (!(strcmp(section_name, ".bss"))) + { + val = 0; + } + else + { + memcpy(&val, + elf.buf + dhdr.sh_offset + sym.st_value, + sizeof(val)); + } + + if (!elf.le_data) + { + log_msg("Big Endian data not supported yet!\n"); + goto bail; + }\ + + switch (mode) + { + case OUTPUT_FMT_RVDS: + printf("%-40s EQU %5d\n", + parse_elf32_string_table(&elf, + shdr.sh_link, + sym.st_name), + val); + break; + case OUTPUT_FMT_GAS: + printf(".equ %-40s, %5d\n", + parse_elf32_string_table(&elf, + shdr.sh_link, + sym.st_name), + val); + break; + default: + printf("%s = %d\n", + parse_elf32_string_table(&elf, + shdr.sh_link, + sym.st_name), + val); + } + } + } + } + } + + if (mode == OUTPUT_FMT_RVDS) + printf(" END\n"); + + return 0; +bail: + log_msg("Parse error: File does not appear to be valid ELF32\n"); + return 1; +} + +int main(int argc, char **argv) +{ + int fd; + output_fmt_t mode; + char *f; + struct stat stat_buf; + uint8_t *file_buf; + int res; + + if (argc < 2 || argc > 3) + { + fprintf(stderr, "Usage: %s [output format] <obj file>\n\n", argv[0]); + fprintf(stderr, " <obj file>\tELF format object file to parse\n"); + fprintf(stderr, "Output Formats:\n"); + fprintf(stderr, " gas - compatible with GNU assembler\n"); + fprintf(stderr, " rvds - compatible with armasm\n"); + goto bail; + } + + f = argv[2]; + + if (!strcmp(argv[1], "rvds")) + mode = OUTPUT_FMT_RVDS; + else if (!strcmp(argv[1], "gas")) + mode = OUTPUT_FMT_GAS; + else + f = argv[1]; + + + fd = open(f, O_RDONLY); + + if (fd < 0) + { + perror("Unable to open file"); + goto bail; + } + + if (fstat(fd, &stat_buf)) + { + perror("stat"); + goto bail; + } + + file_buf = malloc(stat_buf.st_size); + + if (!file_buf) + { + perror("malloc"); + goto bail; + } + + if (read(fd, file_buf, stat_buf.st_size) != stat_buf.st_size) + { + perror("read"); + goto bail; + } + + if (close(fd)) + { + perror("close"); + goto bail; + } + + res = parse_elf32(file_buf, stat_buf.st_size, mode); + //res = parse_coff(file_buf, stat_buf.st_size); + free(file_buf); + + if (!res) + return EXIT_SUCCESS; + +bail: + return EXIT_FAILURE; +} +#endif +#endif + + +#if defined(_MSC_VER) +/* See "Microsoft Portable Executable and Common Object File Format Specification" + for reference. +*/ +#define get_le32(x) ((*(x)) | (*(x+1)) << 8 |(*(x+2)) << 16 | (*(x+3)) << 24 ) +#define get_le16(x) ((*(x)) | (*(x+1)) << 8) + +int parse_coff(unsigned __int8 *buf, size_t sz) +{ + unsigned int nsections, symtab_ptr, symtab_sz, strtab_ptr; + unsigned int sectionrawdata_ptr; + unsigned int i; + unsigned __int8 *ptr; + unsigned __int32 symoffset; + FILE *fp; + + char **sectionlist; //this array holds all section names in their correct order. + //it is used to check if the symbol is in .bss or .data section. + + nsections = get_le16(buf + 2); + symtab_ptr = get_le32(buf + 8); + symtab_sz = get_le32(buf + 12); + strtab_ptr = symtab_ptr + symtab_sz * 18; + + if (nsections > 96) + goto bail; + + sectionlist = malloc(nsections * sizeof * sectionlist); + + //log_msg("COFF: Found %u symbols in %u sections.\n", symtab_sz, nsections); + + /* + The size of optional header is always zero for an obj file. So, the section header + follows the file header immediately. + */ + + ptr = buf + 20; //section header + + for (i = 0; i < nsections; i++) + { + char sectionname[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; + strncpy(sectionname, ptr, 8); + //log_msg("COFF: Parsing section %s\n",sectionname); + + sectionlist[i] = malloc(strlen(sectionname) + 1); + strcpy(sectionlist[i], sectionname); + + if (!strcmp(sectionname, ".data")) sectionrawdata_ptr = get_le32(ptr + 20); + + ptr += 40; + } + + //log_msg("COFF: Symbol table at offset %u\n", symtab_ptr); + //log_msg("COFF: raw data pointer ofset for section .data is %u\n", sectionrawdata_ptr); + + fp = fopen("vpx_asm_offsets.asm", "w"); + + if (fp == NULL) + { + perror("open file"); + goto bail; + } + + /* The compiler puts the data with non-zero offset in .data section, but puts the data with + zero offset in .bss section. So, if the data in in .bss section, set offset=0. + Note from Wiki: In an object module compiled from C, the bss section contains + the local variables (but not functions) that were declared with the static keyword, + except for those with non-zero initial values. (In C, static variables are initialized + to zero by default.) It also contains the non-local (both extern and static) variables + that are also initialized to zero (either explicitly or by default). + */ + //move to symbol table + /* COFF symbol table: + offset field + 0 Name(*) + 8 Value + 12 SectionNumber + 14 Type + 16 StorageClass + 17 NumberOfAuxSymbols + */ + ptr = buf + symtab_ptr; + + for (i = 0; i < symtab_sz; i++) + { + __int16 section = get_le16(ptr + 12); //section number + + if (section > 0 && ptr[16] == 2) + { + //if(section > 0 && ptr[16] == 3 && get_le32(ptr+8)) { + + if (get_le32(ptr)) + { + char name[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; + strncpy(name, ptr, 8); + //log_msg("COFF: Parsing symbol %s\n",name); + fprintf(fp, "%-40s EQU ", name); + } + else + { + //log_msg("COFF: Parsing symbol %s\n", + // buf + strtab_ptr + get_le32(ptr+4)); + fprintf(fp, "%-40s EQU ", buf + strtab_ptr + get_le32(ptr + 4)); + } + + if (!(strcmp(sectionlist[section-1], ".bss"))) + { + symoffset = 0; + } + else + { + symoffset = get_le32(buf + sectionrawdata_ptr + get_le32(ptr + 8)); + } + + //log_msg(" Section: %d\n",section); + //log_msg(" Class: %d\n",ptr[16]); + //log_msg(" Address: %u\n",get_le32(ptr+8)); + //log_msg(" Offset: %u\n", symoffset); + + fprintf(fp, "%5d\n", symoffset); + } + + ptr += 18; + } + + fprintf(fp, " END\n"); + fclose(fp); + + for (i = 0; i < nsections; i++) + { + free(sectionlist[i]); + } + + free(sectionlist); + + return 0; +bail: + + for (i = 0; i < nsections; i++) + { + free(sectionlist[i]); + } + + free(sectionlist); + + return 1; +} + +int main(int argc, char **argv) +{ + int fd; + output_fmt_t mode; + const char *f; + struct _stat stat_buf; + unsigned __int8 *file_buf; + int res; + + if (argc < 2 || argc > 3) + { + fprintf(stderr, "Usage: %s [output format] <obj file>\n\n", argv[0]); + fprintf(stderr, " <obj file>\tELF format object file to parse\n"); + fprintf(stderr, "Output Formats:\n"); + fprintf(stderr, " gas - compatible with GNU assembler\n"); + fprintf(stderr, " rvds - compatible with armasm\n"); + goto bail; + } + + f = argv[2]; + + if (!strcmp(argv[1], "rvds")) + mode = OUTPUT_FMT_RVDS; + else if (!strcmp(argv[1], "gas")) + mode = OUTPUT_FMT_GAS; + else + f = argv[1]; + + if (_sopen_s(&fd, f, _O_BINARY, _SH_DENYNO, _S_IREAD | _S_IWRITE)) + { + perror("Unable to open file"); + goto bail; + } + + if (_fstat(fd, &stat_buf)) + { + perror("stat"); + goto bail; + } + + file_buf = malloc(stat_buf.st_size); + + if (!file_buf) + { + perror("malloc"); + goto bail; + } + + if (_read(fd, file_buf, stat_buf.st_size) != stat_buf.st_size) + { + perror("read"); + goto bail; + } + + if (_close(fd)) + { + perror("close"); + goto bail; + } + + res = parse_coff(file_buf, stat_buf.st_size); + + free(file_buf); + + if (!res) + return EXIT_SUCCESS; + +bail: + return EXIT_FAILURE; +} +#endif diff --git a/build/make/version.sh b/build/make/version.sh new file mode 100755 index 000000000..2bda70106 --- /dev/null +++ b/build/make/version.sh @@ -0,0 +1,75 @@ +#!/bin/bash +## +## Copyright (c) 2010 The VP8 project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license and patent +## grant that can be found in the LICENSE file in the root of the source +## tree. All contributing project authors may be found in the AUTHORS +## file in the root of the source tree. +## + + + +for opt in "$@"; do + optval="${opt#*=}" + case "$opt" in + --bare) bare=true ;; + *) break ;; + esac + shift +done +source_path=${1:-.} +out_file=${2} +id=${3:-VERSION_STRING} + +git_version_id="" +if [ -d ${source_path}/.git ]; then + # Source Path is a git working copy. Check for local modifications. + export GIT_DIR=${source_path}/.git + git_version_id=`git describe --match=v[0-9]* 2>/dev/null` +fi + +changelog_version="" +for p in "${source_path}" "${source_path}/.."; do + if [ -z "$git_version_id" -a -f "${p}/CHANGELOG" ]; then + changelog_version=`head -n1 "${p}/CHANGELOG" | awk '{print $2}'` + changelog_version="${changelog_version}" + break + fi +done +version_str="${changelog_version}${git_version_id}" +bare_version=${version_str#v} +major_version=${bare_version%%.*} +bare_version=${bare_version#*.} +minor_version=${bare_version%%.*} +bare_version=${bare_version#*.} +patch_version=${bare_version%%-*} +bare_version=${bare_version#${patch_version}} +extra_version=${bare_version##-} + +#since they'll be used as integers below make sure they are or force to 0 +for v in major_version minor_version patch_version; do + if eval echo \$$v |grep -E -q '[^[:digit:]]'; then + eval $v=0 + fi +done + +if [ ${bare} ]; then + echo "${changelog_version}${git_version_id}" > $$.tmp +else + cat<<EOF>$$.tmp +#define VERSION_MAJOR $major_version +#define VERSION_MINOR $minor_version +#define VERSION_PATCH $patch_version +#define VERSION_EXTRA "$extra_version" +#define VERSION_PACKED ((VERSION_MAJOR<<16)|(VERSION_MINOR<<8)|(VERSION_PATCH)) +#define ${id}_NOSP "${version_str}" +#define ${id} " ${version_str}" +EOF +fi +if [ -n "$out_file" ]; then +diff $$.tmp ${out_file} >/dev/null 2>&1 || cat $$.tmp > ${out_file} +else +cat $$.tmp +fi +rm $$.tmp |