#AFKMud dynamically loaded commands.
#This makefile can be invoked directly, or via the makefile in the src directory.
#
#Takes any existing C files in this directory and makes dynamically loadable .so files out of them.
C_FILES := $(wildcard *.c)
SO_FILES := $(patsubst %.c,so/%.so,$(C_FILES))
all: $(SO_FILES)
@echo "Done building modular commands.";
clean:
@rm -f so/*.so
$(MAKE) all
purge:
@rm -f so/*.so
so/%.so: %.c
@echo " Compiling $@….";
g++ -c -g2 -shared $< -o $@
#AFKMud dynamically loaded commands.
#This makefile can be invoked directly, or via the makefile in the src directory.
#
#Takes any existing cpp files in this directory and makes dynamically loadable .so files out of them.
#Type of machine to compile for. Athlon works just as well on Duron too.
#The march option needs to match the general family of CPU.
#If you don't know what to set for these options, and your system administrator doesn't either, comment this line out
MACHINE = -march=athlon-xp
# Uncomment the two lines below if compiling on a Solaris box
#SOLARIS_FLAG = -Dsun -DSYSV -Wno-char-subscripts
#SOLARIS_LINK = -lnsl -lsocket -lresolv
#IMC2 - Comment out to disable IMC2 support
IMC = 1
#Internal Web Server - comment out to disable web server code.
WEB = 1
#Multiport support. Comment out to disable this feature.
MULTIPORT = 1
#Miscellaneous compiler options.
OPT_FLAG = -fpic -pipe -Os
DEBUG_FLAG = -g2
#PROF_FLAG = -pg
W_FLAGS = -Wall -Wextra -Wformat=2 -Wshadow -Wpointer-arith -Wcast-align -Wcast-qual -Wredundant-decls -Wconversion
C_FLAGS = $(MACHINE) $(W_FLAGS) $(DEBUG_FLAG) $(OPT_FLAG) $(PROF_FLAG) $(SOLARIS_FLAG)
C_FILES := $(wildcard *.cpp)
O_FILES := $(patsubst %.cpp,o/%.o,$(C_FILES))
SO_FILES := $(patsubst o/%.o,so/%.so,$(O_FILES))
ifdef WEB
C_FLAGS := $(C_FLAGS) -DWEBSVR
endif
ifdef IMC
C_FLAGS := $(C_FLAGS) -DIMC
endif
ifdef MULTIPORT
C_FLAGS := $(C_FLAGS) -DMULTIPORT
endif
all:
$(MAKE) -s obj
$(MAKE) sobj
@echo "Done building modular commands.";
obj: $(O_FILES)
sobj: $(SO_FILES)
clean:
@rm -f o/*.o so/*.so
$(MAKE) all
purge:
@rm -f o/*.o so/*.so
o/%.o: %.cpp
@echo " Compiling $@….";
g++ -c $(C_FLAGS) $< -o $@
so/%.so: %.o
@echo " Linking $@….";
g++ -shared $< -o $@
C_FLAGS = -Wall -g $(DBFLAG) $(PROF)
L_FLAGS = -lz -lpthread -lcrypt -ldl -rdynamic -L/usr/include/mysql -lmysqlclient $(PROF)
SO_I = -g -c -fpic $(DBFLAG) $(PROF)
SO_O = -shared -lm $(PROF) -o
$(CC) $(SO_I) sociallib.c
$(CC) $(SO_O) sociallib.so sociallib.o
$(CC) $(SO_I) helplib.c
$(CC) $(SO_O) helplib.so helplib.o
if( (helplib = dlopen(HELP_LIB, RTLD_LAZY | RTLD_GLOBAL)) == NULL)
{
sprintf(log_buf,"%s",dlerror());
log_string(log_buf);
log_buf[0] = '\0';
}
else
lib_count++;
dlclose(helplib);
helplib = dlopen(HELP_LIB,RTLD_LAZY | RTLD_GLOBAL);
void func(args)
{
void (*handle)()
if( (handle = dlsym(yourlib,"your_func")) == NULL )
regular_func();
else
(*handle)(ch);
}
The Makefile for my codebase in general, right at the moment, is:
Yes, it looks weird and yes it can probably be done better. But. It works. The important part to note is the "command modules" part, which calls a nested Makefile down in the src/cmd directory:
This one isn't my own doing. Chris gave me this Makefile long ago and I just never got around to using it for anything until tonite. It appears to try working, but dies like so:
Building AFKMud….
make -s afkmud
Buidling DNS Resolver…
make -s resolver
Building command modules…
make -C cmd
make[1]: Entering directory `/home/samson/Alsherok/src/cmd'
g++ -g3 -shared -Wl,-soname,o/do_test. -o ./so/do_test.so o/do_test.o
cc do_test.c do_test.so -o do_test
cc: do_test.so: No such file or directory
In file included from do_test.c:1:
../mud.h:32:18: error: vector: No such file or directory
../mud.h:33:16: error: list: No such file or directory
../mud.h:34:15: error: map: No such file or directory
../mud.h:35:18: error: bitset: No such file or directory
In file included from do_test.c:1:
../mud.h:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
../mud.h:62: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'descriptor_data'
../mud.h:63: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'area_data'
../mud.h:64: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'mob_index'
../mud.h:65: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'obj_index'
../mud.h:66: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'room_index'
../mud.h:67: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'char_data'
../mud.h:68: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'pc_data'
../mud.h:69: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'obj_data'
It goes on for another 2 screens full of stupidness like that. Here's the do_test source file:
Short, sweet, to the point. The include as listed there apparently works but I can't figure out why it's then telling me that the stuff in the mud.h file can't be located. This is what's at the top portion of mud.h, which compiles just fine for the regular code:
Currently all of my do_fun code works fine except for do_test which is what I was experminenting with before doing major damage… er… work on the codebase. Anyone have any thoughts as to where I botched this up?
btw, I posted this here because although my specific problem is with AFKMud, this is a more general thing that others who want to do this might run into.