Moving more stuff to new makefiles
authorJohn Hodge <[email protected]>
Sat, 10 Dec 2011 04:02:55 +0000 (12:02 +0800)
committerJohn Hodge <[email protected]>
Sat, 10 Dec 2011 04:02:55 +0000 (12:02 +0800)
13 files changed:
Usermode/Applications/CLIShell_src/main.c
Usermode/Applications/cat_src/rules.mk [new file with mode: 0644]
Usermode/Applications/ifconfig_src/rules.mk [new file with mode: 0644]
Usermode/Applications/ls_src/main.c
Usermode/Applications/ls_src/rules.mk [new file with mode: 0644]
Usermode/Libraries/crt0.o_src/rules.mk
Usermode/Libraries/ld-acess.so_src/lib.c
Usermode/Libraries/ld-acess.so_src/main.c
Usermode/Libraries/ld-acess.so_src/rules.mk
Usermode/Libraries/libimage_sif.so_src/main.c
Usermode/body.mk
Usermode/header.mk
Usermode/rules.mk

index 89bfe0d..7f4ba01 100644 (file)
@@ -7,18 +7,14 @@
 #include <stdio.h>\r
 #include <string.h>\r
 #include "header.h"\r
-\r
-#if USE_READLINE\r
-# include "readline.h"\r
-#endif\r
+#include <readline.h>\r
 \r
 #define _stdin 0\r
 #define _stdout        1\r
 #define _stderr        2\r
 \r
 // ==== PROTOTYPES ====\r
-char   *ReadCommandLine(int *Length);\r
-void   Parse_Args(char *str, char **dest);\r
+ int   Parse_Args(const char *str, char **dest);\r
 void   CallCommand(char **Args);\r
 void   Command_Logout(int argc, char **argv);\r
 void   Command_Clear(int argc, char **argv);\r
@@ -56,11 +52,7 @@ int main(int argc, char *argv[], char **envp)
         int    length = 0;\r
         int    i;\r
         int    iArgCount = 0;\r
-       #if !USE_READLINE\r
-        int    bCached = 1;\r
-       #else\r
        tReadline       *readline_state = Readline_Init(1);\r
-       #endif\r
        \r
        gasEnvironment = envp;\r
        \r
@@ -81,46 +73,17 @@ int main(int argc, char *argv[], char **envp)
        for(;;)\r
        {\r
                // Free last command & arguments\r
-               if(saArgs[0])   free(saArgs);\r
-               #if !USE_READLINE\r
-               if(!bCached)    free(sCommandStr);\r
-               bCached = 0;\r
-               #endif\r
+               if(saArgs[0])   free(saArgs[0]);\r
                \r
                printf("%s$ ", gsCurrentDirectory);\r
                \r
                // Read Command line\r
-               #if USE_READLINE\r
                sCommandStr = Readline( readline_state );\r
                printf("\n");\r
                length = strlen(sCommandStr);\r
-               #else\r
-               sCommandStr = ReadCommandLine( &length );\r
-               \r
-               if(!sCommandStr) {\r
-                       printf("PANIC: Out of heap space\n");\r
-                       return -1;\r
-               }\r
-               \r
-               // Check if the command should be cached\r
-               if(gasCommandHistory == NULL || strcmp(sCommandStr, gasCommandHistory[giLastCommand]) != 0)\r
-               {\r
-                       if(giLastCommand >= giCommandSpace) {\r
-                               giCommandSpace += 12;\r
-                               gasCommandHistory = realloc(gasCommandHistory, giCommandSpace*sizeof(char*));\r
-                       }\r
-                       giLastCommand ++;\r
-                       gasCommandHistory[ giLastCommand ] = sCommandStr;\r
-                       bCached = 1;\r
-               }\r
-               #endif\r
                \r
                // Parse Command Line into arguments\r
-               Parse_Args(sCommandStr, saArgs);\r
-               \r
-               // Count Arguments\r
-               iArgCount = 0;\r
-               while(saArgs[iArgCount])        iArgCount++;\r
+               iArgCount = Parse_Args(sCommandStr, saArgs);\r
                \r
                // Silently Ignore all empty commands\r
                if(saArgs[1][0] == '\0')        continue;\r
@@ -139,157 +102,15 @@ int main(int argc, char *argv[], char **envp)
                // Shall we?\r
                CallCommand( &saArgs[1] );\r
                \r
-               #if USE_READLINE\r
                free( sCommandStr );\r
-               #endif\r
        }\r
 }\r
 \r
-#if !USE_READLINE\r
 /**\r
- * \fn char *ReadCommandLine(int *Length)\r
- * \brief Read from the command line\r
- */\r
-char *ReadCommandLine(int *Length)\r
-{\r
-       char    *ret;\r
-        int    len, pos, space = 1023;\r
-       char    ch;\r
-       #if 0\r
-        int    scrollbackPos = giLastCommand;\r
-       #endif\r
-        \r
-       // Preset Variables\r
-       ret = malloc( space+1 );\r
-       if(!ret)        return NULL;\r
-       len = 0;        pos = 0;\r
-               \r
-       // Read In Command Line\r
-       do {\r
-               ch = getchar(); // Read Character from stdin (read is a blocking call)\r
-               if(ch == '\n')  break;\r
-               \r
-               switch(ch)\r
-               {\r
-               // Control characters\r
-               case '\x1B':\r
-                       ch = getchar(); // Read control character\r
-                       switch(ch)\r
-                       {\r
-                       //case 'D':     if(pos) pos--;  break;\r
-                       //case 'C':     if(pos<len)     pos++;  break;\r
-                       case '[':\r
-                               ch = getchar(); // Read control character\r
-                               switch(ch)\r
-                               {\r
-                               #if 0\r
-                               case 'A':       // Up\r
-                                       {\r
-                                                int    oldLen = len;\r
-                                               if( scrollbackPos > 0 ) break;\r
-                                               \r
-                                               free(ret);\r
-                                               ret = strdup( gasCommandHistory[--scrollbackPos] );\r
-                                               \r
-                                               len = strlen(ret);\r
-                                               while(pos--)    printf("\x1B[D");\r
-                                               write(_stdout, len, ret);       pos = len;\r
-                                               while(pos++ < oldLen)   write(_stdout, 1, " ");\r
-                                       }\r
-                                       break;\r
-                               case 'B':       // Down\r
-                                       {\r
-                                                int    oldLen = len;\r
-                                               if( scrollbackPos < giLastCommand-1 )   break;\r
-                                               \r
-                                               free(ret);\r
-                                               ret = strdup( gasCommandHistory[++scrollbackPos] );\r
-                                               \r
-                                               len = strlen(ret);\r
-                                               while(pos--)    write(_stdout, 3, "\x1B[D");\r
-                                               write(_stdout, len, ret);       pos = len;\r
-                                               while(pos++ < oldLen)   write(_stdout, 1, " ");\r
-                                       }\r
-                                       break;\r
-                               #endif\r
-                               case 'D':       // Left\r
-                                       if(pos == 0)    break;\r
-                                       pos --;\r
-                                       printf("\x1B[D");\r
-                                       break;\r
-                               case 'C':       // Right\r
-                                       if(pos == len)  break;\r
-                                       pos++;\r
-                                       printf("\x1B[C");\r
-                                       break;\r
-                               }\r
-                       }\r
-                       break;\r
-               \r
-               // Backspace\r
-               case '\b':\r
-                       if(len <= 0)            break;  // Protect against underflows\r
-                       putchar(ch);\r
-                       if(pos == len) {        // Simple case of end of string\r
-                               len --;\r
-                               pos--;\r
-                       }\r
-                       else {\r
-                               printf("%.*s ", len-pos, &ret[pos]);    // Move Text\r
-                               printf("\x1B[%iD", len-pos+1);\r
-                               // Alter Buffer\r
-                               memmove(&ret[pos-1], &ret[pos], len-pos);\r
-                               pos --;\r
-                               len --;\r
-                       }\r
-                       break;\r
-               \r
-               // Tab\r
-               case '\t':\r
-                       //TODO: Implement Tab-Completion\r
-                       //Currently just ignore tabs\r
-                       break;\r
-               \r
-               default:                \r
-                       // Expand Buffer\r
-                       if(len+1 > space) {\r
-                               space += 256;\r
-                               ret = realloc(ret, space+1);\r
-                               if(!ret)        return NULL;\r
-                       }\r
-                       \r
-                       // Editing inside the buffer\r
-                       if(pos != len) {\r
-                               putchar(ch);    // Print new character\r
-                               printf("%.*s", len-pos, &ret[pos]);     // Move Text\r
-                               printf("\x1B[%iD", len-pos);\r
-                               memmove( &ret[pos+1], &ret[pos], len-pos );\r
-                       }\r
-                       else {\r
-                               putchar(ch);\r
-                       }\r
-                       ret[pos++] = ch;\r
-                       len ++;\r
-                       break;\r
-               }\r
-       } while(ch != '\n');\r
-       \r
-       // Cap String\r
-       ret[len] = '\0';\r
-       printf("\n");\r
-       \r
-       // Return length\r
-       if(Length)      *Length = len;\r
-       \r
-       return ret;\r
-}\r
-#endif\r
-\r
-/**\r
- * \fn void Parse_Args(char *str, char **dest)\r
+ * \fn int Parse_Args(const char *str, char **dest)\r
  * \brief Parse a string into an argument array\r
  */\r
-void Parse_Args(char *str, char **dest)\r
+int Parse_Args(const char *str, char **dest)\r
 {\r
         int    i = 1;\r
        char    *buf = malloc( strlen(str) + 1 );\r
@@ -297,7 +118,7 @@ void Parse_Args(char *str, char **dest)
        if(buf == NULL) {\r
                dest[0] = NULL;\r
                printf("Parse_Args: Out of heap space!\n");\r
-               return ;\r
+               return 0;\r
        }\r
        \r
        strcpy(buf, str);\r
@@ -324,10 +145,8 @@ void Parse_Args(char *str, char **dest)
                if(*buf == '\0')        break;\r
        }\r
        dest[i] = NULL;\r
-       if(i == 1) {\r
-               free(buf);\r
-               dest[0] = NULL;\r
-       }\r
+       \r
+       return i;\r
 }\r
 \r
 /**\r
diff --git a/Usermode/Applications/cat_src/rules.mk b/Usermode/Applications/cat_src/rules.mk
new file mode 100644 (file)
index 0000000..b6eb000
--- /dev/null
@@ -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 (file)
index 0000000..f420eb8
--- /dev/null
@@ -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
+
index 6ea4da0..4be8f0a 100644 (file)
@@ -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 (file)
index 0000000..9b6b8b0
--- /dev/null
@@ -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
+
index 728bb56..a3afc14 100644 (file)
@@ -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
index a3192bc..da37dea 100644 (file)
@@ -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;
 }
index 59b7ef1..49b2f86 100644 (file)
@@ -14,6 +14,7 @@ void  *DoRelocate(void *base, char **envp, const char *Filename);
 extern char    gLinkedBase[];\r
 extern tLoadedLib      gLoadedLibraries[];\r
 char   **gEnvP;\r
+extern int     memcmp(const void *m1, const void *m2, size_t size);\r
  \r
 // === CODE ===\r
 /**\r
index 5c513aa..a2f7ecc 100644 (file)
@@ -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
index c15652e..c4c59d4 100644 (file)
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <image.h>
 //#include <image_sif.h>
+#include <acess/sys.h> // _SysDebug
 
 // === STRUCTURES ===
 struct sHeader
index 0d77d20..2bd23d7 100644 (file)
@@ -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)
 
index b0e1802..ab0131b 100644 (file)
@@ -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))
index 740da04..4185287 100644 (file)
@@ -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)
 

UCC git Repository :: git.ucc.asn.au