From f8168f419a5b83f6875fc0a3044ce8a8b1572b65 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 10 Dec 2011 12:02:55 +0800 Subject: [PATCH] Moving more stuff to new makefiles --- Usermode/Applications/CLIShell_src/main.c | 199 +----------------- Usermode/Applications/cat_src/rules.mk | 16 ++ Usermode/Applications/ifconfig_src/rules.mk | 14 ++ Usermode/Applications/ls_src/main.c | 14 +- Usermode/Applications/ls_src/rules.mk | 12 ++ Usermode/Libraries/crt0.o_src/rules.mk | 6 +- Usermode/Libraries/ld-acess.so_src/lib.c | 3 +- Usermode/Libraries/ld-acess.so_src/main.c | 1 + Usermode/Libraries/ld-acess.so_src/rules.mk | 2 +- Usermode/Libraries/libimage_sif.so_src/main.c | 1 + Usermode/body.mk | 2 +- Usermode/header.mk | 4 + Usermode/rules.mk | 10 +- 13 files changed, 76 insertions(+), 208 deletions(-) create mode 100644 Usermode/Applications/cat_src/rules.mk create mode 100644 Usermode/Applications/ifconfig_src/rules.mk create mode 100644 Usermode/Applications/ls_src/rules.mk diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index 89bfe0d1..7f4ba01c 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -7,18 +7,14 @@ #include #include #include "header.h" - -#if USE_READLINE -# include "readline.h" -#endif +#include #define _stdin 0 #define _stdout 1 #define _stderr 2 // ==== PROTOTYPES ==== -char *ReadCommandLine(int *Length); -void Parse_Args(char *str, char **dest); + int Parse_Args(const char *str, char **dest); void CallCommand(char **Args); void Command_Logout(int argc, char **argv); void Command_Clear(int argc, char **argv); @@ -56,11 +52,7 @@ int main(int argc, char *argv[], char **envp) int length = 0; int i; int iArgCount = 0; - #if !USE_READLINE - int bCached = 1; - #else tReadline *readline_state = Readline_Init(1); - #endif gasEnvironment = envp; @@ -81,46 +73,17 @@ int main(int argc, char *argv[], char **envp) for(;;) { // Free last command & arguments - if(saArgs[0]) free(saArgs); - #if !USE_READLINE - if(!bCached) free(sCommandStr); - bCached = 0; - #endif + if(saArgs[0]) free(saArgs[0]); printf("%s$ ", gsCurrentDirectory); // Read Command line - #if USE_READLINE sCommandStr = Readline( readline_state ); printf("\n"); length = strlen(sCommandStr); - #else - sCommandStr = ReadCommandLine( &length ); - - if(!sCommandStr) { - printf("PANIC: Out of heap space\n"); - return -1; - } - - // Check if the command should be cached - if(gasCommandHistory == NULL || strcmp(sCommandStr, gasCommandHistory[giLastCommand]) != 0) - { - if(giLastCommand >= giCommandSpace) { - giCommandSpace += 12; - gasCommandHistory = realloc(gasCommandHistory, giCommandSpace*sizeof(char*)); - } - giLastCommand ++; - gasCommandHistory[ giLastCommand ] = sCommandStr; - bCached = 1; - } - #endif // Parse Command Line into arguments - Parse_Args(sCommandStr, saArgs); - - // Count Arguments - iArgCount = 0; - while(saArgs[iArgCount]) iArgCount++; + iArgCount = Parse_Args(sCommandStr, saArgs); // Silently Ignore all empty commands if(saArgs[1][0] == '\0') continue; @@ -139,157 +102,15 @@ int main(int argc, char *argv[], char **envp) // Shall we? CallCommand( &saArgs[1] ); - #if USE_READLINE free( sCommandStr ); - #endif } } -#if !USE_READLINE /** - * \fn char *ReadCommandLine(int *Length) - * \brief Read from the command line - */ -char *ReadCommandLine(int *Length) -{ - char *ret; - int len, pos, space = 1023; - char ch; - #if 0 - int scrollbackPos = giLastCommand; - #endif - - // Preset Variables - ret = malloc( space+1 ); - if(!ret) return NULL; - len = 0; pos = 0; - - // Read In Command Line - do { - ch = getchar(); // Read Character from stdin (read is a blocking call) - if(ch == '\n') break; - - switch(ch) - { - // Control characters - case '\x1B': - ch = getchar(); // Read control character - switch(ch) - { - //case 'D': if(pos) pos--; break; - //case 'C': if(pos 0 ) break; - - free(ret); - ret = strdup( gasCommandHistory[--scrollbackPos] ); - - len = strlen(ret); - while(pos--) printf("\x1B[D"); - write(_stdout, len, ret); pos = len; - while(pos++ < oldLen) write(_stdout, 1, " "); - } - break; - case 'B': // Down - { - int oldLen = len; - if( scrollbackPos < giLastCommand-1 ) break; - - free(ret); - ret = strdup( gasCommandHistory[++scrollbackPos] ); - - len = strlen(ret); - while(pos--) write(_stdout, 3, "\x1B[D"); - write(_stdout, len, ret); pos = len; - while(pos++ < oldLen) write(_stdout, 1, " "); - } - break; - #endif - case 'D': // Left - if(pos == 0) break; - pos --; - printf("\x1B[D"); - break; - case 'C': // Right - if(pos == len) break; - pos++; - printf("\x1B[C"); - break; - } - } - break; - - // Backspace - case '\b': - if(len <= 0) break; // Protect against underflows - putchar(ch); - if(pos == len) { // Simple case of end of string - len --; - pos--; - } - else { - printf("%.*s ", len-pos, &ret[pos]); // Move Text - printf("\x1B[%iD", len-pos+1); - // Alter Buffer - memmove(&ret[pos-1], &ret[pos], len-pos); - pos --; - len --; - } - break; - - // Tab - case '\t': - //TODO: Implement Tab-Completion - //Currently just ignore tabs - break; - - default: - // Expand Buffer - if(len+1 > space) { - space += 256; - ret = realloc(ret, space+1); - if(!ret) return NULL; - } - - // Editing inside the buffer - if(pos != len) { - putchar(ch); // Print new character - printf("%.*s", len-pos, &ret[pos]); // Move Text - printf("\x1B[%iD", len-pos); - memmove( &ret[pos+1], &ret[pos], len-pos ); - } - else { - putchar(ch); - } - ret[pos++] = ch; - len ++; - break; - } - } while(ch != '\n'); - - // Cap String - ret[len] = '\0'; - printf("\n"); - - // Return length - if(Length) *Length = len; - - return ret; -} -#endif - -/** - * \fn void Parse_Args(char *str, char **dest) + * \fn int Parse_Args(const char *str, char **dest) * \brief Parse a string into an argument array */ -void Parse_Args(char *str, char **dest) +int Parse_Args(const char *str, char **dest) { int i = 1; char *buf = malloc( strlen(str) + 1 ); @@ -297,7 +118,7 @@ void Parse_Args(char *str, char **dest) if(buf == NULL) { dest[0] = NULL; printf("Parse_Args: Out of heap space!\n"); - return ; + return 0; } strcpy(buf, str); @@ -324,10 +145,8 @@ void Parse_Args(char *str, char **dest) if(*buf == '\0') break; } dest[i] = NULL; - if(i == 1) { - free(buf); - dest[0] = NULL; - } + + return i; } /** diff --git a/Usermode/Applications/cat_src/rules.mk b/Usermode/Applications/cat_src/rules.mk new file mode 100644 index 00000000..b6eb0003 --- /dev/null +++ b/Usermode/Applications/cat_src/rules.mk @@ -0,0 +1,16 @@ +# cat + +include $(BASE)header.mk + +# Variables +SRCS := main.c +BIN := $(OUTPUTDIR)Bin/cat + +CFLAGS-$(DIR) := $(CFLAGS-$(PDIR)) -g +CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR)) +LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) + +include $(BASE)body.mk + +include $(BASE)footer.mk + diff --git a/Usermode/Applications/ifconfig_src/rules.mk b/Usermode/Applications/ifconfig_src/rules.mk new file mode 100644 index 00000000..f420eb80 --- /dev/null +++ b/Usermode/Applications/ifconfig_src/rules.mk @@ -0,0 +1,14 @@ +# ifconfig + +include $(BASE)header.mk + +# Variables +SRCS := main.c +BIN := $(OUTPUTDIR)Bin/ifconfig + +LDFLAGS-$(DIR) += -lnet + +include $(BASE)body.mk + +include $(BASE)footer.mk + diff --git a/Usermode/Applications/ls_src/main.c b/Usermode/Applications/ls_src/main.c index 6ea4da0c..4be8f0ae 100644 --- a/Usermode/Applications/ls_src/main.c +++ b/Usermode/Applications/ls_src/main.c @@ -152,7 +152,7 @@ void ParseArguments(int argc, char *argv[]) // Human readable sizes case 'h': gbViewHumanReadable = 1; continue; default: - fprintf(stderr, "%s: Unknown option '%c'\n", *str); + fprintf(stderr, "%s: Unknown option '%c'\n", argv[0], *str); ShowUsage(argv[0]); exit(EXIT_FAILURE); } @@ -283,22 +283,22 @@ void DisplayFile(char *Filename) printf("%s %4i %4i ", permStr, owner, group); if(gbViewHumanReadable && type != FTYPE_DIR) { if(size < 2048) { // < 2 KiB - printf("%4i B ", size); + printf("%4lli B ", size); } else if(size < 2048*1024) { // < 2 MiB - printf("%4i KiB ", size>>10); + printf("%4lli KiB ", size>>10); } else if(size < (uint64_t)2048*1024*1024) { // < 2 GiB - printf("%4i MiB ", size>>20); + printf("%4lli MiB ", size>>20); } else if(size < (uint64_t)2048*1024*1024*1024) { // < 2 TiB - printf("%4i GiB ", size>>30); + printf("%4lli GiB ", size>>30); } else { // Greater than 2 TiB (if your files are larger than this, you are Doing It Wrong [TM]) - printf("%4i TiB ", size>>40); + printf("%4lli TiB ", size>>40); } } else { - printf("%8i ", size); + printf("%8lli ", size); } } diff --git a/Usermode/Applications/ls_src/rules.mk b/Usermode/Applications/ls_src/rules.mk new file mode 100644 index 00000000..9b6b8b02 --- /dev/null +++ b/Usermode/Applications/ls_src/rules.mk @@ -0,0 +1,12 @@ +# ls + +include $(BASE)header.mk + +# Variables +SRCS := main.c +BIN := $(OUTPUTDIR)Bin/ls + +include $(BASE)body.mk + +include $(BASE)footer.mk + diff --git a/Usermode/Libraries/crt0.o_src/rules.mk b/Usermode/Libraries/crt0.o_src/rules.mk index 728bb566..a3afc149 100644 --- a/Usermode/Libraries/crt0.o_src/rules.mk +++ b/Usermode/Libraries/crt0.o_src/rules.mk @@ -14,10 +14,10 @@ LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) include $(BASE)body.mk $(filter %crt0.o,$(BIN)): $(filter %crt0.c.o,$(OBJ)) - cp $< $@ + @cp $< $@ $(filter %crtbegin.o,$(BIN)): $(filter %crtbegin.c.o,$(OBJ)) - cp $< $@ + @cp $< $@ $(filter %crtend.o,$(BIN)): $(filter %crtend.c.o,$(OBJ)) - cp $< $@ + @cp $< $@ include $(BASE)footer.mk diff --git a/Usermode/Libraries/ld-acess.so_src/lib.c b/Usermode/Libraries/ld-acess.so_src/lib.c index a3192bc8..da37dea0 100644 --- a/Usermode/Libraries/ld-acess.so_src/lib.c +++ b/Usermode/Libraries/ld-acess.so_src/lib.c @@ -60,7 +60,8 @@ int memcmp(const void *p1, const void *p2, int len) void *memcpy(void *dest, const void *src, size_t len) { - uint8_t *d=dest, *s=src; + uint8_t *d=dest; + const uint8_t *s=src; while(len--) *d++ = *s++; return dest; } diff --git a/Usermode/Libraries/ld-acess.so_src/main.c b/Usermode/Libraries/ld-acess.so_src/main.c index 59b7ef16..49b2f863 100644 --- a/Usermode/Libraries/ld-acess.so_src/main.c +++ b/Usermode/Libraries/ld-acess.so_src/main.c @@ -14,6 +14,7 @@ void *DoRelocate(void *base, char **envp, const char *Filename); extern char gLinkedBase[]; extern tLoadedLib gLoadedLibraries[]; char **gEnvP; +extern int memcmp(const void *m1, const void *m2, size_t size); // === CODE === /** diff --git a/Usermode/Libraries/ld-acess.so_src/rules.mk b/Usermode/Libraries/ld-acess.so_src/rules.mk index 5c513aac..a2f7ecc4 100644 --- a/Usermode/Libraries/ld-acess.so_src/rules.mk +++ b/Usermode/Libraries/ld-acess.so_src/rules.mk @@ -12,7 +12,7 @@ LDFLAGS-$(DIR) := -g -T $(DIR)/arch/$(ARCHDIR).ld -Map $(call fcn_mkobj,map.txt) include $(BASE)body.mk -$(call fcn_addbin, $(OUTPUTDIR)Libs/libld-acess.so, $(call fcn_mkobj,_stublib.c.o)) +$(call fcn_addbin,$(OUTPUTDIR)Libs/libld-acess.so,$(call fcn_src2obj,_stublib.c)) # Handle preprocessed files $(DIR)%: $(DIR)%.h diff --git a/Usermode/Libraries/libimage_sif.so_src/main.c b/Usermode/Libraries/libimage_sif.so_src/main.c index c15652e7..c4c59d4d 100644 --- a/Usermode/Libraries/libimage_sif.so_src/main.c +++ b/Usermode/Libraries/libimage_sif.so_src/main.c @@ -6,6 +6,7 @@ #include #include //#include +#include // _SysDebug // === STRUCTURES === struct sHeader diff --git a/Usermode/body.mk b/Usermode/body.mk index 0d77d203..2bd23d71 100644 --- a/Usermode/body.mk +++ b/Usermode/body.mk @@ -8,6 +8,6 @@ $(call fcn_addbin,$(BIN),$(OBJ)) all-$(DIR): $(BIN) clean-$(DIR): clean-%: $(eval BIN=$(BIN-$*/)) - $(eval OBJ=$(OBJ-$*/)) + $(eval OBJ=$(foreach f, $(BIN), $(OBJ-$f))) $(RM) $(BIN) $(OBJ) $(OBJ:%=%.dep) diff --git a/Usermode/header.mk b/Usermode/header.mk index b0e1802c..ab0131b1 100644 --- a/Usermode/header.mk +++ b/Usermode/header.mk @@ -4,3 +4,7 @@ DIR_$(x) := $(DIR) DIR := $(dir $(lastword $(filter-out %/header.mk,$(MAKEFILE_LIST)))) PDIR := $(DIR_$(x)) EXTRA_DEP-$(DIR) := $(EXTRA_DEP-$(PDIR)) + +CFLAGS-$(DIR) := $(CFLAGS-$(PDIR)) +CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR)) +LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) diff --git a/Usermode/rules.mk b/Usermode/rules.mk index 740da04c..4185287c 100644 --- a/Usermode/rules.mk +++ b/Usermode/rules.mk @@ -18,7 +18,7 @@ fcn_mkobj = $(addprefix $(DIR)$(OBJECT_DIR),$(patsubst $(SOURCE_DIR)%,%,$1)) fcn_src2obj = $(call fcn_mkobj, $(call fcn_src2obj_int,$1)) fcn_obj2src = $(subst $(OBJECT_DIR),$(SOURCE_DIR),$(patsubst %$(OBJECT_SUFFIX).o,%,$1)) -fcn_addbin = $(eval ALL_OBJ:=$(ALL_OBJ) $2) $(eval ALL_BIN:=$(ALL_BIN) $1) $(foreach f,$2 $1,$(eval _DIR-$f := $(DIR))) $(eval $1: $2) $(eval OBJ-$(DIR):=$(OBJ-$(DIR)) $2) $(eval BIN-$(DIR):=$(BIN-$(DIR)) $1) +fcn_addbin = $(eval ALL_OBJ:=$(ALL_OBJ) $2) $(eval ALL_BIN:=$(ALL_BIN) $1) $(foreach f,$2 $1,$(eval _DIR-$f := $(DIR))) $(eval $1: $2) $(eval BIN-$(DIR):=$(BIN-$(DIR)) $1) $(eval OBJ-$1:=$2) # Start of Voodoo code _REL_POS := $(dir $(lastword $(MAKEFILE_LIST))) @@ -105,22 +105,22 @@ $(foreach f,$(ALL_BIN), $(eval $f: $(EXTRA_DEP-$(_DIR-$f)) $(call fcn_getlibs,$f $(eval _dir=$(_DIR-$@)) @echo [AR] ru $@ @$(RM) $@ - @$(AR) ru $@ $(OBJ-$(_dir)) + @$(AR) ru $@ $(OBJ-$@) # Dynamic Library (.so) %.so: $(eval _dir=$(_DIR-$@)) @echo [LD] -shared -o $@ - @$(LD) $(LDFLAGS) -shared -soname $(basename $@) -o $@ $(filter %.o,$^) $(LDFLAGS-$(_dir)) + @$(LD) $(LDFLAGS) -shared -soname $(notdir $@) -o $@ $(OBJ-$@) $(LDFLAGS-$(_dir)) # Executable (.bin) %.bin: $(eval _dir=$(_DIR-$@)) @echo [LD] -o $@ - @$(LD) $(LDFLAGS) -o $@ $(OBJ-$(_dir)) $(LDFLAGS-$(_dir)) + @$(LD) $(LDFLAGS) -o $@ $(OBJ-$@) $(LDFLAGS-$(_dir)) @$(CP) $@ $(@:%.bin=%) $(OUTPUTDIR)%: $(eval _dir=$(_DIR-$@)) @echo [LD] -o $@ - @$(LD) $(LDFLAGS) -o $@ $(OBJ-$(_dir)) $(LDFLAGS-$(_dir)) + @$(LD) $(LDFLAGS) -o $@ $(OBJ-$@) $(LDFLAGS-$(_dir)) -include $(ALL_OBJ:%=%.dep) -- 2.20.1