From c416a4ee66f6005ed2527502871d42df409af039 Mon Sep 17 00:00:00 2001 From: pongo1231 Date: Thu, 29 Aug 2019 01:03:03 +0200 Subject: [PATCH] Add linux and win32 makefiles (win32 doesnt work yet) --- .gitignore | 5 ++- makefile | 83 +++++--------------------------------------------- makefile.linux | 75 +++++++++++++++++++++++++++++++++++++++++++++ makefile.win32 | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 76 deletions(-) create mode 100644 makefile.linux create mode 100644 makefile.win32 diff --git a/.gitignore b/.gitignore index 30a4d74..e830f3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ # Linux builds -build/ +build.linux/ + +# Windows builds +build.win/ # VS Code .vscode/ diff --git a/makefile b/makefile index 22e27e8..654f6d9 100644 --- a/makefile +++ b/makefile @@ -1,75 +1,8 @@ -CXX ?= gcc - -# path # -SRC_PATH = Pongbot -BUILD_PATH = build -BIN_PATH = $(BUILD_PATH)/bin - -# executable # -BIN_NAME = Pongbot.so - -# extensions # -SRC_EXT = cpp - -# code lists # -# Find all source files in the source directory, sorted by -# most recently modified -SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-) -# Set the object file names, with the source directory stripped -# from the path, and the build path prepended in its place -OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o) -# Set the dependency files that will be used to add header dependencies -DEPS = $(OBJECTS:.o=.d) - -# flags # -COMPILE_FLAGS = -Wall -Wextra -fpermissive -w -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \ - -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \ - -Dstrcmpi=strcasecmp -DCOMPILER_GCC -Wall -Wno-non-virtual-dtor -Wno-overloaded-virtual \ - -Werror -fPIC -fno-exceptions -msse -m32 -fno-strict-aliasing -D_LINUX -shared -ggdb -D_DEBUG - # -fno-rtti -INCLUDES = -I $(MLIBS) -I $(MLIBS)/hlsdk $(addprefix -I,$(shell find $(MLIBS)/hlsdk/public -type d -print)) -I $(MLIBS)/hlsdk/engine \ - -I $(MLIBS)/hlsdk/mathlib -I $(MLIBS)/hlsdk/vstdlib -I $(MLIBS)/hlsdk/game -I $(MLIBS)/hlsdk/game/tier1 -I $(MLIBS)/hlsdk/game/tier0 \ - -I $(MLIBS)/hlsdk/tier0 -I $(MLIBS)/hlsdk/tier1 -I $(MLIBS)/hlsdk/game/server -I $(MLIBS)/hlsdk/game/shared -I $(MLIBS)/metamod \ - -I $(MLIBS)/metamod/sourcehook -I Pongbot - -# Space-separated pkg-config libraries used by this project -LIBS = -L$(MLIBS)/hlsdk/lib/linux -ltier0_srv -lvstdlib_srv -l:mathlib_i486.a -l:tier1_i486.a -l:tier2_i486.a -l:tier3_i486.a -ldl - -.PHONY: default_target -default_target: release - -.PHONY: release -release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) -release: dirs - @$(MAKE) all - -.PHONY: dirs -dirs: - @echo "Creating directories" - @mkdir -p $(dir $(OBJECTS)) - @mkdir -p $(BIN_PATH) - -.PHONY: clean -clean: - @echo "Deleting $(BIN_NAME) symlink" - @$(RM) $(BIN_NAME) - @echo "Deleting directories" - @$(RM) -r $(BUILD_PATH) - @$(RM) -r $(BIN_PATH) - -# Creation of the executable -.PHONY: all -all: $(BIN_PATH)/$(BIN_NAME) -$(BIN_PATH)/$(BIN_NAME): $(OBJECTS) - @echo "Linking: $@" - $(CXX) $(CXXFLAGS) $(OBJECTS) $(LIBS) -o $@ - -# Add dependency files, if they exist --include $(DEPS) - -# Source file rules -# After the first compilation they will be joined with the rules from the -# dependency files to provide header dependencies -$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT) - @echo "Compiling: $< -> $@" - $(CXX) $(CXXFLAGS) $(INCLUDES) $(LIBS) -MP -MMD -c $< -o $@ +fail: + @echo "Please specify either \"win32\" or \"linux\"" + +win32: + make -f makefile.win32 + +linux: + make -f makefile.linux \ No newline at end of file diff --git a/makefile.linux b/makefile.linux new file mode 100644 index 0000000..4b27751 --- /dev/null +++ b/makefile.linux @@ -0,0 +1,75 @@ +CXX ?= gcc + +# path # +SRC_PATH = Pongbot +BUILD_PATH = build +BIN_PATH = $(BUILD_PATH)/bin + +# executable # +BIN_NAME = Pongbot.so + +# extensions # +SRC_EXT = cpp + +# code lists # +# Find all source files in the source directory, sorted by +# most recently modified +SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-) +# Set the object file names, with the source directory stripped +# from the path, and the build path prepended in its place +OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o) +# Set the dependency files that will be used to add header dependencies +DEPS = $(OBJECTS:.o=.d) + +# flags # +COMPILE_FLAGS = -Wall -Wextra -fpermissive -w -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \ + -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \ + -Dstrcmpi=strcasecmp -DCOMPILER_GCC -Wall -Wno-non-virtual-dtor -Wno-overloaded-virtual \ + -Werror -fPIC -fno-exceptions -msse -m32 -fno-strict-aliasing -D_LINUX -shared -ggdb -D_DEBUG + # -fno-rtti +INCLUDES = -I $(MLIBS) -I $(MLIBS)/hlsdk $(addprefix -I,$(shell find $(MLIBS)/hlsdk/public -type d -print)) -I $(MLIBS)/hlsdk/engine \ + -I $(MLIBS)/hlsdk/mathlib -I $(MLIBS)/hlsdk/vstdlib -I $(MLIBS)/hlsdk/game -I $(MLIBS)/hlsdk/game/tier1 -I $(MLIBS)/hlsdk/game/tier0 \ + -I $(MLIBS)/hlsdk/tier0 -I $(MLIBS)/hlsdk/tier1 -I $(MLIBS)/hlsdk/game/server -I $(MLIBS)/hlsdk/game/shared -I $(MLIBS)/metamod \ + -I $(MLIBS)/metamod/sourcehook -I Pongbot + +# Space-separated pkg-config libraries used by this project +LIBS = -L$(MLIBS)/hlsdk/lib/linux -ltier0_srv -lvstdlib_srv -l:mathlib_i486.a -l:tier1_i486.a -l:tier2_i486.a -l:tier3_i486.a -ldl + +.PHONY: default_target +default_target: release + +.PHONY: release +release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) +release: dirs + @$(MAKE) -f makefile.linux linux + +.PHONY: dirs +dirs: + @echo "Creating directories" + @mkdir -p $(dir $(OBJECTS)) + @mkdir -p $(BIN_PATH) + +.PHONY: clean +clean: + @echo "Deleting $(BIN_NAME) symlink" + @$(RM) $(BIN_NAME) + @echo "Deleting directories" + @$(RM) -r $(BUILD_PATH) + @$(RM) -r $(BIN_PATH) + +# Creation of the executable +.PHONY: linux +linux: $(BIN_PATH)/$(BIN_NAME) +$(BIN_PATH)/$(BIN_NAME): $(OBJECTS) + @echo "Linking: $@" + $(CXX) $(CXXFLAGS) $(OBJECTS) $(LIBS) -o $@ + +# Add dependency files, if they exist +-include $(DEPS) + +# Source file rules +# After the first compilation they will be joined with the rules from the +# dependency files to provide header dependencies +$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT) + @echo "Compiling: $< -> $@" + $(CXX) $(CXXFLAGS) $(INCLUDES) $(LIBS) -MP -MMD -c $< -o $@ diff --git a/makefile.win32 b/makefile.win32 new file mode 100644 index 0000000..0f65040 --- /dev/null +++ b/makefile.win32 @@ -0,0 +1,77 @@ +CXX ?= i686-w64-mingw32-gcc + +# path # +SRC_PATH = Pongbot +BUILD_PATH = build.win +BIN_PATH = $(BUILD_PATH)/bin + +# executable # +BIN_NAME = Pongbot.dll + +# extensions # +SRC_EXT = cpp + +# code lists # +# Find all source files in the source directory, sorted by +# most recently modified +SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-) +# Set the object file names, with the source directory stripped +# from the path, and the build path prepended in its place +OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o) +# Set the dependency files that will be used to add header dependencies +DEPS = $(OBJECTS:.o=.d) + +# flags # +COMPILE_FLAGS = -Wall -Wextra -fpermissive -w -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \ + -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \ + -Dstrcmpi=strcasecmp -Wall -Wno-non-virtual-dtor -Wno-overloaded-virtual \ + -Werror -fPIC -fno-exceptions -msse -m32 -fno-strict-aliasing -D_WIN32 -shared -ggdb -nostdinc -D_DEBUG + # -fno-rtti +INCLUDES = -I $(MLIBS) -I $(MLIBS)/hlsdk $(addprefix -I,$(shell find $(MLIBS)/hlsdk/public -type d -print)) -I $(MLIBS)/hlsdk/engine \ + -I $(MLIBS)/hlsdk/mathlib -I $(MLIBS)/hlsdk/vstdlib -I $(MLIBS)/hlsdk/game -I $(MLIBS)/hlsdk/game/tier1 -I $(MLIBS)/hlsdk/game/tier0 \ + -I $(MLIBS)/hlsdk/tier0 -I $(MLIBS)/hlsdk/tier1 -I $(MLIBS)/hlsdk/game/server -I $(MLIBS)/hlsdk/game/shared -I $(MLIBS)/metamod \ + -I $(MLIBS)/metamod/sourcehook -I /usr/i686-w64-mingw32/include -I /usr/i686-w64-mingw32/include/c++/9.2.0 \ + -I /usr/i686-w64-mingw32/include/c++/9.2.0/i686-w64-mingw32 -I /usr/lib/gcc/i686-w64-mingw32/9.2.0/include \ + -I /usr/i686-w64-mingw32/include/c++/9.2.0/tr1 -I Pongbot + +# Space-separated pkg-config libraries used by this project +LIBS = -L$(MLIBS)/hlsdk/lib/public -l:tier0.lib -l:vstdlib.lib -l:mathlib.lib -l:tier1.lib -l:tier2.lib -l:tier3.lib -ldl + +.PHONY: default_target +default_target: release + +.PHONY: release +release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) +release: dirs + @$(MAKE) -f makefile.win32 win32 + +.PHONY: dirs +dirs: + @echo "Creating directories" + @mkdir -p $(dir $(OBJECTS)) + @mkdir -p $(BIN_PATH) + +.PHONY: clean +clean: + @echo "Deleting $(BIN_NAME) symlink" + @$(RM) $(BIN_NAME) + @echo "Deleting directories" + @$(RM) -r $(BUILD_PATH) + @$(RM) -r $(BIN_PATH) + +# Creation of the executable +.PHONY: win32 +win32: $(BIN_PATH)/$(BIN_NAME) +$(BIN_PATH)/$(BIN_NAME): $(OBJECTS) + @echo "Linking: $@" + $(CXX) $(CXXFLAGS) $(OBJECTS) $(LIBS) -o $@ + +# Add dependency files, if they exist +-include $(DEPS) + +# Source file rules +# After the first compilation they will be joined with the rules from the +# dependency files to provide header dependencies +$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT) + @echo "Compiling: $< -> $@" + $(CXX) $(CXXFLAGS) $(INCLUDES) $(LIBS) -MP -MMD -c $< -o $@