From 0dd17db452f6c35b57832672ae8750b023757c6a Mon Sep 17 00:00:00 2001 From: Komo Date: Sun, 30 Mar 2025 17:23:43 +0800 Subject: [PATCH] fix(build-system): improve the build system --- .gitattributes | 1 + Makefile.cmake | 8 ++--- src/CMakeLists.txt | 79 ++++++++++++++++++++------------------------ src/Makefile | 60 +++++++++++++++++---------------- src/scripts/Makefile | 32 +++++++++--------- 5 files changed, 86 insertions(+), 94 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..7715199 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +Makefile.cmake linguist-language=makefile diff --git a/Makefile.cmake b/Makefile.cmake index 3b2376b..a30b03f 100644 --- a/Makefile.cmake +++ b/Makefile.cmake @@ -2,14 +2,14 @@ all: @echo "Run 'make install' for installation." @echo "Run 'make uninstall' for uninstallation." mkdir -p build - cd build && cmake -G "CodeBlocks - Unix Makefiles" ../src + cd build && cmake -DCMAKE_INSTALL_PREFIX=$(DESTDIR) ../src install: @echo "Installing" - cd build && cmake -DCMAKE_INSTALL_PREFIX=$(DESTDIR) -G "CodeBlocks - Unix Makefiles" ../src + cd build && cmake -DCMAKE_INSTALL_PREFIX=$(DESTDIR) ../src $(MAKE) -C src/scripts install - $(MAKE) -C build install_build + $(MAKE) -C build install uninstall: $(MAKE) -C src/scripts uninstall - $(MAKE) -C build uninstall_build + $(MAKE) -C build uninstall diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8185ab..a74bcd2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,54 +8,45 @@ include_directories(${GTK_INCLUDE_DIRS}) include_directories(${X11_INCLUDE_DIRS}) set(CMAKE_C_STANDARD 99) -set (CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 11) add_executable(wihotspot-gui ui/main.c ui/h_prop.c ui/h_prop.h ui/ui.c ui/ui.h ui/read_config.cpp ui/read_config.h ui/util.c ui/util.h) target_link_libraries(${PROJECT_NAME} ${GTK_LIBRARIES} ${X11_LIBRARIES}) -include_directories(/usr/include) - -set (source "${CMAKE_SOURCE_DIR}/ui/glade") -set (destination "${CMAKE_CURRENT_BINARY_DIR}/glade") +set(source "${CMAKE_SOURCE_DIR}/ui/glade") +set(destination "${CMAKE_CURRENT_BINARY_DIR}/glade") add_custom_command( - TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E create_symlink ${source} ${destination} - DEPENDS ${destination} - COMMENT "symbolic link resources folder from ${source} => ${destination}" -) - -set (appdir "/usr/share") -set (appbin "/usr/bin") - -add_custom_target(install_build - - COMMAND mkdir -p $ENV{DESTDIR}${appdir}/${PROJECT_NAME} - COMMAND mkdir -p $ENV{DESTDIR}${appdir}/${PROJECT_NAME}/glade - COMMAND install -Dm755 ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} $ENV{DESTDIR}${appdir}/${PROJECT_NAME}/${PROJECT_NAME} - COMMAND install -Dm755 ${CMAKE_CURRENT_BINARY_DIR}/glade/* $ENV{DESTDIR}${appdir}/${PROJECT_NAME}/glade/ - COMMAND ln -rs $ENV{DESTDIR}${appdir}/${PROJECT_NAME}/${PROJECT_NAME} $ENV{DESTDIR}${appbin}/${PROJECT_NAME} - - COMMAND install -Dm644 ${CMAKE_SOURCE_DIR}/desktop/hotspot.png $ENV{DESTDIR}${appdir}/${PROJECT_NAME}/hotspot.png - COMMAND install -Dm644 ${CMAKE_SOURCE_DIR}/desktop/wifihotspot.desktop $ENV{DESTDIR}${appdir}/${PROJECT_NAME}/${PROJECT_NAME}.desktop - COMMAND install -Dm644 ${CMAKE_SOURCE_DIR}/desktop/wifihotspot.desktop $ENV{DESTDIR}${appdir}/applications/${PROJECT_NAME}.desktop - DEPENDS ${PROJECT_NAME} - COMMENT Installing files... - - COMMENT Remove old files if exist - COMMAND rm -rf $ENV{DESTDIR}${appdir}/wihotspot - COMMAND rm -f $ENV{DESTDIR}${appdir}/applications/wihotspot.desktop - ) - -add_custom_target(uninstall_build - COMMAND rm -rf $ENV{DESTDIR}${appdir}/${PROJECT_NAME} - COMMAND rm -f $ENV{DESTDIR}${appbin}/${PROJECT_NAME} - COMMAND rm -f $ENV{DESTDIR}${appdir}/applications/${PROJECT_NAME}.desktop - COMMAND rm -rf $ENV{DESTDIR}${appdir}/${PROJECT_NAME} - COMMENT Uninstalling files... - - COMMENT Remove old files if exist - COMMAND rm -rf $ENV{DESTDIR}${appdir}/wihotspot - COMMAND rm -f $ENV{DESTDIR}${appdir}/applications/wihotspot.desktop - ) \ No newline at end of file + TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E create_symlink ${source} ${destination} + DEPENDS ${destination} + COMMENT "symbolic link resources folder from ${source} => ${destination}") + +install(TARGETS ${PROJECT_NAME} + DESTINATION share/${PROJECT_NAME}) +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/glade + DESTINATION share/${PROJECT_NAME}) +install(CODE "execute_process( \ + COMMAND ${CMAKE_COMMAND} -E create_symlink \ + ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/${PROJECT_NAME} \ + ${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME} \ + )") +install(FILES ${CMAKE_SOURCE_DIR}/desktop/hotspot.png + DESTINATION share/${PROJECT_NAME}) +install(FILES ${CMAKE_SOURCE_DIR}/desktop/wifihotspot.desktop + DESTINATION share/${PROJECT_NAME} + RENAME ${PROJECT_NAME}.desktop) +install(FILES ${CMAKE_SOURCE_DIR}/desktop/wifihotspot.desktop + DESTINATION share/applications + RENAME ${PROJECT_NAME}.desktop) + +add_custom_target(uninstall + COMMAND rm -rf ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME} + COMMAND rm -f ${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME} + COMMAND rm -f ${CMAKE_INSTALL_PREFIX}/share/applications/${PROJECT_NAME}.desktop + COMMAND rm -rf ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME} + COMMENT Uninstalling files... + COMMENT Remove old files if exist + COMMAND rm -rf ${CMAKE_INSTALL_PREFIX}/share/wihotspot + COMMAND rm -f ${CMAKE_INSTALL_PREFIX}/share/applications/wihotspot.desktop) diff --git a/src/Makefile b/src/Makefile index 0378d61..dcd564b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,14 +1,16 @@ -CC=gcc -PKGCONFIG = $(shell which pkg-config) +CC?=cc +PKGCONFIG?=pkg-config -CFLAGS=`pkg-config --cflags gtk+-3.0` -LIBS=`pkg-config --libs gtk+-3.0 --libs x11` -lstdc++ -lpng -lqrencode +EXTRA_CFLAGS?= +EXTRA_LIBS?= -APP_NAME="wihotspot" -APP_GUI_BINARY="wihotspot-gui" +CFLAGS=$(shell $(PKGCONFIG) --cflags gtk+-3.0) $(EXTRA_CFLAGS) +LIBS=$(shell $(PKGCONFIG) --libs gtk+-3.0 --libs x11) -lstdc++ -lpng -lqrencode $(EXTRA_LIBS) -PREFIX=/usr -BINDIR=$(PREFIX)/bin +APP_NAME=wihotspot +APP_GUI_BINARY=wihotspot-gui + +DESTDIR?=/usr ODIR=../build @@ -41,33 +43,33 @@ wihotspot-gui: $(OBJ) $(CC) -o $(ODIR)/$@ $^ $(CFLAGS) $(LIBS) install: $(ODIR)/wihotspot-gui - install -Dm644 desktop/icons/hotspot@64.png $(DESTDIR)$(PREFIX)/share/pixmaps/wihotspot.png - install -Dm644 desktop/icons/hotspot@48.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/48x48/apps/wihotspot.png - install -Dm644 desktop/icons/hotspot@64.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/64x64/apps/wihotspot.png - install -Dm644 desktop/icons/hotspot@256.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/256x256/apps/wihotspot.png - install -Dm644 desktop/icons/hotspot@512.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/512x512/apps/wihotspot.png - install -Dm644 desktop/icons/hotspot.svg $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps/wihotspot.svg - install -Dm644 desktop/wifihotspot.desktop $(DESTDIR)$(PREFIX)/share/applications/$(APP_NAME).desktop - install -Dm644 scripts/policies/polkit.rules $(DESTDIR)$(PREFIX)/share/polkit-1/rules.d/90-org.opensuse.policykit.wihotspot.rules - install -Dm644 scripts/policies/polkit.policy $(DESTDIR)$(PREFIX)/share/polkit-1/actions/org.opensuse.policykit.wihotspot.policy - install -Dm755 $(ODIR)/wihotspot-gui $(DESTDIR)$(BINDIR)/$(APP_GUI_BINARY) + install -Dm644 desktop/icons/hotspot@64.png $(DESTDIR)/share/pixmaps/wihotspot.png + install -Dm644 desktop/icons/hotspot@48.png $(DESTDIR)/share/icons/hicolor/48x48/apps/wihotspot.png + install -Dm644 desktop/icons/hotspot@64.png $(DESTDIR)/share/icons/hicolor/64x64/apps/wihotspot.png + install -Dm644 desktop/icons/hotspot@256.png $(DESTDIR)/share/icons/hicolor/256x256/apps/wihotspot.png + install -Dm644 desktop/icons/hotspot@512.png $(DESTDIR)/share/icons/hicolor/512x512/apps/wihotspot.png + install -Dm644 desktop/icons/hotspot.svg $(DESTDIR)/share/icons/hicolor/scalable/apps/wihotspot.svg + install -Dm644 desktop/wifihotspot.desktop $(DESTDIR)/share/applications/$(APP_NAME).desktop + install -Dm644 scripts/policies/polkit.rules $(DESTDIR)/share/polkit-1/rules.d/90-org.opensuse.policykit.wihotspot.rules + install -Dm644 scripts/policies/polkit.policy $(DESTDIR)/share/polkit-1/actions/org.opensuse.policykit.wihotspot.policy + install -Dm755 $(ODIR)/wihotspot-gui $(DESTDIR)/bin/$(APP_GUI_BINARY) cd scripts && $(MAKE) install uninstall: - rm -f $(DESTDIR)$(PREFIX)/share/pixmaps/wihotspot.png - rm -f $(DESTDIR)$(PREFIX)/share/icons/hicolor/48x48/apps/wihotspot.png - rm -f $(DESTDIR)$(PREFIX)/share/icons/hicolor/64x64/apps/wihotspot.png - rm -f $(DESTDIR)$(PREFIX)/share/icons/hicolor/256x256/apps/wihotspot.png - rm -f $(DESTDIR)$(PREFIX)/share/icons/hicolor/512x512/apps/wihotspot.png - rm -f $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps/wihotspot.svg - rm -f $(DESTDIR)$(PREFIX)/share/applications/$(APP_NAME).desktop - rm -f $(DESTDIR)$(PREFIX)/share/polkit-1/rules.d/90-org.opensuse.policykit.wihotspot.rules - rm -f $(DESTDIR)$(PREFIX)/share/polkit-1/actions/org.opensuse.policykit.wihotspot.policy - rm -f $(DESTDIR)$(BINDIR)/$(APP_GUI_BINARY) + rm -f $(DESTDIR)/share/pixmaps/wihotspot.png + rm -f $(DESTDIR)/share/icons/hicolor/48x48/apps/wihotspot.png + rm -f $(DESTDIR)/share/icons/hicolor/64x64/apps/wihotspot.png + rm -f $(DESTDIR)/share/icons/hicolor/256x256/apps/wihotspot.png + rm -f $(DESTDIR)/share/icons/hicolor/512x512/apps/wihotspot.png + rm -f $(DESTDIR)/share/icons/hicolor/scalable/apps/wihotspot.svg + rm -f $(DESTDIR)/share/applications/$(APP_NAME).desktop + rm -f $(DESTDIR)/share/polkit-1/rules.d/90-org.opensuse.policykit.wihotspot.rules + rm -f $(DESTDIR)/share/polkit-1/actions/org.opensuse.policykit.wihotspot.policy + rm -f $(DESTDIR)/bin/$(APP_GUI_BINARY) cd scripts && $(MAKE) uninstall clean-old: - rm -f $(DESTDIR)$(PREFIX)/share/pixmaps/wihotspot.png + rm -f $(DESTDIR)/share/pixmaps/wihotspot.png clean: rm -f $(ODIR)/*.o diff --git a/src/scripts/Makefile b/src/scripts/Makefile index 3ca0155..3954cfd 100644 --- a/src/scripts/Makefile +++ b/src/scripts/Makefile @@ -1,30 +1,28 @@ -PREFIX=/usr -MANDIR=$(PREFIX)/share/man -BINDIR=$(PREFIX)/bin +DESTDIR?=/usr all: @echo "Run 'make install' for installation." @echo "Run 'make uninstall' for uninstallation." install: - install -CDm755 create_ap $(DESTDIR)$(BINDIR)/create_ap + install -CDm755 create_ap $(DESTDIR)/bin/create_ap install -CDm644 create_ap.conf $(DESTDIR)/etc/create_ap.conf - install -CDm644 create_ap.service $(DESTDIR)$(PREFIX)/lib/systemd/system/create_ap.service - install -CDm644 bash_completion $(DESTDIR)$(PREFIX)/share/bash-completion/completions/create_ap - install -CDm644 README.md $(DESTDIR)$(PREFIX)/share/doc/create_ap/README.md - install -CDm755 wihotspot $(DESTDIR)$(BINDIR)/wihotspot + install -CDm644 create_ap.service $(DESTDIR)/lib/systemd/system/create_ap.service + install -CDm644 bash_completion $(DESTDIR)/share/bash-completion/completions/create_ap + install -CDm644 README.md $(DESTDIR)/share/doc/create_ap/README.md + install -CDm755 wihotspot $(DESTDIR)/bin/wihotspot install-cli-only: - install -CDm755 create_ap $(DESTDIR)$(BINDIR)/create_ap + install -CDm755 create_ap $(DESTDIR)/bin/create_ap install -CDm644 create_ap.conf $(DESTDIR)/etc/create_ap.conf - install -CDm644 create_ap.service $(DESTDIR)$(PREFIX)/lib/systemd/system/create_ap.service - install -CDm644 bash_completion $(DESTDIR)$(PREFIX)/share/bash-completion/completions/create_ap - install -CDm644 README.md $(DESTDIR)$(PREFIX)/share/doc/create_ap/README.md + install -CDm644 create_ap.service $(DESTDIR)/lib/systemd/system/create_ap.service + install -CDm644 bash_completion $(DESTDIR)/share/bash-completion/completions/create_ap + install -CDm644 README.md $(DESTDIR)/share/doc/create_ap/README.md uninstall: - rm -f $(DESTDIR)$(BINDIR)/create_ap + rm -f $(DESTDIR)/bin/create_ap rm -f $(DESTDIR)/etc/create_ap.conf - rm -f $(DESTDIR)$(PREFIX)/lib/systemd/system/create_ap.service - rm -f $(DESTDIR)$(PREFIX)/share/bash-completion/completions/create_ap - rm -f $(DESTDIR)$(PREFIX)/share/doc/create_ap/README.md - rm -f $(DESTDIR)$(BINDIR)/wihotspot + rm -f $(DESTDIR)/lib/systemd/system/create_ap.service + rm -f $(DESTDIR)/share/bash-completion/completions/create_ap + rm -f $(DESTDIR)/share/doc/create_ap/README.md + rm -f $(DESTDIR)/bin/wihotspot