make-libmqttclient.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. mkdir -p libmqttclient libmqttclient/include libmqttclient/lib
  3. cd libmqttclient
  4. if [ ! -f "Makefile" ]; then
  5. cat <<-EOF > Makefile
  6. CC=\$(CROSS_COMPILE)gcc
  7. SRC = \$(wildcard ../*.c \\
  8. ../common/*.c \\
  9. ../common/log/*.c \\
  10. ../common/log/arch/linux/*.c \\
  11. ../network/mbedtls/library/*.c \\
  12. ../network/mbedtls/wrapper/*.c \\
  13. ../mqtt/*.c \\
  14. ../mqttclient/*.c \\
  15. ../network/*.c \\
  16. ../platform/linux/*.c \\
  17. )
  18. INC = -lpthread \\
  19. -I../common \\
  20. -I../common/log \\
  21. -I../network/mbedtls/include \\
  22. -I../network/mbedtls/include/mbedtls \\
  23. -I../network/mbedtls/wrapper \\
  24. -I../mqtt \\
  25. -I../mqttclient \\
  26. -I../network \\
  27. -I../platform/linux \\
  28. -I../test
  29. OBJS = \$(patsubst %.c, %.o, \$(SRC))
  30. FLAG = -g -fpic -I. -Iinclude \$(INC)
  31. TARGET = libmqttclient.so
  32. EOF
  33. echo -e "\n\$(TARGET):\$(OBJS)" >> Makefile
  34. echo -e "\t\$(CC) -shared \$^ -o \$@" >> Makefile
  35. echo -e "\n%.o:%.c" >> Makefile
  36. echo -e "\t\$(CC) -c \$(FLAG) \$^ -o \$@" >> Makefile
  37. echo -e "\nclean:" >> Makefile
  38. echo -e "\trm -rf \$(TARGET) \$(OBJS)" >> Makefile
  39. echo -e "\ninstall:" >> Makefile
  40. echo -e "\tsudo cp -rdf \$(TARGET) /usr/lib/." >> Makefile
  41. echo -e "\nremove:" >> Makefile
  42. echo -e "\tsudo rm -rdf /usr/lib/\$(TARGET)" >> Makefile
  43. echo -e "\n.PHONY:clean" >> Makefile
  44. fi
  45. cp -r ../test/*.h include/.
  46. cp -r ../mqtt/*.h include/.
  47. cp -r ../common/*.h include/.
  48. cp -r ../network/*.h include/.
  49. cp -r ../mqttclient/*.h include/.
  50. cp -r ../common/log/*.h include/.
  51. cp -r ../platform/linux/*.h include/.
  52. cp -r ../network/mbedtls/include/mbedtls include/.
  53. cp -r ../network/mbedtls/wrapper/*.h include/.
  54. if [ " $1" == " " ]; then
  55. make
  56. make install
  57. mv libmqttclient.so lib/.
  58. make clean
  59. elif [ "$1" == "remove" ]; then
  60. make remove
  61. fi