행복아울렛

유닉스 및 리눅스에서 프로그래밍을 위한 와꾸 만들기 본문

Programming

유닉스 및 리눅스에서 프로그래밍을 위한 와꾸 만들기

붕탱구 2006. 12. 6. 09:12

UNIX&LINUX Programming Template


유닉스나 리눅스에서 프로그래밍 할 때에 간단하게 Makefile 및 간단한 소스코드를 생성시켜

주는 쉘스크립트 입니다. 아래 내용을 긁어서 ~/bin/up에 넣어두시고

chmod a+x ~/bin/up  후에

"up 프로그램명"

이런식으로 수행시키시면 됩니다.

#!/bin/bash
DATE=$(date +%y/%m/%d)

if [ $# -lt 1 ]
then
echo "Usage : up 디렉토리명"
echo "Wrong Number of Argument"
exit 1
fi

if [ -d ./$1 ]
then
echo "Directory already exists! Choose another one."
exit 1
else
mkdir ./$1
fi

if [ -f ./$1/Makefile ]
then
echo "Makefile already exists!"
exit 1
else
touch ./$1/Makefile
touch ./$1/$1.c
cd $1
echo "# Makefile by Minwook" >>Makefile
echo "# $DATE" >> Makefile
echo "#   make       : to compile and make executable program" >> Makefile
echo "#   make clean : to remove all reproducible files" >> Makefile
echo "" >> Makefile
echo "" >> Makefile
echo "$1_debug: $1.c" >> Makefile
echo " gcc -DDEBUG -g -o $1 $1.c" >> Makefile
echo "$1: $1.c" >> Makefile
echo " gcc -O -o $1 $1.c" >> Makefile
echo "$1_test: $1.c" >> Makefile
echo " gcc -DDEBUG -DTEST -g -o $1 $1.c" >> Makefile
echo "clean:" >> Makefile
echo " rm -rf $1" >> Makefile
echo " test -z $1.o || rm -f $1.o" >> Makefile
echo " test -z core || rm -f core" >> Makefile
echo "/* for DEBUG MODE : _( Contents ) will include only in debug mode */" >> $1.c
echo "#ifdef DEBUG" >> $1.c
echo "#include <assert.h>" >> $1.c
echo "#define _(x) x" >> $1.c
echo "#else" >> $1.c
echo "#define _(x)" >> $1.c
echo "#endif" >> $1.c
echo "/* STREQ return TRUE if string a and b is same */" >> $1.c
echo "#define STREQ(a,b) (*(a) == *(b) && strcmp((a), (b)) == 0)" >> $1.c
echo "#include <stdio.h>" >> $1.c
echo "" >> $1.c
echo "/***************************************************************" >> $1.c
echo "" >> $1.c
echo " $DATE" >> $1.c
echo " 부서명" >> $1.c
echo " 이름과 이메일주소" >> $1.c
echo "***************************************************************/" >> $1.c
echo "" >> $1.c
echo "int main(void)" >> $1.c
echo "{" >> $1.c
echo "" >> $1.c
echo "   return 0;" >> $1.c
echo "}" >> $1.c
fi

Comments