Blame project/clbuild.sh

81d456
#!/bin/sh
81d456
# a poor man's universal driver (but stay tuned...)
81d456
81d456
error_msg()
81d456
{
81d456
	echo $@ >&2
81d456
}
81d456
81d456
mb_cc=
81d456
mb_ar=
81d456
mb_source_dir=
81d456
mb_project_dir=
81d456
mb_sysroot=
0e817b
version_header=
0e817b
version_macro=
89c3ba
link_target=
81d456
81d456
# one: args
81d456
for arg ; do
81d456
	case "$arg" in
81d456
		--help)	usage
81d456
			;;
81d456
		--cc=*)
81d456
			mb_cc=${arg#*=}
81d456
			;;
81d456
		--ar=*)
81d456
			mb_ar=${arg#*=}
81d456
			;;
81d456
		--source-dir=*)
81d456
			mb_source_dir=${arg#*=}
81d456
			;;
81d456
		--project-dir=*)
81d456
			mb_project_dir=${arg#*=}
81d456
			;;
81d456
		--sysroot=*)
81d456
			mb_sysroot=${arg#*=}
81d456
			;;
0e817b
		--version-header=*)
0e817b
			version_header=${arg#*=}
0e817b
			;;
0e817b
		--version-macro=*)
0e817b
			version_macro='-D'${arg#*=}'=\\\"unknown\\\"'
0e817b
			;;
89c3ba
		--link-target=*)
89c3ba
			link_target=${arg#*=}
89c3ba
			;;
81d456
		*)
81d456
			error_msg ${arg#}: "unsupported config argument."
81d456
			exit 2
81d456
			;;
81d456
	esac
81d456
done
81d456
81d456
if [ -z "$mb_cc" ] || [ -z "$mb_ar" ]           \
81d456
		   || [ -z "$mb_source_dir" ]   \
81d456
		   || [ -z "$mb_project_dir" ]; then
81d456
	usage
81d456
fi
81d456
81d456
# two: clean
81d456
make -s clean || exit 1
81d456
81d456
# three: init
81d456
echo '@echo on'
81d456
echo '@dir . > nul'
81d456
echo
81d456
echo
81d456
echo 'REM override variables either here or from the shell'
81d456
echo 'set source_dir=%source_dir%'
81d456
echo 'set sysroot=%sysroot%'
81d456
echo
81d456
echo
81d456
81d456
# four: build tree
81d456
cmd_abort_on_error='@if %errorlevel% neq 0 exit /b %errorlevel%'
81d456
sysroot_include_arg='-I%sysroot%/include'
81d456
81d456
dirs=`make dirs.tag tree.tag                    \
81d456
	 | grep -v 'make\[1\]:'                 \
81d456
	 | grep -v 'touch dirs.tag'             \
81d456
	 | grep -v 'touch tree.tag'             \
81d456
	 | sed                                  \
81d456
		-e 's/mkdir -p//g'              \
81d456
		-e 's@/@\\\\@g'`
81d456
0e817b
for d in build $dirs; do
81d456
	printf 'if not exist %-20smkdir %s\n' "$d" "$d"
81d456
done
81d456
0e817b
# version.tag
0e817b
make version.tag > /dev/null
0e817b
0e817b
echo
0e817b
echo "type nul > build/$version_header"
0e817b
echo
0e817b
echo "$cmd_abort_on_error"
0e817b
echo
0e817b
81d456
echo
81d456
echo "$cmd_abort_on_error"
81d456
echo
81d456
45b07e
# five: compile assembly sources
45b07e
make shared-objs-asm static-objs-asm                            \
45b07e
	 | grep -v 'make\[1\]:'                                 \
45b07e
	 | grep -v "$mb_project_dir/sysinfo/host"               \
45b07e
	 | grep -v 'touch dirs.tag'                             \
45b07e
	 | grep -v 'touch host.tag'                             \
45b07e
	 | grep -v 'touch app.tag'                              \
45b07e
	 | sed                                                  \
45b07e
		-e 's@'"$mb_cc -c "'@ml64 /nologo @'            \
45b07e
		-e 's@ '"$mb_source_dir"'@ /c %source_dir%@'    \
45b07e
		-e 's@-o @/Fo @g'                               \
45b07e
		-e 's@\.s@\.asm@g'                              \
45b07e
		-e 's,$,\n\n'"$cmd_abort_on_error"'\n,g'
45b07e
45b07e
# six: compile C sources
81d456
make shared-objs static-objs app-objs                           \
81d456
	 | grep -v 'make\[1\]:'                                 \
81d456
	 | grep -v "$mb_project_dir/sysinfo/host"               \
81d456
	 | grep -v 'touch dirs.tag'                             \
81d456
	 | grep -v 'touch host.tag'                             \
81d456
	 | grep -v 'touch version.tag'                          \
81d456
	 | grep -v 'touch app.tag'                              \
81d456
	 | sed                                                  \
81d456
		-e 's@'"$mb_cc -c "'@cl /nologo -c @'           \
81d456
		-e 's@ '"$mb_source_dir"'@ %source_dir%@'       \
81d456
		-e 's@-I'"$mb_source_dir"'@-I%source_dir%@g'    \
81d456
		-e 's@-ffreestanding@/X /GS-@g'                 \
81d456
		-e 's@-o @/Fo:@g'                               \
81d456
		-e 's@-std=c99 @@g'                             \
81d456
		-e 's@-fPIC@@g'                                 \
81d456
		-e 's@-fpic@@g'                                 \
81d456
		-e 's@-g @/Zi @g'                               \
81d456
		-e 's@-g0 @/Zi @g'                              \
81d456
		-e 's@-g1 @/Zi @g'                              \
81d456
		-e 's@-g2 @/Zi @g'                              \
81d456
		-e 's@-g3 @/Zi @g'                              \
81d456
		-e 's@-O @/O2 @g'                               \
81d456
		-e 's@-Os @/O1 @g'                              \
81d456
		-e 's@-O0 @/Od @g'                              \
81d456
		-e 's@-O1 @/O2 @g'                              \
81d456
		-e 's@-O2 @/O2 @g'                              \
81d456
		-e 's@-O3 @/O2 @g'                              \
81d456
		-e 's@-Wall @/Wall @g'                          \
81d456
		-e 's@-Werror @/WX @g'                          \
81d456
		-e 's@-Wextra @@g'                              \
81d456
		-e 's@-Wundef @/Wall @g'                        \
e31b41
		-e 's@-Wno-missing-field-initializers @ @g'     \
4f436d
		-e 's@-Wno-unused-parameter @/wd4100 @g'        \
ef682c
		-e 's@-mno-stack-arg-probe @/Gs65536 @g'        \
81d456
		-e 's@'"$mb_sysroot "'@ @'                      \
0e817b
		-e 's,$, '"$version_macro"' -I%sysroot%/include\n\n'"$cmd_abort_on_error"'\n,g'
81d456
81d456
echo
81d456
echo '@echo.'
81d456
echo '@echo clbuild: successfully built: shared-objs static-objs app-objs.'
81d456
echo '@echo.'
81d456
echo
81d456
45b07e
# seven: create static archive
81d456
make static                                             \
81d456
	 | grep -v 'make\[1\]:'                         \
81d456
	 | grep -v "rm -f "                             \
81d456
	 | sed                                          \
81d456
		-e 's@'"$mb_ar"' rcs @lib /out:@'       \
81d456
		-e 's,$, /nologo\n,g'
81d456
81d456
echo
81d456
echo "$cmd_abort_on_error"
81d456
echo
81d456
81d456
echo
81d456
echo '@echo.'
81d456
echo '@echo clbuild: successfully created: static archive.'
81d456
echo '@echo.'
81d456
echo
81d456
89c3ba
# eight: link
89c3ba
make LDFLAGS_IMPLIB= LDFLAGS_SONAME= $link_target                     \
bfa35b
	 | grep -v 'make\[1\]:'                                       \
89c3ba
	 | grep -v 'rm -f app\.tag'                                   \
bfa35b
	 | sed                                                        \
bfa35b
		-e 's@'"$mb_cc"' -shared @link /dll /nologo @'        \
9125b1
		-e 's@'"$mb_cc"' -static @link /nologo @'             \
89c3ba
		-e 's@'"$mb_cc"' @link /nologo @'                     \
bfa35b
		-e 's@-o @/out:@g'                                    \
bfa35b
		-e 's@ -L@ /libpath:@g'                               \
bfa35b
		-e 's,-static -l\([^ ]\+\), %sysroot%/lib/lib\1.a,g'  \
bfa35b
		-e 's, -l\([^ ]\+\), %sysroot%/lib/lib\1.lib,g'       \
bfa35b
		-e 's@-nostdlib @/nodefaultlib @g'                    \
bfa35b
		-e 's@-Wl,--subsystem=@/subsystem:@g'                 \
bfa35b
		-e 's@-Wl,--entry -Wl,'"''"'@/entry:@g'               \
bfa35b
		-e 's@-Wl,--entry -Wl,@/entry:@g'                     \
bfa35b
		-e 's@-Wl,--no-undefined@@g'                          \
bfa35b
		-e 's@-Wl,--exclude-all-symbols@@g'                   \
bfa35b
		-e 's@'"$mb_sysroot "'@ @'                            \
81d456
81d456
echo
81d456
echo "$cmd_abort_on_error"
81d456
echo
81d456
81d456
echo
81d456
echo '@echo.'
81d456
echo '@echo clbuild: successfully linked: shared library.'
81d456
echo '@echo.'
81d456
echo
81d456
81d456
echo
81d456
echo '@echo.'
81d456
echo '@echo yay.'
81d456
echo '@echo.'
81d456
echo
81d456
81d456
# all done
81d456
exit 0