Thread: I can't spot my mistake...

  1. #61
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    Quote Originally Posted by hamster_nz View Post
    Can't see it compiling any of the -c- source with "-pg" in that output.
    That was because I had done a rebuildall prior to that however looking at another rebuild I noticed that I failed to actually add the variable holding the flags, having done that the output now looks like this:
    Code:
    make profile run
    MAKECMDGOALS=profile run
    make -j 1 --no-print-directory -f main.mak profile run
    PRJ_SRC_FILES = 'test.c alu_bit.c alu_int.c alu_main.c alu_math.c alu_mem.c alu_uint.c alu_vec.c'
    Checking 3rd Party libraries are upto date
    cd 'cloned/fbstdc' && git config pull.rebase true && git pull
    Already up to date.
    Finished checking
    PRJ_DST_BIN=alu_p.AppImage
    PRJ_DST_LIB=libalu_p.so
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o test_p.o -c test.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_bit_p.o -c alu_bit.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_int_p.o -c alu_int.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_main_p.o -c alu_main.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_math_p.o -c alu_math.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_mem_p.o -c alu_mem.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_uint_p.o -c alu_uint.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_vec_p.o -c alu_vec.c
    cc -D NDEBUG -pg -fPIC -shared  -o libalu_p.so alu_bit_p.o alu_int_p.o alu_main_p.o alu_math_p.o alu_mem_p.o alu_uint_p.o alu_vec_p.o -Wl,-rpath=./
    cc -D NDEBUG -pg -fPIE -L .  -o alu_p.AppImage test_p.o -Wl,-rpath=./ -l alu_p
    gprof ./alu_p.AppImage
    gmon.out: No such file or directory
    make[1]: *** [main.mak:83: run] Error 1
    make: *** [1st.mak:6: profile] Error 2
    Compilation failed.

  2. #62
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    Quote Originally Posted by awsdert View Post
    Thanks While I'm implementing that into my makefile targets/goals do you mind having a look at this function, I seem to have made a mistake while trying to implement faster code for it:
    Code:
    int_t alu_reg_not( alu_t *alu, alu_reg_t num )
    {
    	alu_bit_t n, e;
    	void *part;
    	size_t i, stop, mask, mask_init, mask_last;
    	
    	if ( alu )
    	{
    		num.node %= alu_used( alu );
    		part = alu_reg_data( alu, num );
    		
    		n = alu_bit_set_bit( part, num.from );
    		e = alu_bit_set_bit( part, num.upto - 1 );
    		
    		mask = 0;
    		mask = mask_init = mask_last = ~mask;
    		
    		mask_init <<= n.pos;
    		mask_last >>= (bitsof(size_t) - e.pos);
    		
    		stop = e.seg - n.seg;
    		
    		*(n.ptr) ^= SET2IF( stop, mask_init, mask_init & mask_last );
    		
    		for ( i = 1; i < stop; ++i ) n.ptr[i] = ~(n.ptr[i]);
    		
    		*(e.ptr) ^= SET1IF( stop, mask_last );
    	
    		return 0;
    	}
    	
    	return alu_err_null_ptr( "alu" );
    }
    Example of output currently:
    Code:
    test.c:204: reg_modify() ~0x00000000DEADC0DE, Expected 0xFFFFFFFF21523F21, Got 0x7FFFFFFF21523F21, op = '~'
    Seem to have temporarily fixed it by changing
    Code:
    mask_last <<= (bitsof(size_t) - e.pos);
    to
    Code:
    mask_last <<= (bitsof(size_t) - e.pos) - 1;

  3. #63
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    Encountering some VERY strange behaviour, here's the relevant output:
    Code:
    ...
    test.c:393: bitwise() 'Shifting values...'
    test.c:394: bitwise() '==========================================='
    test.c:99: modify() num.node = 8, val.node = 9, _num = 0x00000000DEADC0DE, _val = 0x0000000000000004
    num = 0000000000000000000000000000000000000000000000000000000000000100
    val = 0000000000000000000000000000000000000000000000000000000000000100
    test.c:212: modify() 0x00000000DEADC0DE >> 0x0000000000000004, Expected 0x000000000DEADC0D, Got 0x0000000000000000, op = '>'
    test.c:410: bitwise() 'Rotating values...'
    test.c:411: bitwise() '==========================================='
    test.c:212: modify() 0x00000000DEADC0DE <<< 0x0000000000000004, Expected 0x0000000DEADC0DE0, Got 0x00000000DEADC0DE, op = 'l'
    ...
    And here's the relevant code:
    Code:
    int modify(
    	alu_t *alu
    	, ssize_t _num
    	, ssize_t _val
    	, uint_t info
    	, bool print_anyways
    	, int op
    )
    {
    	int ret = 0;
    	uint_t nodes[2] = {0};
    	alu_reg_t num = {0}, val = {0};
    	ssize_t expect = 0;
    	char pfx[sizeof(size_t) * CHAR_BIT] = {0};
    	
    	ret = alu_get_reg_nodes( alu, nodes, 2, 0 );
    	
    	if ( ret != 0 )
    	{
    		alu_error( ret );
    		return ret;
    	}
    	
    	alu_reg_init( alu, num, nodes[0], info );
    	alu_reg_init( alu, val, nodes[1], info );
    	
    	num.upto = val.upto = bitsof(size_t);
    	
    	alu_reg_set_nil( alu, num );
    	alu_reg_set_nil( alu, val );
    	
    	alu_reg_set_raw( alu, num, &_num, info, sizeof(ssize_t) );
    	alu_reg_set_raw( alu, val, &_val, info, sizeof(ssize_t) );
    	
    #if 1
    	if ( op == '>' )
    	{
    		alu_printf
    		(
    			"num.node = %u, val.node = %u, _num = 0x%016zX, _val = 0x%016zX",
    			num.node, val.node, _num, _val
    		);
    		alu_print_reg( "num", alu, num, 0, 1 );
    		alu_print_reg( "val", alu, val, 0, 1 );
    	}
    #endif
    ...
    When I try moving
    Code:
    	alu_reg_set_raw( alu, num, &_num, info, sizeof(ssize_t) );
    to below
    Code:
    	alu_reg_set_raw( alu, val, &_val, info, sizeof(ssize_t) );
    Somehow val ends up holding 0xDEADC0DE (value of _num) while num remains fixed at 4 (value of _val), if I leave them as they are then both get 4, I don't understand how that is happening when I very clearly stated which I wanted to hold what, anyone have any ideas? Edit: Btw I've already tried rebuilding everything
    Last edited by awsdert; 09-18-2020 at 01:46 PM.

  4. #64
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    Tried making some functions I was inevitably gonna make anyways, swapped out the calls for them instead, still getting the same problem, here's the called code:
    Code:
    	alu_int_set_raw( alu, num.node, _num );
    	alu_int_set_raw( alu, val.node, _val );
    ...
    int_t alu_int_set_raw( alu_t *alu, alu_int_t num, intmax_t val )
    {
    	alu_reg_t NUM;
    	
    	alu_reg_init( alu, NUM, num, ALU_INFO__SIGN );
    	
    	return alu_reg_set_raw( alu, NUM, &val, sizeof(intmax_t), ALU_INFO__SIGN );
    }
    ...
    int_t alu_reg_set_raw
    (
    	alu_t *alu
    	, alu_reg_t num
    	, void *raw
    	, size_t size
    	, uint_t info
    )
    {
    	int ret;
    	void *part;
    	uint_t _tmp;
    	alu_reg_t tmp;
    	
    	size = HIGHEST( size, 1 );
    	ret = alu_get_reg_node( alu, &_tmp, size );
    	
    	if ( ret == 0 )
    	{
    		alu_reg_init( alu, tmp, _tmp, info );
    		
    		part = alu_reg_data( alu, tmp );
    		(void)memcpy( part, raw, size );
    		
    		ret = alu_reg_mov( alu, num, tmp );
    		
    		alu_rem_reg_node( alu, &_tmp );
    		return ret;
    	}
    	
    	alu_error( ret );
    	return ret;
    }
    ...
    int alu_reg_mov(
    	alu_t *alu,
    	alu_reg_t num,
    	alu_reg_t val
    )
    {
    	void *num_part, *val_part;
    	alu_bit_t n = {0}, v, e;
    	
    	if ( alu )
    	{
    		num.node %= alu_used( alu );
    		val.node %= alu_used( alu );
    	
    		num_part = alu_reg_data( alu, num );
    		val_part = alu_reg_data( alu, val );
    		
    		n = alu_bit_set_bit( num_part, num.from );
    		v = alu_bit_set_bit( val_part, val.from );
    				
    		e = alu_bit_set_bit(
    			num_part
    			, (num.upto * (num.upto <= val.upto))
    			| (val.upto * (val.upto <= num.upto))
    		);
    		
    		for ( ; n.bit < e.bit; n = alu_bit_inc(n), v = alu_bit_inc(v) )
    		{
    			*(n.ptr) &= ~(n.mask);
    			*(n.ptr) |= n.mask * !!(*(v.ptr) & v.mask);
    		}
    		
    		for ( ; n.bit < num.upto; n = alu_bit_inc(n) )
    		{
    			*(n.ptr) &= ~(n.mask);
    		}
    		
    		return 0;
    	}
    	
    	return alu_err_null_ptr( "alu" );
    }
    ...
    #define alu_reg_init( alu, alu_reg, reg, inf ) \
    	do \
    	{ \
    		(alu_reg).node = reg; \
    		(alu_reg).info = inf; \
    		(alu_reg).mant = 0; \
    		(alu_reg).from = 0; \
    		(alu_reg).upto = alu_size_perN( alu ) * CHAR_BIT; \
    	} \
    	while (0)
    Anyone have any ideas? Edit: Just noticed I pasted a duplicate thinking I had copied the next function, rectified now
    Last edited by awsdert; 09-19-2020 at 03:20 AM.

  5. #65
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    Managed to narrow the source of the problem to here:
    Code:
    int_t alu_reg_set_raw
    (
    	alu_t *alu
    	, alu_reg_t num
    	, void *raw
    	, size_t size
    	, uint_t info
    )
    {
    	int ret;
    	void *part;
    	uint_t _tmp;
    	alu_reg_t tmp;
    	
    	size = HIGHEST( size, 1 );
    	
    	ret = alu_get_reg_node( alu, &_tmp, size );
    	
    	if ( ret == 0 )
    	{
    		alu_reg_init( alu, tmp, _tmp, info );
    		
    		part = alu_reg_data( alu, tmp );
    		(void)memmove( part, raw, size );
    		
    		alu_print_reg( "tmp", alu, tmp, 0, 1 ); // Does not display the expected result here
    		
    		//tmp.upto = size * CHAR_BIT;
    		
    		ret = alu_reg_mov( alu, num, tmp );
    		
    		alu_rem_reg_node( alu, &_tmp );
    		return ret;
    	}
    	
    	alu_error( ret );
    	return ret;
    }
    It seems the value is not being copied into tmp as it should be, any ideas? Edit: I've checked the value of raw and it definitely holds the expected value, it's just somehow being ignored when passed to tmp (even attempted a manual loop)
    Last edited by awsdert; 09-19-2020 at 06:30 AM.

  6. #66
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    I figured it out, wasn't that the data wasn't getting across, it was that a change I made to alu_bit_inc()/alu_bit_dec() to remove the branch from it also happened to need the setting of the mask to be moved to the bottom, I didn't notice and so it seeped into all math and comparisons

  7. #67
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,091
    As I've mentioned before: if you create a suite of unit tests and integration tests and run them frequently after making changes, you would detect such bugs sooner rather than later because your tests would fail, and you would have a pretty good idea as to the culprit: you could cross reference what you just changed and exactly which tests failed.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #68
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    Quote Originally Posted by laserlight View Post
    As I've mentioned before: if you create a suite of unit tests and integration tests and run them frequently after making changes, you would detect such bugs sooner rather than later because your tests would fail, and you would have a pretty good idea as to the culprit: you could cross reference what you just changed and exactly which tests failed.
    I'll take a quick break then I think I might look into doing that tonight, in the mean time I've added in support for FPN copying to alu_reg_mov(), can I ask you and anyone else interested to take a look at it and point out any problems or make suggestions on how to implement the last part (transferring to/from integers)
    Code:
    int alu_reg_mov(
    	alu_t *alu,
    	alu_reg_t num,
    	alu_reg_t val
    )
    {
    	int ret;
    	void *N, *V;
    	alu_bit_t n = {0}, v, e;
    	size_t ndiff, vdiff;
    	bool neg, NaN = false;
    	alu_reg_t NEXP, NMAN, VEXP, VMAN;
    	
    	ret = alu_reg_clr( alu, num );
    	
    	if ( ret == 0 )
    	{
    		num.node %= alu_used( alu );
    		val.node %= alu_used( alu );
    		
    		N = alu_reg_data( alu, num );
    		V = alu_reg_data( alu, num );
    		
    		if ( alu_reg_floating( val ) )
    		{
    			alu_reg_init( alu, VEXP, val.node, 0 );
    			alu_reg_init( alu, VMAN, val.node, 0 );
    			
    			VEXP.upto = val.upto - 1;
    			VEXP.from = val.from + val.mant;
    			VMAN.upto = val.from + val.mant;
    			VMAN.from = val.from;
    			
    			/* Check for +/- */
    			v = alu_reg_end_bit( alu, VEXP );
    			neg = SET1IF( *(v.ptr) & v.mask, 1 );
    			
    			/* Check for NaN */
    			NEXP.upto = VEXP.upto;
    			NEXP.from = VEXP.from;
    			alu_reg_set_max( alu, NEXP );
    			ret = alu_reg_cmp( alu, VEXP, NEXP );
    			alu_reg_clr( alu, NEXP );
    			
    			if ( ret == 0 )
    			{
    				v = alu_reg_end_bit( alu, VMAN );
    				/* When exponent is max value all 0s indicates +/-infinity,
    				 * anything else indicates NaN */
    				NaN = !!(*(v.ptr) & v.mask);
    			}
    			
    			if ( alu_reg_floating( num ) )
    			{
    				alu_reg_init( alu, NEXP, num.node, 0 );
    				
    				NEXP.upto = num.upto - 1;
    				NEXP.from = num.from + num.mant;
    				NMAN.upto = num.upto - 1;
    				NMAN.from = num.from + num.mant;
    				alu_reg_set_max( alu, NEXP );
    				
    				ret = alu_reg_cmp( alu, VEXP, NEXP );
    				
    				if ( ret >= 0 )
    				{
    					/* Set the sign then Infinity/NaN */
    					n = alu_bit_set_bit( N, NEXP.upto );
    					
    					*(n.ptr) |= SET1IF( neg, n.mask );
    					
    					return alu_reg_set( alu, NMAN, NaN );
    				}
    				
    				/* Simplify code and pass on duties to another instance */
    				alu_reg_mov( alu, NEXP, VEXP );
    				
    				ndiff = NMAN.upto - NMAN.from;
    				vdiff = VMAN.upto - VMAN.from;
    				
    				NMAN.from = NMAN.upto - LOWEST( ndiff, vdiff );
    				
    				return alu_reg_mov( alu, NMAN, VMAN );
    			}
    			// FIXME: Finish implementing moving alu_fpn_t to alu_int_t/alu_uint_t
    			//if ( alu_reg_cmp( alu, EXP, BIAS ) >= 0 )
    			return ENOSYS;
    		}
    		
    		neg = alu_reg_below0( alu, val );
    		ndiff = num.upto - num.from;
    		vdiff = val.upto - val.from;
    		
    		n = alu_bit_set_bit( N, num.from );
    		v = alu_bit_set_bit( V, val.from );
    		e = alu_bit_set_bit( N, num.from + LOWEST( ndiff, vdiff ) );
    		
    		for ( ; n.bit < e.bit; n = alu_bit_inc(n), v = alu_bit_inc(v) )
    		{
    			*(n.ptr) |= SET1IF( *(v.ptr) & v.mask, n.mask );
    		}
    		
    		for ( ; n.bit < num.upto; n = alu_bit_inc(n) )
    		{
    			*(n.ptr) |= SET1IF( neg, n.mask );
    		}
    		
    		return 0;
    	}
    	
    	alu_error( ret );
    	return ret;
    }

  9. #69
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    Quote Originally Posted by laserlight View Post
    As I've mentioned before: if you create a suite of unit tests and integration tests and run them frequently after making changes, you would detect such bugs sooner rather than later because your tests would fail, and you would have a pretty good idea as to the culprit: you could cross reference what you just changed and exactly which tests failed.
    Encountered an issue when trying to align ALU with the directory setup the check tutorial is centered around, I made all the changes I can think to the makefiles but make still has a problem finding the needed files & targets, mind taking a look for me?
    Code:
    TOP_DIR:=../
    include $(TOP_DIR)mak/func.mak
    include $(TOP_DIR)mak/dst_sys.mak
    include $(TOP_DIR)mak/dst_cc.mak
    
    PRJ:=ALU
    PRJ_SFX:=$(DBG_SFX)$(PFL_SFX)
    ALL_GOALS:=info objects build run debug gede clean rebuild rebuildall profile
    
    PRJ_CHK_DIR:=$(TOP_DIR)tests
    PRJ_SRC_DIR:=$(TOP_DIR)src
    PRJ_INC_DIR:=$(TOP_DIR)include
    PRJ_LIB_DIR:=$(TOP_DIR)lib
    PRJ_BIN_DIR:=$(TOP_DIR)bin
    PRJ_EXT_DIR:=$(TOP_DIR)cloned
    
    UNIC_DIR:=$(PRJ_EXT_DIR)/unic
    UNIC_INC_DIR:=$(UNIC_DIR)/include
    
    RPATH_FLAG=-Wl,-rpath=$(PRJ_LIB_DIR)
    
    PRJ_CHK_FILES:=$(wildcard $(PRJ_CHK_DIR)*.c)
    PRJ_SRC_FILES:=$(PRJ_CHK_FILES) $(wildcard $(PRJ_SRC_DIR)*.c)
    PRJ_INC_FILES:=$(wildcard $(PRJ_INC_DIR)*.h)
    PRJ_OBJ_FILES:=$(PRJ_SRC_FILES:%.c=%)
    
    PRJ_CHK_OBJ_FILES:=$(PRJ_CHK_DIR)check_alu
    PRJ_BIN_OBJ_FILES:=$(PRJ_CHK_DIR)test
    PRJ_APP_OBJ_FILES:=$(PRJ_CHK_OBJ_FILES) $(PRJ_BIN_OBJ_FILES)
    PRJ_LIB_OBJ_FILES:=$(filter-out $(PRJ_APP_OBJ_FILES),$(PRJ_OBJ_FILES))
    
    PRJ_DST_CHK:=$(PRJ_BIN_DIR)/check_alu$(PRJ_SFX)$(DST_BIN_SFX)
    PRJ_DST_BIN:=$(PRJ_BIN_DIR)/alu$(PRJ_SFX)$(DST_BIN_SFX)
    PRJ_DST_LIB:=$(PRJ_LIB_DIR)/$(DST_LIB_PFX)alu$(PRJ_SFX)$(DST_LIB_SFX)
    PRJ_DST_OBJ:=$(PRJ_OBJ_FILES:%=%$(PRJ_SFX)$(DST_OBJ_SFX))
    PRJ_TARGETS:=$(PRJ_DST_OBJ) $(PRJ_DST_LIB) $(PRJ_DST_BIN)
    
    ERR_FLAGS:=$(COP)Wall $(COP)Wextra $(F_pedantic)
    INC_FLAGS:=-I $(UNIC_INC_DIR) -I $(PRJ_INC_DIR)
    SRC_FLAGS:=$(DBG_FLAGS) $(PFL_FLAGS) -fPIC $(ERR_FLAGS) $(INC_FLAGS)
    LIB_FLAGS:=$(DBG_FLAGS) $(PFL_FLAGS) -fPIC -shared
    BIN_FLAGS:=$(DBG_FLAGS) $(PFL_FLAGS) -fPIE $(COP)L .
    
    COMPILE_EXE=$(CC) $(BIN_FLAGS) $1 $(COP)o $2 $3 $(RPATH_FLAG) $(COP)l alu$(PRJ_SFX)
    COMPILE_DLL=$(CC) $(LIB_FLAGS) $1 $(COP)o $2 $3 $(RPATH_FLAG)
    COMPILE_OBJ=$(CC) $(SRC_FLAGS) $1 $(COP)o $2 -c $3
    
    $(info PRJ_SRC_FILES = '$(PRJ_SRC_FILES)')
    
    $(call mkdir,$(PRJ_EXT_DIR))
    $(call github_clone,$(UNIC_DIR),$(PRJ_EXT_DIR),awsdert/unic)
    
    $(info Checking 3rd Party libraries are upto date)
    $(info $(call merge,$(UNIC_DIR)))
    $(info Finished checking)
    
    $(info PRJ_DST_BIN=$(PRJ_DST_BIN))
    $(info PRJ_DST_LIB=$(PRJ_DST_LIB))
    
    info: .FORCE
    	@echo CC=$(CC)
    	@echo CXX=$(CXX)
    	@echo COP=$(COP)
    	@echo PRJ=$(PRJ)
    	@echo PRJ_DST_BIN=$(PRJ_DST_BIN)
    	@echo PRJ_DST_LIB=$(PRJ_DST_LIB)
    	@echo PRJ_SRC_FILES=$(PRJ_SRC_FILES)
    	@echo PRJ_INC_FILES=$(PRJ_INC_FILES)
    	@echo PRJ_OBJ_FILES=$(PRJ_OBJ_FILES)
    	@echo PRJ_BIN_OBJ_FILES=$(PRJ_BIN_OBJ_FILES)
    	@echo PRJ_LIB_OBJ_FILES=$(PRJ_LIB_OBJ_FILES)
    	@echo Goals make can process for $(PROJECT):
    	@echo $(TAB_CHAR) all $(ALL_GOALS)
    
    all:
    	cd ../ && $(MAKE) build
    	cd ../ && $(MAKE) debug
    	cd ../ && $(MAKE) profile
    
    rebuildall: clean all
    
    rebuild: clean build
    
    clean:
    	rm -f *.AppImage *.exe *.so *.dll *.o *.obj
    
    run: $(PRJ_TARGETS)
    	$(DBG_APP) $(PFL_APP) ./$(PRJ_DST_BIN)
    	
    debug: $(PRJ_TARGETS)
    
    profile: $(PRJ_TARGETS)
    
    gede: debug
    	gede --args ./$(PRJ_DST_BIN)
    
    build: $(PRJ_TARGETS)
    
    objects: $(PRJ_DST_OBJ)
    
    $(PRJ_BIN_DIR)/%$(PRJ_SFX).AppImage: libalu$(PRJ_SFX).so $(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).o)
    	$(call COMPILE_EXE,,$@,$(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).o))
    
    $(PRJ_BIN_DIR)/%$(PRJ_SFX).16.exe: alu$(PRJ_SFX).16.dll $(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).16.obj)
    	$(call COMPILE_EXE,,$@,$(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).16.obj))
    
    $(PRJ_BIN_DIR)/%$(PRJ_SFX).32.exe: alu$(PRJ_SFX).32.dll $(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).32.obj)
    	$(call COMPILE_EXE,,$@,$(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).32.obj))
    
    $(PRJ_BIN_DIR)/%$(PRJ_SFX).64.exe: alu$(PRJ_SFX).64.dll $(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).64.obj)
    	$(call COMPILE_EXE,,$@,$(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).64.obj))
    	
    $(PRJ_LIB_DIR)/lib%$(PRJ_SFX).so: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).o)
    	$(call COMPILE_DLL,,$@,$^)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).16.dll: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).16.obj)
    	$(call COMPILE_DLL,,$@,$^)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).32.dll: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).32.obj)
    	$(call COMPILE_DLL,,$@,$^)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).64.dll: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).64.obj)
    	$(call COMPILE_DLL,,$@,$^)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).o: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).16.obj: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).32.obj: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).64.obj: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    	
    $(PRJ_SRC_DIR)/%.c: $(PRJ_INC_FILES)
    
    $(TOP_DIR)mak/%.mak.o:
    	@echo Why '$<'?
    
    .PHONY: all $(ALL_GOALS)
    
    .FORCE:

  10. #70
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    Quote Originally Posted by awsdert View Post
    Encountered an issue when trying to align ALU with the directory setup the check tutorial is centered around, I made all the changes I can think to the makefiles but make still has a problem finding the needed files & targets, mind taking a look for me?
    Code:
    TOP_DIR:=../
    include $(TOP_DIR)mak/func.mak
    include $(TOP_DIR)mak/dst_sys.mak
    include $(TOP_DIR)mak/dst_cc.mak
    
    PRJ:=ALU
    PRJ_SFX:=$(DBG_SFX)$(PFL_SFX)
    ALL_GOALS:=info objects build run debug gede clean rebuild rebuildall profile
    
    PRJ_CHK_DIR:=$(TOP_DIR)tests
    PRJ_SRC_DIR:=$(TOP_DIR)src
    PRJ_INC_DIR:=$(TOP_DIR)include
    PRJ_LIB_DIR:=$(TOP_DIR)lib
    PRJ_BIN_DIR:=$(TOP_DIR)bin
    PRJ_EXT_DIR:=$(TOP_DIR)cloned
    
    UNIC_DIR:=$(PRJ_EXT_DIR)/unic
    UNIC_INC_DIR:=$(UNIC_DIR)/include
    
    RPATH_FLAG=-Wl,-rpath=$(PRJ_LIB_DIR)
    
    PRJ_CHK_FILES:=$(wildcard $(PRJ_CHK_DIR)*.c)
    PRJ_SRC_FILES:=$(PRJ_CHK_FILES) $(wildcard $(PRJ_SRC_DIR)*.c)
    PRJ_INC_FILES:=$(wildcard $(PRJ_INC_DIR)*.h)
    PRJ_OBJ_FILES:=$(PRJ_SRC_FILES:%.c=%)
    
    PRJ_CHK_OBJ_FILES:=$(PRJ_CHK_DIR)check_alu
    PRJ_BIN_OBJ_FILES:=$(PRJ_CHK_DIR)test
    PRJ_APP_OBJ_FILES:=$(PRJ_CHK_OBJ_FILES) $(PRJ_BIN_OBJ_FILES)
    PRJ_LIB_OBJ_FILES:=$(filter-out $(PRJ_APP_OBJ_FILES),$(PRJ_OBJ_FILES))
    
    PRJ_DST_CHK:=$(PRJ_BIN_DIR)/check_alu$(PRJ_SFX)$(DST_BIN_SFX)
    PRJ_DST_BIN:=$(PRJ_BIN_DIR)/alu$(PRJ_SFX)$(DST_BIN_SFX)
    PRJ_DST_LIB:=$(PRJ_LIB_DIR)/$(DST_LIB_PFX)alu$(PRJ_SFX)$(DST_LIB_SFX)
    PRJ_DST_OBJ:=$(PRJ_OBJ_FILES:%=%$(PRJ_SFX)$(DST_OBJ_SFX))
    PRJ_TARGETS:=$(PRJ_DST_OBJ) $(PRJ_DST_LIB) $(PRJ_DST_BIN)
    
    ERR_FLAGS:=$(COP)Wall $(COP)Wextra $(F_pedantic)
    INC_FLAGS:=-I $(UNIC_INC_DIR) -I $(PRJ_INC_DIR)
    SRC_FLAGS:=$(DBG_FLAGS) $(PFL_FLAGS) -fPIC $(ERR_FLAGS) $(INC_FLAGS)
    LIB_FLAGS:=$(DBG_FLAGS) $(PFL_FLAGS) -fPIC -shared
    BIN_FLAGS:=$(DBG_FLAGS) $(PFL_FLAGS) -fPIE $(COP)L .
    
    COMPILE_EXE=$(CC) $(BIN_FLAGS) $1 $(COP)o $2 $3 $(RPATH_FLAG) $(COP)l alu$(PRJ_SFX)
    COMPILE_DLL=$(CC) $(LIB_FLAGS) $1 $(COP)o $2 $3 $(RPATH_FLAG)
    COMPILE_OBJ=$(CC) $(SRC_FLAGS) $1 $(COP)o $2 -c $3
    
    $(info PRJ_SRC_FILES = '$(PRJ_SRC_FILES)')
    
    $(call mkdir,$(PRJ_EXT_DIR))
    $(call github_clone,$(UNIC_DIR),$(PRJ_EXT_DIR),awsdert/unic)
    
    $(info Checking 3rd Party libraries are upto date)
    $(info $(call merge,$(UNIC_DIR)))
    $(info Finished checking)
    
    $(info PRJ_DST_BIN=$(PRJ_DST_BIN))
    $(info PRJ_DST_LIB=$(PRJ_DST_LIB))
    
    info: .FORCE
    	@echo CC=$(CC)
    	@echo CXX=$(CXX)
    	@echo COP=$(COP)
    	@echo PRJ=$(PRJ)
    	@echo PRJ_DST_BIN=$(PRJ_DST_BIN)
    	@echo PRJ_DST_LIB=$(PRJ_DST_LIB)
    	@echo PRJ_SRC_FILES=$(PRJ_SRC_FILES)
    	@echo PRJ_INC_FILES=$(PRJ_INC_FILES)
    	@echo PRJ_OBJ_FILES=$(PRJ_OBJ_FILES)
    	@echo PRJ_BIN_OBJ_FILES=$(PRJ_BIN_OBJ_FILES)
    	@echo PRJ_LIB_OBJ_FILES=$(PRJ_LIB_OBJ_FILES)
    	@echo Goals make can process for $(PROJECT):
    	@echo $(TAB_CHAR) all $(ALL_GOALS)
    
    all:
    	cd ../ && $(MAKE) build
    	cd ../ && $(MAKE) debug
    	cd ../ && $(MAKE) profile
    
    rebuildall: clean all
    
    rebuild: clean build
    
    clean:
    	rm -f *.AppImage *.exe *.so *.dll *.o *.obj
    
    run: $(PRJ_TARGETS)
    	$(DBG_APP) $(PFL_APP) ./$(PRJ_DST_BIN)
    	
    debug: $(PRJ_TARGETS)
    
    profile: $(PRJ_TARGETS)
    
    gede: debug
    	gede --args ./$(PRJ_DST_BIN)
    
    build: $(PRJ_TARGETS)
    
    objects: $(PRJ_DST_OBJ)
    
    $(PRJ_BIN_DIR)/%$(PRJ_SFX).AppImage: libalu$(PRJ_SFX).so $(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).o)
    	$(call COMPILE_EXE,,$@,$(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).o))
    
    $(PRJ_BIN_DIR)/%$(PRJ_SFX).16.exe: alu$(PRJ_SFX).16.dll $(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).16.obj)
    	$(call COMPILE_EXE,,$@,$(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).16.obj))
    
    $(PRJ_BIN_DIR)/%$(PRJ_SFX).32.exe: alu$(PRJ_SFX).32.dll $(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).32.obj)
    	$(call COMPILE_EXE,,$@,$(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).32.obj))
    
    $(PRJ_BIN_DIR)/%$(PRJ_SFX).64.exe: alu$(PRJ_SFX).64.dll $(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).64.obj)
    	$(call COMPILE_EXE,,$@,$(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).64.obj))
    	
    $(PRJ_LIB_DIR)/lib%$(PRJ_SFX).so: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).o)
    	$(call COMPILE_DLL,,$@,$^)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).16.dll: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).16.obj)
    	$(call COMPILE_DLL,,$@,$^)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).32.dll: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).32.obj)
    	$(call COMPILE_DLL,,$@,$^)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).64.dll: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).64.obj)
    	$(call COMPILE_DLL,,$@,$^)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).o: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).16.obj: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).32.obj: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    
    $(PRJ_LIB_DIR)/%$(PRJ_SFX).64.obj: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    	
    $(PRJ_SRC_DIR)/%.c: $(PRJ_INC_FILES)
    
    $(TOP_DIR)mak/%.mak.o:
    	@echo Why '$<'?
    
    .PHONY: all $(ALL_GOALS)
    
    .FORCE:
    Never mind, found the reason, forgot to add / after the directory macros

  11. #71
    Registered User
    Join Date
    Sep 2020
    Posts
    138
    If you are serious about performance optimisation you should start timing code.

    I've got evidence that you can speed alu_bit_set_bit by at least 4x::

    Code:
    alu_bit_set_bit() took 4.203500 nanoseconds per iteration
    alu_bit_set_bit_b() took 0.964200 nanoseconds per iteration
    Test passed

    Code:
    struct alu_bit alu_bit_inc( struct alu_bit pos )
    {
            uintptr_t ptr = (uintptr_t)(pos.ptr);
    
    
            pos.bit++;
            pos.mask <<= 1;
            pos.pos = SET2IF( pos.mask, pos.pos + 1, 0 );
            pos.seg = SET2IF( pos.mask, pos.seg, pos.seg + 1 );
            pos.ptr = (size_t*)SET2IF( pos.mask, ptr, ptr + sizeof(size_t) );
            pos.mask = SET2IF( pos.mask, pos.mask, SIZE_T_C(1) );
            return pos;
    }
    
    
    void alu_bit_inc_b( struct alu_bit *pos )
    {
       if(pos == NULL)
         return;
    
       pos->bit++;
       pos->mask <<= 1;
    
       if(pos->mask != 0)
         return;
    
       pos->mask = 1;
       pos->pos  = 0;
       pos->seg++;
       pos->ptr++;
    }
    PS: I can no longer get the project to build without hacking it a little, just to headers.
    Last edited by hamster_nz; 09-20-2020 at 04:54 AM.

  12. #72
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    Quote Originally Posted by hamster_nz View Post
    If you are serious about performance optimisation you should start timing code.

    I've got evidence that you can speed alu_bit_set_bit by at least 4x::

    Code:
    alu_bit_set_bit() took 4.203500 nanoseconds per iteration
    alu_bit_set_bit_b() took 0.964200 nanoseconds per iteration
    Test passed

    Code:
    struct alu_bit alu_bit_inc( struct alu_bit pos )
    {
            uintptr_t ptr = (uintptr_t)(pos.ptr);
    
    
            pos.bit++;
            pos.mask <<= 1;
            pos.pos = SET2IF( pos.mask, pos.pos + 1, 0 );
            pos.seg = SET2IF( pos.mask, pos.seg, pos.seg + 1 );
            pos.ptr = (size_t*)SET2IF( pos.mask, ptr, ptr + sizeof(size_t) );
            pos.mask = SET2IF( pos.mask, pos.mask, SIZE_T_C(1) );
            return pos;
    }
    
    
    void alu_bit_inc_b( struct alu_bit *pos )
    {
       if(pos == NULL)
         return;
    
       pos->bit++;
       pos->mask <<= 1;
    
       if(pos->mask != 0)
         return;
    
       pos->mask = 1;
       pos->pos  = 0;
       pos->seg++;
       pos->ptr++;
    }
    PS: I can no longer get the project to build without hacking it a little, just to headers.
    1st to that PS of yours, that was likely because I was making a bunch of changes to the 3rd party library I'm utilizing for it (what was named fbstdc is now named unic with all macros prepended with UNIC_ and then original macros are checked for and defined in an #ifdef block down bottom of headers), I finished with the bulk of those changes and it mostly compiles fine now, just having linkage issues due to the re-arrange of files to follow what the tutorial for check expects, haven't gotten round to finishing that tutorial yet because of the linkage issues.

    2nd Thank you for finding a speed improvement, After taking a break I'll implement that while hoping you or someone else can figure out why ALU is now having linkage issues since I'm not seeing it right now.

    Code:
    make rebuild
    cd ../ && make --no-print-directory rebuild
    #MAKECMDGOALS=rebuild
    cd mak && make -j 1 --no-print-directory -f main.mak rebuild
    PRJ_SRC_FILES = '../tests/check_alu.c ../tests/test_alu.c ../src/alu_bit.c ../src/alu_fpn.c ../src/alu_int.c ../src/alu_main.c ../src/alu_math.c ../src/alu_mem.c ../src/alu_uint.c ../src/alu_vec.c'
    PRJ_BIN_OBJ_FILES = '../tests/test'
    PRJ_LIB_OBJ_FILES = '../tests/test_alu ../src/alu_bit ../src/alu_fpn ../src/alu_int ../src/alu_main ../src/alu_math ../src/alu_mem ../src/alu_uint ../src/alu_vec'
    Checking 3rd Party libraries are upto date
    cd '../cloned/unic' && git config pull.rebase false && git pull
    Finished checking
    PRJ_DST_BIN=../bin/test_alu.AppImage
    PRJ_DST_LIB=../lib/libalu.so
    rm -f ../bin/*.AppImage ../bin/*.exe
    rm -f ../lib/*.so ../lib/*.dll
    rm -f ../src/*.o ../src/*.obj
    rm -f ../tests/*.o ../tests/*.obj
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../tests/check_alu.o -c ../tests/check_alu.c
    In file included from ../tests/check_alu.c:1:
    ../tests/check_alu.c:3:13: warning: ‘check_alu’ defined but not used [-Wunused-variable]
        3 | START_TEST( check_alu )
          |             ^~~~~~~~~
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../tests/test_alu.o -c ../tests/test_alu.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_bit.o -c ../src/alu_bit.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_fpn.o -c ../src/alu_fpn.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_int.o -c ../src/alu_int.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_main.o -c ../src/alu_main.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_math.o -c ../src/alu_math.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_mem.o -c ../src/alu_mem.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_uint.o -c ../src/alu_uint.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_vec.o -c ../src/alu_vec.c
    cc -D NDEBUG  -fPIC -shared  -o ../lib/libalu.so ../tests/test_alu.o ../src/alu_bit.o ../src/alu_fpn.o ../src/alu_int.o ../src/alu_main.o ../src/alu_math.o ../src/alu_mem.o ../src/alu_uint.o ../src/alu_vec.o -Wl,-rpath=../lib
    make[2]: *** No rule to make target '../bin/test_alu.AppImage', needed by 'build'.  Stop.
    make[1]: *** [makefile:10: rebuild] Error 2
    make: *** [makefile:4: rebuild] Error 2
    Compilation failed.
    main.mak:
    Code:
    TOP_DIR:=../
    PRJ_MAK_DIR:=$(TOP_DIR)mak
    PRJ_CHK_DIR:=$(TOP_DIR)tests
    PRJ_SRC_DIR:=$(TOP_DIR)src
    PRJ_INC_DIR:=$(TOP_DIR)include
    PRJ_LIB_DIR:=$(TOP_DIR)lib
    PRJ_BIN_DIR:=$(TOP_DIR)bin
    PRJ_EXT_DIR:=$(TOP_DIR)cloned
    
    include $(PRJ_MAK_DIR)/func.mak
    include $(PRJ_MAK_DIR)/dst_sys.mak
    include $(PRJ_MAK_DIR)/dst_cc.mak
    
    PRJ:=ALU
    PRJ_SFX:=$(DBG_SFX)$(PFL_SFX)
    ALL_GOALS:=info objects build run debug gede clean rebuild rebuildall profile
    
    UNIC_DIR:=$(PRJ_EXT_DIR)/unic
    UNIC_INC_DIR:=$(UNIC_DIR)/include
    
    RPATH_FLAG=-Wl,-rpath=$(PRJ_LIB_DIR)
    
    PRJ_CHK_FILES:=$(wildcard $(PRJ_CHK_DIR)/*.c)
    PRJ_SRC_FILES:=$(PRJ_CHK_FILES) $(wildcard $(PRJ_SRC_DIR)/*.c)
    PRJ_INC_FILES:=$(wildcard $(PRJ_INC_DIR)/*.h)
    PRJ_OBJ_FILES:=$(PRJ_SRC_FILES:%.c=%)
    
    PRJ_CHK_OBJ_FILES:=$(PRJ_CHK_DIR)/check_alu
    PRJ_BIN_OBJ_FILES:=$(PRJ_CHK_DIR)/test
    PRJ_APP_OBJ_FILES:=$(PRJ_CHK_OBJ_FILES) $(PRJ_BIN_OBJ_FILES)
    PRJ_LIB_OBJ_FILES:=$(filter-out $(PRJ_APP_OBJ_FILES),$(PRJ_OBJ_FILES))
    
    PRJ_DST_CHK:=$(PRJ_BIN_DIR)/check_alu$(PRJ_SFX)$(DST_BIN_SFX)
    PRJ_DST_BIN:=$(PRJ_BIN_DIR)/test_alu$(PRJ_SFX)$(DST_BIN_SFX)
    PRJ_DST_LIB:=$(PRJ_LIB_DIR)/$(DST_LIB_PFX)alu$(PRJ_SFX)$(DST_LIB_SFX)
    PRJ_DST_OBJ:=$(PRJ_OBJ_FILES:%=%$(PRJ_SFX)$(DST_OBJ_SFX))
    PRJ_TARGETS:=$(PRJ_DST_OBJ) $(PRJ_DST_LIB) $(PRJ_DST_BIN)
    
    ERR_FLAGS:=$(COP)Wall $(COP)Wextra $(F_pedantic)
    INC_FLAGS:=-I $(UNIC_INC_DIR) -I $(PRJ_INC_DIR)
    SRC_FLAGS:=$(DBG_FLAGS) $(PFL_FLAGS) -fPIC $(ERR_FLAGS) $(INC_FLAGS)
    LIB_FLAGS:=$(DBG_FLAGS) $(PFL_FLAGS) -fPIC -shared
    BIN_FLAGS:=$(DBG_FLAGS) $(PFL_FLAGS) -fPIE $(COP)L .
    
    COMPILE_EXE=$(CC) $(BIN_FLAGS) $1 $(COP)o $2 $3 $(RPATH_FLAG) $(COP)l alu$(PRJ_SFX)
    COMPILE_DLL=$(CC) $(LIB_FLAGS) $1 $(COP)o $2 $3 $(RPATH_FLAG)
    COMPILE_OBJ=$(CC) $(SRC_FLAGS) $1 $(COP)o $2 -c $3
    
    $(info PRJ_SRC_FILES = '$(PRJ_SRC_FILES)')
    $(info PRJ_BIN_OBJ_FILES = '$(PRJ_BIN_OBJ_FILES)')
    $(info PRJ_LIB_OBJ_FILES = '$(PRJ_LIB_OBJ_FILES)')
    
    $(call mkdir,$(PRJ_EXT_DIR))
    $(call github_clone,$(UNIC_DIR),$(PRJ_EXT_DIR),awsdert/unic)
    
    $(info Checking 3rd Party libraries are upto date)
    $(info $(call merge,$(UNIC_DIR)))
    $(info Finished checking)
    
    $(info PRJ_DST_BIN=$(PRJ_DST_BIN))
    $(info PRJ_DST_LIB=$(PRJ_DST_LIB))
    
    info: .FORCE
    	@echo CC=$(CC)
    	@echo CXX=$(CXX)
    	@echo COP=$(COP)
    	@echo PRJ=$(PRJ)
    	@echo PRJ_DST_BIN=$(PRJ_DST_BIN)
    	@echo PRJ_DST_LIB=$(PRJ_DST_LIB)
    	@echo PRJ_SRC_FILES=$(PRJ_SRC_FILES)
    	@echo PRJ_INC_FILES=$(PRJ_INC_FILES)
    	@echo PRJ_OBJ_FILES=$(PRJ_OBJ_FILES)
    	@echo PRJ_BIN_OBJ_FILES=$(PRJ_BIN_OBJ_FILES)
    	@echo PRJ_LIB_OBJ_FILES=$(PRJ_LIB_OBJ_FILES)
    	@echo Goals make can process for $(PROJECT):
    	@echo $(TAB_CHAR) all $(ALL_GOALS)
    
    all:
    	cd ../ && $(MAKE) build
    	cd ../ && $(MAKE) debug
    	cd ../ && $(MAKE) profile
    
    rebuildall: clean all
    
    rebuild: clean build
    
    clean:
    	rm -f $(PRJ_BIN_DIR)/*.AppImage $(PRJ_BIN_DIR)/*.exe
    	rm -f $(PRJ_LIB_DIR)/*.so $(PRJ_LIB_DIR)/*.dll
    	rm -f $(PRJ_SRC_DIR)/*.o $(PRJ_SRC_DIR)/*.obj
    	rm -f $(PRJ_CHK_DIR)/*.o $(PRJ_CHK_DIR)/*.obj
    
    run: $(PRJ_TARGETS)
    	$(DBG_APP) $(PFL_APP) ./$(PRJ_DST_BIN)
    	
    debug: $(PRJ_TARGETS)
    
    profile: $(PRJ_TARGETS)
    
    gede: debug
    	gede --args ./$(PRJ_DST_BIN)
    
    build: $(PRJ_TARGETS)
    
    objects: $(PRJ_DST_OBJ)
    
    %.AppImage: libalu$(PRJ_SFX).so %.o
    	$(call COMPILE_EXE,,$@,$(PRJ_BIN_OBJ_FILES:%=%$(PRJ_SFX).o))
    
    %.exe: alu$(PRJ_SFX).dll %.obj
    	$(call COMPILE_EXE,,$@,$%.obj))
    
    %.32.exe: alu$(PRJ_SFX).32.dll %.32.obj
    	$(call COMPILE_EXE,,$@,$%.32.obj))
    
    %.64.exe: alu$(PRJ_SFX).64.dll %.64.obj
    	$(call COMPILE_EXE,,$@,$%.64.obj))
    	
    lib%.so: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).o)
    	$(call COMPILE_DLL,,$@,$^)
    
    %.dll: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).obj)
    	$(call COMPILE_DLL,,$@,$^)
    
    %.32.dll: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).32.obj)
    	$(call COMPILE_DLL,,$@,$^)
    
    %.64.dll: $(PRJ_LIB_OBJ_FILES:%=%$(PRJ_SFX).64.obj)
    	$(call COMPILE_DLL,,$@,$^)
    
    %$(PRJ_SFX).o: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    
    %$(PRJ_SFX).obj: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    
    %$(PRJ_SFX).32.obj: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    
    %$(PRJ_SFX).64.obj: %.c
    	$(call COMPILE_OBJ,,$@,$<)
    	
    %.c: $(PRJ_INC_FILES)
    
    $(PRJ_MAK_DIR)/%.mak.o:
    	@echo Why '$<'?
    
    .PHONY: all $(ALL_GOALS)
    
    .FORCE:
    All the changes I've made are uploaded so you can go ahead and look at the new arrangement of files, perhaps you'll see what I haven't

  13. #73
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    Figured it out, I missed the directory path for the executable object dependency, hitting a different issue now:
    Code:
    make rebuild
    cd ../ && make --no-print-directory rebuild
    #MAKECMDGOALS=rebuild
    cd mak && make -j 1 --no-print-directory -f main.mak rebuild
    PRJ_LIB_NAME=alu
    PRJ_SRC_FILES = '../tests/check_alu.c ../tests/test_alu.c ../src/alu_bit.c ../src/alu_fpn.c ../src/alu_int.c ../src/alu_main.c ../src/alu_math.c ../src/alu_mem.c ../src/alu_uint.c ../src/alu_vec.c'
    PRJ_BIN_OBJ_FILES = '../tests/test_alu'
    PRJ_LIB_OBJ_FILES = '../src/alu_bit ../src/alu_fpn ../src/alu_int ../src/alu_main ../src/alu_math ../src/alu_mem ../src/alu_uint ../src/alu_vec'
    Checking 3rd Party libraries are upto date
    cd '../cloned/unic' && git config pull.rebase false && git pull
    Finished checking
    PRJ_DST_BIN=test_alu.AppImage
    PRJ_DST_LIB=libalu.so
    rm -f ../bin/*.AppImage ../bin/*.exe
    rm -f ../lib/*.so ../lib/*.dll
    rm -f ../src/*.o ../src/*.obj
    rm -f ../tests/*.o ../tests/*.obj
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_bit.o -c ../src/alu_bit.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_fpn.o -c ../src/alu_fpn.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_int.o -c ../src/alu_int.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_main.o -c ../src/alu_main.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_math.o -c ../src/alu_math.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_mem.o -c ../src/alu_mem.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_uint.o -c ../src/alu_uint.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../src/alu_vec.o -c ../src/alu_vec.c
    cc -D NDEBUG  -fPIC -Wall -Wextra -pedantic -I ../cloned/unic/include -I ../include  -o ../tests/test_alu.o -c ../tests/test_alu.c
    cc -D NDEBUG  -fPIC -shared  -o ../lib/libalu.so ../src/alu_bit.o ../src/alu_fpn.o ../src/alu_int.o ../src/alu_main.o ../src/alu_math.o ../src/alu_mem.o ../src/alu_uint.o ../src/alu_vec.o -Wl,-rpath=../lib
    cc -D NDEBUG  -fPIE -L ../lib  -o ../bin/test_alu.AppImage ../tests/test_alu.o -Wl,-rpath=../lib -l alu
    /usr/bin/ld: cannot open output file ../bin/test_alu.AppImage: No such file or directory
    collect2: error: ld returned 1 exit status
    make[2]: *** [main.mak:114: test_alu.AppImage] Error 1
    make[1]: *** [makefile:10: rebuild] Error 2
    make: *** [makefile:4: rebuild] Error 2
    Compilation failed.
    Gotta go AFK for a while so won't be responding for about 30min to an hour

  14. #74
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    I see no-one's thought of any suggestions as yet, well since I'm out of ideas myself I'll just quit for the night and try again tomorrow, with any luck there'll be at least one suggestion by that time.

  15. #75
    Registered User
    Join Date
    Sep 2020
    Posts
    138
    Quote Originally Posted by awsdert View Post
    I see no-one's thought of any suggestions as yet, well since I'm out of ideas myself I'll just quit for the night and try again tomorrow, with any luck there'll be at least one suggestion by that time.
    Maybe "mkdir lib" and "mkdir bin" will help - when I cloned the repo there was no lib or bin directory.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can anyone help to spot mistake in the code
    By chess_queen in forum C Programming
    Replies: 1
    Last Post: 10-21-2012, 10:37 AM
  2. Can you spot my mistake?
    By Brewer in forum C Programming
    Replies: 13
    Last Post: 11-12-2006, 12:50 PM
  3. going to a certain spot in a file...
    By agerealm in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2002, 02:31 AM

Tags for this Thread