fix: fix makefile generation
This commit is contained in:
parent
467dc53b69
commit
426c6f17b2
@ -19,8 +19,8 @@ targets_list="$(printf "\n$sources_list" | sed 's/\.cp*/\.o/g' | tr '\n' ' ')"
|
|||||||
get_compiler(){
|
get_compiler(){
|
||||||
for source_ in "$sources_list"; do
|
for source_ in "$sources_list"; do
|
||||||
case "$source_" in
|
case "$source_" in
|
||||||
*.cpp) printf "\ng++" && return;;
|
*.cpp) comp="g++" && return;;
|
||||||
*.c) printf "\ngcc";;
|
*.c) comp="gcc";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -31,11 +31,19 @@ is_c_project(){
|
|||||||
|
|
||||||
make_rule(){
|
make_rule(){
|
||||||
if [ "$comp" = "gcc" ]; then
|
if [ "$comp" = "gcc" ]; then
|
||||||
printf "\n$1.o : $1.c $1.h" >> makefile
|
if [ "$1" = "main" ]; then
|
||||||
echo -e "\t\$(CC) -c $1.c \$(FLAGS)" >> makefile
|
printf "\n$1.o : $1.c" >> makefile
|
||||||
else
|
else
|
||||||
printf "\n$1.o : $1.cpp $1.h" >> makefile
|
printf "\n$1.o : $1.c $1.h" >> makefile
|
||||||
echo -e "\t\$(CC) -c $1.cpp \$(FLAGS)" >> makefile
|
fi
|
||||||
|
printf "\n\t\$(CC) -c $1.c \$(FLAGS)" >> makefile
|
||||||
|
else
|
||||||
|
if [ "$1" = "main" ]; then
|
||||||
|
printf "\n$1.o : $1.cpp" >> makefile
|
||||||
|
else
|
||||||
|
printf "\n$1.o : $1.cpp $1.hpp" >> makefile
|
||||||
|
fi
|
||||||
|
printf "\n\t\$(CC) -c $1.cpp \$(FLAGS)" >> makefile
|
||||||
fi
|
fi
|
||||||
printf "\n" >> makefile
|
printf "\n" >> makefile
|
||||||
}
|
}
|
||||||
@ -45,11 +53,11 @@ if ! is_c_project; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
comp=get_compiler
|
get_compiler
|
||||||
|
|
||||||
touch makefile
|
touch makefile
|
||||||
|
|
||||||
printf "\nBIN = main" > makefile
|
printf "BIN = main" > makefile
|
||||||
printf "\nTARGETS = $targets_list" >> makefile
|
printf "\nTARGETS = $targets_list" >> makefile
|
||||||
printf "\n" >> makefile
|
printf "\n" >> makefile
|
||||||
printf "\nCC = $comp" >> makefile
|
printf "\nCC = $comp" >> makefile
|
||||||
@ -58,7 +66,7 @@ printf "\n" >> makefile
|
|||||||
printf "\nall : \$(BIN)" >> makefile
|
printf "\nall : \$(BIN)" >> makefile
|
||||||
printf "\n" >> makefile
|
printf "\n" >> makefile
|
||||||
printf "\n\$(BIN) : \$(TARGETS)" >> makefile
|
printf "\n\$(BIN) : \$(TARGETS)" >> makefile
|
||||||
echo -e "\t\$(CC) \$(TARGETS) -o \$(BIN) \$(FLAGS)" >> makefile
|
printf "\n\t\$(CC) \$(TARGETS) -o \$(BIN) \$(FLAGS)" >> makefile
|
||||||
printf "\n" >> makefile
|
printf "\n" >> makefile
|
||||||
|
|
||||||
for module in $modules_list; do
|
for module in $modules_list; do
|
||||||
@ -66,7 +74,7 @@ for module in $modules_list; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
printf "\nclean :" >> makefile
|
printf "\nclean :" >> makefile
|
||||||
echo -e "\trm \$(BIN) *.o vgcore.*" >> makefile
|
printf "\n\trm \$(BIN) *.o vgcore.*" >> makefile
|
||||||
|
|
||||||
sed -i 's/\s$//' makefile
|
sed -i 's/\s$//' makefile
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user