Page 1 of 1

My Makefile for win32-gcc for a static lib creates a dll

Posted: Tue Apr 15, 2008 11:26 am
by MasterGod
Hi.
My engine is a static lib and my Makefile for win32-gcc creates a dll (that works!). Even though it works I don't want that dll so how can I make it only a static lib?

Makefile:

Code: Select all

VERSION = 0.1

# make
# This will compile NGE, create a static lib (libNGE.a), and copy it into the subdirectory lib/Linux. That's all.

# If you want NGE to be compiled as shared lib (libNGE.so.versionnumber), then run:
# make sharedlib
# make install

#List of object files
NGEOBJ = CConfigManager.o CursorController.o FontController.o Game.o GameEntity.o GameManager.o GameState.o GridSceneNode.o CIniFileReaderIrr.o CIniFileReaderStub.o CIrrKlangDevice.o CIrrKlangPlayedSound.o CIrrKlangSoundObj.o NGEReceiver.o NUSoftwareIntroSceneNode.o StateCredits.o StateIntro.o StateMenu.o StatePlay.o StateSettings.o IAudioDevice.o IConfigManager.o IIniFileReader.o nge.o NUS.o CLevelManager.o CEmptyLevelNode.o CRegionLevelNode.o CWorldLevelNode.o CZoneGroupLevelNode.o CZoneLevelNode.o Level.o NUSoftwareIntroLevel.o CNullAudioDevice.o CNullPlayedSound.o CNullSoundObj.o ISoundEmitterSceneNode.o ISoundListenerSceneNode.o CSceneNodeControllerAnimator.o IActor.o INPC.o IPlayer.o PlayerSpaceship.o IItemEntity.o

# Next variable is for additional scene nodes etc. of customized NGE versions
EXTRAOBJ =

LINKOBJ := $(NGEOBJ) $(EXTRAOBJ)

###############
#Compiler flags
CXXINCS = -I../include -IIrrlicht -IirrKlang
CPPFLAGS = $(CXXINCS) -DIRRLICHT_EXPORTS=1
CXXFLAGS = -Wall
ifndef NDEBUG
CXXFLAGS += -g -D_DEBUG
else
CXXFLAGS += -fexpensive-optimizations -O3
endif
ifdef PROFILE
CXXFLAGS += -pg
endif
CFLAGS := -fexpensive-optimizations -O3 -DPNG_NO_MMX_CODE -DPNG_NO_MNG_FEATURES

#Linux specific options
STATIC_LIB = libNGE.a
SHARED_LIB = libNGE.so

NGE_DLL := ../bin/Win32-gcc/NGE.dll
LIB_PATH = ../lib/$(SYSTEM)
INSTALL_DIR = /usr/local/lib
staticlib sharedlib install: SYSTEM = Linux
staticlib sharedlib : LDFLAGS = --no-export-all-symbols --add-stdcall-alias
sharedlib : LDFLAGS += -L/usr/X11R6/lib -lGL -lXxf86vm -L../lib/Linux ../lib/Linux/libIrrKlang.so
staticlib sharedlib : CXXINCS += -I/usr/X11R6/include

#Windows specific options
sharedlib_win32 staticlib_win32: SYSTEM = Win32-gcc
sharedlib_win32: LDFLAGS = -lgdi32 -L../lib/Win32-gcc -lirrlicht -lirrKlang
sharedlib_win32 staticlib_win32: CPPFLAGS += -DIRR_COMPILE_WITH_DX9_DEV_PACK -D__GNUWIN32__ -D_WIN32 -DWIN32 -D_WINDOWS -D_MBCS -D_USRDLL
staticlib_win32: CPPFLAGS += -D_IRR_STATIC_LIB_

####################
# All target, builds NGE as static lib (libNGE.a) and copies it into /lib/Linux
all linux: staticlib

# Builds NGE as shared lib (libNGE.so.versionNumber) and copies it into /lib/Linux
sharedlib: $(LINKOBJ)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -shared -Wl,-soname,$(SHARED_LIB).1 -fPIC -o $(SHARED_LIB).$(VERSION) $^ $(LDFLAGS)
	cp $(SHARED_LIB).$(VERSION) $(LIB_PATH)

# Builds NGE as static lib (libNGE.a)
$(STATIC_LIB): $(LINKOBJ)
	$(AR) rs $@ $^

# Copies static lib into /lib/Linux
staticlib: $(STATIC_LIB)
	cp $^ $(LIB_PATH)

# Builds NGE as dll (NGE.dll) into ../bin/Win32-gcc
all_win32 win32: sharedlib_win32
sharedlib_win32: $(NGE_DLL)
../bin/Win32-gcc/NGE.dll: $(LINKOBJ)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -shared -o $@ $^ $(LDFLAGS) -Wl,--out-implib,../lib/Win32-gcc/$(STATIC_LIB)
# Copies static lib into /lib/Win32-gcc
staticlib_win32: $(STATIC_LIB)
	cp $^ $(LIB_PATH)

# Installs NGE if it was created as shared lib
install:
	cp $(LIB_PATH)/$(SHARED_LIB).$(VERSION) $(INSTALL_DIR)
	cd $(INSTALL_DIR) && ln -s libNGE.so.$(VERSION) $(SHARED_LIB)
	ldconfig -n $(INSTALL_DIR)

# Create dependency files for automatic recompilation
%.d:%.cpp
	$(CXX) $(CPPFLAGS) -MM -MF $@ $<

-include $(LINKOBJ:.o=.d)

help:
	@echo "Available targets for NGE"
	@echo " sharedlib: Build shared library NGE.so for Linux"
	@echo " staticlib: Build static library NGE.a for Linux"
	@echo " install: Copy shared library to /usr/lib"
	@echo ""
	@echo " sharedlib_win32: Build shared library NGE.dll for Windows"
	@echo " staticlib_win32: Build static library NGE.a for Windows"
	@echo ""
	@echo " clean: Clean up directory"

# Cleans all temporary files and compilation results.
clean:
	$(RM) $(LINKOBJ) $(SHARED_LIB).$(VERSION) $(STATIC_LIB) $(LINKOBJ:.o=.d)

.PHONY: all sharedlib staticlib sharedlib_win32 staticlib_win32 help install clean
Thanks.

P.S
randomMesh created that Makefile.

Posted: Thu Apr 17, 2008 7:06 am
by rooly
there's never any command to create a static lib file.

where it says NGE_DLL:= ...
add an extra variable that += on the dll path, the file extension
so instead of

Code: Select all

NGE_DLL := ../bin/Win32-gcc/NGE.dll
use

Code: Select all

NGE_DLL := ../bin/Win32-gcc/NGE.
NGE_DLL_EXT = .dll
NGE_STA_EXT = "whatever"
and add this variable to the back of the correct compile spots
i guess...i'm not to familiar with windows makefile build systems

Posted: Thu Apr 17, 2008 7:51 pm
by hybrid
Well, since the makefile is just a rewrite of Irrlicht's, the usual 'make staticlib' should work.

Posted: Tue Apr 22, 2008 8:50 am
by MasterGod
hybrid wrote:Well, since the makefile is just a rewrite of Irrlicht's, the usual 'make staticlib' should work.
I tried: mingw32-make NDEBUG=1 all_win32 staticlib
and I get:

Code: Select all

ar: creating libNGE.a
cp libNGE.a ../lib/Linux
process_begin: CreateProcess(NULL, cp libNGE.a ../lib/Linux, ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make: *** [staticlib] Error 2

C:\nge\source>
And I still get a dll AND a libNGE.a file.

@rooly: "and add this variable to the back of the correct compile spots" - and where is that exactly :wink: :?:
And you mean this variable yes? NGE_STA_EXT.
And what about the `= "whatever" `?

Posted: Tue Apr 22, 2008 12:22 pm
by hybrid
Oh, I guess you should use staticlib_win32. Also use it as the only target after a clean. Also, your makefile environment should provide a cp command, as it is required for make.

Posted: Tue Jun 30, 2009 8:35 am
by xDan
Just to note, to get rid of the "cannot find the file specified", save this

Code: Select all

set cppatha1=%1
set cppathb1=%2

set cppatha2=%cppatha1:/=\%
set cppathb2=%cppathb1:/=\%

copy %cppatha2% %cppathb2%
as a bat file called "cp.bat" in the windows directory, to provide an equivalent to the unix cp command.

Posted: Fri Jul 03, 2009 12:53 pm
by MasterGod
Thanks but I did this:

clean_tmp_files.bat

Code: Select all

del *.a /Q
del *.o /Q
del *.d /Q
del *.user /Q
del *.ncb /Q
del *.suo /Q
mingw32_build_debug.bat

Code: Select all

mingw32-make all_win32
del ..\bin\Win32-gcc\NGE.dll /Q
clean_tmp_files
mingw32_build_release.bat

Code: Select all

mingw32-make NDEBUG=1 all_win32
del ..\bin\Win32-gcc\NGE.dll /Q
clean_tmp_files
And I also realize why everything happens.
when I do all_win32 it makes the staticlib config as well as dynamic lib config. Now what hybrid suggested is to compile using only the static lib config (which is right). I just don't really care about it anymore and because maybe in the future I would make it also as a DLL I don't care letting it says this way.

But thanks anyways!

Posted: Fri Jul 03, 2009 2:34 pm
by xDan
well, it was more for the benefit of anyone else who stumbled across this problem. I guessed you would have solved it by now ;)

Posted: Sat Jul 04, 2009 10:25 am
by MasterGod
Cool, Thanks anyways!