Allowed CONFIG_USE_LIBSG=0 to suppress STLink/V1 compilation
authorNed Konz <ned@bike-nomad.com>
Fri, 21 Oct 2011 02:21:43 +0000 (19:21 -0700)
committerNed Konz <ned@bike-nomad.com>
Fri, 21 Oct 2011 02:21:43 +0000 (19:21 -0700)
This will let people with Macintosh OS/X computers compile and use stlink with STLink/V2 devices, as libsg3 is not available for that platform.

Makefile
flash/Makefile
flash/main.c
gdbserver/Makefile
gdbserver/gdb-server.c
src/stlink-sg.c
src/test_sg.c

index a6545e83b64b54141b26ba3ea5ce126118e2a570..c5bb1d9a1f082db033aea7d5da793578475537c2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,21 +1,36 @@
-
+# make ... for both libusb and libsg
+#
+# make CONFIG_USE_LIBSG=0 ...
+# for just libusb
+#
 VPATH=src
 
-SOURCES_LIB=stlink-common.c stlink-usb.c stlink-sg.c
+SOURCES_LIB=stlink-common.c stlink-usb.c
 OBJS_LIB=$(SOURCES_LIB:.c=.o)
+TEST_PROGRAMS=test_usb
+LDFLAGS=-lusb-1.0 -L. -lstlink
+
+ifeq ($(CONFIG_USE_LIBSG),)
+CONFIG_USE_LIBSG=1
+endif
+
+ifneq ($(CONFIG_USE_LIBSG),0)
+SOURCES_LIB+=stlink-sg.c
+CFLAGS+=-DCONFIG_USE_LIBSG=1
+LDFLAGS+=-lsgutils2
+TEST_PROGRAMS+=test_sg
+endif
 
 CFLAGS+=-g
-CFLAGS+=-DCONFIG_USE_LIBUSB
-CFLAGS+=-DCONFIG_USE_LIBSG
-CFLAGS+=-DDEBUG
+CFLAGS+=-DCONFIG_USE_LIBUSB=1
+CFLAGS+=-DDEBUG=1
 CFLAGS+=-std=gnu99
 CFLAGS+=-Wall -Wextra
 
-LDFLAGS=-lstlink -lusb-1.0 -lsgutils2 -L.
 
 LIBRARY=libstlink.a
 
-all:  $(LIBRARY) flash gdbserver test_usb test_sg 
+all:  $(LIBRARY) flash gdbserver $(TEST_PROGRAMS)
 
 $(LIBRARY): $(OBJS_LIB)
        @echo "objs are $(OBJS_LIB)"
@@ -48,7 +63,7 @@ distclean: clean
        $(MAKE) -C gdbserver clean
        
 flash:
-       $(MAKE) -C flash
+       $(MAKE) -C flash CONFIG_USE_LIBSG="$(CONFIG_USE_LIBSG)" 
 
 gdbserver:
        $(MAKE) -C gdbserver
index aee2f3726d6ed83c58b45de5595ef02efac8947a..8a30b4113a6bcebf88951810e7d83129e45f4f7d 100644 (file)
@@ -1,14 +1,27 @@
+# make ... for both libusb and libsg
+#
+# make CONFIG_USE_LIBSG=0 ...
+# for just libusb
+#
 CC=gcc
 
 CFLAGS+=-g
-CFLAGS+=-DCONFIG_USE_LIBUSB
-CFLAGS+=-DCONFIG_USE_LIBSG
+CFLAGS+=-DCONFIG_USE_LIBUSB=1
 CFLAGS+=-DDEBUG
 CFLAGS+=-std=gnu99
 CFLAGS+=-Wall -Wextra
 CFLAGS+=-I../src
 
-LDFLAGS=-L.. -lstlink -lusb-1.0 -lsgutils2
+LDFLAGS=-lusb-1.0 -L.. -lstlink 
+
+ifeq ($(CONFIG_USE_LIBSG),)
+CONFIG_USE_LIBSG=1
+endif
+
+ifneq ($(CONFIG_USE_LIBSG),0)
+CFLAGS+=-DCONFIG_USE_LIBSG=1
+LDFLAGS+=-lsgutils2
+endif
 
 SRCS=main.c
 OBJS=$(SRCS:.c=.o)
index a443f95f6bb58b59460e3231a5a650d637763d6c..e474174377b1ac154d17cfaf96e46823f087e551 100644 (file)
@@ -86,9 +86,14 @@ int main(int ac, char** av)
 
   if (o.devname != NULL) /* stlinkv1 */
   {
+#if CONFIG_USE_LIBSG
     static const int scsi_verbose = 2;
     sl = stlink_quirk_open(o.devname, scsi_verbose);
     if (sl == NULL) goto on_error;
+#else
+    printf("not compiled for use with STLink/V1");
+    goto on_error;
+#endif
   }
   else /* stlinkv2 */
   {
index e9d2774f35b7f6826f0fd4e4c5be35113820ee8f..a8d1b90aa3b35dda5ba88637e1b65ddb51a9c798 100644 (file)
@@ -1,13 +1,24 @@
+# make ... for both libusb and libsg
+#
+# make CONFIG_USE_LIBSG=0 ...
+# for just libusb
+#
 
 PRG := st-util
 OBJS = gdb-remote.o gdb-server.o
 
 CFLAGS+=-g -Wall -Werror -std=gnu99 -I../src
-CFLAGS+=-DCONFIG_USE_LIBUSB
-CFLAGS+=-DCONFIG_USE_LIBSG
-LIBS := -lstlink -lusb-1.0 -lsgutils2
-LDFLAGS+=$(LIBS) -L..
+CFLAGS+=-DCONFIG_USE_LIBUSB=1
+LDFLAGS=-lusb-1.0 -L.. -lstlink 
 
+ifeq ($(CONFIG_USE_LIBSG),)
+CONFIG_USE_LIBSG=1
+endif
+
+ifneq ($(CONFIG_USE_LIBSG),0)
+CFLAGS+=-DCONFIG_USE_LIBSG=1
+LDFLAGS+=-lsgutils2
+endif
 
 all: $(PRG)
 
index 22dcb94804eac5b28d20f200b10633c50b1c74ea..67f0be0e61d4edd42992b72865b393c0ff3c186a 100644 (file)
@@ -91,15 +91,10 @@ int main(int argc, char** argv) {
 
        switch(argc) {
 
-               default: {
-                       fprintf(stderr, HelpStr, NULL);
-                       return 1;
-               }
-
                case 3 : {
                        //sl = stlink_quirk_open(argv[2], 0);
-                        // FIXME - hardcoded to usb....
-                        sl = stlink_open_usb(10);
+                       // FIXME - hardcoded to usb....
+                       sl = stlink_open_usb(10);
                        if(sl == NULL) return 1;
                        break;
                }
@@ -111,6 +106,7 @@ int main(int argc, char** argv) {
                        }
                }
 
+#if CONFIG_USE_LIBSG
                case 1 : { // Search ST-LINK (from /dev/sg0 to /dev/sg99)
                        const int DevNumMax = 99;
                        int ExistDevCount = 0;
@@ -148,11 +144,17 @@ int main(int argc, char** argv) {
                        }
                        break;
                }
+#endif
+
+               default: {
+                       fprintf(stderr, HelpStr, NULL);
+                       return 1;
+               }
        }
 
-        if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
-            stlink_exit_dfu_mode(sl);
-        }
+       if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
+               stlink_exit_dfu_mode(sl);
+       }
 
        if(stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) {
          stlink_enter_swd_mode(sl);
index f8865e1e4e6b9e061836db44d59e6541be122303..b8220de133bf2c26a5f6b92338c87b288bb8e09c 100644 (file)
 #include <sys/stat.h>
 #include <sys/mman.h>
 
+#include "stlink-common.h"
+
+#if CONFIG_USE_LIBSG
 // sgutils2 (apt-get install libsgutils2-dev)
 #include <scsi/sg_lib.h>
 #include <scsi/sg_pt.h>
-
-#include "stlink-common.h"
 #include "stlink-sg.h"
+#endif
 
 
 // Suspends execution of the calling process for
index 137eca4cf1a34e894ba60be8a75b32340c3ec7e2..34fbe540caa000c2665a87582b7578487b2f1816 100644 (file)
@@ -6,8 +6,10 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#if CONFIG_USE_LIBSG
 #include <scsi/sg_lib.h>
 #include <scsi/sg_pt.h>
+#endif
 #include "stlink-common.h"
 
 int main(int argc, char *argv[]) {
@@ -210,4 +212,4 @@ int main(int argc, char *argv[]) {
 
        //fflush(stderr); fflush(stdout);
        return EXIT_SUCCESS;
-}
\ No newline at end of file
+}