antirez / sds

Simple Dynamic Strings library for C
BSD 2-Clause "Simplified" License
4.89k stars 473 forks source link

Make install target #97

Open topilski opened 6 years ago

topilski commented 6 years ago

May be will be useful add make install target.

oxr463 commented 5 years ago

Here is a rough draft,

all: sds-install sds-lib sds-test

sds-install: sds-lib
        cp -a libsds.so.2.0.0 /usr/local/lib/
        ln -s /usr/local/lib/libsds.so.2.0.0 /usr/local/lib/libsds.so
        ln -s /usr/local/lib/libsds.so.2.0.0 /usr/local/lib/libsds.so.2
        mkdir -p /usr/local/include/sds
        cp -a sds.h /usr/local/include/sds/

sds-lib: sds.c sds.h sdsalloc.h
        $(CC) -fPIC -fstack-protector -std=c99 -pedantic -Wall -Werror -shared \
                -o libsds.so.2.0.0 -Wl,-soname=libsds.so.2.0.0 sds.c sds.h sdsalloc.h

sds-test: sds.c sds.h testhelp.h
        $(CC) -o sds-test sds.c -Wall -std=c99 -pedantic -O2 -DSDS_TEST_MAIN
        @echo ">>> Type ./sds-test to run the sds.c unit tests."

clean:
        rm -f sds-test libsd.so.2.0.0

See also: cJSON/Makefile

Also, the compiler complains about sdsalloc.h with -pedantic, so I appended the following,

echo "typedef int sdsvoid;" >> sdsalloc.h

Bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64502

Here is an example program,

#include <sds/sds.h>
#include <stdio.h>

int main (void)
{
    sds mystring = sdsnew("Hello World!");
    printf("%s\n", mystring);
    sdsfree(mystring);
    return 0;
}

Compile with gcc -o hello hello.c -lsds, and run,

./hello
Hello World!

NOTE: Don't forget to run ldconfig!