From 5dc983925380bb06a4d6d0d660e2c8b80a71eac4 Mon Sep 17 00:00:00 2001 From: midipix Date: Fri, 14 Dec 2018 07:12:25 -0500 Subject: build system: created skeleton. --- sofort/cfgtest.sh | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ sofort/custom.mk | 76 +++++++++++++++++++++++++ sofort/defs.mk | 66 ++++++++++++++++++++++ sofort/pkgconf.mk | 40 +++++++++++++ sofort/pkgconf.sh | 92 ++++++++++++++++++++++++++++++ sofort/version.mk | 63 +++++++++++++++++++++ 6 files changed, 501 insertions(+) create mode 100644 sofort/cfgtest.sh create mode 100644 sofort/custom.mk create mode 100644 sofort/defs.mk create mode 100644 sofort/pkgconf.mk create mode 100755 sofort/pkgconf.sh create mode 100644 sofort/version.mk (limited to 'sofort') diff --git a/sofort/cfgtest.sh b/sofort/cfgtest.sh new file mode 100644 index 0000000..cb1e069 --- /dev/null +++ b/sofort/cfgtest.sh @@ -0,0 +1,164 @@ +# cfgtest.sh: sofort's config test framework, +# for use from within a project's custom cfgdefs.sh. + +# in the common scenario, target-specific tests are preceded +# by a single invocation of cfgtest_target_section, whereas +# native (build) system tests are preceded by the invocation +# of cfgtest_native_section. + +# cfgdefs fraework variables: +# mb_cfgtest_cc: the compiler used for the current test +# mb_cfgtest_cflags: the compiler flags used for the current test +# mb_cfgtest_cfgtype: the type of the current test (target/native) +# mb_cfgtest_makevar: the make variable affected by the current test +# mb_cfgtest_headers: headers for ad-hoc inclusion with the current test + + +cfgtest_newline() +{ + printf '\n' >> $mb_pwd/cfgdefs.mk +} + + +cfgtest_comment() +{ + mb_internal_str='#' + + for mb_internal_arg ; do + mb_internal_str="$mb_internal_str $mb_internal_arg" + done + + printf '%s\n' "$mb_internal_str" >> $mb_pwd/cfgdefs.mk +} + + +cfgtest_target_section() +{ + mb_cfgtest_cc=$(make -s -f "$mb_pwd/Makefile.tmp" .display-cc) + mb_cfgtest_cflags=$(make -s -f "$mb_pwd/Makefile.tmp" .display-cflags) + mb_cfgtest_cfgtype='target' + + cfgtest_comment 'target-specific tests' +} + + +cfgtest_native_section() +{ + mb_cfgtest_cc="$mb_native_cc" + mb_cfgtest_cflags="$mb_native_cc_cflags" + mb_cfgtest_cfgtype='native' + + cfgtest_comment 'native system tests' +} + + +cfgtest_makevar_append() +{ + mb_internal_str='+=' + + for mb_internal_arg ; do + mb_internal_str="$mb_internal_str $mb_internal_arg" + done + + printf '%-24s%s\n' "$mb_cfgtest_makevar" "$mb_internal_str" \ + >> $mb_pwd/cfgdefs.mk +} + + +cfgtest_cflags_append() +{ + if [ $mb_cfgtest_cfgtype = 'target' ]; then + mb_internal_makevar='CFLAGS_CONFIG' + else + mb_internal_makevar='NATIVE_CC_CFLAGS' + fi + + mb_cfgtest_makevar_saved=$mb_cfgtest_makevar + mb_cfgtest_makevar=$mb_internal_makevar + + cfgtest_makevar_append "$@" + mb_cfgtest_makevar=$mb_cfgtest_makevar_saved +} + + +cfgtest_ldflags_append() +{ + if [ $mb_cfgtest_cfgtype = 'target' ]; then + mb_internal_makevar='LDFLAGS_CONFIG' + else + mb_internal_makevar='NATIVE_CC_LDFLAGS' + fi + + mb_cfgtest_makevar_saved=$mb_cfgtest_makevar + mb_cfgtest_makevar=$mb_internal_makevar + + cfgtest_makevar_append "$@" + mb_cfgtest_makevar=$mb_cfgtest_makevar_saved +} + + +cfgtest_header_presence() +{ + $mb_cfgtest_cc -E -xc - \ + $mb_cfgtest_cflags \ + --include="$@" \ + < /dev/null \ + > /dev/null 2>/dev/null \ + || return + + mb_internal_str=$(printf '%s%s' '-DHAVE_' "$@" \ + | sed -e 's/\./_/g' \ + | tr "[:lower:]" "[:upper:]") + + cfgtest_cflags_append "$mb_internal_str" +} + + +cfgtest_header_absence() +{ + $mb_cfgtest_cc -E -xc - \ + $mb_cfgtest_cflags \ + --include="$@" \ + < /dev/null \ + > /dev/null 2>/dev/null \ + && return + + mb_internal_str=$(printf '%s%s' '-DHAVE_NO_' "$@" \ + | sed -e 's/\./_/g' \ + | tr "[:lower:]" "[:upper:]") + + cfgtest_cflags_append "$mb_internal_str" +} + + +cfgtest_interface_presence() +{ + mb_internal_cflags='' + + for mb_header in $mb_cfgtest_headers; do + mb_internal_cflags="$mb_internal_cflags --include=$mb_header" + done + + printf 'void * addr = &%s;' "$@" \ + | $mb_cfgtest_cc -S -xc - -o - \ + $mb_cfgtest_cflags \ + $mb_internal_cflags \ + > /dev/null 2>/dev/null \ + || return 1 + + return 0 +} + +cfgtest_library_presence() +{ + printf 'int main(void){return 0;}' \ + | $mb_cfgtest_cc -o a.out -xc - \ + $mb_cfgtest_cflags \ + $@ \ + > /dev/null 2>/dev/null \ + || return 1 + + rm -f a.out + + return 0 +} diff --git a/sofort/custom.mk b/sofort/custom.mk new file mode 100644 index 0000000..8e0bbc4 --- /dev/null +++ b/sofort/custom.mk @@ -0,0 +1,76 @@ +ifeq ($(OS_BINFMT),PE) +include $(PROJECT_DIR)/sysinfo/os/pe.mk +endif + +ifeq ($(OS_BINFMT),ELF) +include $(PROJECT_DIR)/sysinfo/os/elf.mk +endif + + + +ifeq ($(DISABLE_STATIC),yes) +package-static: +package-install-static: +else +package-static: static +package-install-static: install-static +endif + +ifeq ($(DISABLE_SHARED),yes) +package-shared: +package-install-shared: +else +package-shared: shared +package-install-shared: install-shared +endif + + + +ifeq ($(DISABLE_FRONTEND),yes) +app-tag: +package-install-app: +package-install-extras: +else +app-tag: package-app app.tag +package-install-app: install-app +package-install-extras: install-extras +endif + + + +ifeq ($(ALL_STATIC),yes) + +package-app: static-app +app: PACKAGE_APP = $(STATIC_APP) +app-tag: PACKAGE_APP = $(STATIC_APP) +app.tag: $(STATIC_APP) + + +else ifeq ($(ALL_SHARED),yes) + +package-app: shared-app +app: PACKAGE_APP = $(SHARED_APP) +app-tag: PACKAGE_APP = $(SHARED_APP) +app.tag: $(SHARED_APP) + + +else + +package-app: default-app +app: PACKAGE_APP = $(DEFAULT_APP) +app-tag: PACKAGE_APP = $(DEFAULT_APP) +app.tag: $(DEFAULT_APP) + +endif + + + +ifeq ($(CUSTOM_INSTALL_HEADERS),yes) + +install-headers:install-headers-custom + +else + +install-headers:install-headers-default + +endif diff --git a/sofort/defs.mk b/sofort/defs.mk new file mode 100644 index 0000000..151bc3d --- /dev/null +++ b/sofort/defs.mk @@ -0,0 +1,66 @@ +SHARED_LIB_DEPS = +SHARED_APP_DEPS = +STATIC_APP_DEPS = + +COMMON_LOBJS = $(COMMON_SRCS:.c=.lo) +COMMON_OBJS = $(COMMON_SRCS:.c=.o) + +ARCH_LOBJS = $(ARCH_SRCS:.c=.lo) +ARCH_OBJS = $(ARCH_SRCS:.c=.o) + +APP_LOBJS = $(APP_SRCS:.c=.lo) +APP_OBJS = $(APP_SRCS:.c=.o) + +SHARED_OBJS = $(COMMON_LOBJS) $(ARCH_LOBJS) +STATIC_OBJS = $(COMMON_OBJS) $(ARCH_OBJS) + +STATIC_LIB_NAME = $(OS_LIB_PREFIX)$(PACKAGE)$(OS_ARCHIVE_EXT) +STATIC_LIB = lib/$(STATIC_LIB_NAME) + +DSO_VER = $(OS_LIB_PREFIX)$(PACKAGE)$(OS_LIB_PREFIXED_SUFFIX)$(VER_XYZ)$(OS_LIB_SUFFIXED_SUFFIX) +DSO_SONAME = $(OS_LIB_PREFIX)$(PACKAGE)$(OS_LIB_PREFIXED_SUFFIX)$(VER_SONAME)$(OS_LIB_SUFFIXED_SUFFIX) +DSO_SOLINK = $(OS_LIB_PREFIX)$(PACKAGE)$(OS_LIB_SUFFIX) + +SHARED_LIB = lib/$(DSO_VER) +SHARED_SONAME = lib/$(DSO_SONAME) +SHARED_SOLINK = lib/$(DSO_SOLINK) + +IMP_DEF = $(OS_LIB_PREFIX)$(PACKAGE)$(VER_XYZ)$(OS_LIBDEF_EXT) +IMP_VER = $(OS_LIB_PREFIX)$(PACKAGE)$(VER_XYZ)$(OS_IMPLIB_EXT) +IMP_SONAME = $(OS_LIB_PREFIX)$(PACKAGE)$(VER_SONAME)$(OS_IMPLIB_EXT) +IMP_SOLINK = $(OS_LIB_PREFIX)$(PACKAGE)$(OS_IMPLIB_EXT) + +IMPLIB_DEF = lib/$(IMP_DEF) +IMPLIB_VER = lib/$(IMP_VER) +IMPLIB_SONAME = lib/$(IMP_SONAME) +IMPLIB_SOLINK = lib/$(IMP_SOLINK) + +APP = bin/$(OS_APP_PREFIX)$(NICKNAME)$(OS_APP_SUFFIX) +DEFAULT_APP = bin/$(OS_APP_PREFIX)$(NICKNAME)-default$(OS_APP_SUFFIX) +SHARED_APP = bin/$(OS_APP_PREFIX)$(NICKNAME)-shared$(OS_APP_SUFFIX) +STATIC_APP = bin/$(OS_APP_PREFIX)$(NICKNAME)-static$(OS_APP_SUFFIX) + +CFLAGS = $(CFLAGS_DEBUG) $(CFLAGS_CONFIG) $(CFLAGS_SYSROOT) \ + $(CFLAGS_COMMON) $(CFLAGS_CMDLINE) $(CFLAGS_HOST) \ + $(CFLAGS_PATH) $(CFLAGS_OS) $(CFLAGS_SITE) \ + $(CFLAGS_VERSION) $(CFLAGS_STRICT) \ + $(CFLAGS_LAST) $(CFLAGS_ONCE) + +CFLAGS_SHARED = $(CFLAGS) $(CFLAGS_PIC) $(CFLAGS_SHARED_ATTR) +CFLAGS_STATIC = $(CFLAGS) $(CFLAGS_OBJ) $(CFLAGS_STATIC_ATTR) +CFLAGS_APP = $(CFLAGS) $(CFLAGS_OBJ) $(CFLAGS_APP_ATTR) $(CFLAGS_UTIL) + +LDFLAGS_SHARED = $(LDFLAGS_DEBUG) $(LDFLAGS_CONFIG) $(LDFLAGS_SYSROOT) \ + $(LDFLAGS_COMMON) $(LDFLAGS_CMDLINE) $(LDFLAGS_HOST) \ + $(LDFLAGS_PATH) $(SHARED_LIB_DEPS) $(LDFLAGS_STRICT) \ + $(LDFLAGS_LAST) $(LDFLAGS_ONCE) + +LDFLAGS_APP = $(LDFLAGS_DEBUG) $(LDFLAGS_CONFIG) $(LDFLAGS_SYSROOT) \ + $(LDFLAGS_COMMON) $(LDFLAGS_CMDLINE) $(LDFLAGS_HOST) \ + $(LDFLAGS_PATH) $(SHARED_APP_DEPS) $(LDFLAGS_STRICT) \ + $(LDFLAGS_UTIL) $(LDFLAGS_LAST) $(LDFLAGS_ONCE) + +LDFLAGS_STATIC = $(LDFLAGS_DEBUG) $(LDFLAGS_CONFIG) $(LDFLAGS_SYSROOT) \ + $(LDFLAGS_COMMON) $(LDFLAGS_CMDLINE) $(LDFLAGS_HOST) \ + $(LDFLAGS_PATH) $(STATIC_APP_DEPS) $(LDFLAGS_STRICT) \ + $(LDFLAGS_LAST) $(LDFLAGS_ONCE) diff --git a/sofort/pkgconf.mk b/sofort/pkgconf.mk new file mode 100644 index 0000000..59a54e0 --- /dev/null +++ b/sofort/pkgconf.mk @@ -0,0 +1,40 @@ +ifeq ($(PKGCONF),no) + +install-pkgconf: + +else + +PKGCONF_VERSION = $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) + +build/$(PACKAGE).pc: .pkgconf + +build/$(PACKAGE).pc: + @touch $@ + @chmod 0644 $@ + PKGCONF_NAME='$(PKGNAME)' \ + PKGCONF_DESC='$(PKGDESC)' \ + PKGCONF_USRC='$(PKGUSRC)' \ + PKGCONF_REPO='$(PKGREPO)' \ + PKGCONF_PSRC='$(PKGPSRC)' \ + PKGCONF_DURL='$(PKGDURL)' \ + PKGCONF_DEFS='$(PKGDEFS)' \ + PKGCONF_LIBS='$(PKGLIBS)' \ + \ + PKGCONF_EXEC_PREFIX='$(EXEC_PREFIX)' \ + PKGCONF_PREFIX='$(PREFIX)' \ + PKGCONF_LIBDIR='$(LIBDIR)' \ + PKGCONF_INCLUDEDIR='$(INCLUDEDIR)' \ + PKGCONF_VERSION='$(PKGCONF_VERSION)' \ + $(PROJECT_DIR)/sofort/pkgconf.sh > $@ + +install-pkgconf: build/$(PACKAGE).pc + mkdir -p $(DESTDIR)$(LIBDIR)/pkgconfig + cp -p build/$(PACKAGE).pc $(DESTDIR)$(LIBDIR)/pkgconfig + +install-shared: install-pkgconf + +install-static: install-pkgconf + +.PHONY: .pkgconf install-pkgconf + +endif diff --git a/sofort/pkgconf.sh b/sofort/pkgconf.sh new file mode 100755 index 0000000..a3f8eb0 --- /dev/null +++ b/sofort/pkgconf.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +# prefix, exec_prefix +if [ "$PKGCONF_PREFIX" = "$PKGCONF_EXEC_PREFIX" ]; then + echo 'prefix='${PKGCONF_PREFIX} + echo 'exec_prefix=${prefix}' +else + echo 'prefix='${PKGCONF_PREFIX} + echo 'exec_prefix='${PKGCONF_EXEC_PREFIX} +fi + + +# (relative) includedir +prefix=`dirname "$PKGCONF_INCLUDEDIR"` +base=`basename "$PKGCONF_INCLUDEDIR"` + +if [ "$prefix/$base" = "$PKGCONF_PREFIX/$base" ]; then + echo 'includedir=${prefix}/'${base} +else + echo 'includedir='${PKGCONF_INCLUDEDIR} +fi + +if [ "$prefix/$base" = "$PKGCONF_PREFIX/include" ]; then + CFLAGS= +else + CFLAGS='-I{includedir}' +fi + + +# (relative) libdir +prefix=`dirname "$PKGCONF_LIBDIR"` +base=`basename "$PKGCONF_LIBDIR"` + +if [ "$prefix/$base" = "$PKGCONF_EXEC_PREFIX/$base" ]; then + echo 'libdir=${prefix}/'${base} +else + echo 'libdir='${PKGCONF_LIBDIR} +fi + +if [ "$prefix/$base" = "$PKGCONF_EXEC_PREFIX/lib" ]; then + LDFLAGS='-l'${PKGCONF_NAME} +elif [ "$prefix/$base" = "$PKGCONF_EXEC_PREFIX/lib64" ]; then + LDFLAGS='-l'${PKGCONF_NAME} +else + LDFLAGS='-L'${PKGCONF_LIBDIR} '-l'${PKGCONF_NAME} +fi + + +# name, description, url, version +echo +echo 'Name: '${PKGCONF_NAME} +echo 'Description: '${PKGCONF_DESC} +echo 'URL: '${PKGCONF_USRC} +echo 'Version: '${PKGCONF_VERSION} + + +# repo (optional) +if ! [ -z "$PKGCONF_REPO" ]; then + echo 'Repo: '${PKGCONF_REPO} +fi + + +# patches (optional) +if ! [ -z "$PKGCONF_PSRC" ]; then + echo 'Patches: '${PKGCONF_PSRC} +fi + + +# disto (optional) +if ! [ -z "$PKGCONF_DURL" ]; then + echo 'Distro: '${PKGCONF_DURL} +fi + + +# Cflags +if [ -z "$PKGCONF_DEFS" ] && [ -z "$CFLAGS" ]; then + echo 'Cflags:' +elif [ -z "$PKGCONF_DEFS" ]; then + echo 'Cflags: '${CFLAGS} +elif [ -z "$CFLAGS" ]; then + echo 'Cflags: '${PKGCONF_DEFS} +else + echo 'Cflags: '${PKGCONF_DEFS} ${CFLAGS} +fi + + +# Libs +if [ -z "$PKGCONF_LIBS" ]; then + echo 'Libs: '${LDFLAGS} +else + echo 'Libs: '${PKGCONF_LIBS} ${LDFLAGS} +fi diff --git a/sofort/version.mk b/sofort/version.mk new file mode 100644 index 0000000..5ef0ee2 --- /dev/null +++ b/sofort/version.mk @@ -0,0 +1,63 @@ +include $(PROJECT_DIR)/project/tagver.mk + +CFLAGS_VERSION += -D$(VER_NAMESPACE)_TAG_VER_MAJOR=$(VER_MAJOR) +CFLAGS_VERSION += -D$(VER_NAMESPACE)_TAG_VER_MINOR=$(VER_MINOR) +CFLAGS_VERSION += -D$(VER_NAMESPACE)_TAG_VER_PATCH=$(VER_PATCH) + +ifeq ($(AVOID_VERSION),yes) + +VER_XYZ = +VER_SONAME = + +package-shared-soname: +package-shared-solink: +package-install-soname: +package-install-solink: + +else + +VER_XYZ = .$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) +VER_SONAME = .$(VER_MAJOR) + +package-shared-soname: shared-soname +package-shared-solink: shared-solink +package-install-soname: install-soname +package-install-solink: install-solink + + + +# libfoo.so (common) +install-solink: install-lib + rm -f $(SHARED_SOLINK).tmp + ln -s $(DSO_VER) $(SHARED_SOLINK).tmp + mv $(SHARED_SOLINK).tmp $(DESTDIR)$(LIBDIR)/$(DSO_SOLINK) + +$(SHARED_SOLINK): $(SHARED_LIB) + rm -f $@.tmp + ln -s $(DSO_VER) $@.tmp + mv $@.tmp $@ + +# libfoo.so.x (symlink) +ifeq ($(OS_SONAME),symlink) +$(SHARED_SONAME): $(SHARED_LIB) + rm -f $@.tmp + ln -s $(DSO_VER) $@.tmp + mv $@.tmp $@ + +install-soname: install-lib + rm -f $(SHARED_SONAME).tmp + ln -s $(DSO_VER) $(SHARED_SONAME).tmp + mv $(SHARED_SONAME).tmp $(DESTDIR)$(LIBDIR)/$(DSO_SONAME) +endif + + +# libfoo.so.x (copy) +ifeq ($(OS_SONAME),copy) +install-soname: install-lib + cp $(SHARED_LIB) $(DESTDIR)$(LIBDIR)/$(DSO_SONAME) + +$(SHARED_SONAME): $(SHARED_LIB) + cp $(SHARED_LIB) $(SHARED_SONAME) +endif + +endif -- cgit v1.2.3