Skip to content
Snippets Groups Projects
Commit ef54529a authored by deuce's avatar deuce
Browse files

Initial outline of common build system (gmake only)

parent 8d1d4894
No related branches found
No related tags found
No related merge requests found
#########################################################################
# #
# Common macro setup for GNU make #
# #
# Common Build Macros REQUIRED: #
# SRC_ROOT - *MUST* be set to the src dir #
# #
# Common Build Macros Used: #
# DEBUG - Create a debug build #
# RELEASE - Create a release build #
# (Mutually exclusive, if both are set, RELEASE #
# is cleared) #
# DONT_CLOBBER_CC - Do not change the default setting of CC #
# OBJPATH_SUFFIX - Suffix appended to OBJPATH usefull for compiling #
# different options of the same source file #
# #
# Common Build Macros Defined: #
# OBJODIR - Object output dir #
# LIBODIR - Library output dir #
# EXEODIR - Executable output dir #
# DEBUG - Set for debug builds #
# RELEASE - Set for release builds #
# One of DEBUG or RELEASE is always set! #
# QUIET - Target command prefix to show/not show commands #
# (Toggled off by setting VERBOSE) #
# CFLAGS - Common C and C++ compiler flags #
# CCFLAGS - C specific compiler flags #
# CXXFLAGS - C++ specific compiler flags #
# LDFLAGS - Linker flags #
# CC - C compiler #
# CXX - C++ compiler #
# EXEFILE - Executable file extension (Includes .) #
# OFILE - Object file extension (Includes .) #
# SOFILE - Shared object (DLL) file extension (Includes .) #
# LIBFILE - Static library file extension (Include .) #
# LIBPREFIX - Prefix to library filename #
# LIBS - Library names (Appropriate for dependencies) #
# LIB_LDFLAGS - Libraries appropriate for link command-line usage #
# COMPILE_MSG - Message saying a target is being compiled #
# DIRSEP - The directory seperator this system likes most #
# VERSION - Synchronet version number in MAJOR.MINOR format #
# (Numeric ONLY) #
# #
#########################################################################
# Set VERSION
ifndef VERSION
VERSION := 3.12
endif
# Set DEBUG
ifdef DEBUG
ifdef RELEASE
undef RELEASE
endif
endif
ifndef DEBUG
ifndef RELEASE
DEBUG := 1
endif
endif
# VERBOSE/QUIET
ifndef VERBOSE
QUIET := @
endif
# Compiler-specific options
CFLAGS += -MMD
ifdef BUILD_DEPENDS
ifdef DONT_CLOBBER_CC
CC ?= gcc
else
CC := gcc
endif
CCPRE := $(CC)
CC := $(SRC_ROOT)/build/mkdep -a
CXX := $(SRC_ROOT)/build/mkdep -a
LD := echo
COMPILE_MSG := Depending
else
ifdef DONT_CLOBBER_CC
CC ?= gcc
else
CC := gcc
endif
CCPRE := $(CC)
CXX ?= g++
LD ?= ld
COMPILE_MSG := Compiling
endif
ifdef DEBUG
BUILD = debug
else
BUILD = release
endif
BUILDPATH ?= $(BUILD)
# Get OS
ifndef os
os := $(shell uname)
endif
os := $(shell echo $(os) | tr '[A-Z]' '[a-z]' | tr ' ' '_')
machine := $(shell if uname -m | egrep -v "(i[3456789]|x)86" > /dev/null; then uname -m | tr "[A-Z]" "[a-z]" | tr " " "_" ; fi)
ifeq ($(machine),sun4u)
CFLAGS += -D__BIG_ENDIAN__
endif
ifeq ($(machine),)
machine := $(os)
else
machine := $(os).$(machine)
endif
LIBODIR := $(CCPRE).$(machine).lib.$(BUILDPATH)
OBJODIR := $(CCPRE).$(machine).obj.$(BUILDPATH)$(OBJPATH_SUFFIX)
EXEODIR := $(CCPRE).$(machine).exe.$(BUILDPATH)
LDFLAGS += -L$(LIBODIR)
ifeq ($(os),netbsd)
DELETE := rm -f
else
ifeq ($(os),openbsd)
DELETE := rm -f
else
ifeq ($(os),sunos)
DELETE := rm -f
else
DELETE = rm -fv
endif
endif
endif
LIBPREFIX := lib
DIRSEP := /
OFILE := .o
EXEFILE :=
SOFILE := .so
LIBFILE := .a
ifeq ($(os),openbsd)
SOFILE := $(SOFILE)$(VERSION)
else
ifeq ($(os),darwin)
SOFILE = .dylib
endif
endif
# OS Specific Flags
ifeq ($(os),sunos) # Solaris
CFLAGS += -D__solaris__ -DNEEDS_DAEMON -DNEEDS_FORKPTY -DNEEDS_SETENV -DNEEDS_CFMAKERAW
endif
ifeq ($(os),netbsd) # NetBSD
CFLAGS += -D__unix__ -I/usr/pkg/include -I/usr/pkg/pthreads/include -DNEEDS_FORKPTY
endif
ifeq ($(os),darwin)
CFLAGS += -D__unix__ -fno-common -D__DARWIN__
LDFLAGS += -lm
endif
ifdef DEBUG
CFLAGS += -ggdb
CFLAGS += -D_DEBUG
else # RELEASE
CFLAGS := -O3 $(CFLAGS)
endif
-include targets.mk
-include $(SRC_ROOT)/rules.mk
-include objects.mk # defines $(OBJS)
-include libobjs.mk # defines $(LIB_OBJS)
# Implicit C Compile Rule
$(OBJODIR)/%.o : %.c $(BUILD_DEPENDS)
@echo $(COMPILE_MSG) $<
$(QUIET)$(CC) $(CFLAGS) $(CCFLAGS) -o $@ -c $<
# Implicit C++ Compile Rule
$(OBJODIR)/%.o : %.cpp $(BUILD_DEPENDS)
@echo $(COMPILE_MSG) $<
$(QUIET)$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $<
depend:
$(QUIET)$(DELETE) $(OBJODIR)/.depend
$(QUIET)$(DELETE) $(LIBODIR)/.depend
$(QUIET)$(DELETE) $(EXEODIR)/.depend
$(QUIET)$(MAKE) BUILD_DEPENDS=FORCE
FORCE:
-include $(OBJODIR)/.depend
-include $(LIBODIR)/.depend
-include $(EXEODIR)/.depend
-include $(OBJODIR)/*.d
-include $(LIBODIR)/*.d
-include $(EXEODIR)/*.d
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment