Newer
Older
snipet / project / trunk / tools / adlint / init / adlint.sh
#!/bin/sh

if [ "${1}" != "" ];then
TOPDIR=${1}
else
TOPDIR=../../..
fi



# ------------------------------------------------------------------------------
#  設定
# ------------------------------------------------------------------------------
PROJECT=project
TOPDIR_REGEXP=`echo "${TOPDIR}" | sed "s/\\([\\.|\\/]\\)/\\\\\\\\\\1/g"`
TARGET_OS=`grep "TARGET_OS" "${TOPDIR}/env.mk" | grep -v "^#" | sed "s/.*\\(OS_.*\\)$/\\1/"`



# ------------------------------------------------------------------------------
#  設定ファイル定義
# ------------------------------------------------------------------------------
INCLUDE_P_ENV=../include_p.env
INCLUDE_C_ENV=../include_c.env
TYPE_ENV=../type.env
CONFIG_DIR=../config
MAKEFILE=${CONFIG_DIR}/Makefile
ADLINT_CINIT_H=${CONFIG_DIR}/adlint_cinit.h
ADLINT_PINIT_H=${CONFIG_DIR}/adlint_pinit.h
ADLINT_FILES_TXT=${CONFIG_DIR}/adlint_files.txt
ADLINT_TRAITS_YML=${CONFIG_DIR}/adlint_traits.yml



# ------------------------------------------------------------------------------
#  adlint_traits.yml 生成
# ------------------------------------------------------------------------------
function mkTraits()
{
cat <<EOF > ${ADLINT_TRAITS_YML}
# ------------------------------------------------------------------------------
#  ADLINT のバージョン
# ------------------------------------------------------------------------------
version: "3.0.0"

# ------------------------------------------------------------------------------
#  ソースコード検査パッケージ設定
# ------------------------------------------------------------------------------
exam_packages:
  - "c_builtin"



# ============================================================================== 
#  プロジェクトの設定
# ============================================================================== 
project_traits:
  # ----------------------------------------------------------------------------
  #  プロジェクト名
  # ----------------------------------------------------------------------------
  project_name: "${PROJECT}"

  # ----------------------------------------------------------------------------
  #  プロジェクト ルートディレクトリ
  # ----------------------------------------------------------------------------
  project_root: "${TOPDIR}"

  # ----------------------------------------------------------------------------
  #  対象ファイル
  # ----------------------------------------------------------------------------
  target_files:
    inclusion_paths:
      - "${TOPDIR}"
    exclusion_paths:


  # ----------------------------------------------------------------------------
  #  プロジェクト固有のイニシャルヘッダファイル
  # ----------------------------------------------------------------------------
  initial_header: "${ADLINT_PINIT_H}"

  # ----------------------------------------------------------------------------
  #  プロジェクトヘッダファイル検索パス
  # ----------------------------------------------------------------------------
  file_search_paths:
    - "${TOPDIR}/include"
    - "${TOPDIR}/include/sc"
EOF
# 追加 include パスを追加します.
if [ -f ${INCLUDE_P_ENV} ]; then
cat ${INCLUDE_P_ENV} >> ${ADLINT_TRAITS_YML}
fi
cat <<EOF >> ${ADLINT_TRAITS_YML}
  
  # ----------------------------------------------------------------------------
  #  コーディングスタイル
  # ----------------------------------------------------------------------------
  # indent_style: "K%R"
  # indent_style: "GNU"
  coding_style:
    indent_style: "Allman"
    tab_width: 4
    indent_width: 4

  # ----------------------------------------------------------------------------
  #  ファイルエンコード
  # ----------------------------------------------------------------------------
  file_encoding: UTF-8



# ============================================================================== 
#  コンパイラの設定
# ============================================================================== 
compiler_traits:

  # ----------------------------------------------------------------------------
  #  コンパイラ固有のイニシャルヘッダファイル
  # ----------------------------------------------------------------------------
  initial_header: "${ADLINT_CINIT_H}"

  # ----------------------------------------------------------------------------
  #  コンパイラヘッダファイル検索パス
  # ----------------------------------------------------------------------------
  file_search_paths:
EOF
# 追加 include パスを追加します.
if [ -f ${INCLUDE_C_ENV} ]; then
cat ${INCLUDE_C_ENV} >> ${ADLINT_TRAITS_YML}
fi
cat <<EOF >> ${ADLINT_TRAITS_YML}

  # ----------------------------------------------------------------------------
  #  コンパイラ型タイプ
  # ----------------------------------------------------------------------------
  standard_types:
EOF
cat ${TYPE_ENV} >> ${ADLINT_TRAITS_YML}
cat <<EOF >> ${ADLINT_TRAITS_YML}

  # ----------------------------------------------------------------------------
  #  コンパイラ固有の拡張機能調整 (使用時 W0061出力)
  # ----------------------------------------------------------------------------
  extension_substitutions:
    "__extension__": ""
    "__attribute__(__adlint__any)": ""
    "__cdecl": ""
    "__inline__": "inline"
    "__asm__ __adlint__any(__adlint__any)": ""
    "near": ""
    "far": ""

  # ----------------------------------------------------------------------------
  #  コンパイラ固有の拡張機能調整 (使用時 エラー出力なし)
  # ----------------------------------------------------------------------------
  arbitrary_substitutions:
    "typeof": "__typeof__"
    "__typeof": "__typeof__"
    "alignof": "__alignof__"
    "__alignof": "__alignof__"



# ============================================================================== 
#  リンカの設定
# ============================================================================== 
linker_traits:
  identifier_max: 128
  identifier_ignore_case: false



# ============================================================================== 
#  メッセージ設定
# ============================================================================== 
message_traits:
  language: "ja_JP"
  individual_suppression: true

  exclusion:
    messages:
      W0070: "c_builtin"
      W0105: "c_builtin"
      W0576: "c_builtin"
      W0628: "c_builtin"

  inclusion:

EOF

}



# ------------------------------------------------------------------------------
#  adlint_cinit.h 生成
# ------------------------------------------------------------------------------
function mkCinit()
{
cat adlint_cinit.h.tmpl >> ${ADLINT_CINIT_H}
}



# ------------------------------------------------------------------------------
#  adlint_pinit.h 生成
# ------------------------------------------------------------------------------
function mkPinit()
{
cat <<EOF > ${ADLINT_PINIT_H}
/* =============================================================================
 * プロジェクトのマクロ・型定義
 * =============================================================================
 */
#define TARGET_OS ${TARGET_OS}

EOF
}



# ------------------------------------------------------------------------------
#  adlint_files.txt 生成
# ------------------------------------------------------------------------------
function mkFiles()
{
	find ${TOPDIR}/modules -name *.c | grep -v unittest > ${ADLINT_FILES_TXT}
	echo "" >> ${ADLINT_FILES_TXT}
}



# ------------------------------------------------------------------------------
#  Makefile 生成
# ------------------------------------------------------------------------------
function mkMakefile()
{
cat <<EOF > ${MAKEFILE}
PROJECT = ${PROJECT}

SOURCES = \\
EOF

cat ${ADLINT_FILES_TXT} | sed "s/${TOPDIR_REGEXP}\\//\t/" >> ${MAKEFILE}

cat <<EOF >> ${MAKEFILE}

VPATH=${TOPDIR}
VPATH_COMPONENTS=3

EOF
cat Makefile.tmpl >> ${MAKEFILE}

}


# ------------------------------------------------------------------------------
#  各設定ファイル生成
# ------------------------------------------------------------------------------

if [ ! -f ${ADLINT_TRAITS_YML} ]; then
	mkTraits
fi
if [ ! -f ${ADLINT_CINIT_H} ]; then
	mkCinit
fi
if [ ! -f ${ADLINT_PINIT_H} ]; then
	mkPinit
fi


mkFiles
mkMakefile