annotate examples/simpletest/Makefile @ 285:89fe52066db1 tip master

MSCV missing ssize_t fix
author Jamie Bullock <jamie@jamiebullock.com>
date Tue, 16 Jul 2019 18:29:20 +0100
parents 0dbd0078d1c4
children
rev   line source
jamie@252 1 ####
jamie@252 2 #### Generic Makefile for C or C++ projects
jamie@252 3 ####
jamie@252 4 #### This file is public domain.
jamie@252 5 #### Jamie Bullock 2014 <jamie@jamiebullock.com>
jamie@252 6 ####
jamie@252 7
jamie@252 8 ###################################
jamie@252 9 ### User configurable variables ###
jamie@252 10 ###################################
jamie@252 11
jamie@252 12 #### It is best not to modify this file
jamie@252 13 #### Instead override these variables in a separate Make.config file if needed
jamie@252 14
jamie@252 15 # The name of the product to build (default uses parent directory name)
jamie@252 16 NAME ?= $(notdir $(CURDIR))
jamie@252 17 # The file suffix of source files, can be .c or .cpp
jamie@252 18 SUFFIX ?= .c
jamie@252 19 # List of directories containing source files to be compiled
jamie@252 20 DIRS ?= .
jamie@252 21 # Flags to pass to the compiler for release builds
jamie@252 22 FLAGS ?= -O3
jamie@252 23 # Flags to pass to the compiler for debug builds
jamie@252 24 DEBUG_FLAGS ?= -O0 -g
jamie@252 25 # Flags to pass to the linker
jamie@252 26 LDFLAGS ?=
jamie@252 27 # Type of product to build: "shared" for a shared library, "static" for a static library, empty for standalone
jamie@252 28 LIBRARY ?= static
jamie@252 29 # Prefix to the path that the "install" target will install into. libs to $(PREFIX)/lib, executables to $(PREFIX)/bin
jamie@252 30 PREFIX ?= /usr/local
jamie@252 31
jamie@252 32 ##############################################
jamie@252 33 ### Do not modify anything below this line ###
jamie@252 34 ##############################################
jamie@252 35
jamie@252 36 ifeq ($(OS),Windows_NT)
jamie@252 37 else
jamie@252 38 PLATFORM := $(shell uname -s)
jamie@252 39 endif
jamie@252 40
jamie@252 41 -include Make.config
jamie@252 42
jamie@252 43 OUT_DIR := .build
jamie@252 44 SRC := $(foreach dir, $(DIRS), $(wildcard $(dir)/*$(SUFFIX)))
jamie@252 45 OBJ_ := $(SRC:$(SUFFIX)=.o)
jamie@252 46 OBJ := $(addprefix $(OUT_DIR)/,$(OBJ_))
jamie@252 47 DEPS := $(OBJ:.o=.d)
jamie@252 48 SHARED_SUFFIX := dll
jamie@252 49 STATIC_SUFFIX := lib
jamie@252 50 INSTALL_DIR := $(PREFIX)/lib
jamie@252 51
jamie@252 52 ifeq "$(PLATFORM)" "Darwin"
jamie@252 53 SHARED_SUFFIX := dylib
jamie@252 54 STATIC_SUFFIX := a
jamie@252 55 endif
jamie@252 56
jamie@252 57 ifeq "$(PLATFORM)" "Linux"
jamie@252 58 SHARED_SUFFIX := so
jamie@252 59 STATIC_SUFFIX := a
jamie@252 60 endif
jamie@252 61
jamie@252 62 ifeq "$(LIBRARY)" "shared"
jamie@252 63 OUT=lib$(NAME).$(SHARED_SUFFIX)
jamie@252 64 LDFLAGS += -shared
jamie@252 65 else ifeq "$(LIBRARY)" "static"
jamie@252 66 OUT=lib$(NAME).$(STATIC_SUFFIX)
jamie@252 67 else
jamie@252 68 OUT=$(NAME)
jamie@252 69 INSTALL_DIR := $(PREFIX)/bin
jamie@252 70 endif
jamie@252 71
jamie@252 72 ifeq "$(SUFFIX)" ".cpp"
jamie@252 73 COMPILER := $(CXX)
jamie@252 74 else ifeq "$(SUFFIX)" ".c"
jamie@252 75 COMPILER := $(CC)
jamie@252 76 endif
jamie@252 77
jamie@252 78 .SUFFIXES:
jamie@252 79 .PHONY: debug clean install uninstall
jamie@252 80
jamie@252 81 $(OUT): $(OBJ)
jamie@252 82 ifeq "$(LIBRARY)" "static"
jamie@252 83 @$(AR) rcs $@ $^
jamie@252 84 else
jamie@278 85 @$(COMPILER) $^ $(LDFLAGS) -o $@
jamie@252 86 endif
jamie@252 87
jamie@252 88 debug: FLAGS = $(DEBUG_FLAGS)
jamie@252 89 debug: $(OUT)
jamie@252 90
jamie@252 91 $(OUT_DIR)/%.o: %$(SUFFIX)
jamie@252 92 @mkdir -p $(dir $@)
jamie@252 93 @$(COMPILER) $(CXXFLAGS) $(FLAGS) -MMD -MP -fPIC -c $< -o $@
jamie@252 94
jamie@278 95 check: $(OUT)
jamie@278 96 @./$(OUT)
jamie@278 97
jamie@278 98 test: check
jamie@278 99
jamie@252 100 install: $(OUT)
jamie@252 101 @install -d $(INSTALL_DIR)
jamie@252 102 @install $(OUT) $(INSTALL_DIR)
jamie@252 103
jamie@252 104 uninstall:
jamie@252 105 @$(RM) $(INSTALL_DIR)/$(OUT)
jamie@252 106
jamie@252 107 clean:
jamie@252 108 @$(RM) -r $(OUT) $(OUT_DIR)
jamie@252 109
jamie@252 110 -include: $(DEPS)