Use auto CRNL; compile demo for Linux too
authorhpa <hpa>
Wed, 1 Dec 2004 00:11:20 +0000 (00:11 +0000)
committerhpa <hpa>
Wed, 1 Dec 2004 00:11:20 +0000 (00:11 +0000)
com32/modules/Makefile
com32/modules/fancyhello.c

index cfd44b4..737e6f5 100644 (file)
@@ -25,7 +25,8 @@ LD         = ld -m elf_i386
 AR        = ar
 NASM      = nasm
 RANLIB    = ranlib
-CFLAGS     = -W -Wall -march=i386 -Os -fomit-frame-pointer -I../include
+CFLAGS     = -W -Wall -march=i386 -Os -fomit-frame-pointer -I../include  -D__COM32__
+LNXCFLAGS  = -W -Wall -march=i386 -Os -g
 SFLAGS     = -march=i386
 LDFLAGS    = -T ../lib/com32.ld
 OBJCOPY    = objcopy
@@ -35,7 +36,7 @@ LIBGCC    := $(shell $(CC) --print-libgcc)
 
 .SUFFIXES: .lss .c .o .elf .c32
 
-all: hello.c32 fancyhello.c32
+all: hello.c32 fancyhello.c32 fancyhello.lnx
 
 .PRECIOUS: %.o
 %.o: %.S
@@ -49,6 +50,10 @@ all: hello.c32 fancyhello.c32
 %.elf: %.o $(LIB)
        $(LD) $(LDFLAGS) -o $@ $^ $(LIBGCC)
 
+.PRECIOUS: %.lnx
+%.lnx: %.c
+       $(CC) $(LNXCFLAGS) -o $@ $^
+
 %.c32: %.elf
        $(OBJCOPY) -O binary $< $@
 
index a59be43..42c04d9 100644 (file)
@@ -1,3 +1,4 @@
+
 #ident "$Id$"
 /* ----------------------------------------------------------------------- *
  *   
 /*
  * fancyhello.c
  *
- * Hello, World! using libcom32 and ASI console
+ * Hello, World! using libcom32 and ANSI console; also possible to compile
+ * as a Linux application for testing.
  */
 
 #include <string.h>
 #include <stdio.h>
+
+#ifdef __COM32__
+
 #include <console.h>
 
+static void console_init(void)
+{
+  /* Write both to the ANSI console and the serial port, if configured */
+  openconsole(&dev_stdcon_r, &dev_ansiserial_w);
+  printf("\033[20h");          /* Automatically convert \r\n -> \n */
+}  
+
+#else
+
+static void console_init(void)
+{
+  /* Do Linux initialization (none needed) */
+}  
+
+#endif
+
 int main(void)
 {
   char buffer[1024];
 
-  /* Write both to the ANSI console and the serial port, if configured */
-  openconsole(&dev_stdcon_r, &dev_ansiserial_w);
+  console_init();
 
-  printf("(lifesign)\r\n(another)\r\n(another)\r\n");
-  printf("\033[1;33;44m *** \033[37mHello, World!\033[33m *** \033[0m\r\n");
+  printf("\033[1;33;44m *** \033[37mHello, World!\033[33m *** \033[0m\n");
 
   for (;;) {
     printf("\033[1;36m>\033[0m ");
     fgets(buffer, sizeof buffer, stdin);
-    /* fgets() prints an \n for us, but not \r */
-    putchar('\r');
     if ( !strncmp(buffer, "exit", 4) )
       break;
-    printf("\033[1m:\033[0m %s\r", buffer);
+    printf("\033[1m:\033[0m %s", buffer);
   }
   return 0;
 }