From 96599ae0ac8e59c27c6f143dfa579b4449c74733 Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Thu, 11 May 2023 05:00:44 +0300 Subject: [PATCH] [improve] Improve the project structure --- .idea/.gitignore | 8 ++ .idea/inspectionProfiles/Project_Default.xml | 6 ++ .idea/misc.xml | 18 ++++ .idea/vcs.xml | 6 ++ Makefile | 82 +++++++++++-------- arg.h => src/arg.h | 0 {components => src/components}/battery.c | 0 {components => src/components}/cpu.c | 0 {components => src/components}/datetime.c | 0 {components => src/components}/disk.c | 0 {components => src/components}/entropy.c | 0 {components => src/components}/hostname.c | 0 {components => src/components}/ip.c | 0 .../components}/kernel_release.c | 0 .../components}/keyboard_indicators.c | 0 {components => src/components}/keymap.c | 0 {components => src/components}/load_avg.c | 0 {components => src/components}/netspeeds.c | 0 {components => src/components}/num_files.c | 0 {components => src/components}/ram.c | 0 {components => src/components}/run_command.c | 0 {components => src/components}/separator.c | 0 {components => src/components}/swap.c | 0 {components => src/components}/temperature.c | 0 {components => src/components}/uptime.c | 0 {components => src/components}/user.c | 0 {components => src/components}/volume.c | 0 {components => src/components}/wifi.c | 0 config.def.h => src/config.def.h | 0 config.h => src/config.h | 0 slstatus.c => src/slstatus.c | 0 slstatus.h => src/slstatus.h | 0 util.c => src/util.c | 0 util.h => src/util.h | 0 34 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml rename arg.h => src/arg.h (100%) rename {components => src/components}/battery.c (100%) rename {components => src/components}/cpu.c (100%) rename {components => src/components}/datetime.c (100%) rename {components => src/components}/disk.c (100%) rename {components => src/components}/entropy.c (100%) rename {components => src/components}/hostname.c (100%) rename {components => src/components}/ip.c (100%) rename {components => src/components}/kernel_release.c (100%) rename {components => src/components}/keyboard_indicators.c (100%) rename {components => src/components}/keymap.c (100%) rename {components => src/components}/load_avg.c (100%) rename {components => src/components}/netspeeds.c (100%) rename {components => src/components}/num_files.c (100%) rename {components => src/components}/ram.c (100%) rename {components => src/components}/run_command.c (100%) rename {components => src/components}/separator.c (100%) rename {components => src/components}/swap.c (100%) rename {components => src/components}/temperature.c (100%) rename {components => src/components}/uptime.c (100%) rename {components => src/components}/user.c (100%) rename {components => src/components}/volume.c (100%) rename {components => src/components}/wifi.c (100%) rename config.def.h => src/config.def.h (100%) rename config.h => src/config.h (100%) rename slstatus.c => src/slstatus.c (100%) rename slstatus.h => src/slstatus.h (100%) rename util.c => src/util.c (100%) rename util.h => src/util.h (100%) diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..973f941 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..53624c9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Makefile b/Makefile index 2f93b87..9bc3120 100644 --- a/Makefile +++ b/Makefile @@ -1,63 +1,75 @@ -# See LICENSE file for copyright and license details -# slstatus - suckless status monitor .POSIX: include config.mk REQ = util -COM =\ - components/battery\ - components/cpu\ - components/datetime\ - components/disk\ - components/entropy\ - components/hostname\ - components/ip\ - components/kernel_release\ - components/keyboard_indicators\ - components/keymap\ - components/load_avg\ - components/netspeeds\ - components/num_files\ - components/ram\ - components/run_command\ - components/separator\ - components/swap\ - components/temperature\ - components/uptime\ - components/user\ - components/volume\ +COM = \ + components/battery \ + components/cpu \ + components/datetime \ + components/disk \ + components/entropy \ + components/hostname \ + components/ip \ + components/kernel_release \ + components/keyboard_indicators \ + components/keymap \ + components/load_avg \ + components/netspeeds \ + components/num_files \ + components/ram \ + components/run_command \ + components/separator \ + components/swap \ + components/temperature \ + components/uptime \ + components/user \ + components/volume \ components/wifi -all: slstatus +BUILD_DIR = build +OBJ_DIR = $(BUILD_DIR)/obj +SRC_DIR = src -$(COM:=.o): config.mk $(REQ:=.h) -slstatus.o: slstatus.c slstatus.h arg.h config.h config.mk $(REQ:=.h) +COM_OBJ = $(COM:%=$(OBJ_DIR)/%.o) +REQ_OBJ = $(REQ:%=$(OBJ_DIR)/%.o) +SLSTATUS_OBJ = $(OBJ_DIR)/slstatus.o -.c.o: +all: $(BUILD_DIR)/slstatus + +$(COM_OBJ): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.c $(REQ_OBJ) config.mk $(REQ:%=$(SRC_DIR)/%.h) + @mkdir -p $(@D) + $(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) $< + +$(REQ_OBJ): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.c $(SRC_DIR)/%.h + @mkdir -p $(@D) + $(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) $< + +$(SLSTATUS_OBJ): $(SRC_DIR)/slstatus.c $(SRC_DIR)/slstatus.h $(SRC_DIR)/arg.h config.mk $(REQ_OBJ) $(REQ:%=$(SRC_DIR)/%.h) + @mkdir -p $(@D) $(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) $< config.h: cp config.def.h $@ -slstatus: slstatus.o $(COM:=.o) $(REQ:=.o) - $(CC) -o $@ $(LDFLAGS) $(COM:=.o) $(REQ:=.o) slstatus.o $(LDLIBS) +$(BUILD_DIR)/slstatus: $(SLSTATUS_OBJ) $(COM_OBJ) $(REQ_OBJ) + $(CC) -o $@ $(LDFLAGS) $(SLSTATUS_OBJ) $(COM_OBJ) $(REQ_OBJ) $(LDLIBS) clean: - rm -f slstatus slstatus.o $(COM:=.o) $(REQ:=.o) + rm -rf $(BUILD_DIR) dist: rm -rf "slstatus-$(VERSION)" mkdir -p "slstatus-$(VERSION)/components" cp -R LICENSE Makefile README config.mk config.def.h \ - arg.h slstatus.c $(COM:=.c) $(REQ:=.c) $(REQ:=.h) \ - slstatus.1 "slstatus-$(VERSION)" + arg.h $(SRC_DIR)/slstatus.c $(COM:%=$(SRC_DIR)/%.c) $(REQ:%=$(SRC_DIR)/%.c) $(REQ:%=$(SRC_DIR)/%.h) \ + slstatus.1 "slstatus-$(VERSION)" tar -cf - "slstatus-$(VERSION)" | gzip -c > "slstatus-$(VERSION).tar.gz" rm -rf "slstatus-$(VERSION)" install: all mkdir -p "$(DESTDIR)$(PREFIX)/bin" - cp -f slstatus "$(DESTDIR)$(PREFIX)/bin" + cp -f $(BUILD_DIR)/slstatus "$(DESTDIR)$(PREFIX)/bin" chmod 755 "$(DESTDIR)$(PREFIX)/bin/slstatus" mkdir -p "$(DESTDIR)$(MANPREFIX)/man1" cp -f slstatus.1 "$(DESTDIR)$(MANPREFIX)/man1" @@ -66,3 +78,5 @@ install: all uninstall: rm -f "$(DESTDIR)$(PREFIX)/bin/slstatus" rm -f "$(DESTDIR)$(MANPREFIX)/man1/slstatus.1" + +.PHONY: all clean dist install uninstall diff --git a/arg.h b/src/arg.h similarity index 100% rename from arg.h rename to src/arg.h diff --git a/components/battery.c b/src/components/battery.c similarity index 100% rename from components/battery.c rename to src/components/battery.c diff --git a/components/cpu.c b/src/components/cpu.c similarity index 100% rename from components/cpu.c rename to src/components/cpu.c diff --git a/components/datetime.c b/src/components/datetime.c similarity index 100% rename from components/datetime.c rename to src/components/datetime.c diff --git a/components/disk.c b/src/components/disk.c similarity index 100% rename from components/disk.c rename to src/components/disk.c diff --git a/components/entropy.c b/src/components/entropy.c similarity index 100% rename from components/entropy.c rename to src/components/entropy.c diff --git a/components/hostname.c b/src/components/hostname.c similarity index 100% rename from components/hostname.c rename to src/components/hostname.c diff --git a/components/ip.c b/src/components/ip.c similarity index 100% rename from components/ip.c rename to src/components/ip.c diff --git a/components/kernel_release.c b/src/components/kernel_release.c similarity index 100% rename from components/kernel_release.c rename to src/components/kernel_release.c diff --git a/components/keyboard_indicators.c b/src/components/keyboard_indicators.c similarity index 100% rename from components/keyboard_indicators.c rename to src/components/keyboard_indicators.c diff --git a/components/keymap.c b/src/components/keymap.c similarity index 100% rename from components/keymap.c rename to src/components/keymap.c diff --git a/components/load_avg.c b/src/components/load_avg.c similarity index 100% rename from components/load_avg.c rename to src/components/load_avg.c diff --git a/components/netspeeds.c b/src/components/netspeeds.c similarity index 100% rename from components/netspeeds.c rename to src/components/netspeeds.c diff --git a/components/num_files.c b/src/components/num_files.c similarity index 100% rename from components/num_files.c rename to src/components/num_files.c diff --git a/components/ram.c b/src/components/ram.c similarity index 100% rename from components/ram.c rename to src/components/ram.c diff --git a/components/run_command.c b/src/components/run_command.c similarity index 100% rename from components/run_command.c rename to src/components/run_command.c diff --git a/components/separator.c b/src/components/separator.c similarity index 100% rename from components/separator.c rename to src/components/separator.c diff --git a/components/swap.c b/src/components/swap.c similarity index 100% rename from components/swap.c rename to src/components/swap.c diff --git a/components/temperature.c b/src/components/temperature.c similarity index 100% rename from components/temperature.c rename to src/components/temperature.c diff --git a/components/uptime.c b/src/components/uptime.c similarity index 100% rename from components/uptime.c rename to src/components/uptime.c diff --git a/components/user.c b/src/components/user.c similarity index 100% rename from components/user.c rename to src/components/user.c diff --git a/components/volume.c b/src/components/volume.c similarity index 100% rename from components/volume.c rename to src/components/volume.c diff --git a/components/wifi.c b/src/components/wifi.c similarity index 100% rename from components/wifi.c rename to src/components/wifi.c diff --git a/config.def.h b/src/config.def.h similarity index 100% rename from config.def.h rename to src/config.def.h diff --git a/config.h b/src/config.h similarity index 100% rename from config.h rename to src/config.h diff --git a/slstatus.c b/src/slstatus.c similarity index 100% rename from slstatus.c rename to src/slstatus.c diff --git a/slstatus.h b/src/slstatus.h similarity index 100% rename from slstatus.h rename to src/slstatus.h diff --git a/util.c b/src/util.c similarity index 100% rename from util.c rename to src/util.c diff --git a/util.h b/src/util.h similarity index 100% rename from util.h rename to src/util.h