1# Defaults 2CFLAGS ?= -O3 -g -ggdb 3LDFLAGS ?= 4 5BASIC_CFLAGS = -Wall -fPIC 6BASIC_LDFLAGS = -lm 7 8# We use ALL_* variants 9ALL_CFLAGS = $(BASIC_CFLAGS) $(CFLAGS) 10ALL_LDFLAGS = $(BASIC_LDFLAGS) $(LDFLAGS) 11 12LIBNAME=libargparse 13 14DYLIBSUFFIX=so 15STLIBSUFFIX=a 16DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX) 17DYLIB_MAKE_CMD=$(CC) -shared -o $(DYLIBNAME) $(ALL_LDFLAGS) 18STLIBNAME=$(LIBNAME).$(STLIBSUFFIX) 19STLIB_MAKE_CMD=ar rcs $(STLIBNAME) 20 21# Platform-specific overrides 22uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 23ifeq ($(uname_S),Darwin) 24 DYLIBSUFFIX=dylib 25 DYLIB_MAKE_CMD=$(CC) -shared -o $(DYLIBNAME) $(ALL_LDFLAGS) 26endif 27 28all: $(DYLIBNAME) $(STLIBNAME) 29 30OBJS += argparse.o 31OBJS += test_argparse.o 32 33$(OBJS): %.o: %.c 34 $(CC) -o $*.o -c $(ALL_CFLAGS) $< 35 36$(DYLIBNAME): argparse.o 37 $(DYLIB_MAKE_CMD) $^ 38 39$(STLIBNAME): argparse.o 40 $(STLIB_MAKE_CMD) $^ 41 42test: test_argparse 43 @echo "###### Unit Test #####" 44 @./test.sh 45 46test_argparse: $(OBJS) 47 $(CC) $(ALL_CFLAGS) -o $@ $^ $(ALL_LDFLAGS) 48 49clean: 50 rm -rf test_argparse 51 rm -rf *.[ao] 52 rm -rf *.dylib 53