← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcpp-plugin-sdk-c/trunk] Rev 14: makefile: proper output dir, detect mingw, detect x64

 

------------------------------------------------------------
revno: 14
committer: poy <poy@xxxxxxxxxx>
branch nick: dcpp-plugin-sdk-c
timestamp: Fri 2013-04-26 17:11:39 +0200
message:
  makefile: proper output dir, detect mingw, detect x64
modified:
  projects/make/Makefile


--
lp:dcpp-plugin-sdk-c
https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-c/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcpp-plugin-sdk-c.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-c/trunk/+edit-subscription
=== modified file 'projects/make/Makefile'
--- projects/make/Makefile	2013-02-05 18:52:29 +0000
+++ projects/make/Makefile	2013-04-26 15:11:39 +0000
@@ -1,17 +1,20 @@
 # This is a rudimentary Makefile that compiles files from the pluginsdk & src directories into a
 # shared library. Adapt to your needs.
 
-TARGET = MyPlugin # Rename to your plugin's name.
+# Rename to your plugin's name.
+TARGET = MyPlugin
 
-CPPFLAGS += -march=i686 # Remove if your target architecture is not x86.
+CC = gcc
+CXX = g++
 
 CPPFLAGS += -Wall -Wextra -g -pipe -O3 -I../../
+CXXFLAGS += -std=gnu++0x
 LINKFLAGS += -static-libgcc -g -O3 -shared -Wl,--add-stdcall-alias
+LINKXXFLAGS += -static-libstdc++
 
 VPATH = ../../
 
 OUTPUT_DIR = build
-OUTPUT_OPTION = -o $(OUTPUT_DIR)/$@
 
 OBJS = \
 	pluginsdk/Config.o \
@@ -19,38 +22,59 @@
 	src/Plugin.o \
 	src/stdafx.o
 
-ifeq ($(OS), Windows_NT)
+ifeq ($(findstring mingw, $(shell gcc -dumpmachine)),)
+	LIBEXT = .so
+else
 	CPPFLAGS += -D_WIN32_WINNT=0x502 -DWINVER=0x502 -D_WIN32_IE=0x600 \
 				-DNOMINMAX -DSTRICT -DWIN32_LEAN_AND_MEAN \
 				-DWIN32 -D_WIN32 -DUNICODE -D_UNICODE
+	LIBEXT = .dll
 	OBJS += src/resource.o
-	LIBEXT = .dll
+	OUTPUT_DIR := $(OUTPUT_DIR)-mingw
+endif
+
+ifeq ($(findstring x86_64, $(shell gcc -dumpmachine)),)
+	CPPFLAGS += -march=i686
+	OUTPUT_DIR := $(OUTPUT_DIR)-x86
+else
+	OUTPUT_DIR := $(OUTPUT_DIR)-x64
+endif
+
+ifeq ($(OS), Windows_NT)
 	ifeq ($(findstring Cygwin, $(SHELL)),)
 		MKDIR = if not exist $(subst /,\,$1) md $(subst /,\,$1)
 		RMDIR = if exist $(subst /,\,$1) rd /s /q $(subst /,\,$1)
 	else
 		MKDIR = mkdir -p $1
-		RMDIR += $(RM) -r $1
+		RMDIR = $(RM) -r $1
 	endif
 else
-	LIBEXT = .so
 	MKDIR = mkdir -p $1
-	RMDIR += $(RM) -r $1
+	RMDIR = $(RM) -r $1
 endif
 
-all: \
-	ensure-dirs \
-	$(TARGET)
+TARGET := $(OUTPUT_DIR)/$(TARGET)$(LIBEXT)
+OBJS := $(addprefix $(OUTPUT_DIR)/, $(OBJS))
+
+all: $(TARGET)
 
 $(TARGET): $(OBJS)
-	cd $(OUTPUT_DIR) && $(CC) $^ $(LINKFLAGS) -o $@$(LIBEXT)
-
-ensure-dirs:
+	$(CC) $^ $(LINKFLAGS) $(OUTPUT_OPTION)
+
+$(OUTPUT_DIR)/%.o: %.c
+	$(COMPILE.c) $< $(OUTPUT_OPTION)
+
+$(OUTPUT_DIR)/%.o: %.cpp
+	$(COMPILE.cpp) $< $(OUTPUT_OPTION)
+
+$(OUTPUT_DIR)/%.o: %.rc
+	windres $< $(OUTPUT_OPTION)
+
+$(OBJS): | $(OUTPUT_DIR)
+
+$(OUTPUT_DIR):
 	$(call MKDIR,$(OUTPUT_DIR)/pluginsdk)
 	$(call MKDIR,$(OUTPUT_DIR)/src)
 
-src/resource.o:
-	windres ../../src/resource.rc $(OUTPUT_OPTION)
-
-clear:
+clean:
 	$(call RMDIR,$(OUTPUT_DIR))