gcopy ex
This commit is contained in:
parent
5f9b6fcda0
commit
7b1fcf28ae
|
@ -0,0 +1,106 @@
|
||||||
|
# Makefile generated by command: smake.sh -t gcopy -Pglib-2.0 -Pgobject-2.0
|
||||||
|
# This file is generated with smake.sh.
|
||||||
|
# You can use this make file with instruction make to
|
||||||
|
# use one of build mode: debug, profile, develop, release.
|
||||||
|
# No need to call make clean if You make with other mode,
|
||||||
|
# because the Makefile containes rules for automatically clean.
|
||||||
|
# Some usage examples:
|
||||||
|
# make # default mode is debug
|
||||||
|
# CFLAGS="-O2 -march=core2 -mtune=core2 -msse4.1 -mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1" make mode=develop
|
||||||
|
# CFLAGS="-O2 -march=amdfam10 -mtune=amdfam10 -msse4a --mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1" make mode=profile
|
||||||
|
# CFLAGS="-O2 -march=k6-2 -mtune=k6-2 -m3dnow --mfpmath=387 -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1" make mode=release
|
||||||
|
# Report bugs to <mecareful@gmail.com>
|
||||||
|
|
||||||
|
#_________________________________
|
||||||
|
# ENVIRONMENT |
|
||||||
|
#________________________________|
|
||||||
|
TARGET0=gcopy
|
||||||
|
TARGETS= $(TARGET0)
|
||||||
|
CC=cc
|
||||||
|
CXX=c++
|
||||||
|
CFLAGS := $(CFLAGS)
|
||||||
|
CXXFLAGS := $(CXXFLAGS)
|
||||||
|
LDFLAGS := $(LDFLAGS)
|
||||||
|
LIBS=-lglib-2.0 -lgobject-2.0
|
||||||
|
SRC=
|
||||||
|
INCLUDES=-I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
|
||||||
|
#________________________________________
|
||||||
|
# BUILD SCRIPT (don't change) |
|
||||||
|
#_______________________________________|
|
||||||
|
ifeq ($(mode),)
|
||||||
|
mode = debug
|
||||||
|
endif
|
||||||
|
ifeq ($(mode),debug)
|
||||||
|
CFLAGS := -O0 -g -DDEBUG -std=c99 -pedantic -Wextra -Wconversion $(CFLAGS)
|
||||||
|
LDFLAGS := $(LDFLAGS)
|
||||||
|
endif
|
||||||
|
ifeq ($(mode),profile)
|
||||||
|
CFLAGS := -O0 -g -DDEBUG -std=c99 -p -ftest-coverage -Wcoverage-mismatch $(CFLAGS)
|
||||||
|
LDFLAGS := -g -p $(LDFLAGS)
|
||||||
|
endif
|
||||||
|
ifeq ($(mode),develop)
|
||||||
|
CFLAGS := -O2 -g -DDEBUG -std=c99 $(CFLAGS)
|
||||||
|
LDFLAGS := -O1 $(LDFLAGS)
|
||||||
|
endif
|
||||||
|
ifeq ($(mode),release)
|
||||||
|
CFLAGS := -O2 -std=c99 $(CFLAGS)
|
||||||
|
LDFLAGS := -O1 $(LDFLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS += -Wall $(INCLUDES)
|
||||||
|
LDFLAGS += -Wall
|
||||||
|
|
||||||
|
all:
|
||||||
|
@make change_make_options &>/dev/null
|
||||||
|
+make $(TARGETS)
|
||||||
|
|
||||||
|
ifneq ($(mode),debug)
|
||||||
|
ifneq ($(mode),profile)
|
||||||
|
ifneq ($(mode),develop)
|
||||||
|
ifneq ($(mode),release)
|
||||||
|
@echo "Invalid build mode."
|
||||||
|
@echo "Please use 'make mode=release', 'make mode=develop', 'make mode=profile' or 'make mode=debug'"
|
||||||
|
@exit 1
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
@echo ".........................."
|
||||||
|
@echo "Building on "$(mode)" mode "
|
||||||
|
@echo "CFLAGS=$(CFLAGS)"
|
||||||
|
@echo "LDFLAGS=$(LDFLAGS)"
|
||||||
|
@echo ".........................."
|
||||||
|
|
||||||
|
OLD_BUILD_MODE=$(shell grep ^MODE make_options.out 2>/dev/null | sed 's~^MODE=~~')
|
||||||
|
OLD_BUILD_CFLAGS=$(shell grep ^CFLAGS make_options.out 2>/dev/null | sed 's~^CFLAGS=~~')
|
||||||
|
OLD_BUILD_LDFLAGS=$(shell grep ^LDFLAGS make_options.out 2>/dev/null | sed 's~^LDFLAGS=~~')
|
||||||
|
change_make_options:
|
||||||
|
ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS))
|
||||||
|
@echo CLEANING...
|
||||||
|
@make clean
|
||||||
|
@echo "MODE=$(mode)" > make_options.out
|
||||||
|
@echo "CFLAGS=$(CFLAGS)" >> make_options.out
|
||||||
|
@echo "LDFLAGS=$(LDFLAGS)" >> make_options.out
|
||||||
|
endif
|
||||||
|
|
||||||
|
%.o :
|
||||||
|
$(CC) -c $(CFLAGS) $(SRC) -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.out callgrind.out.* *.gcno $(TARGETS)
|
||||||
|
|
||||||
|
.PHONY: all change_make_options clean
|
||||||
|
|
||||||
|
#_________________________________
|
||||||
|
# R U L E S |
|
||||||
|
#________________________________|
|
||||||
|
target_objs0 = \
|
||||||
|
gcopy.o
|
||||||
|
|
||||||
|
$(TARGET0): $(target_objs0)
|
||||||
|
$(CC) $(LDFLAGS) -o $@ $(target_objs0) $(LIBS)
|
||||||
|
|
||||||
|
|
||||||
|
gcopy.o: \
|
||||||
|
gcopy.c
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
#include <glib.h>
|
||||||
|
#include <glib-object.h>
|
||||||
|
|
||||||
|
static void test_int (void)
|
||||||
|
{
|
||||||
|
GValue a_value = {0, };
|
||||||
|
GValue b_value = {0, };
|
||||||
|
guint64 a, b;
|
||||||
|
|
||||||
|
a = 0xdeadbeaf;
|
||||||
|
|
||||||
|
g_value_init (&a_value, G_TYPE_UINT64);
|
||||||
|
g_value_set_uint64 (&a_value, a);
|
||||||
|
|
||||||
|
g_value_init (&b_value, G_TYPE_UINT64);
|
||||||
|
g_value_copy (&a_value, &b_value);
|
||||||
|
|
||||||
|
b = g_value_get_uint64 (&b_value);
|
||||||
|
|
||||||
|
if (a == b) {
|
||||||
|
g_print ("Yay !! 10 lines of code to copy around a uint64.\n");
|
||||||
|
} else {
|
||||||
|
g_print ("Are you sure this is not a Z80 ?\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_object (void)
|
||||||
|
{
|
||||||
|
GObject *obj;
|
||||||
|
GValue obj_vala = {0, };
|
||||||
|
GValue obj_valb = {0, };
|
||||||
|
obj = g_object_new (MAMAN_BAR_TYPE, NULL);
|
||||||
|
|
||||||
|
g_value_init (&obj_vala, MAMAN_BAR_TYPE);
|
||||||
|
g_value_set_object (&obj_vala, obj);
|
||||||
|
|
||||||
|
g_value_init (&obj_valb, G_TYPE_OBJECT);
|
||||||
|
|
||||||
|
/* g_value_copy's semantics for G_TYPE_OBJECT types is to copy the reference.
|
||||||
|
This function thus calls g_object_ref.
|
||||||
|
It is interesting to note that the assignment works here because
|
||||||
|
MAMAN_BAR_TYPE is a G_TYPE_OBJECT.
|
||||||
|
*/
|
||||||
|
g_value_copy (&obj_vala, &obj_valb);
|
||||||
|
|
||||||
|
g_object_unref (G_OBJECT (obj));
|
||||||
|
g_object_unref (G_OBJECT (obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
test_int ();
|
||||||
|
|
||||||
|
test_object ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue