全てのプロジェクトをビルドするスクリプト

今回のネタは凄く短い・・・

実は、少しぶれてた・・
要は、複数ディレクトリーに色々なプロジェクトがあり、それらを全てコンパイル
する手順だった。

「glfw_app」の場合

drwxr-xr-x 1 hira None   0 9月  22 09:02 basic/
drwxr-xr-x 1 hira None   0 9月  22 09:05 bmc/
drwxr-xr-x 1 hira None   0 9月  22 09:09 cave/
drwxr-xr-x 1 hira None   0 7月   9 08:21 common/
drwxr-xr-x 1 hira None   0 9月  22 09:13 daev/
drwxr-xr-x 1 hira None   0 9月  21 12:43 dllcollect/
drwxr-xr-x 1 hira None   0 7月   9 08:21 docs/
drwxr-xr-x 1 hira None   0 9月  22 09:16 effv/
drwxr-xr-x 1 hira None   0 9月  22 09:16 gui_test/
drwxr-xr-x 1 hira None   0 9月  22 00:00 image/
drwxr-xr-x 1 hira None   0 9月  22 09:16 iod_make/
drwxr-xr-x 1 hira None   0 7月   9 08:21 libraries/
drwxr-xr-x 1 hira None   0 8月  17 15:38 MPU6050viewer/
drwxr-xr-x 1 hira None   0 9月  22 09:24 open_ide/
drwxr-xr-x 1 hira None   0 9月  22 09:24 piano_sim/
drwxr-xr-x 1 hira None   0 9月  21 22:21 player/
drwxr-xr-x 1 hira None   0 9月  22 09:25 pmdv/
drwxr-xr-x 1 hira None   0 9月  22 09:27 pn/
drwxr-xr-x 1 hira None   0 9月  22 09:27 spinv/
drwxr-xr-x 1 hira None   0 9月  22 09:28 vfs/
drwxr-xr-x 1 hira None   0 9月  22 09:29 vplayer/

一番簡単なのは、各プロジェクトのディレクトリーを指定して、「make」を実行す
る方法だ、しかしこれだと、プロジェクトが増える度に編集が必要となる。

RL78 では、xxx_sample をプロジェクトのディレクトリーとして、そのディレクト
リーに移動して「make」するスクリプトを作っていた。

ADC_sample/            DS1371_sample/              KiCAD_lib/         SDC_sample/
ADC_SWITCH_sample/     DS3231_sample/              LCD_DOT_sample/    SOFT_DELAY_sample/
ff12a/                 LCD_FILER_sample/           START_BOARD/
ARITH_sample/          FIRST_sample/               LICENSE            TMPtest/
BMP180_sample/         G13/                        MPU6050_sample/    TOUCH_sample/
chip/                  I2C_sample/                 PWM_sample/        UART_sample/
common/                images/                     R5F100LGA.jpg      VS1063_PLAYER_sample/
DATA_FLASH_sample/     INTERVAL_TIMER_sample/      README.md          WAV_PLAYER_sample/
Doxyfile               INTERVAL_TIMER_TAU_sample/  rl78prog/

ただ、これだと、「rl78prog」内のツールはビルでされない・・

そこで、良く考えたら、「Makefile」が存在するディレクトリーだけ抜き出して、「make」
を起動すれば良いと判った、何でこんな簡単な事を思いつかなかったのか不思議である。

その要件に従い、shell スクリプトを作成した。
OS-X で期待した動作にならなかったので修正
「clean」を事前に全て実行するように修正

#!/bin/bash
CMDNAME=`basename $0`
if [[ $1 = "help" ]]; then
  echo "Usage: $CMDNAME [clean]"
  echo ""
  exit
fi

RED=`tput setaf 1`
GREEN=`tput setaf 2`
PINK=`tput setaf 5`
LIGHTBLUE=`tput setaf 6`
NOCOLOR=`tput sgr0`

# make clean
if [[ $1 = "clean" ]]; then
  for file in `ls -d *`
  do
    if [ -e "${file}/Makefile" ]; then
      cd "${file}"
      echo "${GREEN}Clean project: " ${file} "${NOCOLOR}"
      make clean >& /dev/null
      if [ $? -ne 0 ]; then
        echo "${RED}Error: " ${file} "${NOCOLOR}"
        echo ""
        break;
      fi
      cd ..
    fi
  done
fi

# make
for file in `ls -d *`
do
  if [ -e "${file}/Makefile" ]; then
    echo "${PINK}Start project: " ${file} "${NOCOLOR}"
    cd "${file}"
    make > /dev/null
    if [ $? -ne 0 ]; then
      echo "${RED}Compile error: " ${file} "${NOCOLOR}"
      echo ""
      break;
    fi
    cd ..
    echo "${LIGHTBLUE}Build project: " ${file} "${NOCOLOR}"
  fi
done

これで、glfw_app、R8C、RL78 と全て動的に全ビルドが出来るようになった。

機能としては、

sh all_project_build.sh

単独で起動すれば、全体に「make」を行なう。

sh all_project_build.sh clean

とすれば、一旦「make clean」してから「make」する。

OS-X って、何で「echo」の「-e」
オプションが出来ないのか・・・

「全てのプロジェクトをビルドするスクリプト」への1件のフィードバック

  1. 今晩は。
    直ぐに試して見るのが習性で早速RL78でやって見ました。
    m_test.sh(make testの意)に上記スクリプトをコピペして
    ebi@ebi-PC MSYS /usr/local/src/gnu/rl78
    $ sh m_test.sh
    Start project: ADC_sample
    mkdir -p release/; \
    rl78-elf-g++ -MM -DDEPEND_ESCAPE -std=c++14 -Wall -Werror -Wno-unused-variable -Wno-exceptions -Wno-unused-function -Os -flto -mmul=g13 -DF_CLK=32000000 -DDEVICE_SIG=R5F100LGAFB -I. -I../ -I../G13 main.cpp \
    途中略
    rl78-elf-objcopy –srec-forceS3 –srec-len 32 -O srec wav_play_sample.elf wav_play_sample.mot
    rl78-elf-objdump -h -S wav_play_sample.elf > wav_play_sample.lst
    End project: WAV_PLAYER_sample

    すべてのmakeが出来ました。
    便利なスクリプトですね。
    スクリプトの中味は理解していません.

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください