From: Laurent MAZET Date: Fri, 26 Apr 2024 15:45:13 +0000 (+0200) Subject: update makefile X-Git-Tag: cmore-1.0~35 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=6b456e0c8cabdc2ddd4807ebdf15c6585135416b;p=cmore.git update makefile --- diff --git a/appli.c b/appli.c deleted file mode 100644 index aa1245e..0000000 --- a/appli.c +++ /dev/null @@ -1,145 +0,0 @@ -/* depend: */ -/* cflags: */ -/* linker: cmd.o tui.o -lpdcurses */ - -#include - -#include "cmd.h" -#include "tui.h" - -int display (char **lines, int xmax, int ymax) -{ - int stop = 0; - - statusmsg ("Press 'q' or escape to quit"); - - int skip = 0; - while (!stop) { - clsbody (); - int i = 0; - int eol = 0; - for (i = 0; i <= ymax; i++) { - if (lines [skip + i] == NULL) { - break; - } - if (eol) { - bodymsg ("\n"); - } - bodymsg (lines[skip + i]); - eol = (lines[skip + i][xmax - 1 ] == '\0'); - } - int key = waitforkey (); - switch (key) { - case 'q': - case KEY_ESC: - stop = 1; - break; - case 'i': - case KEY_UP: - skip = (skip > 0) ? skip - 1 : skip; - break; - case 'k': - case KEY_DOWN: - skip = (lines[skip + 1] != NULL) ? skip + 1 : skip; - break; - case ALT_F: - case ALT_H: - stop = 2; - break; - } - } - - rmstatus(); - - return (stop == 1); -} - -int view (char *cmd) -{ - char *buffer; - - int xmax, ymax; - WINDOW *wbody = bodywin (); - getmaxyx (wbody, ymax, xmax); - - buffer = exec_cmd (cmd); - if (buffer == NULL) { - char msg[80]; - sprintf (msg, "Error executing %s", cmd); - statusmsg (msg); - return 1; - } - - char **lines = split_lines (buffer, xmax); - free (buffer); - - int rc = display (lines, xmax, ymax); - free_lines (lines); - - return rc; -} - -void exec_ipconfig (void) -{ - static int index = 0; - - switch (index) { - case 0: view ("ipconfig"); break; - case 1: view ("ps aux"); break; - case 2: view ("ls"); break; - } - index = (index + 1) % 3; -} - -menu SubMenu0[] = -{ - { "Refresh", exec_ipconfig, "Various shell commands" }, - { "Exit", DoExit, "Terminate program" }, - { "", (FUNC)0, "" } -}; - -void sub0 (void) -{ - domenu (SubMenu0); -} - -menu SubMenu1[] = -{ - { "About", DoExit, "About..." }, - { "", (FUNC)0, "" } -}; - -void sub1 (void) -{ - domenu (SubMenu1); -} - -menu MainMenu[] = -{ - { "File", sub0, "File menu" }, - { "Help", sub1, "Help menu" }, - { "", (FUNC)0, "" } /* always add this as the last item! */ -}; - -void init (void) -{ - int rc = view ("ipconfig"); - if (!rc) { - mainmenu (MainMenu); - } -} - -int main (int argc, char *argv[]) -{ - char titre[256] = {0}; - - sprintf (titre, "Application: %s", (argc > 1) ? argv[1] : "demonstration program"); - - //setlocale (LC_ALL, ""); - - startmenu (MainMenu, titre, init); - - return 0; -} - -/* vim: set ts=4 sw=4 et: */ diff --git a/cmore.c b/cmore.c new file mode 100644 index 0000000..aa1245e --- /dev/null +++ b/cmore.c @@ -0,0 +1,145 @@ +/* depend: */ +/* cflags: */ +/* linker: cmd.o tui.o -lpdcurses */ + +#include + +#include "cmd.h" +#include "tui.h" + +int display (char **lines, int xmax, int ymax) +{ + int stop = 0; + + statusmsg ("Press 'q' or escape to quit"); + + int skip = 0; + while (!stop) { + clsbody (); + int i = 0; + int eol = 0; + for (i = 0; i <= ymax; i++) { + if (lines [skip + i] == NULL) { + break; + } + if (eol) { + bodymsg ("\n"); + } + bodymsg (lines[skip + i]); + eol = (lines[skip + i][xmax - 1 ] == '\0'); + } + int key = waitforkey (); + switch (key) { + case 'q': + case KEY_ESC: + stop = 1; + break; + case 'i': + case KEY_UP: + skip = (skip > 0) ? skip - 1 : skip; + break; + case 'k': + case KEY_DOWN: + skip = (lines[skip + 1] != NULL) ? skip + 1 : skip; + break; + case ALT_F: + case ALT_H: + stop = 2; + break; + } + } + + rmstatus(); + + return (stop == 1); +} + +int view (char *cmd) +{ + char *buffer; + + int xmax, ymax; + WINDOW *wbody = bodywin (); + getmaxyx (wbody, ymax, xmax); + + buffer = exec_cmd (cmd); + if (buffer == NULL) { + char msg[80]; + sprintf (msg, "Error executing %s", cmd); + statusmsg (msg); + return 1; + } + + char **lines = split_lines (buffer, xmax); + free (buffer); + + int rc = display (lines, xmax, ymax); + free_lines (lines); + + return rc; +} + +void exec_ipconfig (void) +{ + static int index = 0; + + switch (index) { + case 0: view ("ipconfig"); break; + case 1: view ("ps aux"); break; + case 2: view ("ls"); break; + } + index = (index + 1) % 3; +} + +menu SubMenu0[] = +{ + { "Refresh", exec_ipconfig, "Various shell commands" }, + { "Exit", DoExit, "Terminate program" }, + { "", (FUNC)0, "" } +}; + +void sub0 (void) +{ + domenu (SubMenu0); +} + +menu SubMenu1[] = +{ + { "About", DoExit, "About..." }, + { "", (FUNC)0, "" } +}; + +void sub1 (void) +{ + domenu (SubMenu1); +} + +menu MainMenu[] = +{ + { "File", sub0, "File menu" }, + { "Help", sub1, "Help menu" }, + { "", (FUNC)0, "" } /* always add this as the last item! */ +}; + +void init (void) +{ + int rc = view ("ipconfig"); + if (!rc) { + mainmenu (MainMenu); + } +} + +int main (int argc, char *argv[]) +{ + char titre[256] = {0}; + + sprintf (titre, "Application: %s", (argc > 1) ? argv[1] : "demonstration program"); + + //setlocale (LC_ALL, ""); + + startmenu (MainMenu, titre, init); + + return 0; +} + +/* vim: set ts=4 sw=4 et: */ diff --git a/makefile b/makefile index 5199905..9e0aa28 100644 --- a/makefile +++ b/makefile @@ -2,7 +2,8 @@ CC = gcc -INCLUDES = -I../debug -D__MEMORY_ALLOCATION__ +#INCLUDES = -I../debug -D__MEMORY_ALLOCATION__ +INCLUDES = OFLAGS = -O4 -Os #OFLAGS = -O4 -ffast-math -finline-functions #OFLAGS = -O4 -finline-functions @@ -10,24 +11,25 @@ OFLAGS = -O4 -Os #OFLAGS += -minline-all-stringops -fsingle-precision-constant #OFLAGS += -malign-double CFLAGS += -W -Wall -Wextra -g -CFLAGS += -std=c99 -D_XOPEN_SOURCE=500 -CFLAGS += $(OFLAGS) $(INCLUDES) $(GCOVER) -LDFLAGS += -g +#CFLAGS += -std=c99 -D_XOPEN_SOURCE=500 +CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS) +LDFLAGS += -g $(OPTIONS) + +ifeq ($(OS),Windows_NT) +#LDLIBS += -lws2_32 +endif + # Targets ALLEXE = -#ALLEXE += test -#ALLEXE += kbhit -#ALLEXE += tetris -ALLEXE += appli -#ALLEXE += line -#ALLEXE += skel +ALLEXE += cmore SHELL = bash -MAKE = mingw32-make +#MAKE = mingw32-make MAKEFLAGS += -s +include $(wildcard .makefile) # Functions @@ -53,7 +55,7 @@ count: clean: $(call TITLE, "Cleaning") touch clean - rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_*) + rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out) $(call PASS, SUCCESS) depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE)) @@ -61,19 +63,22 @@ depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE)) gcovs: $(MAKE) $(addprefix gcov_,$(ALLEXE)) +gprofs: + $(MAKE) $(addprefix gprof_,$(ALLEXE)) + purge: clean $(call TITLE, "Purging") touch purge rm -f purge $(ALLEXE:%=%.exe) $(call PASS, SUCCESS) -valgrinds: +valgrinds: all $(MAKE) $(addprefix valgrind_,$(ALLEXE)) wipe: purge $(call TITLE, "Wiping") touch wipe - rm -f wipe $(wildcard *.gcda *.gcno) + rm -f wipe $(wildcard *.gcda *.gcno *.gcov *.glog) $(call PASS, SUCCESS) tests: all @@ -86,55 +91,75 @@ include $(wildcard *.ld) gcov_%: $(MAKE) purge - CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs -ftest-coverage" $(MAKE) + OPTIONS="-coverage -O0" $(MAKE) $(MAKE) test_$(@:gcov_%=%) gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)` touch gcov rm -f gcov $(wildcard *.gcda *.gcno) $(MAKE) purge + grep '#####' *.c.gcov || true + +gprof_%: + $(MAKE) purge + $(MAKE) depends + OPTIONS="-pg" $(MAKE) ${@:gprof_%=%}.exe + $(MAKE) ${@:gprof_%=%}.test + IFS=$$'\n'; id=1; \ + for test in `cat ${@:gprof_%=%}.test | sed 's,${@:gprof_%=%}.exe,./${@:gprof_%=%}.exe,g'`; do \ + log=${@:gprof_%=%}.prof-$$id.glog; \ + $(call TITLE, test: $$test); \ + echo $$test > $$log; \ + eval $$test >> $$log; \ + [ $$? -eq 0 ] \ + && echo -e "\033[1;32mSUCCESS\033[0;0m" \ + || echo -e "\033[1;31mFAILED\033[0;0m"; \ + [ -f gmon.out ] && { gprof ${@:gprof_%=%}.exe gmon.out >> $$log; rm gmon.out; }; \ + let id++; \ + done; + $(MAKE) purge %.test: %.c $(call TITLE, "Building $@") # awk '/\/\* *test:.*\*\// { sub(/^.*\/\* *test: */, ""); sub(/ *\*\/.*$$/, ""); print }' $< > $@ - ./getcomments.pl -p='test:\s' -f='%' $< > $@ + perl -- getcomments.pl -p='test:\s' -f='%' $< > $@ $(call PASS, SUCCESS) test_%: %.test %.exe IFS=$$'\n'; RC=0; \ - for test in `cat $< | sed 's,${<:.test=.exe},./${<:.test=.exe},g'`; do \ + for test in `cat $< | sed 's,${<:.test=.exe},$(VALGRIND) ./${<:.test=.exe},g'`; do \ echo "=== $$test ==="; \ - eval $(VALGRIND) $$test; \ + eval $$test; \ [ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \ || { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \ done; \ - test "$$RC" -ne 1 + test "$$RC" -ne 1 valgrind_%: %.exe - VALGRIND="valgrind -v --leak-check=full --show-reachable=yes --log-fd=2"; \ + VALGRIND="valgrind -v --leak-check=full --log-fd=3"; \ export VALGRIND; \ - $(MAKE) $(@:valgrind_%=test_%) + $(MAKE) $(@:valgrind_%=test_%) 3>$@.log %.d: %.c $(call TITLE, "Building $@") $(CC) $(INCLUDES) -MM $< -o $@~ - echo ${<:.c=.o}: $(shell ./getcomments.pl -p='depend:\s' -f='%' $<) >> $@~ + echo ${<:.c=.o}: $(shell perl -- getcomments.pl -p='depend:\s' -f='%' $<) >> $@~ mv $@~ $@ $(call PASS, SUCCESS) %.ld: %.c $(call TITLE, "Building $@") - echo ${<:.c=.exe}: $(shell ./getcomments.pl -p='linker:\s' -f='%' $< | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@ + echo ${<:.c=.exe}: $(shell perl -- getcomments.pl -p='linker:\s' -f='%' $< | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@ $(call PASS, SUCCESS) %.o: %.c $(call TITLE, "Building $@") - $(CC) $(CFLAGS) $(INCLUDES) $(shell ./getcomments.pl -p='cflags:\s' -f='%' $<) -c $< -o $@ + $(CC) $(CFLAGS) $(INCLUDES) $(shell perl -- getcomments.pl -p='cflags:\s' -f='%' $<) -c $< -o $@ $(call PASS, SUCCESS) %.exe: %.o %.d $(call TITLE, "Building $@") - $(CC) $(LDFLAGS) $(shell ./getcomments.pl -p='linker:\s' -f='%' ${<:.o=.c}) $< -o $@ + $(CC) $(LDFLAGS) $< $(shell perl -- getcomments.pl -p='linker:\s' -f='%' ${<:.o=.c}) $(LDLIBS) -o $@ $(call PASS, SUCCESS) ## Phony